templates.schema.json 15.7 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": "A list of translation templates. See https://meta.wikimedia.org/wiki/Web2Cit/Early_adopters#templates.json",
Diegodlh's avatar
Diegodlh committed
6
7
  "type": "array",
  "items": {
8
9
    "title": "Translation template",
    "description": "A translation template defines translation procedures to extract relevant metadata from a specific template webpage",
Diegodlh's avatar
Diegodlh committed
10
11
12
    "type": "object",
    "properties": {
      "path": {
13
14
        "title": "Path",
        "description": "Path of the webpage used as translation template. 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
24
        "title": "Fields",
        "description": "A list of template fields. Mandatory fields \"itemType\" and \"title\" must be included, or template will be ignored.",
Diegodlh's avatar
Diegodlh committed
25
26
        "type": "array",
        "items": {
27
28
          "title": "Template field",
          "description": "A 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
29
30
31
          "type": "object",
          "properties": {
            "fieldname": {
32
33
34
35
36
37
38
39
40
41
42
43
44
45
              "title": "Field name",
              "description": "Name of the template field (see https://meta.wikimedia.org/wiki/Web2Cit/Early_adopters#Translation_field_types). Duplicate template fields with the same field name will be ignored.",
              "type": "string",
              "enum": [
                "itemType",
                "title",
                "authorFirst",
                "authorLast",
                "date",
                "publishedIn",
                "publishedBy",
                "language",
                "control"
              ]
Diegodlh's avatar
Diegodlh committed
46
47
            },
            "required": {
48
49
50
51
              "Title": "Required",
              "description": "Whether the template field is required or not (mandatory fields \"itemType\" and \"title\" are always required). Given a target webpage, the output of all required fields must be valid for the template to be applicable.",
              "type": "boolean",
              "default": true
Diegodlh's avatar
Diegodlh committed
52
53
            },
            "procedures": {
54
              "title": "Procedures",
Diegodlh's avatar
Diegodlh committed
55
56
57
              "description": "A list of translation procedures",
              "type": "array",
              "items": {
58
59
                "title": "Translation procedure",
                "description": "A translation procedure defines a series of selection and transformation steps to extract and manipulate relevant metadata",
Diegodlh's avatar
Diegodlh committed
60
61
62
                "type": "object",
                "properties": {
                  "selections": {
63
                    "title": "Selection",
64
                    "description": "A list of selection steps (see https://meta.wikimedia.org/wiki/Web2Cit/Early_adopters#Selection_types_and_configs); the combined output of all selection steps is given as input to the first transformation step below",
65
                    "default": [],
Diegodlh's avatar
Diegodlh committed
66
67
                    "type": "array",
                    "items": {
68
69
                      "title": "Selection step",
                      "description": "A selection step selects and extracts individual elements from the target webpage",
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
                      "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",
                              "description": "Any valid Citoid/Zotero base field name; creators (e.g., \"author\") are split into creatorFirst and creatorLast. Use the \"citation\" endpoint of Wikimedia REST API (format \"mediawiki-basefields\") to check what Citoid returns for the target webpage: https://en.wikipedia.org/api/rest_v1/#/Citation/getCitation.",
                              "type": "string"
                            }
                          },
                          "required": [
                            "type",
                            "config"
90
                          ]
Diegodlh's avatar
Diegodlh committed
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
                        { 
                          "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",
                              "description": "Any valid XPath expression. Your browser's inspector may help you get one.",
                              "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
133
                        }
134
                      ]
Diegodlh's avatar
Diegodlh committed
135
136
137
                    }
                  },
                  "transformations": {
138
                    "title": "Transformation",
139
                    "description": "A list of transformation steps to be applied one after the other (see https://meta.wikimedia.org/wiki/Web2Cit/Early_adopters#Transformation_types_and_configs); the output of the last transformation step is the procedure's output",
Diegodlh's avatar
Diegodlh committed
140
141
                    "type": "array",
                    "items": {
142
143
                      "title": "Transformation step",
                      "description": "Transformation steps transform selected elements (if needed) to return the expected output",
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
                      "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"
195
                          ]
Diegodlh's avatar
Diegodlh committed
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
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
282
283
284
285
286
287
288
289
                        {
                          "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",
                              "description": "One or more zero-based comma-separated ranges: \"start(:end)\", \"start:\" or \":end\".",
                              "type": "string"
                            },
                            "itemwise": {
                              "$ref": "#/definitions/itemwise",
                              "default": false
                            }
                          },
                          "required": [
                            "type",
                            "config",
                            "itemwise"
                          ]
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
311
312
313
314
315
                        {
                          "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
316
                        }
317
                      ]
318
                    }                      
Diegodlh's avatar
Diegodlh committed
319
                  }
Diegodlh's avatar
Diegodlh committed
320
                },
321
322
323
324
                "required": [
                  "selections",
                  "transformations"
                ]
Diegodlh's avatar
Diegodlh committed
325
              }
Diegodlh's avatar
Diegodlh committed
326
            }
Diegodlh's avatar
Diegodlh committed
327
          },
328
329
330
331
332
          "required": [
            "fieldname",
            "required",
            "procedures"
          ]
Diegodlh's avatar
Diegodlh committed
333
        }
Diegodlh's avatar
Diegodlh committed
334
      }
Diegodlh's avatar
Diegodlh committed
335
    },
336
337
338
339
    "required": [
      "path",
      "fields"
    ]
340
341
342
343
344
345
346
  },
  "definitions": {
    "itemwise": {
      "title": "Item-wise",
      "description": "Whether transformation should be applied to each item of the input independently (true), or to the entire input as a whole (false)",
      "type": "boolean"
    }
Diegodlh's avatar
Diegodlh committed
347
  }
348
}