string morphword(string word) { string end = ""; string tmpbuf = ""; if (word == null) { return(null); } Exceptions e = new Exceptions(word, pos); string tmp = e.next(); if (tmp != null) { return(tmp); } if (pos.name == "adverb") { return(null); } if (pos.name == "noun") { if (word.EndsWith("ful")) { tmpbuf = word.Substring(0, word.Length - 3); end = "ful"; } else if (word.EndsWith("ss") || word.Length <= 2) { return(null); } } if (tmpbuf.Length == 0) { tmpbuf = word; } int offset = offsets[pos.ident]; int cnt = cnts[pos.ident]; for (int i = 0; i < cnt; i++) { if (tmpbuf.EndsWith(sufx[i + offset])) { // TDMS 11 Oct 2005 - bug fix - "word" substituted with "tmpbuf" as per // wordnet code morph.c //string retval = word.Substring(0,word.Length-sufx[i+offset].Length)+addr[i+offset]; string retval = tmpbuf.Substring(0, tmpbuf.Length - sufx[i + offset].Length) + addr[i + offset]; if (WNDB.is_defined(retval, pos).NonEmpty) { return(retval + end); } } } return(null); }
public string next() { string word, tmp; int prep, cnt, st_idx = 0, end_idx = 0, end_idx1, end_idx2; string append = ""; /* first time through for this string */ if (firsttime) { firsttime = false; cnt = str.Split('_').Length; svprep = 0; /* first try exception list */ e = new Exceptions(str, pos); if ((tmp = e.next()) != null && tmp != str) { svcnt = 1; /* force next time to pass NULL */ return(tmp); } /* then try simply morph on original string */ if (pos.name != "verb" && ((tmp = morphword(str)) != null) && str != tmp) { return(tmp); } if (pos.name == "verb" && cnt > 1 && (prep = hasprep(str, cnt)) != 0) { svprep = prep; return(morphprep(str)); } else { svcnt = cnt = str.Split('_').Length; while (--cnt > 0) { end_idx1 = str.Substring(st_idx).IndexOf('_') + st_idx; end_idx2 = str.Substring(st_idx).IndexOf('-') + st_idx; if (end_idx1 >= st_idx && end_idx2 >= st_idx) { if (end_idx1 < end_idx2) { end_idx = end_idx1; append = "_"; } else { end_idx = end_idx2; append = "-"; } } else if (end_idx1 >= st_idx) { end_idx = end_idx1; append = "_"; } else { end_idx = end_idx2; append = "-"; } if (end_idx < 0) { return(null); } word = str.Substring(st_idx, end_idx - st_idx); if ((tmp = morphword(word)) != null) { searchstr += tmp; } else { searchstr += word; } searchstr += append; st_idx = end_idx + 1; } word = str.Substring(st_idx); if ((tmp = morphword(word)) != null) { searchstr += tmp; } else { searchstr += word; } if (searchstr != str && WNDB.is_defined(searchstr, pos).NonEmpty) { return(searchstr); } else { return(null); } } } else // not firsttime { if (svprep > 0) { svprep = 0; return(null); } else if (svcnt == 1) { return(e.next()); } else { svcnt = 1; e = new Exceptions(str, pos); if ((tmp = e.next()) != null && tmp != str) { return(tmp); } return(null); } } }
string morphprep(string s) { string excWord, lastwd = null; int i, offset, cnt, rest, last; string word, end, retval; /* Assume that the verb is the first word in the phrase. Strip it * off, check for validity, then try various morphs with the * rest of the phrase tacked on, trying to find a match. */ rest = s.IndexOf('_'); last = s.LastIndexOf('_'); end = ""; if (rest != last) { // more than 2 words lastwd = morphword(s.Substring(last + 1)); if (lastwd != null) { end = s.Substring(rest, last - rest + 1) + lastwd; } } word = s.Substring(0, rest); for (i = 0; i < word.Length; i++) { if (!char.IsLetterOrDigit(word[i])) { return(null); } } offset = offsets[PartOfSpeech.of("verb").ident]; cnt = cnts[PartOfSpeech.of("verb").ident]; /* First try to find the verb in the exception list */ Exceptions e = new Exceptions(word, PartOfSpeech.of("verb")); while ((excWord = e.next()) != null && excWord != word) { retval = excWord + s.Substring(rest); if (WNDB.is_defined(retval, PartOfSpeech.of("verb")).NonEmpty) { return(retval); } else if (lastwd != null) { retval = excWord + end; if (WNDB.is_defined(retval, PartOfSpeech.of("verb")).NonEmpty) { return(retval); } } } for (i = 0; i < cnt; i++) { if ((excWord = wordbase(word, i + offset)) != null && excWord != word) // ending is different { retval = excWord + s.Substring(rest); if (WNDB.is_defined(retval, PartOfSpeech.of("verb")).NonEmpty) { return(retval); } else if (lastwd != null) { retval = excWord + end; if (WNDB.is_defined(retval, PartOfSpeech.of("verb")).NonEmpty) { return(retval); } } } } retval = word + s.Substring(rest); if (s != retval) { return(retval); } if (lastwd != null) { retval = word + end; if (s != retval) { return(retval); } } return(null); }