-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathod-api-basex.xquery
More file actions
619 lines (606 loc) · 23.6 KB
/
od-api-basex.xquery
File metadata and controls
619 lines (606 loc) · 23.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
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
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
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
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
490
491
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
518
519
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
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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
xquery version "3.1" encoding "UTF-8";
module namespace od-api = "od-api-basex";
(:~
: A library module for the Oxford Dictionaries API.
:
: @author Adam Steffanick
: https://www.steffanick.com/adam/
: @version v0.6.0
: https://github.com/AdamSteffanick/od-api-xquery
: September 8, 2017
:)
(:
MIT License
Copyright (c) 2017 Adam Steffanick
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
:)
(: # API v1.8.0 :)
(: # General functions :)
(: ## Add metadata :)
declare function od-api:metadata($response as item()*) as item()* {
let $metadata := $response/json/metadata
let $date := $response[1]/*[fn:name()="http:header"][@name="Date"]/@value/fn:string()
let $version := "v0.6.0"
return element {"metadata"} {
$metadata/node(),
element {"od_api_xquery"} {$version},
element {"date"} {$date}
}
};
(: ## Create elements for optional fragment arrays :)
declare function od-api:option($fragment as item()*, $function as xs:string) as item()* {
(: ### General arrays :)
if ($fragment and $function = "arrayofstrings") then
od-api:arrayofstrings($fragment)
else if ($fragment and $function = "CategorizedTextList") then
element {"notes"} {
for $note in $fragment/_
return od-api:CategorizedTextList($note, "note")
}
(: ### Lemmatron arrays :)
else if ($fragment and $function = "headwordLemmatron") then
element {"results"} {
for $result in $fragment/_
return od-api:headwordLemmatron($result)
}
else if ($fragment/fn:name() = "grammaticalFeatures" and $function = "lemmatronGrammaticalFeaturesList") then
element {"grammaticalFeatures"} {
for $grammaticalFeature in $fragment/_
return od-api:lemmatronGrammaticalFeaturesList($grammaticalFeature, "grammaticalFeature")
}
(: ### Dictionary :)
else if ($fragment and $function = "dictionaryCategorizedTextList") then
element {"notes"} {
for $note in $fragment/_
return od-api:dictionaryCategorizedTextList($note, "note")
}
(: ### Dictionary arrays :)
else if ($fragment and $function = "headwordEntry") then
element {"results"} {
for $result in $fragment/_
return od-api:headwordEntry($result)
}
else if ($fragment and $function = "ArrayOfRelatedEntries") then
element {"relatedEntries"} {
for $relatedEntry in $fragment/_
return od-api:dictionaryArrayOfRelatedEntries($relatedEntry, "relatedEntry")
}
else if ($fragment and $function = "entry") then
element {"entries"} {
for $entry in $fragment/_
return od-api:entry($entry)
}
else if (($fragment/fn:name() = "senses" or "subsenses") and $function = "sense") then
if ($fragment/fn:name() = "senses") then
element {"senses"} {
for $sense in $fragment/_
return od-api:sense($sense, "sense")
}
else if ($fragment/fn:name() = "subsenses") then
element {"subsenses"} {
for $subsense in $fragment/_
order by $subsense/domains, $subsense/regions, $subsense/registers
return od-api:sense($subsense, "subsense")
}
else ()
else if ($fragment/fn:name() = "pronunciations" and $function = "dictionaryPronunciationsList") then
element {"pronunciations"} {
for $pronunciation in $fragment/_
return od-api:dictionaryPronunciationsList($pronunciation, "pronunciation")
}
else if ($fragment/fn:name() = "pronunciations" and $function = "dictionaryPronunciationsList") then
element {"pronunciations"} {
for $pronunciation in $fragment/_
return od-api:dictionaryPronunciationsList($pronunciation, "pronunciation")
}
else if ($fragment/fn:name() = "grammaticalFeatures" and $function = "dictionaryGrammaticalFeaturesList") then
element {"grammaticalFeatures"} {
for $grammaticalFeature in $fragment/_
return od-api:dictionaryGrammaticalFeaturesList($grammaticalFeature, "grammaticalFeature")
}
else if ($fragment/fn:name() = "variantForms" and $function = "dictionaryVariantFormsList") then
element {"variantForms"} {
for $variantForm in $fragment/_
order by $variantForm/text
return od-api:dictionaryVariantFormsList($variantForm, "variantForm")
}
else if ($fragment/fn:name() = "crossReferences" and $function = "dictionaryCrossReferencesList") then
element {"crossReferences"} {
for $crossReference in $fragment/_
return od-api:dictionaryCrossReferencesList($crossReference, "crossReference")
}
else if ($fragment/fn:name() = "examples" and $function = "dictionaryExamplesList") then
element {"examples"} {
for $example in $fragment/_
return od-api:dictionaryExamplesList($example, "example")
}
else if ($fragment/fn:name() = "translations" and $function = "dictionaryTranslationsList") then
element {"translations"} {
for $translation in $fragment/_
return od-api:dictionaryTranslationsList($translation, "translation")
}
(: ### Thesaurus :)
else if ($fragment and $function = "thesaurusCategorizedTextList") then
element {"notes"} {
for $note in $fragment/_
return od-api:thesaurusCategorizedTextList($note, "note")
}
(: ### Thesaurus arrays :)
else if ($fragment and $function = "headwordThesaurus") then
element {"results"} {
for $result in $fragment/_
return od-api:headwordThesaurus($result)
}
else if ($fragment and $function = "thesaurusEntry") then
element {"entries"} {
for $entry in $fragment/_
return od-api:thesaurusEntry($entry)
}
else if (($fragment/fn:name() = "senses" or "subsenses") and $function = "thesaurusSense") then
if ($fragment/fn:name() = "senses") then
element {"senses"} {
for $sense in $fragment/_
return od-api:thesaurusSense($sense, "sense")
}
else if ($fragment/fn:name() = "subsenses") then
element {"subsenses"} {
for $subsense in $fragment/_
order by $subsense/domains, $subsense/regions, $subsense/registers
return od-api:thesaurusSense($subsense, "subsense")
}
else ()
else if ($fragment/fn:name() = "variantForms" and $function = "thesaurusVariantFormsList") then
element {"variantForms"} {
for $variantForm in $fragment/_
order by $variantForm/text
return od-api:thesaurusVariantFormsList($variantForm, "variantForm")
}
else if (($fragment/fn:name() = "synonyms" or "antonyms") and $function = "thesaurusSynonymsAntonyms") then
if ($fragment/fn:name() = "synonyms") then
element {"synonyms"} {
for $synonym in $fragment/_
order by $synonym/text
return od-api:thesaurusSynonymsAntonyms($synonym, "synonym")
}
else if ($fragment/fn:name() = "antonyms") then
element {"antonyms"} {
for $antonym in $fragment/_
return od-api:thesaurusSynonymsAntonyms($antonym, "antonym")
}
else ()
else if ($fragment and $function = "thesaurusExamplesList") then
element {"examples"} {
for $example in $fragment/_
return od-api:thesaurusExamplesList($example, "example")
}
else if ($fragment and $function = "thesaurusTranslationsList") then
element {"translations"} {
for $translation in $fragment/_
return od-api:thesaurusTranslationsList($translation, "translation")
}
else if ($fragment and $function = "thesaurusGrammaticalFeaturesList") then
element {"grammaticalFeatures"} {
for $grammaticalFeature in $fragment/_
return od-api:thesaurusGrammaticalFeaturesList($grammaticalFeature, "grammaticalFeature")
}
else ()
};
(: CategorizedTextList :) (: deprecated :)
declare function od-api:CategorizedTextList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
od-api:option($fragment/id, "arrayofstrings"),
$fragment/text,
$fragment/type
}
};
(: ## Create elements for string arrays :)
declare function od-api:arrayofstrings($nodes as node()*) as item()* {
for $node in $nodes
return typeswitch($node)
case text() return $node
case element(crossReferenceMarkers) return element {fn:name($node)} {
for $n in $node/_
return element {"crossReferenceMarker"} {od-api:arrayofstrings($n/node())}
}
case element(definitions) return element {fn:name($node)} {
for $n in $node/_
return element {"definition"} {od-api:arrayofstrings($n/node())}
}
case element(dialects) return element {fn:name($node)} {
for $n in $node/_
return element {"dialect"} {od-api:arrayofstrings($n/node())}
}
case element(domains) return element {fn:name($node)} {
for $n in $node/_
return element {"domain"} {od-api:arrayofstrings($n/node())}
}
case element(etymologies) return element {fn:name($node)} {
for $n in $node/_
return element {"etymology"} {od-api:arrayofstrings($n/node())}
}
case element(regions) return element {fn:name($node)} {
for $n in $node/_
return element {"region"} {od-api:arrayofstrings($n/node())}
}
case element(registers) return element {fn:name($node)} {
for $n in $node/_
return element {"register"} {od-api:arrayofstrings($n/node())}
}
case element(senseIds) return element {fn:name($node)} {
for $n in $node/_
return element {"senseId"} {od-api:arrayofstrings($n/node())}
}
default return $node
};
(: # Lemmatron functions [API v1.8.0] :)
(: ## Lemmatron :)
declare function od-api:lemmatron($source_lang as xs:string, $word-id as xs:string, $filter as xs:string, $id as xs:string, $key as xs:string) {
let $word_id := fn:encode-for-uri(fn:lower-case(fn:translate($word-id, " ", "_")))
let $filters :=
if ($filter) then
fn:concat("/", $filter)
else ()
let $request :=
<http:request href="https://od-api.oxforddictionaries.com/api/v1/inflections/{$source_lang}/{$word_id}{$filters}" method="get">
<http:header name="app_key" value="{$key}"/>
<http:header name="app_id" value="{$id}"/>
</http:request>
let $response := http:send-request($request)
return
element {"lemmatron"} {
attribute {"input"} {$word_id},
attribute {"language"} {$source_lang},
od-api:metadata($response),
od-api:option($response/json/results, "headwordLemmatron")
}
};
(: ## HeadwordLemmatron :)
declare function od-api:headwordLemmatron($result as node()*) as item()* {
element {"result"} {
$result/id,
$result/language,
element {"lexicalEntries"} {
for $lexicalEntry in $result/lexicalEntries/_
return od-api:lemmatronLexicalEntry($lexicalEntry)
},
$result/type,
$result/word
}
};
(: ## LemmatronLexicalEntry :)
declare function od-api:lemmatronLexicalEntry($lexicalEntry as node()*) as item()* {
element {"lexicalEntry"} {
od-api:option($lexicalEntry/grammaticalFeatures, "lemmatronGrammaticalFeaturesList"),
od-api:lemmatronInflectionsList($lexicalEntry/inflectionOf),
$lexicalEntry/language,
$lexicalEntry/lexicalCategory,
$lexicalEntry/text
}
};
(: ## GrammaticalFeaturesList :)
declare function od-api:lemmatronGrammaticalFeaturesList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
$fragment/text,
$fragment/type
}
};
(: ## InflectionsList :)
declare function od-api:lemmatronInflectionsList($inflectionOf as node()*) as item()* {
element {"inflectionOf"} {
for $wordform in $inflectionOf/_
order by $wordform/text
return element {"wordform"} {
$wordform/id,
$wordform/text
}
}
};
(: # Dictionary functions [API v1.8.0] :)
(: ## Dictionary :)
declare function od-api:dictionary($source_lang as xs:string, $word-id as xs:string, $filter as xs:string, $id as xs:string, $key as xs:string) {
let $word_id := fn:encode-for-uri(fn:lower-case(fn:translate($word-id, " ", "_")))
let $filters :=
if ($filter) then
fn:concat("/", $filter)
else ()
let $request :=
<http:request href="https://od-api.oxforddictionaries.com/api/v1/entries/{$source_lang}/{$word_id}{$filters}" method="get">
<http:header name="app_key" value="{$key}"/>
<http:header name="app_id" value="{$id}"/>
</http:request>
let $response := http:send-request($request)
return
element {"dictionary"} {
attribute {"input"} {$word_id},
attribute {"language"} {$source_lang},
od-api:metadata($response),
od-api:option($response/json/results, "headwordEntry")
}
};
(: ## HeadwordEntry :)
declare function od-api:headwordEntry($result as node()*) as item()* {
element {"result"} {
$result/id,
$result/language,
element {"lexicalEntries"} {
for $lexicalEntry in $result/lexicalEntries/_
return od-api:lexicalEntry($lexicalEntry)
},
od-api:option($result/pronunciations, "dictionaryPronunciationsList"),
$result/type,
$result/word
}
};
(: ## lexicalEntry :)
declare function od-api:lexicalEntry($lexicalEntry as node()*) as item()* {
element {"lexicalEntry"} {
od-api:option($lexicalEntry/derivativeOf, "ArrayOfRelatedEntries"),
od-api:option($lexicalEntry/entries, "entry"),
od-api:option($lexicalEntry/grammaticalFeatures, "dictionaryGrammaticalFeaturesList"),
$lexicalEntry/language,
$lexicalEntry/lexicalCategory,
od-api:option($lexicalEntry/notes, "dictionaryCategorizedTextList"),
od-api:option($lexicalEntry/pronunciations, "dictionaryPronunciationsList"),
$lexicalEntry/text,
od-api:option($lexicalEntry/variantForms, "dictionaryVariantFormsList")
}
};
(: ## PronunciationsList :)
declare function od-api:dictionaryPronunciationsList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
$fragment/audioFile,
od-api:option($fragment/dialects, "arrayofstrings"),
$fragment/phoneticNotation,
$fragment/phoneticSpelling,
od-api:option($fragment/regions, "arrayofstrings")
}
};
(: ## ArrayOfRelatedEntries :)
declare function od-api:dictionaryArrayOfRelatedEntries($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
od-api:option($fragment/domains, "arrayofstrings"),
$fragment/id,
$fragment/language,
od-api:option($fragment/regions, "arrayofstrings"),
od-api:option($fragment/registers, "arrayofstrings"),
$fragment/text
}
};
(: ## Entry :)
declare function od-api:entry($entry as node()*) as item()* {
element {"entry"} {
od-api:option($entry/etymologies, "arrayofstrings"),
od-api:option($entry/grammaticalFeatures, "dictionaryGrammaticalFeaturesList"),
$entry/homographNumber,
od-api:option($entry/notes, "dictionaryCategorizedTextList"),
od-api:option($entry/pronunciations, "dictionaryPronunciationsList"),
od-api:option($entry/senses, "sense"),
od-api:option($entry/variantForms, "dictionaryVariantFormsList")
}
};
(: ## GrammaticalFeaturesList :)
declare function od-api:dictionaryGrammaticalFeaturesList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
$fragment/text,
$fragment/type
}
};
(: CategorizedTextList :)
declare function od-api:dictionaryCategorizedTextList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
$fragment/id,
$fragment/text,
$fragment/type
}
};
(: ## VariantFormsList :)
declare function od-api:dictionaryVariantFormsList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
od-api:option($fragment/regions, "arrayofstrings"),
$fragment/text
}
};
(: ## Sense :)
declare function od-api:sense($sense as node()*, $element as xs:string) as item()* {
element {$element} {
od-api:option($sense/crossReferenceMarkers, "arrayofstrings"),
od-api:option($sense/crossReferences, "dictionaryCrossReferencesList"),
od-api:option($sense/definitions, "arrayofstrings"),
od-api:option($sense/domains, "arrayofstrings"),
od-api:option($sense/examples, "dictionaryExamplesList"),
$sense/id,
od-api:option($sense/notes, "dictionaryCategorizedTextList"),
od-api:option($sense/pronunciations, "dictionaryPronunciationsList"),
od-api:option($sense/regions, "arrayofstrings"),
od-api:option($sense/registers, "arrayofstrings"),
od-api:option($sense/subsenses, "sense"),
od-api:option($sense/translations, "dictionaryTranslationsList"),
od-api:option($sense/variantForms, "dictionaryVariantFormsList")
}
};
(: ## CrossReferencesList :)
declare function od-api:dictionaryCrossReferencesList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
$fragment/id,
$fragment/text,
$fragment/type
}
};
(: ## ExamplesList :)
declare function od-api:dictionaryExamplesList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
od-api:option($fragment/definitions, "arrayofstrings"),
od-api:option($fragment/domains, "arrayofstrings"),
od-api:option($fragment/notes, "dictionaryCategorizedTextList"),
od-api:option($fragment/regions, "arrayofstrings"),
od-api:option($fragment/registers, "arrayofstrings"),
od-api:option($fragment/senseIds, "arrayofstrings"),
$fragment/text,
od-api:option($fragment/translations, "dictionaryTranslationsList")
}
};
(: ## TranslationsList :)
declare function od-api:dictionaryTranslationsList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
od-api:option($fragment/domains, "arrayofstrings"),
od-api:option($fragment/grammaticalFeatures, "dictionaryGrammaticalFeaturesList"),
$fragment/language,
od-api:option($fragment/notes, "dictionaryCategorizedTextList"),
od-api:option($fragment/regions, "arrayofstrings"),
od-api:option($fragment/registers, "arrayofstrings"),
$fragment/text
}
};
(: # Thesaurus functions [API v1.8.0] :)
(: ## Thesaurus :)
declare function od-api:thesaurus($source_lang as xs:string, $word-id as xs:string, $operation as xs:string, $id as xs:string, $key as xs:string) {
let $word_id := fn:encode-for-uri(fn:lower-case(fn:translate($word-id, " ", "_")))
let $request :=
<http:request href="https://od-api.oxforddictionaries.com/api/v1/entries/{$source_lang}/{$word_id}/{$operation}" method="get">
<http:header name="app_key" value="{$key}"/>
<http:header name="app_id" value="{$id}"/>
</http:request>
let $response := http:send-request($request)
return
element {"thesaurus"} {
attribute {"input"} {$word_id},
attribute {"language"} {$source_lang},
od-api:metadata($response),
od-api:option($response/json/results, "headwordThesaurus")
}
};
(: ## HeadwordThesaurus :)
declare function od-api:headwordThesaurus($result as node()*) as item()* {
element {"result"} {
$result/id,
$result/language,
element {"lexicalEntries"} {
for $lexicalEntry in $result/lexicalEntries/_
return od-api:thesaurusLexicalEntry($lexicalEntry)
},
$result/type,
$result/word
}
};
(: ## ThesaurusLexicalEntry :)
declare function od-api:thesaurusLexicalEntry($lexicalEntry as node()*) as item()* {
element {"lexicalEntry"} {
od-api:option($lexicalEntry/entries, "thesaurusEntry"),
$lexicalEntry/language,
$lexicalEntry/lexicalCategory,
$lexicalEntry/text,
od-api:option($lexicalEntry/variantForms, "thesaurusVariantFormsList")
}
};
(: ## ThesaurusEntry :)
declare function od-api:thesaurusEntry($entry as node()*) as item()* {
element {"entry"} {
$entry/homographNumber,
od-api:option($entry/senses, "thesaurusSense"),
od-api:option($entry/variantForms, "thesaurusVariantFormsList")
}
};
(: ## VariantFormsList :)
declare function od-api:thesaurusVariantFormsList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
od-api:option($fragment/regions, "arrayofstrings"),
$fragment/text
}
};
(: ## ThesaurusSense :)
declare function od-api:thesaurusSense($sense as node()*, $element as xs:string) as item()* {
element {$element} {
od-api:option($sense/antonyms, "thesaurusSynonymsAntonyms"),
od-api:option($sense/domains, "arrayofstrings"),
od-api:option($sense/examples, "thesaurusExamplesList"),
$sense/id,
od-api:option($sense/regions, "arrayofstrings"),
od-api:option($sense/registers, "arrayofstrings"),
od-api:option($sense/subsenses, "thesaurusSense"),
od-api:option($sense/synonyms, "thesaurusSynonymsAntonyms")
}
};
(: ## SynonymsAntonyms :)
declare function od-api:thesaurusSynonymsAntonyms($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
od-api:option($fragment/domains, "arrayofstrings"),
$fragment/id,
$fragment/language,
od-api:option($fragment/regions, "arrayofstrings"),
od-api:option($fragment/registers, "arrayofstrings"),
$fragment/text
}
};
(: ## ExamplesList :)
declare function od-api:thesaurusExamplesList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
od-api:option($fragment/definitions, "arrayofstrings"),
od-api:option($fragment/domains, "arrayofstrings"),
od-api:option($fragment/notes, "thesaurusCategorizedTextList"),
od-api:option($fragment/regions, "arrayofstrings"),
od-api:option($fragment/registers, "arrayofstrings"),
od-api:option($fragment/senseIds, "arrayofstrings"),
$fragment/text,
od-api:option($fragment/translations, "thesaurusTranslationsList")
}
};
(: CategorizedTextList :)
declare function od-api:thesaurusCategorizedTextList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
$fragment/id,
$fragment/text,
$fragment/type
}
};
(: ## TranslationsList :)
declare function od-api:thesaurusTranslationsList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
od-api:option($fragment/domains, "arrayofstrings"),
od-api:option($fragment/grammaticalFeatures, "thesaurusGrammaticalFeaturesList"),
$fragment/language,
od-api:option($fragment/notes, "thesaurusCategorizedTextList"),
od-api:option($fragment/regions, "arrayofstrings"),
od-api:option($fragment/registers, "arrayofstrings"),
$fragment/text
}
};
(: ## GrammaticalFeaturesList :)
declare function od-api:thesaurusGrammaticalFeaturesList($fragment as node()*, $element as xs:string) as item()* {
element {$element} {
$fragment/text,
$fragment/type
}
};
(: # Translation functions [API v1.8.0] :)
(: ## Translation :)
declare function od-api:translation($source_lang as xs:string, $word-id as xs:string, $target_lang as xs:string, $id as xs:string, $key as xs:string) {
let $word_id := fn:encode-for-uri(fn:lower-case(fn:translate($word-id, " ", "_")))
let $request :=
<http:request href="https://od-api.oxforddictionaries.com/api/v1/entries/{$source_lang}/{$word_id}/translations={$target_lang}" method="get">
<http:header name="app_key" value="{$key}"/>
<http:header name="app_id" value="{$id}"/>
</http:request>
let $response := http:send-request($request)
return
element {"translation"} {
attribute {"input"} {$word_id},
attribute {"language"} {$source_lang},
attribute {"target-language"} {$target_lang},
od-api:metadata($response),
od-api:option($response/json/results, "headwordEntry")
}
};