Skip to content

Instantly share code, notes, and snippets.

View emchateau's full-sized avatar

Emmanuel Château-Dutier emchateau

View GitHub Profile
@emchateau
emchateau / permutations.xq
Last active June 12, 2020 15:32
permutations in a sequence in XQuery
xquery version "3.1" ;
(:~
: permutations in a sequence in XQuery
: generates all unique orderings of each unique pair of elements, eliminating the x,x duplicates
:)
let $seq := (1, 2, 3, 4)
for $i in $seq
for $j in $seq
where $j != $i
return <pair>{($i, $j)}</pair>
@emchateau
emchateau / catesianProduct.xq
Last active June 12, 2020 15:44
Cartesian product of a sequence with XQuery
xquery version "3.1" ;
(:~
: Cartesian product of a sequence
: generates every possible pairing of elements, including all duplicates
:)
let $seq := (1, 2, 3, 4)
for $i in $seq
for $j in $seq
return <pair>{($i, $j)}</pair>
@emchateau
emchateau / euclid.xqy
Created May 20, 2020 23:58 — forked from CliffordAnderson/euclid.xqy
The Euclidean Algorithm in XQuery
xquery version "3.1";
(: The Euclidean algorithm calculates the lowest common denominator of two integers :)
declare function local:euclid($num1 as xs:integer, $num2 as xs:integer) as xs:integer*
{
if ($num1 > $num2) then local:euclid($num2, $num1 - $num2)
else if ($num2 > $num1) then local:euclid($num1, $num2 - $num1)
else $num1
};
@emchateau
emchateau / wikidata.md
Created May 20, 2020 23:55 — forked from CliffordAnderson/wikidata.md
Wikidata for Theological Librarians

Getting Started with Wikidata

This tutorial introduces the basics of Wikidata, an offshot of Wikipedia. Since its launch on October 30, 2012, Wikidata has developed rapidly and has become a repository of all kinds of facts across the Wikipedia language editions. In what follows, you will become familiar with the purpose and goals of Wikidata, including how to contribute to its development.

Learning Outcomes

  • Articulate the short and long term goals of Wikidata
  • Learn various ways to contribute Wikidata
  • Write simple SPARQL queries to retrieve data from Wikidata
  • Understand the potential of Wikidata for scholarly communications

XQuery Working Group

Text Mining at Scale

In this session, we will extract poems from the Victorian Women Writers Project. The electronic editions of these documents are maintained in TEI P5 format on Github. You can also download a zip file of the entire corpus.

The following exercises assume that you have loaded the documents from the Victorian Women Writers Project into a BaseX database. It is also assumed that you have named that database vwwp_tei.

@emchateau
emchateau / 00-introduction.md
Created May 20, 2020 23:54 — forked from CliffordAnderson/00-introduction.md
Code snippets for XQuery Working Group (Text Mining at Scale)

XQuery Working Group

XQuery and XPath Full Text 1.0

In this session, we will be exploring the XQuery and XPath Full Text 1.0 standard. Our goal is to take the records that we created during our prior class from the Victorian Women Writers Project and persist them to another database where we will analyze their contents for textual patterns.

The following exercises assume that you have loaded the documents from the Victorian Women Writers Project into a BaseX database. It is also assumed that you have named that database vwwp_tei.

@emchateau
emchateau / 00-introduction.md
Created May 20, 2020 23:54 — forked from CliffordAnderson/00-introduction.md
Text Mining at Scale (XQuery Working Group) Natural Language Processing

Natural Language Processing

Today, we’ll be exploring patterns in a corpus of genuine and fake news collected in 2016 by Buzz Feed and scored for veracity by professional journalists. As you might imagine, the corpus contains very partisan perspectives; individual articles may contain disturbing language and viewpoints. In the initial code example below, you will need to have downloaded the data set and have created a database called articles.

We’ll begin our investigation of natural language processing by using Aylien, which bill itself as a “News Intelligence Platform,” to classify these articles, analyze their topics, identify the people, places, things they discuss, and to discern the sentiment or tone of the articles. If you would like to follow along, please sign up for a free API key.

Artistic Influence

Introduction

This graph studies the relations of infuence between artists. The data comes from this query of Wikidata:

@emchateau
emchateau / palindrome.xqy
Created May 20, 2020 23:52 — forked from CliffordAnderson/palindrome.xqy
Recursive function to evaluate whether a phrase is a palindrome
xquery version "3.0";
(: Recursive function to evaluate whether a phrase is a palindrome :)
declare function local:test-palindrome($palindrome as xs:string?) as xs:boolean {
switch (fn:string-length($palindrome))
case 0 return fn:true()
case 1 return fn:true()
default return
let $first := fn:substring($palindrome, 1, 1)
@emchateau
emchateau / sortStringsBeforeLetters.xq
Created April 23, 2020 18:43
Sorts strings, prefer letters to numbers
(:~
: Sorts strings, prefer letters to numbers.
: @param $items strings to be sorted
: @return sorted sequence
: Christian Grün on SlackXML 2020
:)
declare function local:sort(
$items as xs:string*
) as xs:string* {
sort($items, (), function($item) {