Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Looking up words in the OED with XQuery
xquery version "3.1";
let $word := "person"
let $request :=
<http:request href="https://od-api.oxforddictionaries.com/api/v1/entries/en/{$word}" method="get">
<http:header name="app_key" value="###"/>
<http:header name="app_id" value="###"/>
</http:request>
return http:send-request($request)
xquery version "3.1";
let $word := "person"
let $request :=
<http:request href="https://od-api.oxforddictionaries.com/api/v1/entries/en/{$word}/synonyms" method="get">
<http:header name="app_key" value="###"/>
<http:header name="app_id" value="###"/>
</http:request>
return http:send-request($request)
xquery version "3.1";
declare function local:get-synonym($word as xs:string) as xs:string?
{
let $request :=
<http:request href="https://od-api.oxforddictionaries.com/api/v1/entries/en/{$word}/synonyms" method="get">
<http:header name="app_key" value="###"/>
<http:header name="app_id" value="###"/>
</http:request>
let $synonyms := http:send-request($request)[2]
where $synonyms/json
return ($synonyms//_/synonyms/_/id/string())[1]
};
let $sentence := fn:tokenize("I sing of arms and woman", "\W+")
let $new-words :=
for $word in $sentence
return local:get-synonym($word)
return fn:string-join($new-words, " ") || "."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment