Created
March 23, 2015 19:01
-
-
Save CliffordAnderson/6ed7e1f9a32abf15d9fd to your computer and use it in GitHub Desktop.
An Alternative Pig Latin Converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
declare function local:pig-parser($word as xs:string?) as xs:string? | |
{ | |
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 local:pig-parser(fn:substring($word,2) || $first-letter) | |
}; | |
string-join( | |
let $sentence := "I speak Pig Latin" | |
for $word in fn:tokenize($sentence, " ") | |
let $word := local:pig-parser($word) | |
return $word, " ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment