Skip to content

Instantly share code, notes, and snippets.

View mathias-goebel's full-sized avatar
🎠
black pony

Mathias mathias-goebel

🎠
black pony
View GitHub Profile
@mathias-goebel
mathias-goebel / http-post-form.xql
Created April 9, 2020 04:39
EXPath HTTP Client post form data – an example
let $parameter1 := "one"
let $parameter2 := "two"
let $parameter3 := "three"
let $boundary := current-dateTime() => util:hash("md5") => substring(0,17)
let $request :=
<hc:request method="POST" href="{ $webauthUrl }" http-version="1.0">
<hc:header name="Connection" value="close" />
<hc:multipart media-type="multipart/form-data" boundary="------------------------{$boundary}">
<hc:header name="Content-Disposition" value='form-data; name="parameter1"'/>
<hc:body media-type="text/plain">{$parameter1}</hc:body>
@mathias-goebel
mathias-goebel / convert.xq
Created December 10, 2018 13:30
eXist-db http client with easyrdf converter
xquery version "3.1";
let $content :=
<httpclient:fields>
<httpclient:field name="data" value="" type="string"/>
<httpclient:field name="in" value="guess" type="string"/>
<httpclient:field name="out" value="rdfxml" type="string"/>
<httpclient:field name="raw" value="1" type="string"/>
<httpclient:field name="uri" value="http://njh.me/" type="string"/>
</httpclient:fields>
@mathias-goebel
mathias-goebel / wikidata.xq
Created September 3, 2018 16:16
wikidata to dracor
xquery version "3.1";
import module namespace functx="http://www.functx.com";
declare namespace tei="http://www.tei-c.org/ns/1.0";
let $path := "......../dlina/GerDraCor and Wikidata.csv"
let $rows :=
(file:read-binary($path)
=> util:binary-to-string()
=> tokenize("\n"))[position() gt 1]
@mathias-goebel
mathias-goebel / wikidata.xq
Created September 3, 2018 16:16
wikidata to dracor
xquery version "3.1";
import module namespace functx="http://www.functx.com";
declare namespace tei="http://www.tei-c.org/ns/1.0";
let $path := "......../dlina/GerDraCor and Wikidata.csv"
let $rows :=
(file:read-binary($path)
=> util:binary-to-string()
=> tokenize("\n"))[position() gt 1]
@mathias-goebel
mathias-goebel / convert.xq
Created December 12, 2017 10:53
TCF to sentence in plain text
xquery version "3.1";
declare namespace dta="http://www.dspin.de/data/textcorpus";
declare function local:load-dta($source, $target) {
let $collection-uri := $target,
$directory := $source,
$pattern := "**/*",
$mime-type := "application/xml",
$preserve-structure := true()
@mathias-goebel
mathias-goebel / restore.xq
Last active October 20, 2017 08:35
eXist-db restoring from XQuery
xquery version "3.1";
declare function local:do($path-external as xs:string, $path-internal as xs:string) {
let $list := file:list( $path-external )
return (
for $dir in $list/file:directory
let $name := replace(string( $dir/@name ), "\s", "_")
return(
@mathias-goebel
mathias-goebel / TextGrid-CRUD.xq
Created October 7, 2016 13:23
Store nodes in the TextGrid Repository
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
(: TextGrid CRUD
: Store nodes in the TextGrid Repository
: https://textgridlab.org/doc/services/submodules/tg-crud/docs/index.html#create
: :)
(: ESX-2 = productive :)
@mathias-goebel
mathias-goebel / query.xq
Created May 30, 2016 21:08
TextGrid Agg Names
xquery version "3.0";
declare namespace ore="http://www.openarchives.org/ore/terms/";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
let $seq:= ("textgrid:jfsm.0",
"textgrid:jg0m.0",
"textgrid:jk7p.0",
"textgrid:jkhw.0",
@mathias-goebel
mathias-goebel / lb-handling.xquery
Created May 18, 2016 12:13
TEI:lb and other empty elements in XQuery
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare function local:magic($nodes as node()*) {
(:let $test:= console:log($nodes/local-name()):)
(:return:)
for $node in $nodes return
typeswitch($node)
case element(*)
@mathias-goebel
mathias-goebel / TEI-JSON.xq
Created March 8, 2016 10:59
sunburst tree for TEI data
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare option exist:serialize "method=text media-type=text/plain omit-xml-declaration=yes";
declare function local:recurse($node as node()*) as xs:string* {
for $n in $node
return(
'{' ||
string-join(
('"name": "', $n/local-name(), '"',
if( not($n/*) )