Skip to content

Instantly share code, notes, and snippets.

View CliffordAnderson's full-sized avatar

Clifford Anderson CliffordAnderson

View GitHub Profile
@CliffordAnderson
CliffordAnderson / IA-GeoJSON.xqy
Created October 30, 2013 21:39
Reads a page from a given book at the Internet Archive and extracts disambiguated geographic entities as GeoJSON using the Alchemy API
(: Extracts entities from Internet Archive texts using the Alchemy API :)
(: Serializes disambiguated Entities to GeoJSON :)
xquery version "3.0";
declare namespace csv = "http://basex.org/modules/json";
declare function local:read-page($title as xs:string, $page as xs:integer) as item()?
{
let $text := fn:string-join(
let $doc := fn:doc(fn:concat("geojson/", $title))//OBJECT[$page]
@CliffordAnderson
CliffordAnderson / convert.xqy
Last active December 29, 2015 18:19
Converts an integer to a corresponding sequence of words
xquery version "3.0";
(:~
: Converts an integer to a corresponding sequence of words
: @author Clifford Anderson
: @version 1.0
:
:)
(: This function is adapted from a function by Nelson Wells :)
@CliffordAnderson
CliffordAnderson / fibonacci.xqy
Last active December 31, 2015 14:08
Fibonacci sequence in XQuery
xquery version "3.0";
(: Fibonacci Sequence :)
declare function local:fibo-numbers($num1 as xs:integer, $num2 as xs:integer, $limit as xs:integer) as xs:integer* {
if ($limit > 0) then ($num1, local:fibo-numbers($num2, $num1 + $num2, $limit -1))
else $num1
};
declare function local:fibo-sequence($limit as xs:integer) as xs:integer* {
@CliffordAnderson
CliffordAnderson / word-frequency.xqy
Last active December 31, 2015 19:29
Produces word frequency list for speakers in Much Ado about Nothing.
xquery version "3.0";
(: Produces word lists with frequency per speaker :)
declare namespace tei="http://www.tei-c.org/ns/1.0";
let $doc := fn:doc("db/shakespeare/Ado.xml")
for $character in fn:distinct-values($doc//tei:sp/tei:speaker/tei:w/text())
let $bag :=
for $speaker in $doc//tei:sp
@CliffordAnderson
CliffordAnderson / wordcloud.R
Last active December 31, 2015 20:29
A brief R script to generate tag clouds of the primary words used by characters (in the case, Leonato) in Shakespeare's *Much Ado about Nothing*.
words <- read.csv(file.choose(), header=FALSE)
leonato <- subset(words, V1=="LEONATO", select=c(V2, V3))
pal <- brewer.pal(8, "Accent")
wordcloud(leonato$V2, leonato$V3, min.freq=3, colors=pal)
@CliffordAnderson
CliffordAnderson / http-get.xqy
Created December 22, 2013 16:24
HTTP GET Request with eXistDB
xquery version "3.0";
(: HTTP GET request :)
let $url := 'http://www.rest.com'
return httpclient:get(xs:anyURI($url), fn:false(), ())/httpclient:body/html
@CliffordAnderson
CliffordAnderson / query.xqy
Created December 22, 2013 17:48
Query across collections in ExistDB
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
fn:collection("db/shakespeare")//tei:seriesStmt
@CliffordAnderson
CliffordAnderson / long-short.xqy
Created December 22, 2013 19:57
Query for long and short phrases in Shakespeare's plays
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
for $result in fn:collection("/db/shakespeare")//tei:ab
let $length :=
if (fn:string-length($result) gt 20) then "long-phrase"
else "short-phrase"
group by $length
return element { $length } { count($result) }
@CliffordAnderson
CliffordAnderson / paths.txt
Created December 29, 2013 19:41
A list of all the paths in the Folger XML edition of *Much Ado About Nothing*
TEI
TEI/teiHeader
TEI/teiHeader/encodingDesc
TEI/teiHeader/encodingDesc/editorialDecl
TEI/teiHeader/encodingDesc/editorialDecl/correction
TEI/teiHeader/encodingDesc/editorialDecl/correction/p
TEI/teiHeader/encodingDesc/editorialDecl/hyphenation
TEI/teiHeader/encodingDesc/editorialDecl/hyphenation/p
TEI/teiHeader/encodingDesc/editorialDecl/hyphenation/p/gi
TEI/teiHeader/encodingDesc/editorialDecl/interpretation
@CliffordAnderson
CliffordAnderson / nav.xslt
Created December 29, 2013 19:46
Provides a hook for CSS/JQuery effects to the top level elements in DSpace community lists
<!-- Provides class hook for accordion effect in community-list -->
<xsl:template name="top-browse-only" match="dri:referenceSet[@rend='hierarchy']">
<xsl:for-each select="dri:reference">
<xsl:variable name="item-dim" select="document(concat(confman:getProperty('dspace.baseUrl'), @url))//dim:dim"/>
<div class="artifact-description top-level-nav">
<div class="artifact-title">
<a href="{concat('/xmlui/handle', substring-after($item-dim/dim:field[@element='identifier'], 'http://hdl.handle.net'))}">
<xsl:value-of select="$item-dim/dim:field[@element='title']"/>
</a>
</div>