Title: Introduction to Programming With Java
1Introduction to Programming With Java
Lecture - 11 UMESH PATIL (umesh_at_cse.iitb.ac.in)
nlp-ai_at_cse.iitb
2Contents for Todays Lecture
- Programming practice Program for morphological
analysis of English nouns.
nlp-ai_at_cse.iitb
3Problem
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 ? Ws Input indices
Output root index suffix ices
Morphology rule Wex ? Wices
nlp-ai_at_cse.iitb
4Plurals 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_at_cse.iitb
5Algorithm
- 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_at_cse.iitb
6Required Methods of String class
- boolean endsWith(String suffix)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_at_cse.iitb
7Required Methods of String class continued
- 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.ParametersbeginIndex - the beginning
index, inclusive.endIndex - the ending index,
exclusive. - eg. If s mississippi thens.substring(0,4)
will return misss.substring(6,9) will return
sips.substring(0,11) will return
mississippis.substring(0,0) will return
nlp-ai_at_cse.iitb
8 Required Methods of String class continued
- 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 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_at_cse.iitb
9 Required Methods of String class continued
- String concat(String str)Returns a string after
concatenating the specified string, ie. str, to
the end of the current string.Parametersstr -
the string that is concatenated to the end of the
current string. - eg. if s man thens.concat(go) will return
mangos.concat() will return man - Detailed explanation of the String class.
nlp-ai_at_cse.iitb
10Core 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 "Wex ?
Wices"
nlp-ai_at_cse.iitb
11Some Testing
- matrix ? matrices
- life ? lives
- analysis ? analyses
- criterion ? criteria
- Does the program work for these examples?
- If yes, how?
- If no, why?
nlp-ai_at_cse.iitb
12Assignment
- 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_at_cse.iitb
13Assignment 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_at_cse.iitb
14To Remind
The best way to learn programming is writing a
lot of programs on your own.
nlp-ai_at_cse.iitb
15End
Thank you ?
nlp-ai_at_cse.iitb