public string Next() { string word, tmp; int cnt, st_idx = 0, end_idx1, end_idx2; /* 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, netData); 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.Key != "verb" && ((tmp = Morphword(str)) != null) && str != tmp) { return(tmp); } int prep; if (pos.Key == "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; int end_idx; string append; 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 && netData.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, netData); if ((tmp = e.Next()) != null && tmp != str) { return(tmp); } return(null); } } }
private 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"), netData); while ((excWord = e.Next()) != null && excWord != word) { retval = excWord + s.Substring(rest); if (netData.Is_defined(retval, PartOfSpeech.Of("verb")).NonEmpty) { return(retval); } else if (lastwd != null) { retval = excWord + end; if (netData.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 (netData.Is_defined(retval, PartOfSpeech.Of("verb")).NonEmpty) { return(retval); } else if (lastwd != null) { retval = excWord + end; if (netData.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); }