Skip to content

Instantly share code, notes, and snippets.

@CliffordAnderson
Created August 18, 2017 16:02
Show Gist options
  • Save CliffordAnderson/b9bc1b51a53319c33bdd5eb6949effd5 to your computer and use it in GitHub Desktop.
Save CliffordAnderson/b9bc1b51a53319c33bdd5eb6949effd5 to your computer and use it in GitHub Desktop.
Entity Extraction with Rosette
xquery version "3.1";
declare namespace ead = "urn:isbn:1-931666-22-9";
declare namespace http = "http://expath.org/ns/http-client";
let $texts := fn:doc("https://raw.githubusercontent.com/HeardLibrary/finding-aids/master/rosenzweig.xml")//ead:item/text()
for $text in $texts
let $json := map {
"content" : fn:normalize-space($text),
"genre" : "social-media"
} => json:serialize()
let $url := "https://api.rosette.com/rest/v1/entities"
let $request :=
<http:request href="{$url}" method="post">
<http:header name="X-RosetteAPI-Key" value="[YOUR KEY HERE]"/>
<http:header name="Content-Type" value="application/json"/>
<http:header name="Cache-Control" value="no-cache"/>
<http:body media-type='application/json'>{$json}</http:body>
</http:request>
let $response := http:send-request($request)[2]
where $response/json/entities/_
return $response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment