public static WordInfo FindWordInfo( string word, bool tagged_only, bool includeMorphs, bool forceMorhps) { word = word.ToLower(); WordInfo wordinfo = lookupWord(word, tagged_only); if (forceMorhps) { // include morphology even if some parts of speech were found if (includeMorphs) { WordInfo morphinfo = lookupWordMorphs(word, tagged_only); wordinfo = WordInfo.Compine(wordinfo, morphinfo); } } else { // include morphology if nothing was found on the original word if (wordinfo.Strength == 0 && includeMorphs) { wordinfo = lookupWordMorphs(word, tagged_only); } } return(wordinfo); }
private static WordInfo lookupWordMorphs(string word, bool tagged_only) { // OVERVIEW: This functions only gets called when the word was not found with // an exact match. So, enumerate all the parts of speech, then enumerate // all of the word's morphs in each category. Perform a lookup on each // morph and save the morph/strength/part-of-speech data sets. Finally, // loop over all the data sets and then pick the strongest one. ArrayList wordinfos = new ArrayList(); // for each part of speech... for (int i = 0; i < enums.Length; i++) { // get a valid part of speech Wnlib.PartsOfSpeech pos = enums[i]; if (pos == Wnlib.PartsOfSpeech.Unknown) { continue; } // generate morph list Wnlib.MorphStr morphs = new Wnlib.MorphStr(word, Wnlib.PartOfSpeech.of(pos)); string morph = ""; while ((morph = morphs.next()) != null) { // get an index to a synset collection Wnlib.Index index = Wnlib.Index.lookup(morph, Wnlib.PartOfSpeech.of(pos)); // none found? if (index == null) { continue; } // none tagged if (tagged_only && index.tagsense_cnt == 0) { continue; } // save the wordinfo WordInfo wordinfo = getMorphInfo(wordinfos, morph); if (tagged_only) { wordinfo.senseCounts[i] = index.tagsense_cnt; } else { wordinfo.senseCounts[i] = index.sense_cnt; } } } return(WordInfo.Compine(wordinfos)); /* * // search the wordinfo list for the best match * WordInfo bestWordInfo = new WordInfo(); * int maxStrength = 0; * foreach( WordInfo wordinfo in wordinfos ) * { * // for each part of speech... * int maxSenseCount = 0; * int strength = 0; * for( int i=0; i<enums.Length; i++ ) * { * // get a valid part of speech * Wnlib.PartsOfSpeech pos = enums[i]; * if( pos == Wnlib.PartsOfSpeech.Unknown ) * continue; * * // determine part of speech and strength * strength += wordinfo.senseCounts[i]; * if( wordinfo.senseCounts[i] > maxSenseCount ) * { * maxSenseCount = wordinfo.senseCounts[i]; * wordinfo.partOfSpeech = pos; * } * } * * // best match? * if( strength > maxStrength ) * { * maxStrength = strength; * bestWordInfo = wordinfo; * } * } * * return bestWordInfo; */ }