List:Commits« Previous MessageNext Message »
From:eherman Date:October 20 2007 7:29pm
Subject:bk commit into 6.0 tree (eherman:1.2638)
View as plain text  
Below is the list of changes that have just been committed into a local
6.0 repository of eric. When eric does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-10-20 21:29:12+02:00, eherman@stripped +3 -0
  "yay" to "way" conversion per wikipedia Pig Latin
  deal with special cases: qu, ALL CAPS, y as the second letter
  simplified implementation

  plugin/java_udf/com/mysql/udf/test/JniSimulationTest.java@stripped, 2007-10-20 21:29:07+02:00, eherman@stripped +2 -2
    made more obvious that it's pig latin.

  plugin/java_udf/test/PigLatin.java@stripped, 2007-10-20 21:29:07+02:00, eherman@stripped +45 -19
    "yay" to "way" conversion per wikipedia Pig Latin
    deal with special cases: qu, ALL CAPS, y as the second letter
    ditch the enumeration of compoundConsonants

  plugin/java_udf/test/PigLatinTest.java@stripped, 2007-10-20 21:29:08+02:00, eherman@stripped +9 -3
    "yay" to "way" conversion per wikipedia Pig Latin
    Added all sorts of extra special cases: ALL CAPS, y as the second letter,

diff -Nrup a/plugin/java_udf/com/mysql/udf/test/JniSimulationTest.java b/plugin/java_udf/com/mysql/udf/test/JniSimulationTest.java
--- a/plugin/java_udf/com/mysql/udf/test/JniSimulationTest.java	2007-10-20 19:38:30 +02:00
+++ b/plugin/java_udf/com/mysql/udf/test/JniSimulationTest.java	2007-10-20 21:29:07 +02:00
@@ -69,9 +69,9 @@ public class JniSimulationTest extends T
         invoker.init();
 
         // function execute
-        callback.setArgs(Collections.singletonList("one"));
+        callback.setArgs(Collections.singletonList("trivial example"));
         invoker.exec();
-        assertEquals("oneyay", callback.resultAsString());
+        assertEquals("ivialtray exampleway", callback.resultAsString());
 
         callback.setArgs(Collections.singletonList("Pig Latin."));
         invoker.exec();
diff -Nrup a/plugin/java_udf/test/PigLatin.java b/plugin/java_udf/test/PigLatin.java
--- a/plugin/java_udf/test/PigLatin.java	2007-10-20 20:13:43 +02:00
+++ b/plugin/java_udf/test/PigLatin.java	2007-10-20 21:29:07 +02:00
@@ -1,29 +1,39 @@
 package test;
 
-import java.util.Arrays;
-import java.util.List;
-
 public class PigLatin {
 
-    /* I'm sure there are more of these ... */
-    private static List compoundConsonants = Arrays.asList(new String[] { "bl",
-            "br", "ch", "cl", "cr", "dr", "dw", "fl", "fr", "gl", "gr", "th",
-            "kl", "kn", "ph", "pl", "pn", "pr", "sc", "sh", "sk", "sl", "sn",
-            "sm", "sp", "sq", "st", "sw", "tr", "tw", "wh", "wr" });
-
     public static String toPigLatin(String english) {
+        if (english == null) {
+            return null;
+        }
+
         String[] words = english.split(" ");
 
         String pigLatin = "";
 
         for (int i = 0; i < words.length; i++) {
-            pigLatin += pigLatinizeWord(words[i]) + " ";
+            pigLatin += pigLatinizeWord(words[i], allUpper(english)) + " ";
         }
 
         return pigLatin.trim();
     }
 
-    static String pigLatinizeWord(String word) {
+    private static boolean allUpper(String english) {
+        if (english.length() < 2) {
+            // "I" becomes 'Iway"
+            return false;
+        }
+        boolean allUpper = true;
+        for (int i = 0; i < english.length(); i++) {
+            char c = english.charAt(i);
+            if (Character.isLetter(c) && Character.isLowerCase(c)) {
+                allUpper = false;
+            }
+        }
+        return allUpper;
+    }
+
+    private static String pigLatinizeWord(String word, boolean allUpper) {
         if (word.length() == 0) {
             return word;
         }
@@ -54,17 +64,33 @@ public class PigLatin {
             word = word.substring(0, word.length() - 1);
         }
 
-        boolean capitalize = Character.isUpperCase(word.charAt(0));
-        word = word.toLowerCase();
+        boolean capitalize = false;
+        if (!allUpper) {
+            capitalize = Character.isUpperCase(word.charAt(0));
+            word = word.toLowerCase();
+        }
 
-        String suffix = "ay";
-        int offset = 1;
+        String vowels = "aeiouAEIOU"; // no 'y' as the first letter
+        int offset = 0;
+        while (vowels.indexOf(word.charAt(offset)) < 0) {
+            if (offset == 0) {
+                vowels += "yY"; // but is a vowel as the second letter;
+            }
+            offset++;
+        }
 
-        if ("aeiou".indexOf(word.charAt(0)) >= 0) {
-            suffix = "yay";
-            offset = 0;
-        } else if (compoundConsonants.contains(word.substring(0, 2))) {
+        // queen -> eenquay
+        if (offset == 1 && word.length() > 2
+                && Character.toLowerCase(word.charAt(0)) == 'q'
+                && Character.toLowerCase(word.charAt(1)) == 'u') {
             offset = 2;
+        }
+
+        String suffix;
+        if (offset == 0) {
+            suffix = (allUpper) ? "WAY" : "way";
+        } else {
+            suffix = (allUpper) ? "AY" : "ay";
         }
 
         String pigLatin = word.substring(offset) + word.substring(0, offset)
diff -Nrup a/plugin/java_udf/test/PigLatinTest.java b/plugin/java_udf/test/PigLatinTest.java
--- a/plugin/java_udf/test/PigLatinTest.java	2007-10-20 19:38:31 +02:00
+++ b/plugin/java_udf/test/PigLatinTest.java	2007-10-20 21:29:08 +02:00
@@ -11,21 +11,27 @@ public class PigLatinTest extends TestCa
     public void testPigLatin() {
         check("foo", "oofay");
 
-        check("I", "Iyay");
-        check("is an", "isyay anyay");
+        check("I", "Iway");
+        check("is an", "isway anway");
 
         check("slow", "owslay");
         check("pnumonia", "umoniapnay");
         check("knock", "ockknay");
         check("write", "itewray");
+        check("string", "ingstray");
+        check("question", "estionquay");
+        check("you system", "ouyay ystemsay");
 
         check("Pig Latin", "Igpay Atinlay");
         check("Pig Latin.", "Igpay Atinlay.");
         check("Pig ... Latin.", "Igpay ... Atinlay.");
         check("be 40 Pig ... Latin.", "ebay 40 Igpay ... Atinlay.");
 
+        check("THIS IS A TEST", "ISTHAY ISWAY AWAY ESTTAY");
+
+        // from: http://en.wikipedia.org/wiki/Pig_Latin
         String english = "This is an example of Pig Latin. As you can see, it is silly, but sort of fun for children.";
-        String pigLatin = "Isthay isyay anyay exampleyay ofyay Igpay Atinlay. Asyay ouyay ancay eesay, ityay isyay illysay, utbay ortsay ofyay unfay orfay ildrenchay.";
+        String pigLatin = "Isthay isway anway exampleway ofway Igpay Atinlay. Asway ouyay ancay eesay, itway isway illysay, utbay ortsay ofway unfay orfay ildrenchay.";
         check(english, pigLatin);
     }
 }
Thread
bk commit into 6.0 tree (eherman:1.2638)eherman24 Oct