Skip to content

Instantly share code, notes, and snippets.

@CliffordAnderson
Created March 23, 2015 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CliffordAnderson/e75fd3e4e3e569a661cf to your computer and use it in GitHub Desktop.
Save CliffordAnderson/e75fd3e4e3e569a661cf to your computer and use it in GitHub Desktop.
Pig Latin Converter
xquery version "3.0";
(: Takes a sentence in English and converts it to its equivalent in Pig Latin :)
(: Note that this expression does not handle punction :)
fn:string-join(
let $sentence := "I speak Pig Latin"
let $words := fn:tokenize($sentence, " ")
for $word in $words
let $vowels := ("a","e","i","o","u","y")
let $first-letter := fn:lower-case(fn:substring($word,1,1))
return
if ($first-letter = $vowels) then $word || "ay"
else fn:substring($word,2) || $first-letter || "ay"
, " ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment