Last active
December 26, 2015 22:49
-
-
Save CliffordAnderson/7226156 to your computer and use it in GitHub Desktop.
Serializes disambiguated entities to CSV
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
(: Extracts entities from web-accessible texts using the Alchemy api :) | |
(: Serializes Disambiguated Entities to CSV :) | |
xquery version "3.0"; | |
declare namespace csv = "http://basex.org/modules/csv"; | |
let $apiKey := [Your Key Here] | |
let $url := "https://raw.github.com/iulibdcs/tei_text/master/vwwp_text/VAB7013.txt" | |
let $csv := | |
<csv>{ | |
let $entities := | |
http:send-request( | |
<http:request method='post' href='http://access.alchemyapi.com/calls/url/URLGetRankedNamedEntities'> | |
<http:body media-type='application/x-www-form-urlencoded' method='text'>apikey={$apiKey}&url={$url}</http:body> | |
</http:request> | |
)/results/entities | |
for $entity in $entities/entity | |
where $entity//geo | |
return | |
<record> | |
{$entity/text} | |
<lon>{fn:substring-before($entity/disambiguated/geo, " ")}</lon> | |
<lat>{fn:substring-after($entity/disambiguated/geo, " ")}</lat> | |
</record> | |
} | |
</csv> | |
return csv:serialize($csv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample CSV output:
London,51.50805555555556,-0.12472222222222222
Indiana University,39.775555555555556,-86.17666666666666