templates.schema.json 19.6 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": [
30
31
32
33
34
35
36
37
            { "$ref": "#/definitions/itemType" },
            { "$ref": "#/definitions/title"},
            { "$ref": "#/definitions/authorLast"},
            { "$ref": "#/definitions/authorFirst"},
            { "$ref": "#/definitions/date"},
            { "$ref": "#/definitions/publishedIn"},
            { "$ref": "#/definitions/publishedBy"},
            { "$ref": "#/definitions/control"}
38
          ]
Diegodlh's avatar
Diegodlh committed
39
        }
Diegodlh's avatar
Diegodlh committed
40
      }
Diegodlh's avatar
Diegodlh committed
41
    },
42
43
44
45
    "required": [
      "path",
      "fields"
    ]
46
47
  },
  "definitions": {
Diegodlh's avatar
Diegodlh committed
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
    "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
80
81
                      "enum": ["citoid"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
                    },
                    "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
103
104
                      "enum": ["xpath"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
                    },
                    "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
126
127
                      "enum": ["fixed"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
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
                    },
                    "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
159
160
                      "enum": ["join"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
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
                    },
                    "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
186
187
                      "enum": ["split"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
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
                    },
                    "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
213
214
                      "enum": ["date"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
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
246
247
248
249
250
251
252
253
254
255
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
                    },
                    "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
282
283
                      "enum": ["range"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
                    },
                    "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
310
311
                      "enum": ["match"],
                      "options": { "hidden": true }
Diegodlh's avatar
Diegodlh committed
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
                    },
                    "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"
        ]
      }
    },
339
340
    "itemwise": {
      "title": "Item-wise",
341
342
      "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." },
343
      "type": "boolean"
Diegodlh's avatar
Diegodlh committed
344
    },
345
346
347
348
349
350
351
352
353
354
    "itemType": {
      "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 }
Diegodlh's avatar
Diegodlh committed
355
        },
356
357
358
359
360
361
        "required": {
          "$ref": "#/definitions/required"
        },
        "procedures": {
          "$ref": "#/definitions/procedures"
        }
Diegodlh's avatar
Diegodlh committed
362
      },
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
      "required": [
        "fieldname",
        "required",
        "procedures"
      ]
    },
    "title": {
      "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 }
Diegodlh's avatar
Diegodlh committed
379
        },
380
381
382
383
384
385
        "required": {
          "$ref": "#/definitions/required"
        },
        "procedures": {
          "$ref": "#/definitions/procedures"
        }
Diegodlh's avatar
Diegodlh committed
386
      },
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
      "required": [
        "fieldname",
        "required",
        "procedures"
      ]
    },
    "authorLast": {
      "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 }
Diegodlh's avatar
Diegodlh committed
403
        },
404
405
406
407
408
409
        "required": {
          "$ref": "#/definitions/required"
        },
        "procedures": {
          "$ref": "#/definitions/procedures"
        }
Diegodlh's avatar
Diegodlh committed
410
      },
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
      "required": [
        "fieldname",
        "required",
        "procedures"
      ]
    },
    "authorFirst": {
      "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 }
Diegodlh's avatar
Diegodlh committed
427
        },
428
429
430
431
432
433
        "required": {
          "$ref": "#/definitions/required"
        },
        "procedures": {
          "$ref": "#/definitions/procedures"
        }
Diegodlh's avatar
Diegodlh committed
434
      },
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
      "required": [
        "fieldname",
        "required",
        "procedures"
      ]
    },
    "date": {
      "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 }
Diegodlh's avatar
Diegodlh committed
451
        },
452
453
454
455
456
457
        "required": {
          "$ref": "#/definitions/required"
        },
        "procedures": {
          "$ref": "#/definitions/procedures"
        }
Diegodlh's avatar
Diegodlh committed
458
      },
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
      "required": [
        "fieldname",
        "required",
        "procedures"
      ]
    },
    "publishedIn": {
      "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 }
Diegodlh's avatar
Diegodlh committed
475
        },
476
477
478
479
480
481
        "required": {
          "$ref": "#/definitions/required"
        },
        "procedures": {
          "$ref": "#/definitions/procedures"
        }
Diegodlh's avatar
Diegodlh committed
482
      },
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
      "required": [
        "fieldname",
        "required",
        "procedures"
      ]
    },
    "publishedBy": {
      "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 }
Diegodlh's avatar
Diegodlh committed
499
        },
500
501
502
503
504
505
        "required": {
          "$ref": "#/definitions/required"
        },
        "procedures": {
          "$ref": "#/definitions/procedures"
        }
Diegodlh's avatar
Diegodlh committed
506
      },
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
      "required": [
        "fieldname",
        "required",
        "procedures"
      ]
    },
    "language": {
      "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 }
Diegodlh's avatar
Diegodlh committed
523
        },
524
525
526
527
528
529
        "required": {
          "$ref": "#/definitions/required"
        },
        "procedures": {
          "$ref": "#/definitions/procedures"
        }
Diegodlh's avatar
Diegodlh committed
530
      },
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
      "required": [
        "fieldname",
        "required",
        "procedures"
      ]
    },
    "control": {
      "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 }
Diegodlh's avatar
Diegodlh committed
547
        },
548
549
550
551
552
553
554
555
556
557
558
559
        "required": {
          "$ref": "#/definitions/required"
        },
        "procedures": {
          "$ref": "#/definitions/procedures"
        }
      },
      "required": [
        "fieldname",
        "required",
        "procedures"
      ]
560
    }
Diegodlh's avatar
Diegodlh committed
561
  }
562
}