Skip to content

Instantly share code, notes, and snippets.

View AdamSteffanick's full-sized avatar

Adam Steffanick AdamSteffanick

View GitHub Profile
for $doc in fn:collection("books")//book[@full-text eq "true"]
where fn:not($doc//subjects/subject = "Protected DAISY") (: existential quantification! :)
for $key in $doc/key/text()
let $data := fetch:text("https://openlibrary.org" || $key || ".json") => json:parse()
let $ocaid := $data//ocaid/text()
for $book in $ocaid
return fetch:text("https://archive.org/5/items/" || $book || "/" || $book || "_djvu.txt")
@AdamSteffanick
AdamSteffanick / 01-simple-api.xqy
Last active October 28, 2016 20:23 — forked from CliffordAnderson/01-simple-api.xqy
Sample code for extracting, transforming, and loading IA metadata into BaseX
xquery version "3.1";
declare %updating function local:persist($db as xs:string, $doc as element()) as empty-sequence()
{
let $book := element book {$doc/*}
let $key := $book//key/text()
return db:replace($db, $key, $book)
};
let $db := "books"
@AdamSteffanick
AdamSteffanick / 01-return-JSON-from-Open-Library.xquery
Last active October 26, 2016 15:33
Open Library (these are inefficient queries intended to teach using functions and an API; please visit https://openlibrary.org/developers/dumps to obtain data for local storage)
xquery version "3.1";
let $uri := "http://openlibrary.org/search.json?title=digital+humanities"
let $json := fetch:text($uri)
return $json
<compounds>
<word>bookcase</word>
<word>classmate</word>
<word>bookmark</word>
<word>newspaper</word>
</compounds>
<div lang="la" id="tei-document">
<p data-paragraph="1">
<span data-sentence="1">Lorem ipsum dolor sit amet, consectetur adipiscing <span class="quotes">‘elit’</span>.</span>
<span data-sentence="2">Vestibulum nec lorem vitae dui varius <i>gravida</i>.</span>
<span data-sentence="3">Cras eget tristique <b>eros</b>, id ultrices eros. Mauris nec turpis elit.</span>
<span data-sentence="4">In tincidunt eget ante quis semper.</span>
<span data-sentence="5">Praesent a mi et nisi ullamcorper feugiat nec non ipsum.</span>
<span data-sentence="6">Ut malesuada finibus lorem nec gravida.</span>
<span data-sentence="7">Praesent lobortis magna sed scelerisque molestie.</span>
<span data-sentence="8">Aenean nec sapien quis quam commodo aliquam et et lorem.</span>
@AdamSteffanick
AdamSteffanick / except.xqy
Created April 29, 2016 20:18 — forked from CliffordAnderson/except.xqy
Combining Node Sequences
xquery version "3.1";
let $old-words :=
<stopwords>
<word>the</word>
<word>a</word>
<word>in</word>
<word>of</word>
<word>as</word>
</stopwords>
@AdamSteffanick
AdamSteffanick / basic.xqy
Created March 11, 2016 18:54 — forked from CliffordAnderson/basic.xqy
XQuery Full-Text Examples
xquery version "3.1";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
for $p in fn:collection("fleurs-du-mal")//tei:p/text()
where $p contains text "fleurs"
return $p
@AdamSteffanick
AdamSteffanick / simple-dpla-with-params.xqy
Created March 4, 2016 21:18 — forked from CliffordAnderson/simple-dpla-with-params-xml.xqy
Just a quick example of searching the DPLA API using XQuery and returning a simple webpage.
module namespace page = 'http://library.vanderbilt.edu/dpla';
(: Just a quick example of searching the DPLA API
and returning a simple webpage. :)
declare
%rest:path("dpla/{$search}")
%rest:query-param("key", "{$key}")
%output:method("html")
function page:html($search as xs:string, $key as xs:string)
@AdamSteffanick
AdamSteffanick / gbif-api.txt
Created February 5, 2016 21:45 — forked from baskaufs/gbif-api.txt
Some test API calls to get JSON with geocoordinates from the Global Biodiversity Information Facility (GBIF)
See http://www.gbif.org/developer/summary for background.
Find the single occurrence with identifier http://bioimages.vanderbilt.edu/vanderbilt/7-314#2002-06-14
http://api.gbif.org/v1/occurrence/search?occurrenceID=http%3A%2F%2Fbioimages.vanderbilt.edu%2Fvanderbilt%2F7-314%232002-06-14
Note: the occurrenceID is URLencoded.
Find occurrences
- with scientificName=Quercus%20macrocarpa (bur oak, note: space between genus and species is URLencoded as "%20")
- with decimalLatitude between 35.81 and 36.45
- with decimalLongitude between -87.21 and -86.27
--reference implementation in Haskell
qsort' :: (Ord a) => [a] -> [a]
qsort' [] = []
qsort' (x:xs) = qsort' smaller ++ [x] ++ qsort' larger
where larger = [a | a <- xs, a > x]
smaller = [b | b <- xs, b <= x]