public static ArrayList GetAllSenses(string word, string pos) { int senseCount = 0; Opt[] relatednessTypes = null; ArrayList senses = new ArrayList(); MyWnLexicon.WSDWordInfo wordInfo = MyWnLexicon.Lexicon.FindWordInfo(word, true); Wnlib.PartsOfSpeech POS = Wnlib.PartsOfSpeech.Unknown; if (pos == "noun") { POS = PartsOfSpeech.Noun; senseCount = wordInfo.senseCounts[1]; } if (pos == "verb") { POS = PartsOfSpeech.Verb; senseCount = wordInfo.senseCounts[2]; } if (pos == "adj") { POS = PartsOfSpeech.Adj; senseCount = wordInfo.senseCounts[3]; } if (pos == "adv") { POS = PartsOfSpeech.Adv; senseCount = wordInfo.senseCounts[4]; } relatednessTypes = WordsMatching.Relatedness.GetRelatedness(POS); //senseCount = wordInfo.senseCounts[1]; if (relatednessTypes == null) { return(null); } for (int i = 0; i < senseCount; i++) { string gloss = GetRelatednessGlosses(word, i + 1, relatednessTypes); senses.Add(gloss); } return(senses); }
/// <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); }
/// <summary> /// Get a related word from the data files and desired PartsOfSpeech /// NOTE: Must call LoadDataFiles() before calling. /// </summary> /// <param name="p">Desired PartsOfSpeech.</param> /// <returns>Desired PartsOfSpeech word string from WordNet</returns> public static String GetRelatedWord(Wnlib.PartsOfSpeech p) { String word = ""; try { Random rand = new Random(); int r = 0; string[] synset_raw = new string[] { "" }; switch (p) { case PartsOfSpeech.Adj: r = rand.Next(AdjDataList.Count - 29);//do not choose the comments in the first lines synset_raw = AdjDataList[r].Split(' '); break; case PartsOfSpeech.Adv: r = rand.Next(AdvDataList.Count - 29);//do not choose the comments in the first lines synset_raw = AdvDataList[r].Split(' '); break; case PartsOfSpeech.Noun: r = rand.Next(NounDataList.Count - 29);//do not choose the comments in the first lines synset_raw = NounDataList[r].Split(' '); break; case PartsOfSpeech.Verb: r = rand.Next(VerbDataList.Count - 29);//do not choose the comments in the first lines synset_raw = VerbDataList[r].Split(' '); break; default: break; } word = synset_raw[4]; } catch (Exception ex) { Console.WriteLine(ex.Message); } return(word); }
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; } } } }
public MyWordInfo(string word, Wnlib.PartsOfSpeech pos) { this.Word=word; this.Pos=pos; this.Sense =0; }
public MyWordInfo(string word, Wnlib.PartsOfSpeech pos) { this.Word = word; this.Pos = pos; this.Sense = 0; }