templates.schema.json 25 KB
Newer Older
Diegodlh's avatar
Diegodlh committed
1
2
3
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://gitlab.wikimedia.org/diegodlh/w2c-core/-/blob/main/templates.schema.json",
Diegodlh's avatar
Diegodlh committed
4
  "title": "Domain translation templates configuration for Web2Cit",
5
  "description": "Each translation template defines translation procedures to extract relevant metadata from a specific template webpage (see https://meta.wikimedia.org/wiki/Web2Cit/Early_adopters#templates.json)",
Diegodlh's avatar
Diegodlh committed
6
7
  "type": "array",
  "items": {
8
    "title": "Translation template",
Diegodlh's avatar
Diegodlh committed
9
10
11
    "type": "object",
    "properties": {
      "path": {
12
        "title": "Path",
13
14
        "description": "Path of the webpage used as translation template",
        "options": { "infoText": "Do not include the hostname; just the path beginning with \"/\". You may also include query (?) and fragment (#) components. Duplicate translation templates for the same path will be ignored." },
Diegodlh's avatar
Diegodlh committed
15
16
17
        "type": "string"
      },
      "label": {
18
        "title": "Label",
Diegodlh's avatar
Diegodlh committed
19
20
21
22
        "description": "Fancy name for this translation template",
        "type": "string"
      },
      "fields": {
23
        "title": "Fields",
24
        "description": "Each template field defines translation procedures to extract metadata belonging to a specific citation field (see https://meta.wikimedia.org/wiki/Web2Cit/Early_adopters#Translation_field_types)",
Diegodlh's avatar
Diegodlh committed
25
        "options": { "infoText": "Mandatory fields \"itemType\" and \"title\" must be included, or template will be ignored. Duplicate template fields with the same field name will be ignored." },
Diegodlh's avatar
Diegodlh committed
26
27
        "type": "array",
        "items": {
28
          "title": "Template field",
Diegodlh's avatar
Diegodlh committed
29
          "oneOf": [
Diegodlh's avatar
Diegodlh committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
            {
              "title": "Item type field (mandatory)",
              "description": "Type of the cited resource | Valid output: one of the Citoid/Zotero supported types (see https://aurimasv.github.io/z2csl/typeMap.xml)",
              "type": "object",
              "properties": {
                "fieldname": {
                  "title": "Field name",
                  "type": "string",
                  "enum": ["itemType"],
                  "options": { "hidden": true }
                },
                "required": {
                  "$ref": "#/definitions/required"
                },
                "procedures": {
                  "$ref": "#/definitions/procedures"
                }
              },
              "required": [
                "fieldname",
                "required",
                "procedures"
              ]
            },
            {
              "title": "Title field (mandatory)",
              "description": "Title of the cited resource | Valid output: a single non-empty string",
              "type": "object",
              "properties": {
                "fieldname": {
                  "title": "Field name",
                  "type": "string",
                  "enum": ["title"],
                  "options": { "hidden": true }
                },
                "required": {
                  "$ref": "#/definitions/required"
                },
                "procedures": {
                  "$ref": "#/definitions/procedures"
                }
              },
              "required": [
                "fieldname",
                "required",
                "procedures"
              ]
            },
            {
              "title": "Author last names field",
              "description": "Authors' last or full names | Valid output: one or more non-empty strings",
              "type": "object",
              "properties": {
                "fieldname": {
                  "title": "Field name",
                  "type": "string",
                  "enum": ["authorLast"],
                  "options": { "hidden": true }
                },
                "required": {
                  "$ref": "#/definitions/required"
                },
                "procedures": {
                  "$ref": "#/definitions/procedures"
                }
              },
              "required": [
                "fieldname",
                "required",
                "procedures"
              ]
            },
            {
              "title": "Author first names field",
              "description": "Authors' first names | Valid output: one or more empty or non-empty strings",
              "type": "object",
              "properties": {
                "fieldname": {
                  "title": "Field name",
                  "type": "string",
                  "enum": ["authorFirst"],
                  "options": { "hidden": true }
                },
                "required": {
                  "$ref": "#/definitions/required"
                },
                "procedures": {
                  "$ref": "#/definitions/procedures"
                }
              },
              "required": [
                "fieldname",
                "required",
                "procedures"
              ]
            },
            {
              "title": "Date field",
              "description": "Publishing date | Valid output: a single yyyy-mm-dd, yyyy-mm or yyyy value",
              "type": "object",
              "properties": {
                "fieldname": {
                  "title": "Field name",
                  "type": "string",
                  "enum": ["date"],
                  "options": { "hidden": true }
                },
                "required": {
                  "$ref": "#/definitions/required"
                },
                "procedures": {
                  "$ref": "#/definitions/procedures"
                }
              },
              "required": [
                "fieldname",
                "required",
                "procedures"
              ]
            },
            {
              "title": "Published in field",
              "description": "Work containing the cited resource | Valid output: a single non-empty string",
              "type": "object",
              "properties": {
                "fieldname": {
                  "title": "Field name",
                  "type": "string",
                  "enum": ["publishedIn"],
                  "options": { "hidden": true }
                },
                "required": {
                  "$ref": "#/definitions/required"
                },
                "procedures": {
                  "$ref": "#/definitions/procedures"
                }
              },
              "required": [
                "fieldname",
                "required",
                "procedures"
              ]
            },
            {
              "title": "Published by field",
              "description": "Publisher of the cited resource | Valid output: a single non-empty string",
              "type": "object",
              "properties": {
                "fieldname": {
                  "title": "Field name",
                  "type": "string",
                  "enum": ["publishedBy"],
                  "options": { "hidden": true }
                },
                "required": {
                  "$ref": "#/definitions/required"
                },
                "procedures": {
                  "$ref": "#/definitions/procedures"
                }
              },
              "required": [
                "fieldname",
                "required",
                "procedures"
              ]
            },
            {
              "title": "Language field",
              "description": "Publishing language | Valid output: a single xx or xx-xx* language code",
              "type": "object",
              "properties": {
                "fieldname": {
                  "title": "Field name",
                  "type": "string",
                  "enum": ["language"],
                  "options": { "hidden": true }
                },
                "required": {
                  "$ref": "#/definitions/required"
                },
                "procedures": {
                  "$ref": "#/definitions/procedures"
                }
              },
              "required": [
                "fieldname",
                "required",
                "procedures"
              ]
            },
            {
              "title": "Control field",
              "description": "Template applicability control | Valid output: a single non-empty string",
              "type": "object",
              "properties": {
                "fieldname": {
                  "title": "Field name",
                  "type": "string",
                  "enum": ["control"],
                  "options": { "hidden": true }
                },
                "required": {
                  "$ref": "#/definitions/required"
                },
                "procedures": {
                  "$ref": "#/definitions/procedures"
                }
              },
              "required": [
                "fieldname",
                "required",
                "procedures"
              ]
            }
246
          ]
Diegodlh's avatar
Diegodlh committed
247
        }
Diegodlh's avatar
Diegodlh committed
248
      }
Diegodlh's avatar
Diegodlh committed
249
    },
250
251
252
253
    "required": [
      "path",
      "fields"
    ]
254
255
  },
  "definitions": {
Diegodlh's avatar
Diegodlh committed
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
    "required": {
      "Title": "Required",
      "description": "Whether the template field is required or not",
      "options": { "infoText": "Given a target webpage, the output of all required fields must be valid for the template to be applicable. Mandatory fields \"itemType\" and \"title\" are always required." },
      "type": "boolean",
      "default": true
    },
    "procedures": {
      "title": "Procedures",
      "description": "Each translation procedure defines a series of selection and transformation steps to extract and manipulate relevant metadata",
      "type": "array",
      "items": {
        "title": "Translation procedure",
        "type": "object",
        "properties": {
          "selections": {
            "title": "Selection",
            "description": "Selection steps select and extract individual elements from the target webpage (see https://meta.wikimedia.org/wiki/Web2Cit/Early_adopters#Selection_types_and_configs)",
            "options": { "infoText": "The combined output of all selection steps is given as input to the first transformation step below." },
            "default": [],
            "type": "array",
            "items": {
              "title": "Selection step",
              "oneOf": [
                {
                  "title": "Citoid selection",
                  "description": "Selects a field from the Citoid response for the target webpage",
                  "type": "object",
                  "properties": {
                    "type": {
                      "title": "Type",
                      "type": "string",
Diegodlh's avatar
Diegodlh committed
288
289
                      "enum": ["citoid"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
290
291
292
                    },
                    "config": {
                      "title": "Configuration",
293
                      "description": "Any valid Citoid/Zotero base field name; use Wikimedia REST API (\"citation\" endpoint, \"mediawiki-basefields\" format) to check Citoid response for the target webpage: https://en.wikipedia.org/api/rest_v1/#/Citation/getCitation",
Diegodlh's avatar
Diegodlh committed
294
                      "options": { "infoText": "Creator fields (e.g., \"author\") are split into creatorFirst and creatorLast fields." },
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
                      "type": "string",
                      "enum": [
                        "abstractNote",
                        "accessDate",
                        "applicationNumber",
                        "archive",
                        "archiveLocation",
                        "artworkSize",
                        "assignee",
                        "attorneyAgentFirst",
                        "attorneyAgentLast",
                        "authorFirst",
                        "authorLast",
                        "bookAuthorFirst",
                        "bookAuthorLast",
                        "callNumber",
                        "castMemberFirst",
                        "castMemberLast",
                        "code",
                        "codeNumber",
                        "commenterFirst",
                        "commenterLast",
                        "committee",
                        "composerFirst",
                        "composerLast",
                        "conferenceName",
                        "contributorFirst",
                        "contributorLast",
                        "cosponsorFirst",
                        "cosponsorLast",
                        "counselFirst",
                        "counselLast",
                        "country",
                        "court",
                        "date",
                        "DOI",
                        "edition",
                        "editorFirst",
                        "editorLast",
                        "extra",
                        "filingDate",
                        "guestFirst",
                        "guestLast",
                        "history",
                        "interviewerFirst",
                        "interviewerLast",
                        "isbn",
                        "issn",
                        "issue",
                        "issuingAuthority",
                        "itemType",
                        "journalAbbreviation",
                        "language",
                        "legalStatus",
                        "legislativeBody",
                        "libraryCatalog",
                        "medium",
                        "meetingName",
                        "number",
                        "numberOfVolumes",
                        "numPages",
                        "oclc",
                        "pages",
                        "place",
                        "PMCID",
                        "PMID",
                        "priorityNumbers",
                        "producerFirst",
                        "producerLast",
                        "programmingLanguage",
                        "publicationTitle",
                        "publisher",
                        "recipientFirst",
                        "recipientLast",
                        "references",
                        "reporter",
                        "reviewedAuthorFirst",
                        "reviewedAuthorLast",
                        "rights",
                        "runningTime",
                        "scale",
                        "scriptwriterFirst",
                        "scriptwriterLast",
                        "section",
                        "series",
                        "seriesEditorFirst",
                        "seriesEditorLast",
                        "seriesNumber",
                        "seriesText",
                        "seriesTitle",
                        "session",
                        "shortTitle",
                        "system",
                        "tags",
                        "title",
                        "translatorFirst",
                        "translatorLast",
                        "type",
                        "url",
                        "versionNumber",
                        "volume",
                        "wordsByFirst",
                        "wordsByLast"
                      ]
Diegodlh's avatar
Diegodlh committed
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
                    }
                  },
                  "required": [
                    "type",
                    "config"
                  ]
                },
                {
                  "title": "XPath selection",
                  "description": "Selects a node from the target webpage's HTML using XPath",
                  "type": "object",
                  "properties": {
                    "type": {
                      "title": "Type",
                      "type": "string",
Diegodlh's avatar
Diegodlh committed
414
415
                      "enum": ["xpath"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
                    },
                    "config": {
                      "title": "Configuration",
                      "description": "Any valid XPath expression",
                      "options": { "infoText": "Your web browser's inspector (shown with F12 in some browsers) may help you get an XPath expression for an HTML node." },
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "config"
                  ]
                },
                {
                  "title": "Fixed selection",
                  "description": "Always returns the same predefined value",
                  "type": "object",
                  "properties": {
                    "type": {
                      "title": "Type",
                      "type": "string",
Diegodlh's avatar
Diegodlh committed
437
438
                      "enum": ["fixed"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
                    },
                    "config": {
                      "title": "Configuration",
                      "description": "The predefined value to be returned.",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "config"
                  ]
                }
              ]
            }
          },
          "transformations": {
            "title": "Transformation",
            "description": "Transformation steps transform selected elements (if needed) to return the expected output (see https://meta.wikimedia.org/wiki/Web2Cit/Early_adopters#Transformation_types_and_configs)",
            "options": { "infoText": "Transformation steps are applied one after the other, and the output of the last transformation step is the procedure's output." },
            "type": "array",
            "items": {
              "title": "Transformation step",
              "oneOf": [
                {
                  "title": "Join transformation",
                  "description": "Joins two or more items in a list into one, using the separator specified",
                  "type": "object",
                  "properties": {
                    "type": {
                      "title": "Type",
                      "type": "string",
Diegodlh's avatar
Diegodlh committed
470
471
                      "enum": ["join"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
472
473
474
475
476
477
478
479
                    },
                    "config": {
                      "title": "Configuration",
                      "description": "The separator to use.",
                      "type": "string"
                    },
                    "itemwise": {
                      "$ref": "#/definitions/itemwise",
480
                      "options": { "infoText": "default: false (join transformation)" },
Diegodlh's avatar
Diegodlh committed
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
                      "default": false
                    }
                  },
                  "required": [
                    "type",
                    "config",
                    "itemwise"
                  ]
                },
                {
                  "title": "Split transformation",
                  "description": "Splits a string at the separator specified into two or more substrings",
                  "type": "object",
                  "properties": {
                    "type": {
                      "title": "Type",
                      "type": "string",
Diegodlh's avatar
Diegodlh committed
498
499
                      "enum": ["split"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
500
501
502
503
504
505
506
507
                    },
                    "config": {
                      "title": "Configuration",
                      "description": "The separator to use.",
                      "type": "string"
                    },
                    "itemwise": {
                      "$ref": "#/definitions/itemwise",
508
                      "options": { "infoText": "default: true (split transformation)" },
Diegodlh's avatar
Diegodlh committed
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
                      "default": true
                    }
                  },
                  "required": [
                    "type",
                    "config",
                    "itemwise"
                  ]
                },
                {
                  "title": "Date transformation",
                  "description": "Uses the Sugar.js to try and parse natural language dates into the YYYY-MM-DD format",
                  "type": "object",
                  "properties": {
                    "type": {
                      "title": "Type",
                      "type": "string",
Diegodlh's avatar
Diegodlh committed
526
527
                      "enum": ["date"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
                    },
                    "config": {
                      "title": "Configuration",
                      "description": "Any of the currently supported locales",
                      "type": "string",
                      "enum": [
                        "ca",
                        "da",
                        "de",
                        "en",
                        "es",
                        "fi",
                        "fr",
                        "it",
                        "ja",
                        "ko",
                        "nl",
                        "no",
                        "pl",
                        "pt",
                        "ru",
                        "sv",
                        "zh-CN",
                        "zh-TW"
                      ],
                      "options": {
                        "enum_titles": [
                          "Catalan (ca)",
                          "Danish (da)",
                          "German (de)",
                          "English (en)",
                          "Spanish (es)",
                          "Finnish (fi)",
                          "French (fr)",
                          "Italian (it)",
                          "Japanese (ja)",
                          "Korean (ko)",
                          "Dutch (nl)",
                          "Norwegian (no)",
                          "Polish (pl)",
                          "Portuguese (pt)",
                          "Russian (ru)",
                          "Swedish (sv)",
                          "Chinese (zh-CN)",
                          "Chinese (zh-TW)"
                        ]
                      }
                    },
                    "itemwise": {
                      "$ref": "#/definitions/itemwise",
578
                      "options": { "infoText": "default: true (date transformation)" },
Diegodlh's avatar
Diegodlh committed
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
                      "default": true
                    }
                  },
                  "required": [
                    "type",
                    "config",
                    "itemwise"
                  ]
                },
                {
                  "title": "Range transformation",
                  "description": "Returns one or more items or ranges of items in the order specified",
                  "type": "object",
                  "properties": {
                    "type": {
                      "title": "Type",
                      "type": "string",
Diegodlh's avatar
Diegodlh committed
596
597
                      "enum": ["range"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
598
599
600
601
                    },
                    "config": {
                      "title": "Configuration",
                      "description": "One or more comma-separated ranges: \"start(:end)\", \"start:\" or \":end\".",
602
                      "options": { "infoText": "Ranges use one-based numbering, meaning that the first item is item 1" },
Diegodlh's avatar
Diegodlh committed
603
604
605
606
                      "type": "string"
                    },
                    "itemwise": {
                      "$ref": "#/definitions/itemwise",
607
                      "options": { "infoText": "default: false (range transformation)" },
Diegodlh's avatar
Diegodlh committed
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
                      "default": false
                    }
                  },
                  "required": [
                    "type",
                    "config",
                    "itemwise"
                  ]
                },
                {
                  "title": "Match transformation",
                  "description": "Returns one or more substrings matching a target",
                  "type": "object",
                  "properties": {
                    "type": {
                      "title": "Type",
                      "type": "string",
Diegodlh's avatar
Diegodlh committed
625
626
                      "enum": ["match"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
627
628
629
630
631
632
633
634
                    },
                    "config": {
                      "title": "Configuration",
                      "description": "The matching target, expressed as either plain string or /regular expression/ (see https://meta.wikimedia.org/wiki/Web2Cit/Early_adopters#Match_transformation).",
                      "type": "string"
                    },
                    "itemwise": {
                      "$ref": "#/definitions/itemwise",
635
                      "options": { "infoText": "default: true (match transformation)" },
Diegodlh's avatar
Diegodlh committed
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
                      "default": true
                    }
                  },
                  "required": [
                    "type",
                    "config",
                    "itemwise"
                  ]
                }
              ]
            }                      
          }
        },
        "required": [
          "selections",
          "transformations"
        ]
      }
    },
655
656
    "itemwise": {
      "title": "Item-wise",
657
      "description": "Whether transformation should be applied to each item of the input independently (true) or to the entire input as a whole (false).",
658
659
      "type": "boolean"
    }
Diegodlh's avatar
Diegodlh committed
660
  }
661
}