Skip to content

Instantly share code, notes, and snippets.

@Ramona2020
Forked from AdamSteffanick/01-lookup-words.xquery
Created January 20, 2017 21:43
Show Gist options
  • Save Ramona2020/0cfea42dcaabe767565bcb51bb956708 to your computer and use it in GitHub Desktop.
Save Ramona2020/0cfea42dcaabe767565bcb51bb956708 to your computer and use it in GitHub Desktop.
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