Permalink
Browse files

fixed the bug related to "and" as in " one hundred and fifty".

  • Loading branch information...
1 parent aa12123 commit 99d3a89398e97170eb7acb93986d36a5e7ec9e0c @aasish committed Apr 29, 2011
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
@@ -14,7 +14,6 @@ public static String segmentNum(String wordNumber)
ArrayList<String> items = new ArrayList<String>();
for (int i = 0; i < arrayStr.length; i++){items.add(arrayStr[i]);}
-
String[] digit = {"one","two","three","four","five","six","seven","eight","nine"};
List list_digit = Arrays.asList(digit);
String[] special = {"zero","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
@@ -23,6 +22,8 @@ public static String segmentNum(String wordNumber)
List list_ten = Arrays.asList(ten);
String[] hundred = {"one hundred","two hundred","three hundred","four hundred","five hundred","six hundred","seven hundred","eight hundred","nine hundred"};
List list_hundred = Arrays.asList(hundred);
+ String[] AND = {"and"};
+ List list_and = Arrays.asList(AND);
ArrayList<String> list = new ArrayList<String>();
@@ -31,6 +32,7 @@ public static String segmentNum(String wordNumber)
int present_class = 0;
String add_element;
//System.out.println(items.get(i));
+
if (items.get(i).equals("hundred"))
{
//System.out.println("find hundred");
@@ -46,15 +48,23 @@ public static String segmentNum(String wordNumber)
}
String final_str = "";
String i = null;
+ int prev_is_and = 0;
for(int j = 0; j < list.size();j++){
int present_class = 999;
//System.out.println(list.get(j));
i = list.get(j);
+ if (list_and.contains(i)){prev_is_and = 1;continue;}
if (list_digit.contains(i)){present_class = 1;}
else if(list_ten.contains(i)){present_class = 2;}
else if(list_hundred.contains(i)){present_class = 3;}
else if(list_special.contains(i)){present_class = 0;}
- if (present_class != 0){
+ if (prev_is_and == 1){
+ final_str = final_str + i +' ';
+ prev_is_and = 0;
+
+
+ }
+ else if (present_class != 0){
if(present_class >= prev_class){final_str = final_str +"| "+i+" ";}
else {final_str = final_str + i + " ";}
prev_class = present_class;
@@ -69,7 +79,7 @@ public static String segmentNum(String wordNumber)
prev_class = present_class;
}
System.out.println(final_str);
-
+
return final_str;
}

0 comments on commit 99d3a89

Please sign in to comment.