160 likes | 383 Views
“Introduction to Programming With Java”. Lecture - 11 U MESH P ATIL (umesh@cse.iitb.ac.in). nlp-ai@cse.iitb. Contents for Today’s Lecture. Programming practice: Program for morphological analysis of English nouns. nlp-ai@cse.iitb. Problem .
E N D
“Introduction to Programming With Java” Lecture - 11 UMESHPATIL (umesh@cse.iitb.ac.in) nlp-ai@cse.iitb
Contents for Today’s Lecture • Programming practice: Program for morphological analysis of English nouns. nlp-ai@cse.iitb
Problem Write a Java program that finds out the root & suffix of the given noun plural in English. Also print the morphology rule applied for forming the plural. Sample input & output –Input:boysOutput: root = boy suffix = s Morphology rule = [[W]] [[W][s]] Input:indicesOutput: root = index suffix = ices Morphology rule = [[W][ex]] [[W][ices]] nlp-ai@cse.iitb
Plurals in English • Example • boy boys • bus buses • lady ladies • leaf leaves • datum data • formula formulae • index indices • matrix matrices • radius radii • cherub cherubim • Morphology Rule • W Ws • W Wes • Wy Wies • Wf Wves • Wum Wa • W We • Wex Wices • Wx Wces • Wus Wi • W Wim nlp-ai@cse.iitb
Algorithm • Read the input word • Find the suffix • Remove suffix & get the root • If needed, prepare the correct rooteg. indices ind ind + ex = index • Print the output nlp-ai@cse.iitb
Required Methods of String class • boolean endsWith(Stringsuffix)Returns true if the string ends with the specified suffix; false otherwise. Parameters: the String suffix. • eg. If s = “indices” thens.endsWith(“ices”) will return trues.endsWith(“s”) will return trues.endsWith(“”) will return trues.endsWith(“indices”) will return trueButs.endsWith(“ice”) will return false nlp-ai@cse.iitb
Required Methods of String class… continued • String substring(intbeginIndex, intendIndex)Returns a new string that is a substring of the current string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. It will give error (throw exception) if the beginIndex is negative, or endIndex is larger than the length the string, or beginIndex is larger than endIndex.Parameters:beginIndex - the beginning index, inclusive.endIndex - the ending index, exclusive. • eg. If s = “mississippi” thens.substring(0,4) will return “miss”s.substring(6,9) will return “sip”s.substring(0,11) will return “mississippi”s.substring(0,0) will return “” nlp-ai@cse.iitb
Required Methods of String class… continued • int lastIndexOf(Stringstr)Returns the index within the current string of the rightmost occurrence of the specified substring. If str does not occur as a substring, -1 is returned.Parameters: str - the substring to search for. • eg. If s = “mississippi” thens.lastIndexOf(“is”) will return 4s.lastIndexOf(“i”) will return 10s.lastIndexOf(“”) will return 11s.lastIndexOf(“mississippi”) will return 0Ands.lastIndexOf(“abc”) will return -1 nlp-ai@cse.iitb
Required Methods of String class… continued • String concat(Stringstr)Returns a string after concatenating the specified string, ie. str, to the end of the current string.Parameters:str - the string that is concatenated to the end of the current string. • eg. if s = “man” thens.concat(“go”) will return “mango”s.concat(“”) will return “man” • Detailed explanation of the String class. nlp-ai@cse.iitb
Core Part of the Program • Suppose input word = “indices”; • if (word.endsWith("ices")) { // word = “indices” • suffix = "ices"; • i = word.lastIndexOf("ices"); // i = 3 • root = word.substring(0,i); // root = “ind” • root = root.concat("ex"); // root = “index” • morphRule = "[[W][ex]] [[W][ices]]"; • } nlp-ai@cse.iitb
Some Testing • matrix matrices • life lives • analysis analyses • criterion criteria • Does the program work for these examples? • If yes, how? • If no, why? nlp-ai@cse.iitb
Assignment • Do the morphological analysis of the following inflected verbs in English and write a Java program that finds out the root & suffix of the given inflected verb. Also print the morphology rule that is applied. • fetch fetches, fetching, fetched • carry carries, carrying, carried • enjoy enjoys, enjoying, enjoyed • burn burns, burning, burnt • beat beats, beating, beaten • forbid forbids, forbidding, forbided, forbidden • blow blows, blowing, blowed, blown • save saves, saving, saved nlp-ai@cse.iitb
Assignment … continued say says, saying, said drop drops, dropping, dropped admit admits, admitting, admitted repel repels, repelling, repelled dog dogs, dogging, dogged can cans, canning, canned spur spurs, spurring, spurred stem stems, stemming, stemmed stab stabs, stabbing, stabbed kid kids, kidding, kidded mimic mimics, mimicking, mimicked nlp-ai@cse.iitb
To Remind The best way to learn programming is writing a lot of programs on your own. nlp-ai@cse.iitb
End Thank you nlp-ai@cse.iitb