Skip to content

Instantly share code, notes, and snippets.

View joewiz's full-sized avatar

Joe Wicentowski joewiz

  • Arlington, Virginia
View GitHub Profile
@joewiz
joewiz / 2012-palm-01.xml
Last active August 29, 2015 14:14
Coterminous appointments
<!--
This is a sample data file for capturing coterminous appointments
Store in the /db/cms/apps/principals-chiefs/data/coterminous-appointments collection.
The rule for deriving the file's <id> (and file basename) is to join the following elements with a hyphen:
YYYY: the year of the first appointment
ABCD: the first four letters of the appointee's last name (unless fewer than 4 letters
NN: usually 01, but increment to 02, 03, etc. to prevent id collisions
In this example:
2012: all appointments started in 2012
palm: from Palmer
@joewiz
joewiz / parse-tweets.xq
Last active October 4, 2015 01:28
Parse and transform tweets using XQuery 3.1's JSON support
xquery version "3.1";
(: parse tweets using XQuery 3.1's JSON support
: see http://www.w3.org/TR/xpath-functions-31/#json
: sample JSON from https://dev.twitter.com/rest/reference/get/statuses/user_timeline
:)
let $json := json-doc('/db/user_timeline.json')
let $tweets := $json?*
return
@joewiz
joewiz / json-xml.xqm
Last active June 6, 2021 00:33
An implementation of XQuery 3.1's fn:json-to-xml and fn:xml-to-json functions for eXist
xquery version "3.1";
(:~
: An implementation of XQuery 3.1's fn:json-to-xml and fn:xml-to-json functions for eXist, which does not support them natively as of 4.3.0.
:
: @author Joe Wicentowski
: @version 0.4
: @see http://www.w3.org/TR/xpath-functions-31/#json
:)
module namespace jx = "http://joewiz.org/ns/xquery/json-xml";
@joewiz
joewiz / restxq-template.xqm
Created November 23, 2014 04:04
A starter template for a RestXQ module
xquery version "3.0";
module namespace my-app = "http://my/app";
(: A starter template for a RestXQ module.
Save this file into eXist anywhere (e.g., /db/restxq-template.xqm or /db/apps/my-app/modules/restxq-template.xqm),
And access at http://localhost:8080/exist/restxq/index.html.
(Why? Because /restxq is the URL space for RestXQ, and the function's %rest:path annotation is for requests to "/index.html".)
Note that the collection configuration file where you store the module must invoke the RestXQ trigger:
<collection xmlns="http://exist-db.org/collection-config/1.0">
@joewiz
joewiz / generate-bookworm.xq
Last active August 29, 2015 14:06
Generate a Culturomics Bookworm file from FRUS TEI XML data, using XQuery and eXist
xquery version "3.0";
(: Transform volumes from the FRUS series (TEI XML) into a zip file containing JSON and text files
formatted for Bookworm http://bookworm.culturomics.org/. The resulting data can be accessed at:
http://static.history.state.gov/temp/frus-all.zip (140 MB)
A link to the running demo of the resulting data awaits fixes to the bookworm server,
but @bmschmidt kindly posted one volume's worth of data at
http://benschmidt.org/joewiz/
:)
@joewiz
joewiz / 01-library.xql
Last active June 8, 2018 06:10
Unit testing XQuery with XQSuite in eXist-db: tests for a sample function, how to run tests, and test results
xquery version "3.0";
(: This sample library module contains a single function, iu:analyze-date-string().
: The purpose of the sample is to demonstrate XQSuite tests, a unit test framework that uses
: XQuery 3.0's Annotations facility to embed testing assertions and parameters in XQuery functions.
:
: By writing unit tests and running them after each new change to an application, we can spot new bugs
: right away and prevent regressions.
:
: The XQSuite tests in this example are stored in a separate module, 02-tests-xql.
@joewiz
joewiz / principal-officers-and-chiefs-of-mission-terminations-since-date.xq
Created May 22, 2014 17:02
Principals & Chiefs whose positions ended after a certain date; using XQuery
xquery version "3.0";
(: Displays a list of Principals & Chiefs whose positions ended after a certain date. :)
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "html5";
declare option output:media-type "text/html";
let $all-people := collection('/db/cms/apps/principals-chiefs/data/')/person
let $cut-off := '2008-06-01'
@joewiz
joewiz / principal-officers-and-chiefs-of-mission-from-massachusetts.xq
Created April 21, 2014 20:12
Principal Officers and Chiefs of Mission from Massachusetts; using XQuery
xquery version "3.0";
(: Displays a list of Principals & Chiefs hailing from Massachusetts. :)
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "html5";
declare option output:media-type "text/html";
let $all-people := collection('/db/cms/apps/principals-chiefs/data/')/person
let $state := 'ma'
@joewiz
joewiz / store-files.xq
Created April 21, 2014 14:10
Upload a directory of XML files into eXist-db, with XQuery
xquery version "3.0";
(: Set the absolute file path appropriate for your OS :)
let $source-directory :=
(: Mac :)
(: '/Users/Joe/workspace/myapp/data' :)
(: Windows :)
'C:\Users\wicentowskijc\workspace\myapp\data'
let $target-collection :=
@joewiz
joewiz / days-since-date.xq
Created April 21, 2014 14:01
How many days have you been alive, with XQuery
xquery version "3.0";
declare function local:days-since-date($date as xs:date) {
let $duration := current-date() - $date
let $days := days-from-duration($duration)
return
$days
};
local:days-since-date(xs:date('2012-10-12'))