void Build_WordData() { Opt opt = GetSearchType(WordInfo.Pos); if (opt == null) return; Search se = new Search(WordInfo.Word, true, opt.pos, opt.sch, WordInfo.Sense); if (se.senses != null && se.senses.Count == 0 && se.morphs.Count > 0) { IDictionaryEnumerator getEnum = se.morphs.GetEnumerator(); while (getEnum.MoveNext()) { string morphForm = (string)getEnum.Key; if ((Wnlib.Search)getEnum.Value != null) { se = (Wnlib.Search)getEnum.Value; if (se.senses != null && se.senses.Count > 0) { WordInfo.Word = morphForm; break; } } } } if (WordInfo.Pos == Wnlib.PartsOfSpeech.Verb) { int AA = 0; } if (se.senses != null) Walk(se.senses, null, 1); Compute_DepthMatrix(); }
public List <string> WordNetExtraTerms(List <string> query) { List <string> returnedList = new List <string>(); foreach (string term in query) { Wnlib.Search se = new Wnlib.Search(term, true, Wnlib.PartOfSpeech.of("noun"), new SearchType("DERIVATION"), 0); string[] s = Strings.Split(se.buf, Constants.vbLf); if (s.Length > 6) { string at5 = s[5]; string at6 = s[6]; at5 = at5.Split(new string[] { "--" }, StringSplitOptions.RemoveEmptyEntries)[0]; at6 = at6.Split(new string[] { "--" }, StringSplitOptions.RemoveEmptyEntries)[0]; string[] arrayAt5 = at5.Split(new string[] { " ", "\t", "," }, StringSplitOptions.RemoveEmptyEntries); string[] arrayAt6 = at6.Split(new string[] { " ", "=>", "\t", "," }, StringSplitOptions.RemoveEmptyEntries); returnedList.AddRange(arrayAt5); returnedList.AddRange(arrayAt6); for (int i = 0; i < returnedList.Count; i++) { returnedList[i] = returnedList[i].Trim(new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' }); } } } return(returnedList); }
static bool AddSearchFor(string s, PartOfSpeech pos, ArrayList list) { var se = new Search(s, false, pos, new SearchType(false, "OVERVIEW"), 0); if (se.lexemes.Count > 0) list.Add(se); return se.lexemes.Count > 0; }
bool AddSearchFor(string s,PartOfSpeech pos, ArrayList list) { Search se = new Search(s,false,pos,new SearchType(false,"OVERVIEW"),0); if(se.lexemes.Count > 0) list.Add(se); if(se.lexemes.Count > 0) return true; // results were found else return false; }
static string[] GetAllDefinitionTokens(Search se) { string rels = ""; if (se.senses[0].senses != null) foreach (SynSet ss in se.senses[0].senses) { foreach (Lexeme ww in ss.words) rels += " " + ww.word; rels += ss.defn; } string[] toks = tokenize.Partition(rels); return toks; }
// TDMS 16 July 2006 - removed this method. // Method removed because if called externally // WNDBPart was not correctly constructed. // Calling is_defined(string searchstr,PartOfSpeech fpos) // correctly constructs WNDBPart. /* private static SearchSet is_defined(string word,string p) { Console.WriteLine("is_defined string, string"); return is_defined(word,PartOfSpeech.of(p)); } */ /// <summary> /// Determines if a word is defined in the WordNet database and returns /// all possible searches of the word. /// </summary> /// <example> This sample displays a message stating whether the /// word "car" exists as the part of speech "noun". /// <code> /// Wnlib.WNCommon.path = "C:\Program Files\WordNet\2.1\dict\" /// Dim wrd As String = "car" /// Dim POS As String = "noun" /// Dim b As Boolean = Wnlib.WNDB.is_defined(wrd, Wnlib.PartOfSpeech.of(POS)).NonEmpty.ToString /// /// If b Then /// MessageBox.Show("The word " & wrd & " exists as a " & POS & ".") /// Else /// MessageBox.Show("The word " & wrd & " does not exist as a " & POS & ".") /// End If /// </code> /// </example> /// <param name="searchstr">The word to search for</param> /// <param name="fpos">Part of Speech (noun, verb, adjective, adverb)</param> /// <returns>A SearchSet or null if the word does not exist in the dictionary</returns> public static SearchSet is_defined(string searchstr,PartOfSpeech fpos) { Indexes ixs = new Indexes(searchstr,fpos); Index index; int i; int CLASS = 22; /* - */ int LASTTYPE = CLASS; Search s = new Search(searchstr,fpos,new SearchType(false,"FREQ"),0); SearchSet retval = new SearchSet(); while ((index=ixs.next())!=null) { retval=retval+"SIMPTR"+"FREQ"+"SYNS"+"WNGREP"+"OVERVIEW"; // added WNGREP - TDMS for (i=0;i<index.ptruse.Length;i++) { PointerType pt = index.ptruse[i]; // retval=retval+pt; // WN2.1 - TDMS if (pt.ident <= LASTTYPE) { retval = retval + pt; } else if (pt.mnemonic == "INSTANCE") { retval = retval + "HYPERPTR"; } else if (pt.mnemonic == "INSTANCES") { retval = retval + "HYPOPTR"; } // WN2.1 - TDMS if (pt.mnemonic == "SIMPTR") { retval = retval + "ANTPTR"; } if (fpos.name=="noun") { /* set generic HOLONYM and/or MERONYM bit if necessary */ if (pt>="ISMEMBERPTR" && pt<="ISPARTPTR") retval=retval+"HOLONYM"; else if (pt>="HASMEMBERPTR" && pt<="HASPARTPTR") retval=retval+"MERONYM"; } // WN2.1 - TDMS else if (fpos.name=="adj" && pt.mnemonic=="SIMPTR") // retval=retval+"ANTPTR"; } if (fpos.name=="noun") { retval=retval+"RELATIVES"; if (index.HasHoloMero("HMERONYM",s)) retval=retval+"HMERONYM"; if (index.HasHoloMero("HHOLONYM",s)) retval=retval+"HHOLONYM"; if (retval["HYPERPTR"]) retval = retval+"COORDS"; } else if (fpos.name=="verb") retval=retval+"RELATIVES"+"FRAMES"; // added frames - TDMS } return retval; }
// TDMS 16 July 2006 - removed this method. // Method removed because if called externally // WNDBPart was not correctly constructed. // Calling is_defined(string searchstr,PartOfSpeech fpos) // correctly constructs WNDBPart. /* * private static SearchSet is_defined(string word,string p) * { * Console.WriteLine("is_defined string, string"); * return is_defined(word,PartOfSpeech.of(p)); * } */ /// <summary> /// Determines if a word is defined in the WordNet database and returns /// all possible searches of the word. /// </summary> /// <example> This sample displays a message stating whether the /// word "car" exists as the part of speech "noun". /// <code> /// Wnlib.WNCommon.path = "C:\Program Files\WordNet\2.1\dict\" /// Dim wrd As String = "car" /// Dim POS As String = "noun" /// Dim b As Boolean = Wnlib.WNDB.is_defined(wrd, Wnlib.PartOfSpeech.of(POS)).NonEmpty.ToString /// /// If b Then /// MessageBox.Show("The word " & wrd & " exists as a " & POS & ".") /// Else /// MessageBox.Show("The word " & wrd & " does not exist as a " & POS & ".") /// End If /// </code> /// </example> /// <param name="searchstr">The word to search for</param> /// <param name="fpos">Part of Speech (noun, verb, adjective, adverb)</param> /// <returns>A SearchSet or null if the word does not exist in the dictionary</returns> public static SearchSet is_defined(string searchstr, PartOfSpeech fpos) { Indexes ixs = new Indexes(searchstr, fpos); Index index; int i; int CLASS = 22; /* - */ int LASTTYPE = CLASS; Search s = new Search(searchstr, fpos, new SearchType(false, "FREQ"), 0); SearchSet retval = new SearchSet(); while ((index = ixs.next()) != null) { retval = retval + "SIMPTR" + "FREQ" + "SYNS" + "WNGREP" + "OVERVIEW"; // added WNGREP - TDMS for (i = 0; i < index.ptruse.Length; i++) { PointerType pt = index.ptruse[i]; // retval=retval+pt; // WN2.1 - TDMS if (pt.ident <= LASTTYPE) { retval = retval + pt; } else if (pt.mnemonic == "INSTANCE") { retval = retval + "HYPERPTR"; } else if (pt.mnemonic == "INSTANCES") { retval = retval + "HYPOPTR"; } // WN2.1 - TDMS if (pt.mnemonic == "SIMPTR") { retval = retval + "ANTPTR"; } if (fpos.name == "noun") { /* set generic HOLONYM and/or MERONYM bit if necessary */ if (pt >= "ISMEMBERPTR" && pt <= "ISPARTPTR") { retval = retval + "HOLONYM"; } else if (pt >= "HASMEMBERPTR" && pt <= "HASPARTPTR") { retval = retval + "MERONYM"; } } // WN2.1 - TDMS else if (fpos.name=="adj" && pt.mnemonic=="SIMPTR") // retval=retval+"ANTPTR"; } if (fpos.name == "noun") { retval = retval + "RELATIVES"; if (index.HasHoloMero("HMERONYM", s)) { retval = retval + "HMERONYM"; } if (index.HasHoloMero("HHOLONYM", s)) { retval = retval + "HHOLONYM"; } if (retval["HYPERPTR"]) { retval = retval + "COORDS"; } } else if (fpos.name == "verb") { retval = retval + "RELATIVES" + "FRAMES"; // added frames - TDMS } } return(retval); }
/// <summary> /// /// </summary> /// <param name="word"></param> /// <param name="senseIndex"></param> /// <param name="relatenessSearchTypes"></param> /// <returns></returns> public static string[][] GetRelatednessGlosses(string word, int senseNumber, Opt[] relatednessTypes) { string[][] relations = new string[relatednessTypes.Length + 1][]; for (int i = 0; i < relatednessTypes.Length; i++) { Opt relateness = relatednessTypes[i]; Search se = new Search(word, true, relateness.pos, relateness.sch, senseNumber);// if (se.senses != null && se.senses.Count > 0) { if (relations[0] == null) relations[0] = GetSynsetDefinition(se.senses[0]); if (se.senses[0].senses != null) relations[i + 1] = GetAllDefinitionTokens(se); } else relations[i + 1] = null; } return relations; }
/// <summary> /// Performs a search based on the parameters setup /// in the Search constructor. /// </summary> /// <param name="m">Specify if morphs should be searched</param> /// <param name="p">The Part Of Speech to perform the search on</param> public void do_search(bool m, string p) { if (parts == null) parts = new Hashtable(); Search s = new Search(word, PartOfSpeech.of(p), sch, whichsense); s.do_search(m); parts[p] = s; buf += s.buf; }
public bool HasHoloMero(string s, Search search) { return(HasHoloMero(PointerType.of(s), search)); }
public bool HasHoloMero(PointerType p, Search search) { PointerType pbase; if (p.Mnemonic == "HMERONYM") pbase = PointerType.of("HASMEMBERPTR"); else pbase = PointerType.of("ISMEMBERPTR"); for (int i = 0; i < SynsetOffsets.Length; i++) { SynSet s = new SynSet(SynsetOffsets[i], PartOfSpeech.of("noun"), "", search, 0); if (s.has(pbase) || s.has(pbase + 1) || s.has(pbase + 2)) return true; } return false; }
/// <summary> /// Performs a search based on the parameters setup /// in the Search constructor. /// </summary> /// <param name="doMorphs">Specifies whether to perform a search on morphs. /// This parameter is retrieved in the first /// call from do_search(bool m, string p). If morph searching is specified /// and a morph is found, then on a recursive call to this method /// morphing will be turned off to prevent unnecessary morph searching.</param> internal void do_search(bool doMorphs) { findtheinfo(); if (buf.Length > 0) buf = "\n" + sch.label + " of " + pos.name + " " + word + "\n" + buf; if (!doMorphs) return; morphs = new Hashtable(); MorphStr st = new MorphStr(word, pos); string morphword; // if there are morphs then perform iterative searches // on each morph, filling the morph tree in the search // object. while ((morphword = st.next()) != null) { Search s = new Search(morphword, pos, sch, whichsense); s.do_search(false); // Fill the morphlist - eg. if verb relations of 'drunk' are requested, none are directly // found, but the morph 'drink' will have results. The morph hashtable will be populated // into the search results and should be iterated instead of the returned synset if the // morphs are non-empty morphs[morphword] = s; buf += s.buf; } }
public bool HasHoloMero(string s, Search search) { return HasHoloMero(PointerType.of(s), search); }
public SynSet(Index idx, int sens, Search sch) : this(idx.SynsetOffsets[sens], idx.PartOfSpeech, idx.Wd, sch, sens) { }
public SynSet(Index idx, int sens, Search sch) : this(idx.offs[sens], idx.pos, idx.wd, sch, sens) { }
} // for serialization public SynSet(int offset, PartOfSpeech p, string wd, Search sch, int sens) { pos = p; hereiam = offset; search = sch; sense = sens; StreamReader f = WNDB.data(p); f.DiscardBufferedData(); //f.BaseStream.Seek(off,SeekOrigin.Begin); f.BaseStream.Position = offset; string rec = f.ReadLine(); //string str; if (!rec.StartsWith(offset.ToString("D8"))) { Console.WriteLine("Error reading " + p.name + " file! " + offset + ": " + rec); WNDB.reopen(p); f = WNDB.data(p); f.DiscardBufferedData(); //f.BaseStream.Seek(off, SeekOrigin.Begin); f.BaseStream.Position = offset; rec = f.ReadLine(); //if (!rec.StartsWith(off.ToString("D8"))) // str = ""; //else // Console.WriteLine("Recovered..."); } Parse(rec, pos, wd); }