templates.schema.json 16 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
25
        "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)",
        "options": { "infoText": "Mandatory fields \"itemType\" and \"title\" must be included, or template will be ignored." },
Diegodlh's avatar
Diegodlh committed
26
27
        "type": "array",
        "items": {
28
          "title": "Template field",
Diegodlh's avatar
Diegodlh committed
29
30
31
          "type": "object",
          "properties": {
            "fieldname": {
32
              "title": "Field name",
33
34
              "description": "Name of the template field",
              "options": { "infoText": "Duplicate template fields with the same field name will be ignored." },
35
36
37
38
39
40
41
42
43
44
45
46
              "type": "string",
              "enum": [
                "itemType",
                "title",
                "authorFirst",
                "authorLast",
                "date",
                "publishedIn",
                "publishedBy",
                "language",
                "control"
              ]
Diegodlh's avatar
Diegodlh committed
47
48
            },
            "required": {
49
              "Title": "Required",
50
51
              "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." },
52
53
              "type": "boolean",
              "default": true
Diegodlh's avatar
Diegodlh committed
54
55
            },
            "procedures": {
56
              "title": "Procedures",
57
              "description": "Each translation procedure defines a series of selection and transformation steps to extract and manipulate relevant metadata",
Diegodlh's avatar
Diegodlh committed
58
59
              "type": "array",
              "items": {
60
                "title": "Translation procedure",
Diegodlh's avatar
Diegodlh committed
61
62
63
                "type": "object",
                "properties": {
                  "selections": {
64
                    "title": "Selection",
65
66
                    "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." },
67
                    "default": [],
Diegodlh's avatar
Diegodlh committed
68
69
                    "type": "array",
                    "items": {
70
                      "title": "Selection step",
71
72
73
74
75
76
77
78
79
80
81
82
83
                      "oneOf": [
                        { 
                          "title": "Citoid selection",
                          "description": "Selects a field from the Citoid response for the target webpage",
                          "type": "object",
                          "properties": {
                            "type": {
                              "title": "Type",
                              "type": "string",
                              "enum": ["citoid"]
                            },
                            "config": {
                              "title": "Configuration",
84
85
                              "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." },
86
87
88
89
90
91
                              "type": "string"
                            }
                          },
                          "required": [
                            "type",
                            "config"
92
                          ]
Diegodlh's avatar
Diegodlh committed
93
                        },
94
95
96
97
98
99
100
101
102
103
104
105
                        { 
                          "title": "XPath selection",
                          "description": "Selects a node from the target webpage's HTML using XPath",
                          "type": "object",
                          "properties": {
                            "type": {
                              "title": "Type",
                              "type": "string",
                              "enum": ["xpath"]
                            },
                            "config": {
                              "title": "Configuration",
106
107
                              "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." },
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
                              "type": "string"
                            }
                          },
                          "required": [
                            "type",
                            "config"
                          ]
                        },
                        { 
                          "title": "Fixed selection",
                          "description": "Always returns the same predefined value",
                          "type": "object",
                          "properties": {
                            "type": {
                              "title": "Type",
                              "type": "string",
                              "enum": ["fixed"]
                            },
                            "config": {
                              "title": "Configuration",
                              "description": "The predefined value to be returned.",
                              "type": "string"
                            }
                          },
                          "required": [
                            "type",
                            "config"
                          ]
Diegodlh's avatar
Diegodlh committed
136
                        }
137
                      ]
Diegodlh's avatar
Diegodlh committed
138
139
140
                    }
                  },
                  "transformations": {
141
                    "title": "Transformation",
142
143
                    "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." },
Diegodlh's avatar
Diegodlh committed
144
145
                    "type": "array",
                    "items": {
146
                      "title": "Transformation step",
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
                      "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",
                              "enum": ["join"]
                            },
                            "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",
                              "enum": ["split"]
                            },
                            "config": {
                              "title": "Configuration",
                              "description": "The separator to use.",
                              "type": "string"
                            },
                            "itemwise": {
                              "$ref": "#/definitions/itemwise",
                              "default": true
                            }
                          },
                          "required": [
                            "type",
                            "config",
                            "itemwise"
198
                          ]
Diegodlh's avatar
Diegodlh committed
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
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
                        {
                          "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",
                              "enum": ["date"]
                            },
                            "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",
                              "enum": ["range"]
                            },
                            "config": {
                              "title": "Configuration",
280
281
                              "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" },
282
283
284
285
286
287
288
289
290
291
292
293
                              "type": "string"
                            },
                            "itemwise": {
                              "$ref": "#/definitions/itemwise",
                              "default": false
                            }
                          },
                          "required": [
                            "type",
                            "config",
                            "itemwise"
                          ]
Diegodlh's avatar
Diegodlh committed
294
                        },
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
                        {
                          "title": "Match transformation",
                          "description": "Returns one or more substrings matching a target",
                          "type": "object",
                          "properties": {
                            "type": {
                              "title": "Type",
                              "type": "string",
                              "enum": ["match"]
                            },
                            "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"
                          ]
Diegodlh's avatar
Diegodlh committed
320
                        }
321
                      ]
322
                    }                      
Diegodlh's avatar
Diegodlh committed
323
                  }
Diegodlh's avatar
Diegodlh committed
324
                },
325
326
327
328
                "required": [
                  "selections",
                  "transformations"
                ]
Diegodlh's avatar
Diegodlh committed
329
              }
Diegodlh's avatar
Diegodlh committed
330
            }
Diegodlh's avatar
Diegodlh committed
331
          },
332
333
334
335
336
          "required": [
            "fieldname",
            "required",
            "procedures"
          ]
Diegodlh's avatar
Diegodlh committed
337
        }
Diegodlh's avatar
Diegodlh committed
338
      }
Diegodlh's avatar
Diegodlh committed
339
    },
340
341
342
343
    "required": [
      "path",
      "fields"
    ]
344
345
346
347
  },
  "definitions": {
    "itemwise": {
      "title": "Item-wise",
348
349
      "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." },
350
351
      "type": "boolean"
    }
Diegodlh's avatar
Diegodlh committed
352
  }
353
}