Skip to content

Instantly share code, notes, and snippets.

View CliffordAnderson's full-sized avatar

Clifford Anderson CliffordAnderson

View GitHub Profile
@CliffordAnderson
CliffordAnderson / frenemies
Last active December 15, 2015 00:09
A sample cypher query for Neo4J using the DrWho dataset
START a=node(1) // "Doctor"
MATCH (a)-[:ALLY_OF]->(b)-[:ENEMY_OF]->(a)
RETURN a,b
@CliffordAnderson
CliffordAnderson / luhn-3.1.xqy
Last active December 3, 2016 22:08
An attempt at the Luhn algorithm in XQuery
(: Signature of the fold function changed :)
xquery version "3.1";
(: Implements the Luhn Algorithm (http://en.wikipedia.org/wiki/Luhn_algorithm) in XQuery :)
declare function local:check-luhn($num as xs:integer) as xs:boolean
{
let $seq := fn:reverse(local:number-to-seq(($num)))
let $even-seq := $seq[position() mod 2 = 0]
@CliffordAnderson
CliffordAnderson / loc-sru.xqy
Last active December 19, 2015 22:08
Simple example of requesting items from the SRU gateway at the Library of Congress
xquery version "3.0";
(: Look ups records at the Library of Congress in the specified metadata format :)
declare namespace mods = "http://www.loc.gov/mods/v3";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
declare namespace marcxml = "http://www.loc.gov/MARC21/slim";
declare namespace zs = "http://www.loc.gov/zing/srw/";
(: change the lccn for different items :)
@CliffordAnderson
CliffordAnderson / fizzbuzz.xqy
Created July 18, 2013 00:43
Fizz Buzz in XQuery
xquery version "3.0";
(: Fizz Buzz in XQuery :)
for $i in (1 to 30)
return
if ($i mod 3 = 0 and $i mod 5 = 0) then "fizzbuzz"
else if ($i mod 3 = 0) then "fizz"
else if ($i mod 5 = 0) then "buzz"
else $i
@CliffordAnderson
CliffordAnderson / ead.xqy
Created July 18, 2013 20:29
Simple example of retrieving a record in EAD (or Dublin Core) from the Archives Hub using SRU
xquery version "3.0";
(: Look ups records at the Archives Hub (http://archiveshub.ac.uk/) in the specified metadata format :)
declare namespace sru = "http://www.loc.gov/zing/srw/";
(: change keyword for different documents :)
let $keyword := "castle"
(: change the requested format for different kinds of metadata - "ead", "srw_dc", or "oai_dc":)
@CliffordAnderson
CliffordAnderson / odd-square.xqy
Last active December 20, 2015 01:38
Example of a FLWOR expression
xquery version "3.0";
(: Squares all odd numbers
and returns in reverse sequence :)
for $i in 1 to 10
let $n := $i * $i
where $i mod 2 != 0
order by $n descending
return $n
@CliffordAnderson
CliffordAnderson / alchemy-entities.xq
Created October 30, 2013 01:43
Extracts entities with geographic attributes using the Alchemy api
(: Extracts entities from web-accessible texts using the Alchemy api :)
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=[Your Key Here]&amp;url=https%3A%2F%2Fraw.github.com%2Fiulibdcs%2Ftei_text%2Fmaster%2Fvwwp_text%2FVAB7013.txt</http:body>
</http:request>
)/results/entities
for $entity in $entities/entity
where $entity//geo
return $entity
@CliffordAnderson
CliffordAnderson / alchemy-csv.xqy
Last active December 26, 2015 22:49
Serializes disambiguated entities to CSV
(: 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>{
@CliffordAnderson
CliffordAnderson / alchemy-post.txt
Created October 30, 2013 02:19
HTTPie post to alchemy entity extraction API
http post http://access.alchemyapi.com/calls/url/URLGetRankedNamedEntities apikey=[Your Key Here] url='https://raw.github.com/iulibdcs/tei_text/master/vwwp_text/VAB7017.txt' --form
@CliffordAnderson
CliffordAnderson / alchemy-geojson.xqy
Last active December 26, 2015 23:59
Converts geographic entities from the Alchemy API to GeoJSON
(: Extracts entities from web-accessible texts using the Alchemy api :)
(: Serializes Disambiguated Entities to GeoJSON :)
xquery version "3.0";
declare namespace csv = "http://basex.org/modules/json";
let $api-key := [Your API Key]
let $url:= "https%3A%2F%2Fraw.github.com%2Fiulibdcs%2Ftei_text%2Fmaster%2Fvwwp_text%2FVAB7013.txt"
let $csv :=
<json type="object">