Last active
January 19, 2017 16:00
-
-
Save CliffordAnderson/f36092c801375526e7082aa46a48e37a to your computer and use it in GitHub Desktop.
Looking up words in the OED with XQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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