Presentation is loading. Please wait.

Presentation is loading. Please wait.

“Introduction to Programming With Java” Lecture - 11 U MESH P ATIL

Similar presentations

Presentation on theme: "“Introduction to Programming With Java” Lecture - 11 U MESH P ATIL"— Presentation transcript:

1 “Introduction to Programming With Java” nlp-ai@cse.iitb Lecture - 11 U MESH P ATIL (

2 nlp-ai@cse.iitb Programming practice: Program for morphological analysis of English nouns. Contents for Today’s Lecture

3 nlp-ai@cse.iitb 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: boys Output: root = boy suffix = s Morphology rule = [[W]]  [[W][s]] Input: indices Output: root = index suffix = ices Morphology rule = [[W][ex]]  [[W][ices]] Problem

4 nlp-ai@cse.iitb Example boy  boys bus  buses lady  ladies leaf  leaves datum  data formula  formulae index  indices matrix  matrices radius  radii cherub  cherubim Plurals in English Morphology Rule W  Ws W  Wes Wy  Wies Wf  Wves Wum  Wa W  We Wex  Wices Wx  Wces Wus  Wi W  Wim

5 nlp-ai@cse.iitb 1.Read the input word 2.Find the suffix 3.Remove suffix & get the root 4.If needed, prepare the correct root eg. indices  ind  ind + ex = index 5.Print the output Algorithm

6 nlp-ai@cse.iitb 1. boolean endsWith(String suffix) Returns true if the string ends with the specified suffix; false otherwise. Parameters: the String suffix. eg. If s = “indices” then s.endsWith(“ices”) will return true s.endsWith(“s”) will return true s.endsWith(“”) will return true s.endsWith(“indices”) will return true But s.endsWith(“ice”) will return false Required Methods of String class

7 nlp-ai@cse.iitb 2. String substring(int beginIndex, int endIndex) 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” then s.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 “” Required Methods of String class… continued

8 nlp-ai@cse.iitb 3. int lastIndexOf(String str) 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” then s.lastIndexOf(“is”) will return 4 s.lastIndexOf(“i”) will return 10 s.lastIndexOf(“”) will return 11 s.lastIndexOf(“mississippi”) will return 0 And s.lastIndexOf(“abc”) will return -1 Required Methods of String class… continued

9 nlp-ai@cse.iitb 4. String concat(String str) 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” then s.concat(“go”) will return “mango” s.concat(“”) will return “man” Detailed explanation of the String class. Required Methods of String class… continued

10 nlp-ai@cse.iitb 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]]"; } Core Part of the Program

11 nlp-ai@cse.iitb 1.matrix  matrices  lives 3.analysis  analyses 4.criterion  criteria Does the program work for these examples? If yes, how? If no, why? Some Testing

12 nlp-ai@cse.iitb 1.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 Assignment

13 nlp-ai@cse.iitb 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 Assignment … continued

14 nlp-ai@cse.iitb The best way to learn programming is writing a lot of programs on your own. To Remind

15 nlp-ai@cse.iitb Thank you End

Download ppt "“Introduction to Programming With Java” Lecture - 11 U MESH P ATIL"

Similar presentations

Ads by Google