Skip to content

Instantly share code, notes, and snippets.

View emchateau's full-sized avatar

Emmanuel Château-Dutier emchateau

View GitHub Profile
xquery version "3.0";
(: find the shortest and longest article and get the average word count of a collection of TEI XML articles :)
declare namespace tei="http://www.tei-c.org/ns/1.0";
(: in our case, 'articles' are TEI divs that have @xml:id attributes and no child divs;
we filter out the foreward since they're not full articles. :)
let $milestone-articles := collection('/db/cms/apps/tei-content/data/milestones')//tei:div[@xml:id and not(.//tei:div)][@xml:id ne 'foreword']
let $article-infos :=
xquery version "3.0";
declare namespace fn="http://www.w3.org/2005/xpath-functions";
(: Fix problems with mis-capitalized names. For example:
Before: MACARTHUR, Douglas II
After: MacArthur, Douglas II
:)
declare function local:fix-name-capitalization($name as xs:string) {
(:
xquery version "1.0";
(: A naive approach to sentence tokenization inspired by http://stackoverflow.com/a/2103653/659732
:
: Works well with edited text like newspapers. Parameters like punctuation can/should be edited;
: see the section below called "criteria".
:
: For a more sophisticated approach, see Tibor Kiss and Jan Strunk, "Unsupervised Multilingual
: Sentence Boundary Detection", Computational Linguistics, Volume 32, Issue 4, December 2006,
: pp. 485-525. Also, see these discussions of sentence tokenization:
javascript:(function({
var INSTAPAPER=true,w=window,d=document,pageSelectedTxt=w.getSelection?w.getSelection():(d.getSelection)?d.getSelection():(d.selection?d.selection.createRange().text:0),pageTitle=d.title,pageUri=w.location.href,tmplt="";
tmplt="From ["+pageTitle+"]("+pageUri+"):\n\n";
if(pageSelectedTxt!="") {
pageSelectedTxt=">%20"+pageSelectedTxt;
pageSelectedTxt=pageSelectedTxt.replace(/(\r\n|\n+|\r)/gm,"\n");
pageSelectedTxt=pageSelectedTxt.replace(/\n/g,"\n>%20\n>%20");
w.location.href="nvalt://make/?txt="+encodeURIComponent(tmplt+pageSelectedTxt)+"&title="+encodeURIComponent(pageTitle)
}
else {
@emchateau
emchateau / selectAllExceptFirstAndLast
Last active January 2, 2016 00:49
sélectionne tout sauf le premier et le dernier élément dans une liste
<!--
title: selectAllExceptFirstAndLast
description: sélectionne tout sauf le premier et le dernier élément dans une liste
version: xslt 1.0
-->
<xsl:for-each select="element[not(position() = (1, last() ))]">
<xsl:value-of select="." separator=", "/>
</xsl:for-each>
@emchateau
emchateau / bxListFiles
Created February 18, 2014 11:56
List all files in the directory of your query file in BaseX
(: list all files in the directory of your query file in BaseX :)
let $dir := file:parent(static-base-uri())
for $file in file:list($dir)
return $dir || $file
@emchateau
emchateau / bxCurrentWorkingDir
Created February 18, 2014 11:57
Find out the current working directory in BaseX
(: find out the current working directory in BaseX :)
file:parent('.')
<?xml version="1.0" encoding="UTF-8"?>
<!--
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@Name : .xsl
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@version : 000
@creaDate : 2014/
@modifDate
@vXslt: 2.0
@autor : Emmanuel Château [email protected]
@emchateau
emchateau / splitContentAsAttributeValues.xsl
Last active August 29, 2015 14:01
Split content as attribute values
<!-- Split content as attribute value -->
<xsl:template match="element[@id]">
<xsl:variable name="att-values" select="tokenize(@id, ', ')"/>
<xsl:for-each select="tokenize(., '; ')">
<xsl:variable name="pos" select="position()"/>
<xsl:if test="position() gt 1"><xsl:text>; </xsl:text></xsl:if>
<a href="#{$att-values[$pos]}">
<xsl:value-of select="."/>
</a>
</xsl:for-each>
<div>
<h2>{$heading} - {count($actions/generate)}</h2>
<p>Actions are processes that generate a new item from an existing item.</p>
<div>
{$partial("action1.xml","action",$actions/generate )}
</div>
</div>