Skip to content

Instantly share code, notes, and snippets.

@wsalesky
wsalesky / facets.rq
Created June 15, 2018 13:54
POC of facets used on SPEAR data Syriaca.org. This is a work in progress.
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix cwrc: <http://sparql.cwrc.ca/ontologies/cwrc#>
prefix dcterms: <http://purl.org/dc/terms/>
prefix lawd: <http://lawd.info/ontology/>
prefix person: <https://www.w3.org/ns/person>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix snap: <http://data.snapdrgn.net/ontology/snap#>
prefix syriaca: <http://syriaca.org/schema#>
@wsalesky
wsalesky / spear-source.rq
Created May 14, 2018 18:07
Get SPEAR sources
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix lawd: <http://lawd.info/ontology/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix dcterms: <http://purl.org/dc/terms/>
SELECT ?source ( count(?source) as ?sourceCount )
WHERE {
?s dcterms:source ?source;
dcterms:isPartOf <http://syriaca.org/spear>.
@wsalesky
wsalesky / realtions-citations.rq
Last active May 8, 2018 12:53
SPARQL query to get citations and related subjects for Syriaca.org data
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix lawd: <http://lawd.info/ontology/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix dcterms: <http://purl.org/dc/terms/>
SELECT ?uri (SAMPLE(?l) AS ?label) (SAMPLE(?uriSubject) AS ?subjects) (SAMPLE(?uriCitations) AS ?citations)
{
?uri rdfs:label ?l
FILTER (?uri IN ( <http://syriaca.org/person/782>,<http://syriaca.org/person/552>,<http://syriaca.org/person/684>,<http://syriaca.org/person/492>)).
FILTER ( langMatches(lang(?l), 'en')).
@wsalesky
wsalesky / git-sync-v2.xql
Created November 30, 2017 18:57
Update git-sync XQuery to use eXistdb's native JSON parser.
xquery version "3.1";
(:~
: Webhook endpoint for tcadrt.com data repository, /master/ branch:
: XQuery endpoint to respond to Github webhook requests. Query responds only to push requests from the master branch.

: The EXPath Crypto library supplies the HMAC-SHA1 algorithm for matching Github secret. 

:
: Secret can be stored as environmental variable.
: Will need to be run with administrative privileges, suggest creating a git user with privileges only to relevant app.
:
/*
* eXist Open Source Native XML Database
* Copyright (C) 2001-2015 The eXist Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
@wsalesky
wsalesky / strip-diacritics.xq
Last active October 4, 2017 15:27 — forked from joewiz/strip-diacritics.xq
Strip diacritics, with XQuery
xquery version "3.1";
declare function local:strip-diacritics($string as xs:string) as xs:string {
let $normalized := normalize-unicode($string, 'NFD')
let $stripped := replace($normalized, '\p{M}', '')
return
$stripped
};
declare function local:inspect-diacritics($string as xs:string) as element() {
@wsalesky
wsalesky / facets.xqm
Last active September 20, 2016 13:58
Partial facet implementation for eXist-db based on the EXPath specifications (http://expath.org/spec/facet)
xquery version "3.0";
(:~
: Partial facet implementation for eXist-db based on the EXPath specifications (http://expath.org/spec/facet)
:
: Uses the following eXist-db specific functions:
: util:eval
: request:get-parameter
: request:get-parameter-names()
:
: @author Winona Salesky
let $list := ("http://syriaca.org/person/1631", "http://syriaca.org/person/1442")
for $item in $list
let $uri := $item
return
for $idno in fn:collection('/db/apps/srophe-data/data/persons/tei')//tei:person[tei:idno[. = $uri]]
let $name := $idno/tei:persName[@xml:lang="en"][contains(@syriaca-tags,"#syriaca-headword")]
let $newName :=
<persName xmlns="http://www.tei-c.org/ns/1.0" xml:id="{concat('name',substring-after($idno,'/person/'),'-a')}"
xml:lang="en" syriaca-tags="#syriaca-headword">Anonymi {substring-after($idno,'/person/')}</persName>
xquery version "3.0";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare function local:download-xml($node, $filename) {
response:set-header("Content-Disposition", concat("attachment;
filename=", $filename))
,
response:stream(
$node,
'indent=yes' (: serialization :)
@wsalesky
wsalesky / update-event-persName.xql
Created June 30, 2016 02:14
Update persNames in attestations with headwords and @ref
xquery version "3.0";
import module namespace functx="http://www.functx.com";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare function local:parse-name($name){
if($name/child::*) then
string-join(for $part in $name/child::*
order by $part/@sort ascending, string-join($part/descendant-or-self::text(),' ') descending
return $part/text(),' ')
else $name/text()