private static string[] lookupSynonyms(Wnlib.Index index) { // OVERVIEW: For each sense, grab the synset associated with our index. // Then, add the lexemes in the synset to a list. var synonyms = new ArrayList(10); // for each sense... for (int s = 0; s < index.SynsetOffsets.Length; s++) { // read in the word and its pointers var synset = new Wnlib.SynSet(index.SynsetOffsets[s], index.PartOfSpeech, index.Wd, null, s); // build a string out of the words for (int i = 0; i < synset.words.Length; i++) { string word = synset.words[i].word.Replace("_", " "); // if the word is capitalized, that means it's a proper noun. We don't want those. if (word[0] <= 'Z') { continue; } // add it to the list if it's a different word if (string.Compare(word, index.Wd, true) != 0) { synonyms.Add(word); } } } return((string[])synonyms.ToArray(typeof(string))); }
/// <summary> /// Handles a TreeNode left-click selection. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void TreeControl1AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { try { // e.node.tag can be nothing if the node is a top level POS identifier // if we simply let the exception occur this seems to waste a lot of CPU power for some reason if ((e.Node.Tag != null)) { Wnlib.SynSet ss = (Wnlib.SynSet)e.Node.Tag; txtOutput.Text = ss.defn; } } catch { // when opening a root node } }
/// <summary> /// Handles a right-click on a TreeControl TreeNode and displays a custom popup menu for the node. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="tn">TreeNode that was right-clicked</param> public void TreeControl1TreeRightClick(object sender, System.Windows.Forms.MouseEventArgs e, System.Windows.Forms.TreeNode tn) { Wnlib.SynSet ss = default(Wnlib.SynSet); ss = (Wnlib.SynSet)tn.Tag; //Wnlib.Lexeme wrd = default(Wnlib.Lexeme); // it is possible to have a word list, all with a sense of (0) which will prevent semcor from // working. In that case, prevent the semcor menu. A test search for this condition is overview of "right" -> adjective -> similarity foreach (Wnlib.Lexeme wrd in ss.words) { if (wrd.wnsns > 0) { mnuNodeMenu.Show(treeControl1, new Point(e.X, e.Y)); break; // TODO: might not be correct. Was : Exit For } } }
/// <summary> /// Standardises the addition of a new TreeNode to the TreeView. Lexemes are iterated and comma-separated /// for display purposes. An icon is attached to the node according to the type of the sense. /// </summary> /// <param name="ss"></param> /// <returns></returns> private TreeNode newTreeNode(Wnlib.SynSet ss) { //Wnlib.Lexeme word = default(Wnlib.Lexeme); string words = null; TreeNode childnode = null; words = ""; // Build the words for display in the node. // Words are the lexemes in a search result. foreach (Wnlib.Lexeme word in ss.words) { if (!string.IsNullOrEmpty(words)) { words += ", "; } words += Strings.Replace(word.word, "_", " "); // append the sense number when the sense is not 1 if (word.wnsns != 1) { words += "(" + word.wnsns + ")"; } } // define a new child node childnode = new TreeNode(); childnode.Text = words; // assign an icon according to the ident number of the ptr // (see static void classinit() in util.cs) if ((ss.thisptr != null)) { childnode.ImageIndex = ss.thisptr.ptp.ident; childnode.ToolTipText = ss.thisptr.ptp.label; } childnode.Tag = ss; return(childnode); }
/// <summary> /// Get the semcor values for the selected node. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mnuSemCor(System.Object sender, System.EventArgs e) { string outtxt = null; Wnlib.SynSet ss = default(Wnlib.SynSet); //Wnlib.Lexeme lex = default(Wnlib.Lexeme); outtxt = "SemCor" + Constants.vbCrLf + Constants.vbCrLf; ss = (Wnlib.SynSet)treeControl1.SelectedNode.Tag; // build semcor information for each lexeme foreach (Wnlib.Lexeme lex in ss.words) { lex.semcor = new Wnlib.SemCor(lex, ss.hereiam); outtxt += lex.word + ": " + lex.semcor.semcor + Constants.vbCrLf; } txtOutput.Text = outtxt; }
private static string[] lookupSynonyms(Wnlib.Index index) { // OVERVIEW: For each sense, grab the synset associated with our index. // Then, add the lexemes in the synset to a list. ArrayList synonyms = new ArrayList(10); // for each sense... for (int s = 0; s < index.offs.Length; s++) { // read in the word and its pointers Wnlib.SynSet synset = new Wnlib.SynSet(index.offs[s], index.pos, index.wd, null, s); // build a string out of the words for (int i = 0; i < synset.words.Length; i++) { string word = synset.words[i].word.Replace("_", " "); // if the word is capitalized, that means it's a proper noun. We don't want those. if (word[0] <= 'Z') continue; // add it to the list if it's a different word if (string.Compare(word, index.wd, true) != 0) synonyms.Add(word); } } return (string[])synonyms.ToArray(typeof(string)); }
public string GetLesserTags() { StringBuilder sb = new StringBuilder(); foreach (object key in m_htMap.Keys) { int synId = (int)key; int score = (int)m_htMap[synId]; if (score > 1 && score != m_maxScore) { Wnlib.SynSet synset = null; try { synset = new Wnlib.SynSet(synId, Wnlib.PartOfSpeech.of("noun"), string.Empty, null, 0); } catch { continue; } if (synset == null) continue; sb.Append("<li>{ "); for (int i = 0; i < synset.words.Length; i++) { sb.Append(synset.words[i].word + ", "); } sb.Append(" } [" + score + "]</li>"); } } return sb.ToString(); }
public int FindSynSets() { foreach (Token t in m_tokens) { if (t.Word.Trim().Length < 2) continue; //WnLexicon.WordInfo wordinfo = WnLexicon.Lexicon.FindWordInfo(t.Word, false); // TODO: Include morphs? //Wnlib.SynSet synset = new Wnlib.SynSet(0, , t.Word, Wnlib.Search.ALLSENSES, 0); //int []i = wordinfo.senseCounts; //Stemmer stemmer = new Stemmer(t.Word.ToLower()); //Wnlib.Index idx = Wnlib.Index.lookup(stemmer.StemPlural(), Wnlib.PartOfSpeech.of("noun")); //Wnlib.SynSet[] syns = idx.syns; Wnlib.PartsOfSpeech pos = Wnlib.PartsOfSpeech.Unknown; if (t.POS.Contains("NN")) { pos = Wnlib.PartsOfSpeech.Noun; } else if (t.POS.Contains("VB")) { pos = Wnlib.PartsOfSpeech.Verb; } else if (t.POS.Contains("JJ")) { pos = Wnlib.PartsOfSpeech.Adj; } //string[] st = WnLexicon.Lexicon.FindSynonyms(t.Word, pos, false); if (pos == Wnlib.PartsOfSpeech.Unknown) continue; Wnlib.Index index = Wnlib.Index.lookup(t.Word, Wnlib.PartOfSpeech.of(pos)); // Word not found. Stem it and search again if (index == null) { string newWord = string.Empty; if (t.Word.EndsWith("s")) { char[] trimChars = { 's' }; newWord = t.Word.TrimEnd(trimChars); } if (t.Word[0] < 'Z') { newWord = newWord.ToLower(); } index = Wnlib.Index.lookup(newWord, Wnlib.PartOfSpeech.of(pos)); } if (index != null) { // Get synset Wnlib.SynSet synset = new Wnlib.SynSet(index.offs[0], index.pos, index.wd, null, 0); // Update this entry in hashmap UpdateHashMap(synset.hereiam, 3); // Find hypernyms to level 2 and add them to the hashmap FindHypernyms(synset, 2); } } return m_htMap.Count; }
private void FindMeroHolonyms(Wnlib.SynSet synset) { for (int i = 0; i < synset.ptrs.Length; i++) { if (synset.ptrs[i].ptp.ident == 12 || synset.ptrs[i].ptp.ident == 13) { Wnlib.SynSet daSynSet = new Wnlib.SynSet(synset.ptrs[i].off, synset.pos, synset); } } }
private void FindHypernyms(Wnlib.SynSet synset, int depth) { for (int i = 0; i < synset.ptrs.Length; i++) { if (synset.ptrs[i].ptp.ident == 2) // Hyper Pointer { Wnlib.SynSet parentSynSet = new Wnlib.SynSet(synset.ptrs[i].off, synset.pos, synset); UpdateHashMap(parentSynSet.hereiam, depth); depth--; if (depth != 0) { FindHypernyms(parentSynSet, depth); } } } }