/// <summary> /// Use if sense of word is not known /// </summary> /// <param name="word">word to lookup</param> /// <returns>List of Winlib.Search</returns> public static List <Search> GetWordNetInfo(string word) { List <Search> SearchList = new List <Search>(); WnLexicon.WordInfo wordi = new WnLexicon.WordInfo(); wordi.partOfSpeech = Wnlib.PartsOfSpeech.Unknown; // for each part of speech... Wnlib.PartsOfSpeech[] enums = (Wnlib.PartsOfSpeech[])Enum.GetValues(typeof(Wnlib.PartsOfSpeech)); wordi.senseCounts = new int[enums.Length]; 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; } // get an index to a synset collection Wnlib.Index index = Wnlib.Index.lookup(word, Wnlib.PartOfSpeech.of(pos)); // none found? if (index == null) { continue; } //Add SearchType ser = new SearchType(false, "OVERVIEW"); Search s = new Search(word, true, Wnlib.PartOfSpeech.of(pos), ser, 0); SearchList.Add(s); // does this part of speech have a higher sense count? //wordi.senseCounts[i] = index.sense_cnt; //if (wordi.senseCounts[i] > maxCount) //{ // maxCount = wordi.senseCounts[i]; // wordi.partOfSpeech = pos; //} } return(SearchList); }
private void Init_Relations() { Opt[] relatedness = null; for (int i = 0; i < _contextWords.Length; i++) { WnLexicon.WordInfo wordInfo = WnLexicon.Lexicon.FindWordInfo(_contextWords[i].Word, true); if (wordInfo.partOfSpeech != Wnlib.PartsOfSpeech.Unknown) { if (wordInfo.text != string.Empty) { _contextWords[i].Word = wordInfo.text; } Wnlib.PartsOfSpeech[] posEnum = (Wnlib.PartsOfSpeech[])Enum.GetValues(typeof(Wnlib.PartsOfSpeech)); bool stop = false; int senseCount = 0; for (int j = 1; j < posEnum.Length && !stop; j++) { Wnlib.PartsOfSpeech pos = posEnum[j]; if (wordInfo.SenseCounts[j] > 0 && _contextWords[i].Pos == pos) { senseCount = wordInfo.SenseCounts[j]; relatedness = Relatedness.GetRelatedness(pos); stop = relatedness != null; break; } } if (stop) { string[][][] tmp = Relatedness.GetAllRelatednessData(_contextWords[i].Word, senseCount, relatedness); _relCube[i] = tmp; } } } }
private MyWordInfo[] Disambiguate(string[] words) { if (words.Length == 0) { return(null); } MyWordInfo[] wordInfos = new MyWordInfo [words.Length]; for (int i = 0; i < words.Length; i++) { WnLexicon.WordInfo wordInfo = WnLexicon.Lexicon.FindWordInfo(words[i], true); if (wordInfo.partOfSpeech != Wnlib.PartsOfSpeech.Unknown) { if (wordInfo.text != string.Empty) { words[i] = wordInfo.text; } Wnlib.PartsOfSpeech[] posEnum = (Wnlib.PartsOfSpeech[])Enum.GetValues(typeof(Wnlib.PartsOfSpeech)); for (int j = 0; j < posEnum.Length; j++) { if (wordInfo.SenseCounts[j] > 0) // get the first part of speech { wordInfos[i] = new MyWordInfo(words[i], posEnum[j]); break; } } } } WordSenseDisambiguator wsd = new WordSenseDisambiguator(); wordInfos = wsd.Disambiguate(wordInfos); return(wordInfos); }
private void cmdLookupSYN_Click(object sender, System.EventArgs e) { txtOut.Text = ""; // first find the part of speech WnLexicon.WordInfo wordinfo = WnLexicon.Lexicon.FindWordInfo(txtWord.Text, chkMorphs.Checked); // see if the word was found if (wordinfo.partOfSpeech == Wnlib.PartsOfSpeech.Unknown) { txtOut.AppendText("No Match found!\r\n"); return; } // perform a synonym lookup using the Lexicon string[] synonyms = WnLexicon.Lexicon.FindSynonyms(txtWord.Text, wordinfo.partOfSpeech, chkMorphs.Checked); // display results txtOut.AppendText("Look up: " + txtWord.Text + "\r\n\r\n"); foreach (string s in synonyms) { txtOut.AppendText("\t" + s + "\r\n"); } }
private void cmdLookupPOS_Click(object sender, System.EventArgs e) { txtOut.Text = ""; // perform a part-of-speech lookup using the Lexicon WnLexicon.WordInfo wordinfo = WnLexicon.Lexicon.FindWordInfo(txtWord.Text, chkMorphs.Checked); // NOTE: Including morphology matches only changes the output when no direct matches have been found. // no match? if (wordinfo.partOfSpeech == Wnlib.PartsOfSpeech.Unknown) //if( wordinfo.Strength == 0 ) ^ same as above ^ { txtOut.AppendText("No Match found!\r\n"); return; } // for each part of speech... Wnlib.PartsOfSpeech[] enums = (Wnlib.PartsOfSpeech[])Enum.GetValues(typeof(Wnlib.PartsOfSpeech)); txtOut.AppendText("\r\nSense Counts:\r\n"); for (int i = 0; i < enums.Length; i++) { Wnlib.PartsOfSpeech pos = enums[i]; // skip "Unknown" if (pos == Wnlib.PartsOfSpeech.Unknown) { continue; } // output sense counts txtOut.AppendText(String.Format("{0,12}: {1}\r\n", pos, wordinfo.senseCounts[i])); } txtOut.AppendText(String.Format("\r\nProbable Part Of Speech: {0}\r\n", wordinfo.partOfSpeech)); }
private void Scoring_Overlaps() //Greedy { int wordCount = _contextWords.Length; int[][][][] scoreCube; Init_ScoreCube(out scoreCube, wordCount); for (int i = 0; i < wordCount; i++) { if (_relCube[i] != null) { int iSenseCount = _relCube[i].Length; int bestScoreOf_i = 0; for (int iSense = 0; iSense < iSenseCount; iSense++) { int senseTotalScore = 0; for (int j = 0; j < wordCount; j++) { if (i != j && InContext(i, j, CONTEXT_SIZE) && _relCube[j] != null) { int jSenseCount = _relCube[j].Length; int bestScoreOf_j = 0; for (int jSense = 0; jSense < jSenseCount; jSense++) { int score = 0; if (scoreCube[i][iSense][j][jSense] != 0) { score = scoreCube[i][iSense][j][jSense]; } else if (scoreCube[j][jSense][i][iSense] != 0) { score = scoreCube[j][jSense][i][iSense]; } if (score == 0) { score = ScoringSensePair(_relCube[i][iSense], _relCube[j][jSense]); if (score > 0) { scoreCube[i][iSense][j][jSense] = score; scoreCube[j][jSense][i][iSense] = score; } } if (bestScoreOf_j < score) { bestScoreOf_j = score; } } if (bestScoreOf_j > THRESHOLD) { senseTotalScore += bestScoreOf_j; } } } if (senseTotalScore > bestScoreOf_i) { bestScoreOf_i = senseTotalScore; _bestSenses[i] = iSense; } } _overallScore += bestScoreOf_i; } } for (int i = 0; i < wordCount; i++) { if (_bestSenses[i] == -1) { WnLexicon.WordInfo wordInfo = WnLexicon.Lexicon.FindWordInfo(_contextWords[i].Word, true); if (wordInfo.partOfSpeech != Wnlib.PartsOfSpeech.Unknown && _contextWords[i].Pos != Wnlib.PartsOfSpeech.Unknown) { _bestSenses[i] = 0; } } } }
public static ArrayList GetCATs(string word) { ArrayList CATs = new ArrayList(); WnLexicon.WordInfo wordinfo = null; bool wordnet = false; bool ppn = false; if (OtherWords.Contains(word)) { CATs.AddRange((ArrayList)OtherWords[word]); } else { if (NamesList.BinarySearch(word) >= 0) { ppn = true; CATs.Add("PPN"); } wordnet = true; wordinfo = WnLexicon.Lexicon.FindWordInfo(word, tagged_only, true, true); if (wordinfo.senseCounts != null) { for (int i = 1; i < 5; i++) { if (wordinfo.senseCounts[i] > 0) { switch (i) { case 1: { if (!ppn) { CATs.Add("N"); } break; } case 2: { ArrayList r = findverbinfo(word, wordinfo.texts); if (r == null) { break; } CATs.AddRange(r); break; } case 3: { string s = findadjinfo(word, wordinfo.texts); if (s == null) { break; } CATs.Add(s); break; } case 4: if (word == "BEST" || word == "BETTER" || word == "DEEPER" || word == "FURTHER" || word == "FARTHER" || word == "HARDER" || word == "HARDEST") { break; } CATs.Add("PADV"); break; } } } } } if (CATs.Contains("PADJ")) { CATs.Add("BPADJ"); CATs.Add("CPADJ"); } if ((CATs.Contains("VPSP") || CATs.Contains("VING")) && CATs.Contains("BPADJ")) { CATs.Remove("BPADJ"); } if (CATs.Contains("VPSP") && CATs.Contains("CPADJ")) { CATs.Remove("CPADJ"); } if (CATs.Contains("VING") && CATs.Contains("N")) { CATs.Remove("N"); } if (!wordnet || wordinfo.senseCounts == null || wordinfo.senseCounts[1] == 0) { string org = null; if (word.EndsWith("'S")) { org = word.Remove(word.Length - 2, 2); } else if (word.EndsWith("S'")) { org = word.Remove(word.Length - 1, 1); } if (org != null) { CATs.Add("CNP"); } } if (RuleWords.Contains(word)) { CATs.AddRange((ArrayList)RuleWords[word]); } if (CATs.Count == 0) { bool n = true; foreach (char c in word) { if (!char.IsLetterOrDigit(c)) { n = false; break; } } if (n) { CATs.Add("PPN"); } } return(CATs); }