Skip to content

Instantly share code, notes, and snippets.

View AdamSteffanick's full-sized avatar

Adam Steffanick AdamSteffanick

View GitHub Profile
@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 / 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]
@AdamSteffanick
AdamSteffanick / eval.xqy
Created November 13, 2015 21:44 — forked from CliffordAnderson/eval.xqy
Eval example
xquery version "3.1";
declare namespace functx = "http://www.functx.com";
for $title in fn:collection("books")/record/Title
let $string-fun := "fn:upper-case"
return xquery:eval(
"declare variable $title external;" ||
$string-fun || "($title)",
map { 'title': $title } )
xquery version "3.1";
(: Thanks to Tao You!! :)
declare function local:get_facet ($books as element()*, $path as xs:string, $facet_type as xs:string ) as element()?
{
<facet type="{$facet_type}">{
for $book in $books
let $fld := $book/*[name()=$path]
group by $f := $fld
<terms>
<term>
<path>date</path>
<facet>date</facet>
</term>
</terms>
@AdamSteffanick
AdamSteffanick / multi_facets.xq
Created November 6, 2015 21:11 — forked from taoyou/multi_facets.xq
return list of multiple facets
xquery version "3.1";
declare function local:get_facet ($books as element()*, $path as xs:string, $facet_type as xs:string ) as element()?
{
<facet type="{$facet_type}">{
for $book in $books
let $fld := $book/*[name()=$path]
group by $f := $fld
order by $f descending
return element {$facet_type} {attribute v {$f}, attribute number {fn:count($book)} }