Skip to content

Instantly share code, notes, and snippets.

@AdamSteffanick
Forked from CliffordAnderson/convert.xqy
Last active August 29, 2015 14:25
Show Gist options
  • Save AdamSteffanick/7348a0c890b2f13bc458 to your computer and use it in GitHub Desktop.
Save AdamSteffanick/7348a0c890b2f13bc458 to your computer and use it in GitHub Desktop.
XQuery Working Group Challenge
xquery version "3.1";
(: FUNCTION: Whether all the values in a sequence are distinct http://www.xqueryfunctions.com/xq/functx_are-distinct-values.html :)
declare namespace functx = "http://www.functx.com";
declare function functx:are-distinct-values
($seq as xs:anyAtomicType* ) as xs:boolean {
count(distinct-values($seq)) = count($seq)};
(: Converts sentences into verses and returns verses containing duplicate lemmata :)
(: Official release of the PROIEL treebank of ancient Indo-European languages :)
let $uri := "https://raw.githubusercontent.com/proiel/proiel-treebank/master/latin-nt.xml"
let $doc := fn:doc($uri)
for $citation in fn:distinct-values(fn:data($doc//token/@citation-part))
let $tokens := $doc//token[./@citation-part = $citation]
where fn:not(functx:are-distinct-values($tokens/@lemma))
return element verse {
attribute citation {$citation},
fn:data($tokens[./@citation-part = $citation]/@form)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment