java_lect_11.ppt

15
“Introduction to Programming With Java”

Upload: chander-kumar

Post on 11-Sep-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

  • Introduction to Programming With Java

  • Programming practice: Program for morphological analysis of English nouns.

    Contents for Todays Lecture

  • 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

  • Exampleboy boysbus buseslady ladiesleaf leavesdatum dataformula formulaeindex indicesmatrix matricesradius radiicherub cherubimPlurals in English

    Morphology RuleW WsW WesWy WiesWf WvesWum WaW WeWex WicesWx WcesWus WiW Wim

  • Read the input wordFind the suffixRemove suffix & get the rootIf needed, prepare the correct root eg. indices ind ind + ex = indexPrint the outputAlgorithm

  • 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 falseRequired Methods of String class

  • 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

  • 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

  • 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

  • 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

  • matrix matriceslife livesanalysis analysescriterion criteriaDoes the program work for these examples?If yes, how?If no, why?Some Testing

  • 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, fetchedcarry carries, carrying, carriedenjoy enjoys, enjoying, enjoyedburn burns, burning, burntbeat beats, beating, beatenforbid forbids, forbidding, forbided, forbiddenblow blows, blowing, blowed, blownsave saves, saving, savedAssignment

  • say says, saying, saiddrop drops, dropping, droppedadmit admits, admitting, admittedrepel repels, repelling, repelleddog dogs, dogging, doggedcan cans, canning, cannedspur spurs, spurring, spurredstem stems, stemming, stemmedstab stabs, stabbing, stabbedkid kids, kidding, kiddedmimic mimics, mimicking, mimicked Assignment continued

  • The best way to learn programming is writing a lot of programs on your own.To Remind

  • Thank you End