templates.schema.json 20.8 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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
                    },
                    "config": {
                      "title": "Configuration",
                      "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.",
                      "options": { "infoText": "Creator fields (e.g., \"author\") are split into creatorFirst and creatorLast fields." },
                      "type": "string"
                    }
                  },
                  "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
311
312
                      "enum": ["xpath"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
                    },
                    "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
334
335
                      "enum": ["fixed"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
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
                    },
                    "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
367
368
                      "enum": ["join"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
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
                    },
                    "config": {
                      "title": "Configuration",
                      "description": "The separator to use.",
                      "type": "string"
                    },
                    "itemwise": {
                      "$ref": "#/definitions/itemwise",
                      "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
394
395
                      "enum": ["split"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
                    },
                    "config": {
                      "title": "Configuration",
                      "description": "The separator to use.",
                      "type": "string"
                    },
                    "itemwise": {
                      "$ref": "#/definitions/itemwise",
                      "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
421
422
                      "enum": ["date"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
                    },
                    "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",
                      "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
490
491
                      "enum": ["range"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
                    },
                    "config": {
                      "title": "Configuration",
                      "description": "One or more comma-separated ranges: \"start(:end)\", \"start:\" or \":end\".",
                      "options": { "infoText": "Ranges are zero-based, meaning that the first item is item 0" },
                      "type": "string"
                    },
                    "itemwise": {
                      "$ref": "#/definitions/itemwise",
                      "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
518
519
                      "enum": ["match"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
                    },
                    "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",
                      "default": true
                    }
                  },
                  "required": [
                    "type",
                    "config",
                    "itemwise"
                  ]
                }
              ]
            }                      
          }
        },
        "required": [
          "selections",
          "transformations"
        ]
      }
    },
547
548
    "itemwise": {
      "title": "Item-wise",
549
550
      "description": "Whether transformation should be applied to each item of the input independently",
      "options": { "infoText": "true: apply transformation to each item of the input independently; false: apply transformation to the entire input as a whole." },
551
552
      "type": "boolean"
    }
Diegodlh's avatar
Diegodlh committed
553
  }
554
}