Re: Nice Automator article on O'Reilly
Re: Nice Automator article on O'Reilly
- Subject: Re: Nice Automator article on O'Reilly
- From: David Marshall <email@hidden>
- Date: Sat, 7 May 2005 00:08:52 -0400
"Gary (Lists)" wrote:
Sloppy, poor Pig Grammar and no punctuation but funny, nonetheless.
The punctuation, though essential to a polished project, is too tedious
to contemplate at the moment.
I'm not sure of the formal syntax of Pig Latin; the way I learned it,
words beginning with vowels are translated with "way" appended:
"asparagus" --> "asparagusway" (notice that I also omit the "-" prior
to the suffix). I translate words with fewer than 3 letters, too, but
I'll accept your exclusion of "the." :-)
- - - - -
--> lots of line wrapping here
property vowels : {"a", "e", "i", "o", "u"}
property noPig : {"the"}
set AppleScript's text item delimiters to ""
set mySentence to text returned of (display dialog "text to parse:" &
return & return default answer "")
-->"Yvan answered Yes to Qatar Street question"
set myWords to words of mySentence
set pigWords to {}
repeat with aWord in myWords
if (aWord is not in noPig) then
set aWord to parseChars(aWord)
end if
copy aWord & " " to end of pigWords
end repeat
set pigSentence to characters 1 thru -2 of (pigWords as text) as text
display dialog "\"" & mySentence & "\"" & " in Pig Latin is " & "\"" &
pigSentence & "\""
-->"Yvanway answeredway esYay otay atarQay eetStray estionquay"
on parseChars(thisWord)
set firstChar to first character of thisWord
ignoring case
if firstChar is "y" then
if second character of thisWord is in vowels then
set wordOut to (characters 2 thru end of thisWord as text) &
firstChar & "ay"
else
set wordOut to thisWord & "way"
end if
else
if firstChar is "q" then
if second character of thisWord is "u" then
set wordOut to (characters 3 thru end of thisWord as text) &
firstChar & "uay"
else
set wordOut to (characters 2 thru end of thisWord as text) &
firstChar & "ay"
end if
else
if firstChar is in vowels then
set wordOut to thisWord & "way"
else
set wordOut to parseConsonants(thisWord) & "ay"
end if
end if
end if
end ignoring
end parseChars
on parseConsonants(subWord)
set subWord to characters of subWord
if second item of subWord is in vowels then
return (rest of subWord & first item of subWord) as text
else
set thisSubWord to (rest of subWord & first item of subWord) as text
parseConsonants(thisSubWord)
end if
end parseConsonants
- - - - -
Dave
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden