} // 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); }
public Indexes(string str, PartOfSpeech pos) { string[] strings = new string[stringscount]; str = str.ToLower(); strings[0] = str; strings[1] = str.Replace('_', '-'); strings[2] = str.Replace('-', '_'); strings[3] = str.Replace("-", "").Replace("_", ""); strings[4] = str.Replace(".", ""); // TDMS - 14 Aug 2005 - added two more possibilities // to allow for spaces to be transformed // an example is a search for "11 plus", without this // transformation no result would be found strings[5] = str.Replace(' ', '-'); strings[6] = str.Replace(' ', '_'); offsets[0] = Index.lookup(str, pos); // TDMS - 14 Aug 2005 - changed 5 to 7 to allow for two // new possibilities for (int i = 1; i < stringscount; i++) { if (str != strings[i]) { offsets[i] = Index.lookup(strings[i], pos); } } fpos = pos; }
/// <summary> /// Trace meronyms. /// </summary> /// <param name="pbase"></param> /// <param name="fpos"></param> /// <param name="depth"></param> void traceInherit(PointerType pbase, PartOfSpeech fpos, int depth) { for (int i = 0; i < ptrs.Length; i++) { Pointer pt = ptrs[i]; if (pt.ptp.Ident == HYPERPTR && (pt.sce == 0 || pt.sce == whichword)) { spaces("TRACEI", depth); SynSet cursyn = new SynSet(pt.off, pt.pos, this); search.wordsFrom(cursyn); cursyn.str("=> ", "\n", 1, 0, 0, 1); // TDMS 6 Oct 2005 - build hierarchical results // TODO: verify this if (this.senses == null) { this.senses = new SynSetList(); } cursyn.thisptr = pt; // TDMS 17 Nov 2005 - add this pointer type // TODO: This is adding senses incorrectly this.senses.Add(cursyn); cursyn.tracePtrs(pbase, PartOfSpeech.of("noun"), depth); cursyn.tracePtrs(pbase + 1, PartOfSpeech.of("noun"), depth); cursyn.tracePtrs(pbase + 2, PartOfSpeech.of("noun"), depth); if (depth > 0) { depth = depthcheck(depth); cursyn.traceInherit(pbase, cursyn.pos, depth + 1); } } } search.trunc(); }
public static void reopen(PartOfSpeech p) { index(p).Close(); data(p).Close(); indexfps[p.key] = GetStreamReader(IndexFile(p)); datafps[p.key] = GetStreamReader(DataFile(p)); }
void catword(int wdnum, int adjmarker, int antflag) { search.buf += deadjify(words[wdnum].word); /* Print additional lexicographer information and WordNet sense * number as indicated by flags */ if (words[wdnum].uniq != 0) { search.buf += "" + words[wdnum].uniq; } int s = getsearchsense(wdnum + 1); words[wdnum].wnsns = s; if (WNOpt.opt("-s").flag) { search.buf += "#" + s; } /* For adjectives, append adjective marker if present, and * print antonym if flag is passed */ if (pos.name == "adj") { if (adjmarker > 0) { search.buf += "" + adj_marker.mark; } if (antflag > 0) { strAnt(PartOfSpeech.of("adj"), wdnum + 1, "(vs. ", ")"); } } }
internal Search(string w, PartOfSpeech p, SearchType s, int sn) { word = w; pos = p; sch = s; whichsense = sn; }
/* From search.c: * Find word in index file and return parsed entry in data structure. Input word must be exact match of string in database. */ // From the WordNet Manual (http://wordnet.princeton.edu/man/wnsearch.3WN.html) // index_lookup() finds searchstr in the index file for pos and returns a pointer // to the parsed entry in an Index data structure. searchstr must exactly match the // form of the word (lower case only, hyphens and underscores in the same places) in // the index file. NULL is returned if a match is not found. public static Index lookup(string word, PartOfSpeech pos) { int j; if (word == "") return null; // TDMS 14 Aug 2005 - changed to allow for numbers as well // because the database contains searches that can start with // numerals //if (!char.IsLetter(word[0])) if (!char.IsLetter(word[0]) && !char.IsNumber(word[0])) return null; string line = WNDB.binSearch(word, pos); if (line == null) return null; Index idx = new Index(); StrTok st = new StrTok(line); idx.Wd = st.next(); /* the word */ idx.PartOfSpeech = PartOfSpeech.of(st.next()); /* the part of speech */ idx.SenseCnt = int.Parse(st.next()); /* collins count */ int ptruse_cnt = int.Parse(st.next()); /* number of pointers types */ idx.Ptruse = new PointerType[ptruse_cnt]; for (j = 0; j < ptruse_cnt; j++) idx.Ptruse[j] = PointerType.of(st.next()); int off_cnt = int.Parse(st.next()); idx.SynsetOffsets = new int[off_cnt]; idx.TaggedSensesCount = int.Parse(st.next()); for (j = 0; j < off_cnt; j++) idx.SynsetOffsets[j] = int.Parse(st.next()); return idx; }
internal static ArrayList wngrep(string wordPassed, PartOfSpeech pos) { ArrayList r = new ArrayList(); StreamReader inputFile = index(pos); inputFile.BaseStream.Seek(0L, SeekOrigin.Begin); inputFile.DiscardBufferedData(); string word = wordPassed.Replace(" ", "_"); string line; while ((line = inputFile.ReadLine()) != null) { int lineLen = line.IndexOf(' '); line = line.Substring(0, lineLen); try { if (line.IndexOf(word) >= 0) { r.Add(line.Replace("_", " ")); } } catch { } } return(r); }
public Exceptions(string word, PartOfSpeech pos) { line = WNDB.binSearch(word, excfps[pos.ident]); if (line != null) { endlp = line.IndexOf(' '); } }
public Exceptions(string word, PartOfSpeech pos) { line = WNDB.binSearch(word, (StreamReader)excfps[pos.key]); if (line != null) { endlp = line.IndexOf(' '); } }
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; }
public Search(string w, bool doMorphs, PartOfSpeech p, SearchType s, int sn) : this(w, p, s, sn) { if (p != null) { do_search(doMorphs); } }
public Search(string w, bool doMorphs, PartOfSpeech p, SearchType s, int sn, CustomGrep cg) : this(w, p, s, sn) { customgrep = cg; if (p != null) { do_search(doMorphs); } }
public static void reopen(PartOfSpeech p) { WNDBpart w = WNDBpart.of(p); w.index.Close(); w.data.Close(); w.index = new StreamReader(IndexFile(p)); w.data = new StreamReader(DataFile(p)); }
static Exceptions() { excfps = new StreamReader[PartOfSpeech.parts.Count]; IDictionaryEnumerator d = PartOfSpeech.parts.GetEnumerator(); while (d.MoveNext()) { PartOfSpeech p = (PartOfSpeech)(d.Value); excfps[p.ident] = new StreamReader(WNDB.ExcFile(p)); } }
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; }
/// <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; }
/// <summary> /// Performs a search based on the parameters setup /// in the Search constructor. /// </summary> /// <param name="doMorphs">Specify if morphs should be searched</param> /// <param name="thePartOfSpeech">The Part Of Speech to perform the search on</param> public void do_search(bool doMorphs, string thePartOfSpeech) { if (parts == null) { parts = new Hashtable(); } Search s = new Search(word, PartOfSpeech.of(thePartOfSpeech), sch, whichsense); s.do_search(doMorphs); parts[thePartOfSpeech] = s; buf += s.buf; }
internal void strAnt(PartOfSpeech pos, int wdnum, string head, string tail) { int i, j, wdoff; /* Go through all the pointers looking for anotnyms from the word * indicated by wdnum. When found, print all the antonym's * antonym pointers which point back to wdnum. */ for (i = 0; i < ptrs.Length; i++) { Pointer pt = ptrs[i]; if (pt.ptp.Ident == ANTPTR && pt.sce == wdnum) { SynSet psyn = new SynSet(pt.off, pos, this); for (j = 0; j < psyn.ptrs.Length; j++) { Pointer ppt = psyn.ptrs[j]; if (ppt.ptp.Ident == ANTPTR && ppt.dst == wdnum && ppt.off == hereiam) { wdoff = ppt.sce > 0 ? ppt.sce - 1 : 0; search.buf += head; /* Construct buffer containing formatted antonym, * then add it onto end of return buffer */ search.buf += deadjify(psyn.words[wdoff].word); /* Print additional lexicographer information and * WordNet sense number as indicated by flags */ isDirty = true; // TDMS 19 July 2006 - attempt to tie the logic which // populates buf to the logic that defines whether the // synset is populated with relevant information if (search.prlexid && psyn.words[wdoff].uniq != 0) { search.buf += psyn.words[wdoff].uniq; } int s = getsearchsense(wdoff + 1); psyn.words[wdoff].wnsns = s; if (WnOpt.Opt("-s").Flag) { search.buf += "#" + s; isDirty = true; // TDMS 19 July 2006 - attempt to tie the logic which // populates buf to the logic that defines whether the // synset is populated with relevant information } search.buf += tail; } } } } }
void strAnt(string tail, AdjSynSetType attype, int definition) { int i, wdcnt; bool first = true; if (WnOpt.Opt("-o").Flag) { search.buf += "(" + hereiam + ") "; } if (WnOpt.Opt("-a").Flag) { search.buf += "<" + WNDB.lexfiles[fnum] + "> "; search.prlexid = true; } else { search.prlexid = false; } /* print antonyms from cluster head (of indirect ant) */ search.buf += "INDIRECT (VIA "; for (i = 0, wdcnt = words.Length; i < wdcnt; i++) { if (first) { strAnt(PartOfSpeech.of("adj"), i + 1, "", ", "); first = false; } else { strAnt(PartOfSpeech.of("adj"), i + 1, ", ", ", "); } } search.buf += ") -> "; /* now print synonyms from cluster head (of indirect ant) */ for (i = 0, wdcnt = words.Length; i < wdcnt; i++) { catword(i, 0, 0); if (i < wdcnt - 1) { search.buf += ", "; } } if (WnOpt.Opt("-g").Flag&& defn != null && definition != 0) { search.buf += " -- " + defn; isDirty = true; // TDMS 19 July 2006 - attempt to tie the logic which // populates buf to the logic that defines whether the // synset is populated with relevant information } search.buf += tail; }
public MorphStr(string s, PartOfSpeech p) { string origstr = s; pos = p; if (pos.clss == "SATELLITE") pos = PartOfSpeech.of("adj"); /* Assume string hasnt had spaces substitued with _ */ str = origstr.Replace(' ', '_').ToLower(); searchstr = ""; cnt = str.Split('_').Length; svprep = 0; firsttime = true; }
static Exceptions() { IDictionaryEnumerator d = PartOfSpeech.parts.GetEnumerator(); while (d.MoveNext()) { PartOfSpeech p = (PartOfSpeech)(d.Value); if (!excfps.ContainsKey(p.key)) { excfps[p.key] = WNDB.GetStreamReader(WNDB.ExcFile(p)); } } }
/// <summary> /// Trace coordinate terms. /// </summary> /// <param name="ptp"></param> /// <param name="fpos"></param> /// <param name="depth"></param> internal void traceCoords(PointerType ptp, PartOfSpeech fpos, int depth) { for (int i = 0; i < ptrs.Length; i++) { Pointer pt = ptrs[i]; /* WN2.0 * if (pt.ptp.mnemonic=="HYPERPTR" && * (pt.sce==0 || * pt.sce==whichword)) */ // WN2.1 if statement change - TDMS if ((pt.ptp.Ident == HYPERPTR || pt.ptp.Ident == INSTANCE) && ((pt.sce == 0) || (pt.sce == whichword))) { if (!search.prflag) { strsns(sense + 1); search.prflag = true; } spaces("TRACEC", depth); SynSet cursyn = new SynSet(pt.off, pt.pos, this); search.wordsFrom(cursyn); cursyn.str("-> ", "\n", 1, 0, 0, 1); cursyn.tracePtrs(ptp, cursyn.pos, depth); // TDMS 6 Oct 2005 - build hierarchical results if (this.senses == null) { this.senses = new SynSetList(); } cursyn.thisptr = pt; // TDMS 17 Nov 2005 - add this pointer type this.senses.Add(cursyn); if (depth > 0) { depth = depthcheck(depth); cursyn.traceCoords(ptp, cursyn.pos, depth + 1); // TDMS 6 Oct 2005 - build hierarchical results // TODO: verify this if (this.senses == null) { this.senses = new SynSetList(); } cursyn.thisptr = pt; // TDMS 17 Nov 2005 - add this pointer type this.senses.Add(cursyn); } } } }
public WNDBpart(PartOfSpeech p) { try { index = new StreamReader(WNDB.IndexFile(p)); data = new StreamReader(WNDB.DataFile(p)); fps[p] = this; } catch { // TODO: handle bad dict path // ignore errors - as the user is locating the dictionary location // wordnet classes are trying to instantiate based on an incorrect dict path } }
public Exceptions(string word,PartOfSpeech pos) { if(laststr != ((System.IO.FileStream)(excfps[pos.ident].BaseStream)).Name) { laststr = ((System.IO.FileStream)(excfps[pos.ident].BaseStream)).Name; StreamReader fs = excfps[pos.ident]; Byte[] b = System.Text.Encoding.Unicode.GetBytes(fs.ReadToEnd()); excfps[pos.ident].BaseStream.Seek(0, SeekOrigin.Begin); exc = new MemoryStream(b); } line = WNDB.binSearch(word,exc); //excfps[pos.ident]); if (line!=null) endlp = line.IndexOf(' '); }
void strAnt(string tail, AdjSynSetType attype, int definition) { int i, wdcnt; bool first = true; if (WNOpt.opt("-o").flag) { search.buf += "(" + hereiam + ") "; } if (WNOpt.opt("-a").flag) { search.buf += "<" + WNDB.lexfiles[fnum] + "> "; search.prlexid = true; } else { search.prlexid = false; } /* print antonyms from cluster head (of indirect ant) */ search.buf += "INDIRECT (VIA "; for (i = 0, wdcnt = words.Length; i < wdcnt; i++) { if (first) { strAnt(PartOfSpeech.of("adj"), i + 1, "", ", "); first = false; } else { strAnt(PartOfSpeech.of("adj"), i + 1, ", ", ", "); } } search.buf += ") -> "; /* now print synonyms from cluster head (of indirect ant) */ for (i = 0, wdcnt = words.Length; i < wdcnt; i++) { catword(i, 0, 0); if (i < wdcnt - 1) { search.buf += ", "; } } if (WNOpt.opt("-g").flag&& defn != null && definition != 0) { search.buf += " -- " + defn; } search.buf += tail; }
public static MemoryStream index(PartOfSpeech p) //StreamReader index(PartOfSpeech p) { if (laststr == ((System.IO.FileStream)(WNDBpart.of(p).index.BaseStream)).Name) { return(ms); //WNDBpart.of(p).index; } else { laststr = ((System.IO.FileStream)(WNDBpart.of(p).index.BaseStream)).Name; StreamReader fs = WNDBpart.of(p).index; fs.BaseStream.Position = 0; Byte[] b = System.Text.Encoding.Unicode.GetBytes(fs.ReadToEnd()); ms = new MemoryStream(b); return(ms); //WNDBpart.of(p).index; } }
public MorphStr(string s, PartOfSpeech p) { string origstr = s; pos = p; if (pos.clss == "SATELLITE") { pos = PartOfSpeech.of("adj"); } /* Assume string hasnt had spaces substitued with _ */ str = origstr.Replace(' ', '_').ToLower(); searchstr = ""; cnt = str.Split('_').Length; svprep = 0; firsttime = true; }
public void beginDisambiguate() { Disambiguate(SParseTrees); ///////////////////////////get the text of senses /////////////////////// for (int i = 0; i < NewParseTreeSenses.Count; i++) { MyWordInfo[] mwiArr = (MyWordInfo[])NewParseTreeSenses[i]; ParseTree pt; pt = (ParseTree)NewSParseTrees[i]; AddArrStems(NewSParseTrees); for (int j = 0; j < mwiArr.Length; j++) { Wnlib.PartOfSpeech p = Wnlib.PartOfSpeech.of((Wnlib.PartsOfSpeech)mwiArr[j].Pos); try { //i need the stems here to get index Wnlib.Index index = Wnlib.Index.lookup(mwiArr[j].Word.ToLower(), p); SynSet sense = new SynSet(index, mwiArr[j].Sense, null); NodesSenses.Add(sense.defn); SensesNos.Add(mwiArr[j].Sense); string s = mwiArr[j].Word.ToLower() + " : " + sense.defn; DisambRes.Add(s); } catch { try { Wnlib.Index index = Wnlib.Index.lookup(Stems[j], p); SynSet sense = new SynSet(index, mwiArr[j].Sense, null); NodesSenses.Add(sense.defn); SensesNos.Add(mwiArr[j].Sense); string s = Stems[j].ToLower() + " : " + sense.defn; DisambRes.Add(s); } catch { }; }; } Senses = NodesSenses; } //////////////////////////add sense text & sense no to the nodes////////////////////////////// AddNodesSenses(NewSParseTrees); //////////////////////////put the output parsetrees in SparseTree again////////////////////////////// SParseTrees = NewSParseTrees; }
public Exceptions(string word, PartOfSpeech pos) { if (laststr != ((System.IO.FileStream)(excfps[pos.ident].BaseStream)).Name) { laststr = ((System.IO.FileStream)(excfps[pos.ident].BaseStream)).Name; StreamReader fs = excfps[pos.ident]; Byte[] b = System.Text.Encoding.Unicode.GetBytes(fs.ReadToEnd()); excfps[pos.ident].BaseStream.Seek(0, SeekOrigin.Begin); exc = new MemoryStream(b); } line = WNDB.binSearch(word, exc); //excfps[pos.ident]); if (line != null) { endlp = line.IndexOf(' '); } }
Opt(string a, string m, string p, int h, string b) { arg = a; if (m[0] == '-') { sch = new SearchType(true, m.Substring(1)); } else { sch = new SearchType(false, m); } pos = PartOfSpeech.of(p.ToLower()); helpx = h; label = b; id = opts.Count; opts.Add(this); }
internal void strAnt(PartOfSpeech pos, int wdnum, string head, string tail) { int i, j, wdoff; /* Go through all the pointers looking for anotnyms from the word * indicated by wdnum. When found, print all the antonym's * antonym pointers which point back to wdnum. */ for (i = 0; i < ptrs.Length; i++) { Pointer pt = ptrs[i]; if (pt.ptp.mnemonic == "ANTPTR" && pt.sce == wdnum) { SynSet psyn = new SynSet(pt.off, pos, this); for (j = 0; j < psyn.ptrs.Length; j++) { Pointer ppt = psyn.ptrs[j]; if (ppt.ptp.mnemonic == "ANTPTR" && ppt.dst == wdnum && ppt.off == hereiam) { wdoff = ppt.sce > 0?ppt.sce - 1:0; search.buf += head; /* Construct buffer containing formatted antonym, * then add it onto end of return buffer */ search.buf += deadjify(psyn.words[wdoff].word); /* Print additional lexicographer information and * WordNet sense number as indicated by flags */ if (search.prlexid && psyn.words[wdoff].uniq != 0) { search.buf += psyn.words[wdoff].uniq; } int s = getsearchsense(wdoff + 1); psyn.words[wdoff].wnsns = s; if (WNOpt.opt("-s").flag) { search.buf += "#" + s; } search.buf += tail; } } } } }
/* From search.c: * Find word in index file and return parsed entry in data structure. * Input word must be exact match of string in database. */ // From the WordNet Manual (http://wordnet.princeton.edu/man/wnsearch.3WN.html) // index_lookup() finds searchstr in the index file for pos and returns a pointer // to the parsed entry in an Index data structure. searchstr must exactly match the // form of the word (lower case only, hyphens and underscores in the same places) in // the index file. NULL is returned if a match is not found. public static Index lookup(string word, PartOfSpeech pos) { int j; if (word == "") { return(null); } // TDMS 14 Aug 2005 - changed to allow for numbers as well // because the database contains searches that can start with // numerals //if (!char.IsLetter(word[0])) if (!char.IsLetter(word[0]) && !char.IsNumber(word[0])) { return(null); } string line = WNDB.binSearch(word, pos); if (line == null) { return(null); } Index idx = new Index(); StrTok st = new StrTok(line); idx.wd = st.next(); /* the word */ idx.pos = PartOfSpeech.of(st.next()); /* the part of speech */ idx.sense_cnt = int.Parse(st.next()); /* collins count */ int ptruse_cnt = int.Parse(st.next()); /* number of pointers types */ idx.ptruse = new PointerType[ptruse_cnt]; for (j = 0; j < ptruse_cnt; j++) { idx.ptruse[j] = PointerType.of(st.next()); } int off_cnt = int.Parse(st.next()); idx.offs = new int[off_cnt]; idx.tagsense_cnt = int.Parse(st.next()); for (j = 0; j < off_cnt; j++) { idx.offs[j] = int.Parse(st.next()); } return(idx); }
static WNDB() { //Console.WriteLine("WNDB"); path = WNCommon.path; IDictionaryEnumerator d = PartOfSpeech.parts.GetEnumerator(); while (d.MoveNext()) { PartOfSpeech p = (PartOfSpeech)(d.Value); if (!indexfps.ContainsKey(p.key)) { indexfps[p.key] = GetStreamReader(IndexFile(p)); } if (!datafps.ContainsKey(p.key)) { datafps[p.key] = GetStreamReader(DataFile(p)); } } }
public static PartOfSpeech of(PartsOfSpeech f) { if (f == PartsOfSpeech.Noun) { return(PartOfSpeech.of("noun")); } if (f == PartsOfSpeech.Verb) { return(PartOfSpeech.of("verb")); } if (f == PartsOfSpeech.Adj) { return(PartOfSpeech.of("adj")); } if (f == PartsOfSpeech.Adv) { return(PartOfSpeech.of("adv")); } return(null); // unknown or not unique }
/// <summary> /// Traces pointer hierarchy. /// </summary> /// <param name="stp"></param> /// <param name="fpos"></param> /// <param name="depth"></param> internal void tracePtrs(SearchType stp, PartOfSpeech fpos, int depth) { int i; SynSet cursyn; PointerType ptp = stp.ptp; string prefix; int realptr; // WN2.1 for (i = 0; i < ptrs.Length; i++) { Pointer pt = ptrs[i]; // following if statement is WN2.1 - TDMS if ((ptp.ident == HYPERPTR && (pt.ptp.ident == HYPERPTR || pt.ptp.ident == INSTANCE)) || (ptp.ident == HYPOPTR && (pt.ptp.ident == HYPOPTR || pt.ptp.ident == INSTANCES)) || ((pt.ptp == ptp) && ((pt.sce == 0) || (pt.sce == whichword)))) { realptr = pt.ptp.ident; /* WN2.1 deal with INSTANCE */ if (!search.prflag) // print sense number and synset strsns(sense + 1); search.prflag = true; spaces("TRACEP", depth + (stp.rec ? 2 : 0)); // switch (ptp.mnemonic) // TDMS 11 JUL 2006 - changed switch to ident switch (pt.ptp.mnemonic) // TDMS - WN2.1 MOD switch (pt.ptp.ident) // TDMS 11 JUL 2006 - changed switch to ident { case PERTPTR: if (fpos.name == "adv") // TDMS "adverb") prefix = "Derived from " + pt.pos.name + " "; else prefix = "Pertains to " + pt.pos.name + " "; break; case ANTPTR: // TDMS 26/8/05 if (fpos.name == "adj") //TODO: which adjective will fall into the below? prefix = "Antonym of "; else prefix = ""; break; case PPLPTR: prefix = "Participle of verb"; break; case INSTANCE: prefix = "INSTANCE OF=> "; break; case INSTANCES: prefix = "HAS INSTANCE=> "; break; case HASMEMBERPTR: prefix = " HAS MEMBER: "; break; case HASSTUFFPTR: prefix = " HAS SUBSTANCE: "; break; case HASPARTPTR: prefix = " HAS PART: "; break; case ISMEMBERPTR: prefix = " MEMBER OF: "; break; case ISSTUFFPTR: // TDMS 26/8/05 prefix = " SUBSTANCE OF: "; break; case ISPARTPTR: // TDMS 26/8/05 prefix = " PART OF: "; break; default: prefix = "=> "; break; } /* Read synset pointed to */ cursyn = new SynSet(pt.off, pt.pos, this); search.wordsFrom(cursyn); // TDMS 6 Oct 2005 - build hierarchical results if (this.senses == null) this.senses = new SynSetList(); cursyn.thisptr = pt; // TDMS 17 Nov 2005 - add this pointer type this.senses.Add(cursyn); /* For Pertainyms and Participles pointing to a specific sense, indicate the sense then retrieve the synset pointed to and other info as determined by type. Otherwise, just print the synset pointed to. */ if ((ptp.ident == PERTPTR || ptp.ident == PPLPTR) && pt.dst != 0) { string tbuf = " (Sense " + cursyn.getsearchsense(pt.dst) + ")"; cursyn.str(prefix, tbuf, 0, pt.dst, 0, 1); if (ptp.ident == PPLPTR) // adj pointing to verb { cursyn.str(" =>", "\n", 1, 0, 1, 1); cursyn.tracePtrs(PointerType.of("HYPERPTR"), cursyn.pos, 0); } else if (fpos.name == "adv") // adverb pointing to adjective { cursyn.str(" =>", "\n", 0, 0, (pos.clss == "SATELLITE") ? 0 : 1, 1); // cursyn.traceptrs(HYPERPTR,pos,0); } else // adjective pointing to noun { cursyn.str(" =>", "\n", 1, 0, 1, 1); cursyn.tracePtrs(PointerType.of("HYPERPTR"), pos, 0); } } else cursyn.str(prefix, "\n", 1, 0, 1, 1); /* For HOLONYMS and MERONYMS, keep track of last one printed in buffer so results can be truncated later. */ if (ptp.ident >= PointerType.of("ISMEMBERPTR").ident && ptp.ident <= PointerType.of("HASPARTPTR").ident) { search.mark(); } if (depth > 0) { depth = cursyn.depthcheck(depth); cursyn.tracePtrs(ptp, cursyn.pos, depth + 1); } } } }
/// <summary> /// Trace coordinate terms. /// </summary> /// <param name="ptp"></param> /// <param name="fpos"></param> /// <param name="depth"></param> internal void traceCoords(PointerType ptp, PartOfSpeech fpos, int depth) { for (int i = 0; i < ptrs.Length; i++) { Pointer pt = ptrs[i]; /* WN2.0 if (pt.ptp.mnemonic=="HYPERPTR" && (pt.sce==0 || pt.sce==whichword)) */ // WN2.1 if statement change - TDMS if ((pt.ptp.ident == HYPERPTR || pt.ptp.ident == INSTANCE) && ((pt.sce == 0) || (pt.sce == whichword))) { if (!search.prflag) { strsns(sense + 1); search.prflag = true; } spaces("TRACEC", depth); SynSet cursyn = new SynSet(pt.off, pt.pos, this); search.wordsFrom(cursyn); cursyn.str("-> ", "\n", 1, 0, 0, 1); cursyn.tracePtrs(ptp, cursyn.pos, depth); // TDMS 6 Oct 2005 - build hierarchical results if (this.senses == null) this.senses = new SynSetList(); cursyn.thisptr = pt; // TDMS 17 Nov 2005 - add this pointer type this.senses.Add(cursyn); if (depth > 0) { depth = depthcheck(depth); cursyn.traceCoords(ptp, cursyn.pos, depth + 1); // TDMS 6 Oct 2005 - build hierarchical results // TODO: verify this if (this.senses == null) this.senses = new SynSetList(); cursyn.thisptr = pt; // TDMS 17 Nov 2005 - add this pointer type this.senses.Add(cursyn); } } } }
public static string binSearch(string word,PartOfSpeech pos) { return binSearch(word,WNDB.index(pos)); }
/// <summary> /// Trace meronyms. /// </summary> /// <param name="pbase"></param> /// <param name="fpos"></param> /// <param name="depth"></param> void traceInherit(PointerType pbase, PartOfSpeech fpos, int depth) { for (int i = 0; i < ptrs.Length; i++) { Pointer pt = ptrs[i]; if (pt.ptp.ident == HYPERPTR && (pt.sce == 0 || pt.sce == whichword)) { spaces("TRACEI", depth); SynSet cursyn = new SynSet(pt.off, pt.pos, this); search.wordsFrom(cursyn); cursyn.str("=> ", "\n", 1, 0, 0, 1); // TDMS 6 Oct 2005 - build hierarchical results // TODO: verify this if (this.senses == null) this.senses = new SynSetList(); cursyn.thisptr = pt; // TDMS 17 Nov 2005 - add this pointer type // TODO: This is adding senses incorrectly this.senses.Add(cursyn); cursyn.tracePtrs(pbase, PartOfSpeech.of("noun"), depth); cursyn.tracePtrs(pbase + 1, PartOfSpeech.of("noun"), depth); cursyn.tracePtrs(pbase + 2, PartOfSpeech.of("noun"), depth); if (depth > 0) { depth = depthcheck(depth); cursyn.traceInherit(pbase, cursyn.pos, depth + 1); } } } search.trunc(); }
internal static ArrayList wngrep(string wordPassed, PartOfSpeech pos) { ArrayList r = new ArrayList(); StreamReader fp = index(pos); fp.BaseStream.Position = 0; fp.DiscardBufferedData(); string word = wordPassed.Replace(" ", "_"); string line; while ((line = fp.ReadLine()) != null) { int lineLen = line.IndexOf(' '); line = line.Substring(0, lineLen); try { if (line.IndexOf(word) >= 0) r.Add(line.Replace("_", " ")); } catch { } } return r; }
public static WNDBpart of(PartOfSpeech p) { return (WNDBpart)fps[p]; }
public Search(string w, bool doMorphs, PartOfSpeech p, SearchType s, int sn) : this(w, p, s, sn) { if (p != null) do_search(doMorphs); }
internal static ArrayList wngrep(string wordPassed,PartOfSpeech pos) { ArrayList r = new ArrayList(); MemoryStream ms = index(pos); StreamReader inputFile = new StreamReader(ms); //= index(pos); inputFile.BaseStream.Seek(0L,SeekOrigin.Begin); inputFile.DiscardBufferedData(); string word = wordPassed.Replace(" ","_"); string line; while ((line=inputFile.ReadLine())!=null) { int lineLen = line.IndexOf(' '); line = line.Substring(0,lineLen); try { if (line.IndexOf(word)>=0) r.Add(line.Replace("_"," ")); } catch { } } return r; }
internal static string ExcFile(PartOfSpeech n) { return path+n.name+".exc"; }
public static StreamReader index(PartOfSpeech p) { return (StreamReader)indexfps[p.key]; }
public static StreamReader data(PartOfSpeech p) { return (StreamReader)datafps[p.key]; }
Index[] offsets = new Index[stringscount]; // of Index #endregion Fields #region Constructors public Indexes(string str,PartOfSpeech pos) { string[] strings = new string[stringscount]; str = str.ToLower(); strings[0] = str; strings[1] = str.Replace('_','-'); strings[2] = str.Replace('-','_'); strings[3] = str.Replace("-","").Replace("_",""); strings[4] = str.Replace(".",""); // TDMS - 14 Aug 2005 - added two more possibilities // to allow for spaces to be transformed // an example is a search for "11 plus", without this // transformation no result would be found strings[5] = str.Replace(' ','-'); strings[6] = str.Replace(' ','_'); offsets[0] = Index.lookup(str,pos); // TDMS - 14 Aug 2005 - changed 5 to 7 to allow for two // new possibilities for (int i=1;i<stringscount;i++) if (str!=strings[i]) offsets[i] = Index.lookup(strings[i],pos); fpos = pos; }
Opt(string a,string m,string p,int h,string b) { arg = a; if (m[0]=='-') sch = new SearchType(true,m.Substring(1)); else sch = new SearchType(false,m); pos = PartOfSpeech.of(p.ToLower()); helpx = h; label = b; id = opts.Count; opts.Add(this); }
internal static string DataFile(PartOfSpeech n) { return path+"data."+n.name; // WN2.1 - TDMS }
public WNHelp(SearchType s, PartOfSpeech p) : this((s.rec ? "-" : "") + s.ptp.mnemonic, p) { }
// 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; }
public WNDBpart(PartOfSpeech p) { try { Console.WriteLine("WNDBpart"); index = new StreamReader(WNDB.IndexFile(p)); data = new StreamReader(WNDB.DataFile(p)); fps[p] = this; } catch { MessageBox.Show("Bad dict path"); // TODO: handle bad dict path // ignore errors - as the user is locating the dictionary location // wordnet classes are trying to instantiate based on an incorrect dict path } }
internal void strAnt(PartOfSpeech pos, int wdnum, string head, string tail) { int i, j, wdoff; /* Go through all the pointers looking for anotnyms from the word indicated by wdnum. When found, print all the antonym's antonym pointers which point back to wdnum. */ for (i = 0; i < ptrs.Length; i++) { Pointer pt = ptrs[i]; if (pt.ptp.ident == ANTPTR && pt.sce == wdnum) { SynSet psyn = new SynSet(pt.off, pos, this); for (j = 0; j < psyn.ptrs.Length; j++) { Pointer ppt = psyn.ptrs[j]; if (ppt.ptp.ident == ANTPTR && ppt.dst == wdnum && ppt.off == hereiam) { wdoff = ppt.sce > 0 ? ppt.sce - 1 : 0; search.buf += head; /* Construct buffer containing formatted antonym, then add it onto end of return buffer */ search.buf += deadjify(psyn.words[wdoff].word); /* Print additional lexicographer information and WordNet sense number as indicated by flags */ isDirty = true; // TDMS 19 July 2006 - attempt to tie the logic which // populates buf to the logic that defines whether the // synset is populated with relevant information if (search.prlexid && psyn.words[wdoff].uniq != 0) search.buf += psyn.words[wdoff].uniq; int s = getsearchsense(wdoff + 1); psyn.words[wdoff].wnsns = s; if (WNOpt.opt("-s").flag) { search.buf += "#" + s; isDirty = true; // TDMS 19 July 2006 - attempt to tie the logic which // populates buf to the logic that defines whether the // synset is populated with relevant information } search.buf += tail; } } } } }
public WNHelp(string s, PartOfSpeech p) { help = (string)p.help[s]; }
//StreamReader index(PartOfSpeech p) public static MemoryStream index(PartOfSpeech p) { if(laststr == ((System.IO.FileStream)(WNDBpart.of(p).index.BaseStream)).Name) { return ms; //WNDBpart.of(p).index; } else { laststr = ((System.IO.FileStream)(WNDBpart.of(p).index.BaseStream)).Name; StreamReader fs = WNDBpart.of(p).index; fs.BaseStream.Position = 0; Byte[] b = System.Text.Encoding.Unicode.GetBytes(fs.ReadToEnd()); ms = new MemoryStream(b); return ms; //WNDBpart.of(p).index; } }
public static StreamReader data(PartOfSpeech p) { return WNDBpart.of(p).data; }
internal static string IndexFile(PartOfSpeech n) { return path+"index."+n.name; // WN2.1 - TDMS }