Advertisement
Guest User

Untitled

a guest
Mar 1st, 2012
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1.  
  2.     public static String NLP_verbPastTense(String verb){
  3.        
  4.         /*
  5.             Simple past tense algorithm as defined: http://web2.uvcs.uvic.ca/elc/studyzone/330/grammar/pasted.htm
  6.            
  7.             Verb ending in...  
  8.             e                                           | Add -D                                    | e.g. live
  9.             Consonant +y                                | Change y to i, then add -ED               | e.g. try
  10.             One vowel + one consonant (but NOT w or y)  | Double the consonant, then add -ED        | e.g. tap
  11.             anything else including w                   | Add -ED                                   | e.g. boil
  12.          */
  13.        
  14.        
  15.         Character consonants[] = {'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','x','y','z'};
  16.         Character vowels[] = {'a', 'e', 'i', 'o', 'u'};
  17.        
  18.         String output = verb;
  19.        
  20.         if(verb.length()==0){return "";}
  21.        
  22.         if(verb.charAt(verb.length()-1)=='e'){
  23.             output = verb + "d";
  24.         }else if(Arrays.asList(consonants).contains(verb.charAt(verb.length()-2)) && verb.charAt(verb.length()-1)=='y'){
  25.             output = verb.substring(0, verb.length()-1) + "ied";
  26.         }else if(verb.length()>2 && !Arrays.asList(vowels).contains(verb.charAt(verb.length()-3)) && Arrays.asList(vowels).contains(verb.charAt(verb.length()-2)) && ( Arrays.asList(consonants).contains(verb.charAt(verb.length()-1)) && verb.charAt(verb.length()-1)!='w' && verb.charAt(verb.length()-1)!='y' )){
  27.             output = verb + verb.charAt(verb.length()-1) + "ed";
  28.         }else{
  29.             output = verb + "ed";
  30.         }
  31.        
  32.        
  33.         return output;
  34.        
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement