Skip to content

Instantly share code, notes, and snippets.

View timathom's full-sized avatar

Tim Thompson timathom

  • Yale University Library
  • New Haven, CT
View GitHub Profile
@timathom
timathom / xqy14_sandbox
Last active August 29, 2015 14:02
XQuery Institute Sandbox
(: Looking for Antony's longest speech in "Julius Caesar." Is there a better path? :)
//ab[parent::sp/speaker[w="ANTONY"]][count(.//w) eq max(//ab[parent::sp/speaker[w="ANTONY"]]/count(.//w))]
================================
declare default element namespace "http://www.tei-c.org/ns/1.0";
<speech>{
for $sp in //sp
let $speaker := $sp/speaker
(: Group all actors by Act and Scene :)
(: XQuery solution :)
declare namespace tei="http://www.tei-c.org/ns/1.0";
<results>{
for $actors in //tei:stage/@who
for $actor in $actors ! tokenize(., ' ')
group by $actor
@timathom
timathom / for-each-pair.xq
Last active August 29, 2015 14:02
Use case for fn:for-each-pair
(: See http://stackoverflow.com/questions/17975306/aligning-fields-based-on-position-using-xslt :)
(: XML input :)
(:
<?xml version="1.0" encoding="UTF-8"?>
<collections>
<collection name="anyCollection">
<record>
<field name="materia">comida; bebida; fiesta</field>
@timathom
timathom / select-all-by-group
Last active August 29, 2015 14:23
XForms select-all-by-group checkboxes in XSLTForms
<?xml-stylesheet type="text/xsl" href="http://localhost:8080/exist/apps/xsltforms/xsltforms.xsl"?><?css-conversion no?><?xsltforms-options debug="yes"?><?xml-model href="http://www.oxygenxml.com/1999/xhtml/xhtml-xforms.nvdl" schematypens="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"?>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:bf="http://bibframe.org/vocab/"
xmlns:cwb="http://libserv6.princeton.edu/cwb/"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<head>
<meta
@timathom
timathom / sparql-query.xhtml
Last active March 17, 2016 23:08
XForms submission to request non-XML RDF formats from a SPARQL endpoint (DBpedia)
<?xml-stylesheet href="../build/xsltforms.xsl" type="text/xsl"?><?xsltforms-options debug="no"?><?css-conversion no?><?xml-model href="http://www.oxygenxml.com/1999/xhtml/xhtml-xforms.nvdl" schematypens="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"?>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:cwb="http://example.org/cwb/"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
@timathom
timathom / get-turtle.xhtml
Last active September 7, 2016 06:34
XForms doc and RESTXQ module for retrieving Turtle RDF data
<?xml-stylesheet href="xsltforms/xsltforms.xsl" type="text/xsl"?><?xsltforms-options debug="no"?><?css-conversion no?><?xml-model href="http://www.oxygenxml.com/1999/xhtml/xhtml-xforms.nvdl" schematypens="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"?>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:cwb="http://example.org/cwb/"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
@timathom
timathom / turtle.xqm
Created February 26, 2016 17:19
XQuery Turtle parser (generated by Gunther Rademacher's REx)
xquery version "1.0" encoding "UTF-8";
(: This file was generated on Sat Feb 13, 2016 20:32 (UTC-05) by REx v5.35 which is Copyright (c) 1979-2015 by Gunther Rademacher <grd@gmx.net> :)
(: REx command line: turtle.ebnf -faster -xquery -tree :)
(:~
: The parser that was generated for the turtle grammar.
:)
module namespace p="turtle";
declare default function namespace "http://www.w3.org/2005/xpath-functions";
@timathom
timathom / basex-async.xq
Last active March 21, 2016 13:41
Anonymous inline function with asynchronous evaluation in BaseX
(:~
: Anonymous inline function with asynchronous evaluation in BaseX 8.4.1 beta
:
: @param $query Asynchronously evaluated query
: @return XQuery expression, followed by result of async HTTP request.
:
: BaseX Async Module:
: http://docs.basex.org/wiki/Async_Module
:
: Dimitre Novatchev on recursion with anonymous inline functions in XPath 3.0:
@timathom
timathom / turtle.xml
Created March 3, 2016 20:44
Turtle EBNF syntax tree in XML
<?xml version="1.0" encoding="UTF-8"?>
<turtleDoc>
<statement>
<directive>
<prefixID>
<TOKEN>@prefix</TOKEN>
<PNAME_NS>bf:</PNAME_NS>
<IRIREF>&lt;http://bibframe.org/vocab/&gt;</IRIREF>
<TOKEN>.</TOKEN>
</prefixID>
@timathom
timathom / pymarc_disco.py
Created September 21, 2017 15:28 — forked from anarchivist/pymarc_disco.py
sample MapReduce tasks for Disco to get tag counts from MARC files/streams
#!/usr/bin/env python
#
# pymarc_disco.py - Mark Matienzo
# sample MapReduce tasks for Disco to get tag counts from MARC files/streams
# usage: python pymarc_disco.py <input1> [input2 ... inputN]
import sys
from disco.core import Disco, result_iterator
from disco.settings import DiscoSettings
import pymarc