Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String NLP_verbPastTense(String verb){
- /*
- Simple past tense algorithm as defined: http://web2.uvcs.uvic.ca/elc/studyzone/330/grammar/pasted.htm
- Verb ending in...
- e | Add -D | e.g. live
- Consonant +y | Change y to i, then add -ED | e.g. try
- One vowel + one consonant (but NOT w or y) | Double the consonant, then add -ED | e.g. tap
- anything else including w | Add -ED | e.g. boil
- */
- Character consonants[] = {'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','x','y','z'};
- Character vowels[] = {'a', 'e', 'i', 'o', 'u'};
- String output = verb;
- if(verb.length()==0){return "";}
- if(verb.charAt(verb.length()-1)=='e'){
- output = verb + "d";
- }else if(Arrays.asList(consonants).contains(verb.charAt(verb.length()-2)) && verb.charAt(verb.length()-1)=='y'){
- output = verb.substring(0, verb.length()-1) + "ied";
- }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' )){
- output = verb + verb.charAt(verb.length()-1) + "ed";
- }else{
- output = verb + "ed";
- }
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement