Skip to content

Instantly share code, notes, and snippets.

@joewiz
joewiz / saxon-homebrew-macos-xquery.md
Last active April 7, 2022 16:50
Install saxon via homebrew for command line XQuery on macOS
@rlskoeser
rlskoeser / zotero-rdf-tags.py
Created November 3, 2016 16:28
Python script to generate CSV summary data from a Zotero RDF library export
#! /usr/bin/env python
# simple script to pull data from a Zotero library RDF export
# and generate a CSV file with identifier, type of item, title,
# date, and the number of tags
#
# Only supports book and bookSection item types, all other items are ignored
#
# The CSV file will be generated with the same base name as the
# RDF input file.
xquery version "3.1";
import module namespace http = "http://expath.org/ns/http-client";
(: For generating the personal access token to be used in this script, please select "public_repo | Access public repositories". :)
let $git-token := "<your-github-token>"
let $user-name := "<your-github-username>"
let $repo-name := "<your-repo-name>"
let $file-path := "<file=path>"
let $message := "<commit-message>"
let $new-file-content := serialize(<a/>)
@baskaufs
baskaufs / serialize.xqm
Created September 19, 2016 01:40
xquery module to serialize CSV table data as RDF/XML, RDF/Turtle, or JSON-LD
xquery version "3.1";
module namespace serialize = 'http://bioimages.vanderbilt.edu/xqm/serialize';
import module namespace propvalue = 'http://bioimages.vanderbilt.edu/xqm/propvalue' at 'c:/dropbox/swwg/code/propvalue.xqm';
(:--------------------------------------------------------------------------------------------------:)
declare function serialize:remove-last-comma($temp)
{
concat(fn:substring($temp,1,fn:string-length($temp)-2),"&#10;")
};
@joewiz
joewiz / csv-to-xml.xq
Last active August 30, 2023 23:19
Convert CSV to XML, with XQuery
xquery version "3.1";
(: XQuery adaptation of https://github.com/digital-preservation/csv-tools/blob/master/csv-to-xml_v3.xsl.
See also the thread on basex-talk https://mailman.uni-konstanz.de/pipermail/basex-talk/2016-September/011272.html.
:)
declare function local:get-cells($row as xs:string) {
(: workaround for lack of lookahead support: append comma to end of row :)
let $string-to-analyze := $row || ","
let $analyze := fn:analyze-string($string-to-analyze, '(("[^"]*")+|[^,]*),')
@DianaEromosele
DianaEromosele / Change "origin" of your GIT repository
Created August 7, 2016 00:31
Change "origin" of your GIT repository
$ git remote rm origin
$ git remote add origin git@github.com:aplikacjainfo/proj1.git
$ git config master.remote origin
$ git config master.merge refs/heads/master
@grantmacken
grantmacken / muURL.xqm
Last active March 8, 2023 00:13
xQuery helper functions for dealing with URLs
xquery version "3.0";
(:~
This module contains helper functions for dealing with URLs.
When receiving webmention the post parameter 'source' is a URL pointing to the
origin of the mention.
Before we get and store a sanitized version of an HTML document the url links to
we want to able to
@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";
@joewiz
joewiz / facet-case-1.xq
Last active December 27, 2015 21:09
EXPath Facet Spec workbook
xquery version "3.0";
(:~ An implementation of facet:count as described in "Case 1: Simple facet based on existing attribute"
of the EXPath Facet Spec. Depends on eXist's util:eval() function to handle dynamic path expressions.
@see http://expath.org/spec/facet/20151225#case-1-simple-facet-based-on-existing-attribute
:)
import module namespace util="http://exist-db.org/xquery/util";
xquery version "3.1";
(: Thanks to Tao You!! :)
declare function local:get_facet ($books as element()*, $path as xs:string, $facet_type as xs:string ) as element()?
{
<facet type="{$facet_type}">{
for $book in $books
let $fld := $book/*[name()=$path]
group by $f := $fld