Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<compounds>
<word>bookcase</word>
<word>classmate</word>
<word>bookmark</word>
<word>newspaper</word>
</compounds>
xquery version "3.1";
let $word1 := "book"
let $word2 := "mark"
let $compound-word := fn:concat($word1, $word2)
return $compound-word
xquery version "3.1";
let $word1 := "Governor"
let $word2 := "General"
let $compound-word := fn:concat($word1, $word2)
return $compound-word
xquery version "3.1";
let $word1 := "Governor"
let $word2 := "General"
let $delimiter := " "
let $compound-word := fn:string-join(($word1, $word2), $delimiter)
return $compound-word
<compounds>
<word>bookcase</word>
<word>classmate</word>
<word>bookmark</word>
<word>newspaper</word>
<word>Governor General</word>
<word>Surgeon General</word>
<word>in-law</word>
<word>mother-in-law</word>
<word>father-in-law</word>
</compounds>
xquery version "3.1";
declare function local:form-plural-compound($compound-words as node()*) as node()* {
let $plural-suffix := "s"
let $delimiter := (" ", "-")
return element compounds {
for $compound-word in $compound-words/compounds/word/text()
order by fn:lower-case($compound-word)
return element word {
attribute singular {$compound-word},
if (fn:contains($compound-word, $delimiter[1])) then
let $compound-head := fn:substring-before($compound-word, $delimiter[1])
return fn:replace($compound-word, $compound-head, fn:concat($compound-head, $plural-suffix))
else if (fn:contains($compound-word, $delimiter[2]) and fn:count(fn:tokenize($compound-word, $delimiter[2])) > 2) then
let $compound-head := fn:substring-before($compound-word, $delimiter[2])
return fn:replace($compound-word, $compound-head, fn:concat($compound-head, $plural-suffix))
else
fn:concat($compound-word, $plural-suffix)
}
}
};
let $uri := "https://gist.githubusercontent.com/AdamSteffanick/eed120f4b5915dfb73900ea4bfdf3ace/raw/1289cd32578393ad9f4ef278959f59e0aebf6f8a/even-more-compound-words.xml"
let $dataset := fn:doc($uri)
return local:form-plural-compound($dataset)
<compounds>
<word>bookcase</word>
<word>classmate</word>
<word>bookmark</word>
<word>newspaper</word>
<word>Governor General</word>
<word>Surgeon General</word>
</compounds>
xquery version "3.1";
let $uri := "https://gist.githubusercontent.com/AdamSteffanick/eed120f4b5915dfb73900ea4bfdf3ace/raw/7bc420051ca0bceaa4252c6bef67157235213767/compound-words.xml"
let $compound-words := fn:doc($uri)
return $compound-words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.