Beispiel #1
0
 public SynSetInfo(string word, Wnlib.SynSet synSet)
 {
     this.synSet     = synSet;
     this.word       = SynUtility.Text.UppercaseFirstLetter(word);
     this.defination = GetDefination();
     this.pOfSpeech  = GetPartOfSpeech();
     this.synonyms   = GetSynonyms();
     this.examples   = GetExamples();
 }
 static string[] GetSynsetDefinition(SynSet sense)
 {
     if (sense == null) return null;
     var gloss = sense.defn;
     foreach (Lexeme word in sense.words)            
         gloss += " " + word.word;
     
     string[] toks = Tokenize.Partition(gloss);
     return toks;
 }
        void Walk(SynSetList synsets, SynSet fromSS, int depth)
        {
            foreach (SynSet wsense in synsets)
            {                            
                Add_WordSenses(fromSS, wsense, depth);

                if (wsense.senses != null)
                    Walk(wsense.senses, wsense, depth + 1);
            }
            
        }
 static string[] GetSynsetDefinition(SynSet sense)
 {
     if (sense == null) return null;
     string gloss = sense.defn;
     //			if (gloss.IndexOf(";") != -1)
     //				gloss=gloss.Substring(0, gloss.IndexOf(";")) ;
     foreach (Lexeme word in sense.words)            
         gloss += " " + word.word;
     
     string[] toks = tokenize.Partition(gloss);
     return toks;
 }
Beispiel #5
0
 public SynSet(int off, PartOfSpeech p, SynSet fr)
     : this(off, p, "", fr)
 {
 }
Beispiel #6
0
		void WNOverview()
		{
			Index idx;
			//senses = new ArrayList();
			senses = new SynSetList();
			Indexes ixs = new Indexes(word, pos);
			while ((idx = ixs.next()) != null)
			{
				buf += "\n";
				/* Print synset for each sense.  If requested, precede
				   synset with synset offset and/or lexical file information.*/
				for (int sens = 0; sens < idx.offs.Length; sens++)
				{
					for (int j = 0; j < senses.Count; j++)
					{
						SynSet ss = (SynSet)senses[j];
						if (ss.hereiam == idx.offs[sens])
							goto skipit;

					}
					SynSet cursyn = new SynSet(idx, sens, this);

					bool svdflag = WNOpt.opt("-g").flag;
					WNOpt.opt("-g").flag = true;
					bool svaflag = WNOpt.opt("-a").flag;
					WNOpt.opt("-a").flag = WNOpt.opt("-A").flag;
					bool svoflag = WNOpt.opt("-o").flag;
					WNOpt.opt("-o").flag = WNOpt.opt("-O").flag;

					cursyn.str("" + (sens + 1) + ". ", "\n", 1, 0, 0, 0);

					WNOpt.opt("-g").flag = svdflag;
					WNOpt.opt("-a").flag = svaflag;
					WNOpt.opt("-o").flag = svoflag;
					wordsFrom(cursyn);
					cursyn.frames.Clear(); // TDMS 03 Jul 2006 - frames get added in wordnet.cs after filtering
					senses.Add(cursyn);
				skipit:
					;
				}
				/* Print sense summary message */
				if (senses.Count > 0)
				{
					taggedSenses = 0;

					if (senses.Count == 1)
						buf += "\nThe " + pos.name + " " + idx.wd + " has 1 sense";
					else
						buf += "\nThe " + pos.name + " " + idx.wd + " has " + senses.Count + " senses";
					if (idx.tagsense_cnt > 0)
					{
						taggedSenses = idx.tagsense_cnt;
						buf += " (first " + idx.tagsense_cnt + " from tagged texts)\n";
					}
					else
						buf += " (no senses from tagged texts)\n";
				}
			}
		}
Beispiel #7
0
        void WNOverview()
        {
            Index idx;

            //senses = new ArrayList();
            senses = new SynSetList();
            Indexes ixs = new Indexes(word, pos);

            while ((idx = ixs.next()) != null)
            {
                buf += "\n";

                /* Print synset for each sense.  If requested, precede
                 * synset with synset offset and/or lexical file information.*/
                for (int sens = 0; sens < idx.offs.Length; sens++)
                {
                    for (int j = 0; j < senses.Count; j++)
                    {
                        SynSet ss = (SynSet)senses[j];
                        if (ss.hereiam == idx.offs[sens])
                        {
                            goto skipit;
                        }
                    }
                    SynSet cursyn = new SynSet(idx, sens, this);

                    bool svdflag = WNOpt.opt("-g").flag;
                    WNOpt.opt("-g").flag = true;
                    bool svaflag = WNOpt.opt("-a").flag;
                    WNOpt.opt("-a").flag = WNOpt.opt("-A").flag;
                    bool svoflag = WNOpt.opt("-o").flag;
                    WNOpt.opt("-o").flag = WNOpt.opt("-O").flag;

                    cursyn.str("" + (sens + 1) + ". ", "\n", 1, 0, 0, 0);

                    WNOpt.opt("-g").flag = svdflag;
                    WNOpt.opt("-a").flag = svaflag;
                    WNOpt.opt("-o").flag = svoflag;
                    wordsFrom(cursyn);
                    cursyn.frames.Clear();                     // TDMS 03 Jul 2006 - frames get added in wordnet.cs after filtering
                    senses.Add(cursyn);
skipit:
                    ;
                }
                /* Print sense summary message */
                if (senses.Count > 0)
                {
                    taggedSenses = 0;

                    if (senses.Count == 1)
                    {
                        buf += "\nThe " + pos.name + " " + idx.wd + " has 1 sense";
                    }
                    else
                    {
                        buf += "\nThe " + pos.name + " " + idx.wd + " has " + senses.Count + " senses";
                    }
                    if (idx.tagsense_cnt > 0)
                    {
                        taggedSenses = idx.tagsense_cnt;
                        buf         += " (first " + idx.tagsense_cnt + " from tagged texts)\n";
                    }
                    else
                    {
                        buf += " (no senses from tagged texts)\n";
                    }
                }
            }
        }
Beispiel #8
0
		// From the WordNet Manual (http://wordnet.princeton.edu/man/wnsearch.3WN.html)
		// findtheinfo() is the primary search algorithm for use with database interface 
		// applications. Search results are automatically formatted, and a pointer to the 
		// text buffer is returned. All searches listed in WNHOME/include/wnconsts.h can be 
		// done by findtheinfo().
		void findtheinfo()
		{
			SynSet cursyn = null;
			Indexes ixs = new Indexes(word, pos);
			Index idx = null;
			int depth = sch.rec ? 1 : 0;
			senses = new SynSetList();
			switch (sch.ptp.mnemonic)
			{
				case "OVERVIEW":
					WNOverview();
					break;
				case "FREQ":
					if (countSenses == null)
						countSenses = new ArrayList();
					while ((idx = ixs.next()) != null)
					{
						countSenses.Add(idx.offs.Length);
						buf += "Sense " + countSenses.Count + ": " +
							idx.offs.Length;
					}
					break;
				case "WNGREP":
					strings = WNDB.wngrep(word, pos);
					for (int wi = 0; wi < strings.Count; wi++)
						buf += (string)strings[wi] + "\n";
					break;
				case "VERBGROUP":
					goto case "RELATIVES";
				case "RELATIVES":
					while ((idx = ixs.next()) != null)
						relatives(idx);
					break;
				default:
					/* look at all spellings of word */
					while ((idx = ixs.next()) != null)
					{
						/* Print extra sense msgs if looking at all senses */
						if (whichsense == ALLSENSES)
							buf += "\n";

						/* Go through all of the searchword's senses in the
						   database and perform the search requested. */
						for (int sense = 0; sense < idx.offs.Length; sense++)
							if (whichsense == ALLSENSES || whichsense == sense + 1)
							{
								prflag = false;
								/* Determine if this synset has already been done
								   with a different spelling. If so, skip it. */
								for (int j = 0; j < senses.Count; j++)
								{
									SynSet ss = (SynSet)senses[j];
									if (ss.hereiam == idx.offs[sense])
										goto skipit;
								}
								cursyn = new SynSet(idx, sense, this);

								//TODO: moved senses.add(cursyn) from here to each case and handled it differently according to search - this handling needs to be verified to ensure the filter is not to limiting
								switch (sch.ptp.mnemonic)
								{
									case "ANTPTR":
										if (pos.name == "adj")
											cursyn.traceAdjAnt();
										else
											cursyn.tracePtrs(sch.ptp, pos, depth);

										if (cursyn.isDirty)
										{ // TDMS 25 Oct 2005 - restrict to relevant values
											cursyn.frames.Clear(); // TDMS 03 Jul 2006 - frames get added in wordnet.cs after filtering
											senses.Add(cursyn);
										}
										/*
																				if (cursyn.senses != null )
																					if (cursyn.senses.isDirty)
																					{ // TDMS 25 Oct 2005 - restrict to relevant values
																						cursyn.frames.Clear(); // TDMS 03 Jul 2006 - frames get added in wordnet.cs after filtering
																						senses.Add(cursyn);
																					}
										*/
										// perform the senses restrictions based upon pos
										/*
																					switch(pos.name) {
																						case "verb":
																							if (cursyn.senses != null) // TDMS 25 Oct 2005 - restrict to relevant values
																								senses.Add(cursyn);
																							break;
													
																						default:
																							if (cursyn.senses != null && cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
																								senses.Add(cursyn);
																							break;
																					}
										*/
										break;
									case "COORDS":
										//eg. search for 'car', select Noun -> 'Coordinate Terms'
										cursyn.traceCoords(PointerType.of("HYPOPTR"), pos, depth);

										if (cursyn.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);
										/*
											if (cursyn.senses != null )
												if (cursyn.senses.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
													senses.Add(cursyn);
	*/
										break;
									case "FRAMES":
										//eg. search for 'right', select Verb -> 'Sample Sentences'
										cursyn.strFrame(true);
										// TDMS 03 JUL 2006 fixed relevancy check										if (cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
										if (cursyn.isDirty)
											senses.Add(cursyn);

										/*
											if (cursyn.frames.Count != 0) // TDMS 03 Jul 2006 - only add frame if there are any retrieved
												senses.Add(cursyn);
	*/
										break;
									case "MERONYM":
										//eg. search for 'car', select Noun -> 'Meronym'
										senses.isDirty = false;
										cursyn.tracePtrs(PointerType.of("HASMEMBERPTR"), pos, depth);
										cursyn.tracePtrs(PointerType.of("HASSTUFFPTR"), pos, depth);
										cursyn.tracePtrs(PointerType.of("HASPARTPTR"), pos, depth);

										if (cursyn.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);

										/*
											if (cursyn.senses != null )
												if (cursyn.senses.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
													senses.Add(cursyn);
	 */
										break;
									case "HOLONYM":
										//eg. search for 'car', select Noun -> 'Holonyms'
										cursyn.tracePtrs(PointerType.of("ISMEMBERPTR"), pos, depth);
										cursyn.tracePtrs(PointerType.of("ISSTUFFPTR"), pos, depth);
										cursyn.tracePtrs(PointerType.of("ISPARTPTR"), pos, depth);
										//											if (cursyn.senses != null && cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
										//												senses.Add(cursyn);
										if (cursyn.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);
										/*
																				if (cursyn.senses != null )
																					if (cursyn.senses.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
																						senses.Add(cursyn);
										 */
										break;
									case "HMERONYM":
										//eg. search for 'car', select Noun -> 'Meronyms Tree'
										cursyn.partsAll(sch.ptp);
										if (cursyn.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);
										//                                            senses.Add(SearchTrack.ssParent);
										/*
										if (cursyn.senses != null )
											if (cursyn.senses.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
												senses.Add(cursyn);
										 */
										//											if (cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
										//												senses.Add(cursyn);
										break;
									case "HHOLONYM":
										cursyn.partsAll(sch.ptp);
										if (cursyn.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);
										/*
										if (cursyn.senses != null) // && cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);
										 */
										break;
									case "SEEALSOPTR":
										cursyn.seealso();
										if (cursyn.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);
										/*
										if (cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);
										 */
										break;
									case "SIMPTR":
										goto case "HYPERPTR";
									case "SYNS":
										goto case "HYPERPTR";
									case "HYPERPTR":
										//eg. search for 'car', select Noun -> 'Synonyms/Hypernyms, ordered by estimated frequency'
										wordsFrom(cursyn);
										cursyn.strsns(sense + 1);
										prflag = true;
										cursyn.tracePtrs(sch.ptp, pos, depth);
										if (pos.name == "adj")
										{
											cursyn.tracePtrs(PointerType.of("PERTPTR"), pos, depth);
											cursyn.tracePtrs(PointerType.of("PPLPTR"), pos, depth);
										}
										else if (pos.name == "adv")
											cursyn.tracePtrs(PointerType.of("PERTPTR"), pos, depth);
										if (pos.name == "verb")
											cursyn.strFrame(false);

										if (cursyn.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);
										//												senses.Add(cursyn);
										break;
									case "NOMINALIZATIONS": // 26/8/05 - changed "DERIVATION" to "NOMINALIZATIONS" - this needs to be verified
										// derivation - TDMS
										cursyn.tracenomins(sch.ptp);
										if (cursyn.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);
										/*
																				if (cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
																					senses.Add(cursyn);
										 */
										break;
									//WN3.0
									case "PERTPTR":
										cursyn.strsns(sense + 1);
										prflag = true;
										cursyn.tracePtrs(PointerType.of("PERTPTR"), pos, depth);
										break;

									case "CLASSIFICATION":
										goto case "CLASS";
									case "CLASS":
										//eg. search for 'car', select Noun -> 'Domain Terms'
										cursyn.traceclassif(sch.ptp, new SearchType(false, sch.ptp));
										if (cursyn.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);
										/*
										if (cursyn.senses != null )
											if (cursyn.senses.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
												senses.Add(cursyn);
										 */
										break;

									case "HYPOPTR":
										//eg. search for 'car', select Noun -> 'Hyponyms'
										cursyn.tracePtrs(sch.ptp, pos, depth);
										if (cursyn.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);
										/*
																				if (cursyn.senses != null )
																					if (cursyn.senses.isDirty)
																					{ // TDMS 25 Oct 2005 - restrict to relevant values
																						cursyn.frames.Clear(); // TDMS 03 Jul 2006 - frames get added in wordnet.cs after filtering
																						senses.Add(cursyn);
																					}
										 */
										break;

									default:
										cursyn.tracePtrs(sch.ptp, pos, depth);
										if (cursyn.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
											senses.Add(cursyn);
										/*
																				if (cursyn.senses != null )
																					if (cursyn.senses.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
																						senses.Add(cursyn);
										 */
										break;
								}
							skipit:
								;
							}
					}
					break;
			}
		}
Beispiel #9
0
		RelList findVerbGroups(Index idx, RelList rellist)
		{
			int i, j, k;
			/* Read all senses */
			for (i = 0; i < idx.offs.Length; i++)
			{
				SynSet synset = new SynSet(idx.offs[i], pos, idx.wd, this, i);
				/* Look for VERBGROUP ptr(s) for this sense.  If found,
				   create group for senses, or add to existing group. */
				for (j = 0; j < synset.ptrs.Length; j++)
				{
					Pointer p = synset.ptrs[j];
					if (p.ptp.mnemonic == "VERBGROUP")
						/* Need to find sense number for ptr offset */
						for (k = 0; k < idx.offs.Length; k++)
							if (p.off == idx.offs[k])
							{
								rellist = addRelatives(idx, i, k, rellist);
								break;
							}
				}
			}
			return rellist;
		}
Beispiel #10
0
		public void Insert(int index, SynSet item)
		{
			List.Insert(index, item);
		}
Beispiel #11
0
        public void useList(ArrayList w, string help, ref string tmpstr)
        {
            int    j        = 0;
            int    i        = 0;
            int    x        = 0;
            int    senses   = 0;
            int    ttexts   = 0;
            string wrdtype  = "";
            string srchword = "";
            string tmpword  = null;

            if (help != null & !string.IsNullOrEmpty(help))
            {
            }

            for (j = 0; j <= w.Count - 1; j++)
            {
                Search            se  = (Search)w[j];
                Wnlib.PointerType ptp = (Wnlib.PointerType)se.sch.ptp;

                if (string.IsNullOrEmpty(srchword) & !string.IsNullOrEmpty(se.word))
                {
                    srchword = se.word;
                }

                if (se.senses.Count == 0 & string.IsNullOrEmpty(se.buf))
                {
                    continue;
                }


                if (senses == 0)
                {
                    senses  = se.senses.Count;
                    ttexts  = se.taggedSenses;
                    wrdtype = se.pos.name;
                }

                switch (se.sch.label)
                {
                case "Frequency":
                    ArrayList freqcats = new ArrayList();

                    freqcats.Add("extremely rare");
                    freqcats.Add("very rare");
                    freqcats.Add("rare");
                    freqcats.Add("uncommon");
                    freqcats.Add("common");
                    freqcats.Add("familiar");
                    freqcats.Add("very familiar");
                    freqcats.Add("extremely familiar");

                    string thisfreq = null;
                    int    cnt      = 0;
                    int    familiar = 0;
                    string wrd      = null;

                    cnt = (int)se.countSenses[0];
                    if (cnt == 0)
                    {
                        familiar = 0;
                    }
                    else if (cnt == 1)
                    {
                        familiar = 1;
                    }
                    else if (cnt == 2)
                    {
                        familiar = 2;
                    }
                    else if (cnt >= 3 & cnt <= 4)
                    {
                        familiar = 3;
                    }
                    else if (cnt >= 5 & cnt <= 8)
                    {
                        familiar = 4;
                    }
                    else if (cnt >= 9 & cnt <= 16)
                    {
                        familiar = 5;
                    }
                    else if (cnt >= 17 & cnt <= 32)
                    {
                        familiar = 6;
                    }
                    else if (cnt > 32)
                    {
                        familiar = 7;
                    }

                    switch (se.pos.name)
                    {
                    case "noun":
                        wrd = "a noun";

                        break;

                    case "adj":
                        wrd = "an adjective";

                        break;

                    case "verb":
                        wrd = "a verb";

                        break;

                    case "adverb":
                        wrd = "an adverb";

                        break;

                    default:

                        wrd = "a " + se.pos.name;
                        break;
                    }

                    tmpstr = se.word + " used as " + wrd + " is " + freqcats[familiar] + " (polysemy count=" + cnt + ").";
                    return;


                    break;

                case "Overview":
                    string tmpname = se.pos.name;

                    if (tmpname == "adj")
                    {
                        tmpname = "adjective";
                        // looks better when the full word is presented
                    }
                    tmpstr += "<p class='Type'>" + Strings.UCase(se.sch.label + " of " + tmpname + " " + se.word) + "</p>";

                    Wnlib.SynSet syns = null;
                    string       wrds = null;

                    for (x = 0; x <= se.senses.Count - 1; x++)
                    {
                        tmpstr += "<font color='red'><b>" + x + 1 + ") </b></font> ";
                        //                        tmpstr += "<font color='blue'><b>"

                        syns = (Wnlib.SynSet)se.senses[x];
                        wrds = "";

                        // loop for each synonym in the definition
                        for (i = 0; i <= syns.words.Length - 1; i++)
                        {
                            if (i > 0)
                            {
                                wrds += ",";
                            }

                            tmpword = syns.words[i].word;

                            wrds += tmpword;
                        }



                        string tmpstr2 = null;

                        tmpstr2 = syns.defn;
                        //tmpstr2 = linkDefinition(tmpstr2)
                        tmpstr += formatWrdDefn(wrds, tmpstr2);
                        //tmpstr += "</b><b>:</b></font> " & tmpstr2 & "<br />"
                    }


                    break;

                default:
                    tmpstr = decodeOther(se.buf);
                    break;
                }
            }


            tmpstr += "<font color='green'>";
            tmpstr += "<br />" + Constants.vbCrLf + wrdtype + " " + srchword + " has ";
            if (senses > 0)
            {
                tmpstr += senses + " sense(s)";
            }
            else
            {
                tmpstr += "no senses ";
            }

            if (ttexts > 0)
            {
                tmpstr += " (first " + ttexts + " from tagged texts)";
            }
            tmpstr += "</font>";

            // make contents of quotes italicized
            italicizeQuotes(ref tmpstr);
            //        End If
        }
Beispiel #12
0
        //As SizeF ' of Search
        public void useList(ArrayList w, string help, ref string tmpstr)
        {
            int    j        = 0;
            int    i        = 0;
            int    x        = 0;
            int    senses   = 0;
            int    ttexts   = 0;
            string wrdtype  = "";
            string srchword = "";
            string tmpword  = null;

            if (help != null & !string.IsNullOrEmpty(help))
            {
                //usePassage(help, tmpstr)
                //            tmpstr += help
            }

            // loop for noun, verb, adj, adv
            for (j = 0; j <= w.Count - 1; j++)
            {
                Search            se  = (Search)w[j];
                Wnlib.PointerType ptp = (Wnlib.PointerType)se.sch.ptp;

                if (string.IsNullOrEmpty(srchword) & !string.IsNullOrEmpty(se.word))
                {
                    srchword = se.word;
                }

                if (se.senses.Count == 0 & string.IsNullOrEmpty(se.buf))
                {
                    continue;
                }

                // this info will be used in the search summary
                if (senses == 0)
                {
                    senses  = se.senses.Count;
                    ttexts  = se.taggedSenses;
                    wrdtype = se.pos.name;
                }

                switch (se.sch.label)
                {
                case "Frequency":
                    ArrayList freqcats = new ArrayList();

                    freqcats.Add("extremely rare");
                    freqcats.Add("very rare");
                    freqcats.Add("rare");
                    freqcats.Add("uncommon");
                    freqcats.Add("common");
                    freqcats.Add("familiar");
                    freqcats.Add("very familiar");
                    freqcats.Add("extremely familiar");

                    string thisfreq = null;
                    int    cnt      = 0;
                    int    familiar = 0;
                    string wrd      = null;

                    cnt = (int)se.countSenses[0];
                    if (cnt == 0)
                    {
                        familiar = 0;
                    }
                    else if (cnt == 1)
                    {
                        familiar = 1;
                    }
                    else if (cnt == 2)
                    {
                        familiar = 2;
                    }
                    else if (cnt >= 3 & cnt <= 4)
                    {
                        familiar = 3;
                    }
                    else if (cnt >= 5 & cnt <= 8)
                    {
                        familiar = 4;
                    }
                    else if (cnt >= 9 & cnt <= 16)
                    {
                        familiar = 5;
                    }
                    else if (cnt >= 17 & cnt <= 32)
                    {
                        familiar = 6;
                    }
                    else if (cnt > 32)
                    {
                        familiar = 7;
                    }

                    switch (se.pos.name)
                    {
                    case "noun":
                        wrd = "a noun";

                        break;

                    case "adj":
                        wrd = "an adjective";

                        break;

                    case "verb":
                        wrd = "a verb";

                        break;

                    case "adverb":
                        wrd = "an adverb";

                        break;

                    default:
                        // should never get to here
                        wrd = "a " + se.pos.name;
                        break;
                    }

                    tmpstr = se.word + " used as " + wrd + " is " + freqcats[familiar] + " (polysemy count=" + cnt + ").";
                    return;


                    break;

                case "Overview":
                    string tmpname = se.pos.name;

                    if (tmpname == "adj")
                    {
                        tmpname = "adjective";
                        // looks better when the full word is presented
                    }
                    tmpstr += "<p class='Type'>" + Strings.UCase(se.sch.label + " of " + tmpname + " " + se.word) + "</p>";

                    Wnlib.SynSet syns = null;
                    string       wrds = null;

                    for (x = 0; x <= se.senses.Count - 1; x++)
                    {
                        tmpstr += "<font color='red'><b>" + x + 1 + ") </b></font> ";
                        //                        tmpstr += "<font color='blue'><b>"

                        syns = (Wnlib.SynSet)se.senses[x];
                        wrds = "";

                        // loop for each synonym in the definition
                        for (i = 0; i <= syns.words.Length - 1; i++)
                        {
                            if (i > 0)
                            {
                                wrds += ",";
                            }

                            tmpword = syns.words[i].word;

                            wrds += tmpword;

                            //If syns.words(i).uniq <> 0 Then
                            //    tmpstr += "</b><font color='red'><sup>" & syns.words(i).uniq
                            //    tmpstr += "</sup></font><b>"
                            //End If
                        }

                        //wrds = formatWordList(wrds)

                        //tmpstr += wrds

                        string tmpstr2 = null;

                        //tmpstr2 = syns.defn;
                        //tmpstr2 = linkDefinition(tmpstr2)
                        tmpstr += formatWrdDefn(wrds, syns);
                        //tmpstr += "</b><b>:</b></font> " & tmpstr2 & "<br />"
                    }


                    break;
                //Dim se As Search = CType(w(j), Search)
                //sw = se.word
                //usePassage(se.buf, tmpstr)
                //tmpstr.Text += se.buf;

                default:
                    Wnlib.SynSet ss = new Wnlib.SynSet();
                    ss.defn    = se.buf;
                    ss.hereiam = -1;
                    tmpstr     = decodeOther(ss);
                    break;
                    //tmpstr += se.buf
                    //tmpstr = Replace(tmpstr, "_", " ")
                    //tmpstr = Replace(tmpstr, vbLf, "<br />")
                }
            }

            // show the message at the bottom showing senses and tagged texts
            //        If senses = 0 Then
            //        tmpstr = "No results found for " & srchword & "."
            //        Else
            tmpstr += "<font color='green'>";
            tmpstr += "<br />" + Constants.vbCrLf + wrdtype + " " + srchword + " has ";
            if (senses > 0)
            {
                tmpstr += senses + " sense(s)";
            }
            else
            {
                tmpstr += "no senses ";
            }

            if (ttexts > 0)
            {
                tmpstr += " (first " + ttexts + " from tagged texts)";
            }
            tmpstr += "</font>";

            // make contents of quotes italicized
            italicizeQuotes(ref tmpstr);
            //        End If
        }
Beispiel #13
0
		/// <summary>
		/// Trace adjective antonyms.
		/// </summary>
		internal void traceAdjAnt()
		{
			SynSet newsynptr;
			int i, j;
			AdjSynSetType anttype = AdjSynSetType.DirectAnt;
			SynSet simptr, antptr;
			string similar = "        => ";
			/* This search is only applicable for ADJ synsets which have
			   either direct or indirect antonyms (not valid for pertainyms). */
			if (sstype == AdjSynSetType.DirectAnt || sstype == AdjSynSetType.IndirectAnt)
			{
				strsns(sense + 1);
				search.buf += "\n";
				/* if indirect, get cluster head */
				if (sstype == AdjSynSetType.IndirectAnt)
				{
					anttype = AdjSynSetType.IndirectAnt;
					i = 0;
					while (ptrs[i].ptp.ident != SIMPTR)
						i++;
					newsynptr = new SynSet(ptrs[i].off, PartOfSpeech.of("adj"), this);
				}
				else
					newsynptr = this;
				/* find antonyms - if direct, make sure that the antonym
				   ptr we're looking at is from this word */
				for (i = 0; i < newsynptr.ptrs.Length; i++)
				{
					if (newsynptr.ptrs[i].ptp.ident == ANTPTR && // TDMS 11 JUL 2006 // mnemonic=="ANTPTR" &&
						((anttype == AdjSynSetType.DirectAnt &&
						newsynptr.ptrs[i].sce == newsynptr.whichword) ||
						anttype == AdjSynSetType.IndirectAnt))
					{
						/* read the antonym's synset and print it.  if a
						   direct antonym, print it's satellites. */
						antptr = new SynSet(newsynptr.ptrs[i].off, PartOfSpeech.of("adj"), this);
						search.wordsFrom(antptr);
						// TDMS 6 Oct 2005 - build hierarchical results
						if (this.senses == null)
							this.senses = new SynSetList();
						//TODO: check the ptrs reference
						antptr.thisptr = newsynptr.ptrs[i];  // TDMS 17 Nov 2005 - add this pointer type
						this.senses.Add(antptr);
						if (anttype == AdjSynSetType.DirectAnt)
						{
							antptr.str("", "\n", 1, 0, 1, 1);
							for (j = 0; j < antptr.ptrs.Length; j++)
								if (antptr.ptrs[j].ptp.ident == SIMPTR) // TDMS 11 JUL 2006 - changed to INT //.mnemonic=="SIMPTR")
								{
									simptr = new SynSet(antptr.ptrs[j].off, PartOfSpeech.of("adj"), this);
									search.wordsFrom(simptr);
									simptr.str(similar, "\n", 1, 0, 0, 1);
									// TDMS 6 Oct 2005 - build hierarchical results
									if (antptr.senses == null)
										antptr.senses = new SynSetList();
									antptr.senses.Add(simptr);
								}
						}
						else
							antptr.strAnt("\n", anttype, 1);
					}
				}
			}
		}
Beispiel #14
0
		public void CopyTo(SynSet[] array, int index)
		{
			List.CopyTo(array, index);
		}
        private static MyWordInfo[] LookupCandidates(Index index, MyWordInfo pos)
        {
            if (pos.Sense < 0)
            {
                pos.Sense = 1;
            }
            SynSet synset = new Wnlib.SynSet(index.SynsetOffsets[pos.Sense - 1], index.PartOfSpeech, index.Wd, null, pos.Sense - 1);

            ArrayList lexemes  = new ArrayList();
            ArrayList synIndex = new ArrayList();

            foreach (Lexeme obj in synset.words)
            {
                lexemes.Add(obj);
                synIndex.Add(index.SynsetOffsets[pos.Sense - 1]);
            }

            if (index.SynsetOffsets.Length > 1)
            {
                if (lexemes.Count <= 1)
                {
                    for (int i = 0; i < index.SynsetOffsets.Length; i++)
                    {
                        synset = new SynSet(index.SynsetOffsets[i], index.PartOfSpeech, index.Wd, null, i);

                        foreach (Lexeme obj in synset.words)
                        {
                            synIndex.Add(index.SynsetOffsets[i]);
                            lexemes.Add(obj);
                        }
                    }
                }
                else
                {
                    synset = new SynSet(index.SynsetOffsets[0], index.PartOfSpeech, index.Wd, null, 0);
                    int count = 0;                   //get top most frequency word senses
                    foreach (Lexeme obj in synset.words)
                    {
                        lexemes.Add(obj);
                        synIndex.Add(index.SynsetOffsets[0]);
                        ++count;
                        if (count > 4)
                        {
                            break;
                        }
                    }
                }
            }

            ArrayList sortedSet = new ArrayList();
            Hashtable trace     = new Hashtable();
            int       hasSem    = 0;

            for (int i = 0; i < lexemes.Count; i++)
            {
                Lexeme word = (Lexeme)lexemes[i];
                word.word = word.word.ToLower();

                int senIndex = (int)synIndex[i];
                if (senIndex != -1 && word.wnsns > 0)
                {
                    word.semcor = new Wnlib.SemCor(word, senIndex);
                    lexemes[i]  = word;
                    ++hasSem;
                }

                if (!trace.ContainsKey(word.word))
                {
                    if ((word.semcor != null && word.semcor.semcor > 0) || (hasSem < 4))
                    {
                        trace[word.word] = 1;
                        sortedSet.Add(word);
                    }
                }
                //catch
                {}
            }

            var words = (Lexeme[])sortedSet.ToArray(typeof(Lexeme));

            ArrayList candidates = new ArrayList();

            for (int i = 0; i < words.Length; i++)
            {
                string word = words[i].word.Replace("_", " ");
                if (word[0] <= 'Z')
                {
                    continue;
                }

                MyWordInfo newpos = new MyWordInfo(word, pos.Pos);
                newpos.Sense = words[i].wnsns;
                if (words[i].semcor != null)
                {
                    newpos.Frequency = words[i].semcor.semcor;
                }
                else
                {
                    newpos.Frequency = 0;
                }

                candidates.Add(newpos);
            }

            if (!trace.ContainsKey(index.Wd))
            {
                candidates.Add(pos);
            }

            if (candidates.Count > 1)
            {
                CompareLexeme comparer = new CompareLexeme();
                candidates.Sort(comparer);
            }


            return((MyWordInfo[])candidates.ToArray(typeof(MyWordInfo)));
        }
Beispiel #16
0
		public int IndexOf(SynSet item)
		{
			return List.IndexOf(item);
		}
Beispiel #17
0
		public bool Contains(SynSet item)
		{
			return List.Contains(item);
		}
Beispiel #18
0
		public void Remove(SynSet item)
		{
			isDirty = true;
			List.Remove(item);
		}
Beispiel #19
0
        /// <summary>
        /// Trace classification.
        /// </summary>
        /// <param name="ptp"></param>
        /// <param name="stp"></param>
        internal void traceclassif(PointerType ptp, SearchType stp)         //,PartOfSpeech fpos)
        {
            int j;
            int idx = 0;
            //int svwnsnsflag;
            string head             = "";
            int    LASTTYPE         = PointerType.of("CLASS").Ident;
            int    OVERVIEW         = (LASTTYPE + 9);
            int    MAXSEARCH        = OVERVIEW;
            int    CLASSIF_START    = (MAXSEARCH + 1);
            int    CLASSIF_CATEGORY = (CLASSIF_START);              /* ;c */
            int    CLASSIF_USAGE    = (CLASSIF_START + 1);          /* ;u */
            int    CLASSIF_REGIONAL = (CLASSIF_START + 2);          /* ;r */
            int    CLASSIF_END      = CLASSIF_REGIONAL;
            int    CLASS_START      = (CLASSIF_END + 1);
            int    CLASS_CATEGORY   = (CLASS_START);              /* -c */
            int    CLASS_USAGE      = (CLASS_START + 1);          /* -u */
            int    CLASS_REGIONAL   = (CLASS_START + 2);          /* -r */
            int    CLASS_END        = CLASS_REGIONAL;
            //long prlist[1024];
            ArrayList prlist = new ArrayList();

            for (int i = 0; i < ptrs.Length; i++)
            {
                Pointer pt = ptrs[i];
                if (((pt.ptp.Ident >= CLASSIF_START) &&
                     (pt.ptp.Ident <= CLASSIF_END) && stp.ptp.Ident == PointerType.of("CLASSIFICATION").Ident) ||

                    ((pt.ptp.Ident >= CLASS_START) &&
                     (pt.ptp.Ident <= CLASS_END) && stp.ptp.Ident == PointerType.of("CLASS").Ident))
                {
                    if (!search.prflag)
                    {
                        strsns(sense + 1);
                        search.prflag = true;
                    }

                    SynSet cursyn = new SynSet(pt.off, pt.pos, this);
                    // 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);

                    for (j = 0; j < idx; j++)
                    {
                        if (pt.off == Convert.ToInt16(prlist[j]))
                        {
                            break;
                        }
                    }

                    if (j == idx)
                    {
                        prlist.Add(pt.off);
                        spaces("TRACEP", 0);

                        if (pt.ptp.Ident == CLASSIF_CATEGORY)
                        {
                            head = "TOPIC->(";                             // WN2.1 - TDMS
                        }
                        //							head = "CATEGORY->(";
                        else if (pt.ptp.Ident == CLASSIF_USAGE)
                        {
                            head = "USAGE->(";
                        }
                        else if (pt.ptp.Ident == CLASSIF_REGIONAL)
                        {
                            head = "REGION->(";
                        }
                        else if (pt.ptp.Ident == CLASS_CATEGORY)
                        {
                            head = "TOPIC_TERM->(";                             // WN2.1 - TDMS
                        }
                        //							head = "CATEGORY_TERM->(";
                        else if (pt.ptp.Ident == CLASS_USAGE)
                        {
                            head = "USAGE_TERM->(";
                        }
                        else if (pt.ptp.Ident == CLASS_REGIONAL)
                        {
                            head = "REGION_TERM->(";
                        }

                        head += pt.pos.name;
                        head += ") ";

                        //svwnsnsflag = wnsnsflag;
                        //wnsnsflag = 1;

                        //						printsynset(head, cursyn, "\n", DEFOFF, ALLWORDS,
                        //							SKIP_ANTS, SKIP_MARKER);
                        cursyn.str(head, "\n", 0, 0, 0, 0);

                        //wnsnsflag = svwnsnsflag;
                    }
                }
            }
        }
Beispiel #20
0
        // format lists
        private string decodeOther(SynSet ss)
        {
            string buf    = ss.defn;
            string tmpstr = null;

            string[] tmparr      = null;
            string   retstr      = null;
            string   wrdlst      = null;
            string   defn        = null;
            string   fullAppName = Assembly.GetExecutingAssembly().GetName().CodeBase;
            //This strips off the exe name
            string FullAppPath = Path.GetDirectoryName(fullAppName);

            FullAppPath = Strings.Mid(FullAppPath, Strings.Len("file:\\\\"));

            buf = Strings.Replace(buf, "_", " ");

            // split the summary buffer into lines
            tmparr = Strings.Split(buf, Constants.vbLf);

            int  i         = 0;
            int  x         = 0;
            bool senseflag = false;
            // determine if a sense has been located
            int prevLevel = 0;
            // previous indent level, so the system knows how many ul's to close and how to handle new indents
            ArrayList levelArray = new ArrayList();

            for (i = 2; i <= tmparr.GetUpperBound(0); i++)
            {
                tmpstr = tmparr[i];
                // get a line for processing

                // this is a section separator
                if (Strings.InStr(tmpstr, "----") > 0)
                {
                    continue;
                }

                // Sense, followed by a number (eg. Sense 1) denotes a definition line
                if (Strings.Left(tmpstr, 5) == "Sense" & !(Strings.InStr(tmpstr, "--") > 0))
                {
                    if (Strings.Asc(Strings.Mid(tmpstr, 7, 1)) >= 49 & Strings.Asc(Strings.Mid(tmpstr, 7, 1)) <= 57)
                    {
                        senseflag = true;

                        // collapse all open levels
                        if (prevLevel > 0)
                        {
                            int inc = 0;

                            for (inc = levelArray.Count; inc >= 0; inc += -1)
                            {
                                try
                                {
                                    levelArray.RemoveAt(levelArray.Count - 1);
                                    retstr += "</ul>";
                                }
                                catch
                                {
                                }
                            }

                            prevLevel = 0;
                        }

                        continue;
                    }
                }

                // this is a 'pertains to' line
                //            If Left(LTrim(tmpstr), 11) = "Pertains to" And InStr(tmpstr, "Sense") Then
                // this is 'pertains to' or antonym
                if (Strings.InStr(tmpstr, "(Sense") > 0)
                {
                    retstr   += "<br />" + Constants.vbCrLf + Strings.Left(tmpstr, Strings.InStr(tmpstr, ")"));
                    tmparr[i] = Strings.Mid(tmpstr, Strings.Len(Strings.Left(tmpstr, Strings.InStr(tmpstr, ")"))) + 1);
                    i        -= 1;
                    continue;
                }

                // this is a definition line
                if (senseflag)
                {
                    retstr += "<font color='red'><b>" + x + 1 + ") </b></font> ";
                    tmpstr  = Strings.RTrim(tmpstr);
                    wrdlst  = Strings.Left(tmpstr, Strings.InStr(tmpstr, "--") - 2);
                    defn    = Strings.Mid(tmpstr, Strings.Len(wrdlst) + 6);
                    wrdlst  = Strings.Replace(wrdlst, ", ", ",");

                    Wnlib.SynSet tmpss = new Wnlib.SynSet();
                    tmpss.defn    = defn;
                    tmpss.hereiam = -1;

                    retstr   += formatWrdDefn(wrdlst, tmpss);
                    x        += 1;
                    senseflag = false;
                    // this is an indented definition
                }
                else if (!senseflag & !string.IsNullOrEmpty(Strings.LTrim(Strings.RTrim(tmpstr))))
                {
                    if (Strings.InStr(tmpstr, "CATEGORY TERM") > 0)
                    {
                        // collapse higher levels
                        if (prevLevel > 0)
                        {
                            int inc = 0;

                            for (inc = 1; inc <= prevLevel; inc++)
                            {
                                try
                                {
                                    levelArray.RemoveAt(levelArray.Count - 1);
                                    retstr += "</ul>";
                                }
                                catch
                                {
                                }
                            }

                            prevLevel = 0;
                        }

                        wrdlst = Strings.Mid(tmpstr, Strings.InStr(tmpstr, ")") + 2);
                        wrdlst = formatWordList(wrdlst);
                        defn   = Strings.Left(tmpstr, Strings.InStr(tmpstr, ")"));

                        retstr += "<li>" + Constants.vbTab + defn + " " + wrdlst + "</li>";
                        continue;
                    }
                    else if (Strings.InStr(tmpstr, "(noun)") > 0 || Strings.InStr(tmpstr, "(verb)") > 0 || Strings.InStr(tmpstr, "(adj)") > 0 || Strings.InStr(tmpstr, ("adverb")) > 0)
                    {
                        // this check must be made first, otherwise confusion can occur from colons in the sentence (for the next check)
                        int lvl = 0;

                        lvl = indentLevel(tmpstr);

                        if (lvl < prevLevel)
                        {
                            int levdif = 0;
                            int inc    = 0;

                            levdif = prevLevel - lvl;
                            // get the number of levels we've jumped back

                            for (inc = 1; inc <= levdif; inc++)
                            {
                                // remove the defined level from the tracking array
                                try
                                {
                                    levelArray.RemoveAt(levelArray.Count - 1);
                                    retstr += "</ul>";
                                }
                                catch
                                {
                                }
                            }
                        }
                        else if (lvl > prevLevel)
                        {
                            levelArray.Add(lvl);
                            retstr += "<ul>";
                        }
                        else
                        {
                            if (levelArray.IndexOf(lvl) == -1)
                            {
                                // starting level was level 2, so this confuses the system
                                retstr += "<ul>";
                                levelArray.Add(lvl);
                            }
                        }

                        prevLevel = lvl;

                        wrdlst = Strings.Mid(tmpstr, Strings.InStr(tmpstr, ")") + 2);
                        defn   = "";
                        //defn = Mid(wrdlst, InStr(wrdlst, "--") + 3)
                        //wrdlst = Left(wrdlst, InStr(wrdlst, "--") - 1)
                        Wnlib.SynSet tmpss = new Wnlib.SynSet();
                        tmpss.defn    = "";
                        tmpss.hereiam = -1;
                        wrdlst        = formatWrdDefn(wrdlst, tmpss);

                        retstr += "<li>" + Constants.vbTab + Strings.Left(tmpstr, Strings.InStr(tmpstr, ")")) + " " + wrdlst + "</li>";
                        continue;
                    }
                    else if (Strings.InStr(tmpstr, ">") > 0)
                    {
                        // this check must be made first, otherwise confusion can occur from colons in the sentence (for the next check)
                        int lvl = 0;

                        lvl = indentLevel(tmpstr);

                        if (lvl < prevLevel)
                        {
                            int levdif = 0;
                            int inc    = 0;

                            levdif = prevLevel - lvl;
                            // get the number of levels we've jumped back

                            for (inc = 1; inc <= levdif; inc++)
                            {
                                // remove the defined level from the tracking array
                                try
                                {
                                    levelArray.RemoveAt(levelArray.Count - 1);
                                    retstr += "</ul>";
                                }
                                catch
                                {
                                }
                            }
                        }
                        else if (lvl > prevLevel)
                        {
                            levelArray.Add(lvl);
                            retstr += "<ul>";
                        }
                        else
                        {
                            if (levelArray.IndexOf(lvl) == -1)
                            {
                                // starting level was level 2, so this confuses the system
                                retstr += "<ul>";
                                levelArray.Add(lvl);
                            }
                        }

                        prevLevel = lvl;

                        wrdlst = Strings.Mid(tmpstr, Strings.InStr(tmpstr, ">") + 2);
                        if (wrdlst.IndexOf("--") > -1)
                        {
                            defn   = Strings.Mid(wrdlst, Strings.InStr(wrdlst, "--") + 3);
                            wrdlst = Strings.Left(wrdlst, Strings.InStr(wrdlst, "--") - 1);
                        }
                        else
                        {
                            int z = 1;                             // this line exists purely as a breakpoint placeholder
                        }

                        Wnlib.SynSet tmpss = new Wnlib.SynSet();
                        tmpss.defn    = defn;
                        tmpss.hereiam = -1;
                        wrdlst        = formatWrdDefn(wrdlst, tmpss);
                        retstr       += "<li>" + Constants.vbTab + Strings.Left(tmpstr, Strings.InStr(tmpstr, ">")) + " " + wrdlst + "</li>";
                        continue;
                    }
                    else if (Strings.InStr(tmpstr, ":") > 0)
                    {
                        int lvl = 0;

                        lvl = indentLevel(tmpstr);

                        if (lvl < prevLevel)
                        {
                            int levdif = 0;
                            int inc    = 0;

                            levdif = prevLevel - lvl;
                            // get the number of levels we've jumped back

                            for (inc = 1; inc <= levdif; inc++)
                            {
                                // remove the defined level from the tracking array
                                try
                                {
                                    levelArray.RemoveAt(levelArray.Count - 1);
                                    retstr += "</ul>";
                                }
                                catch
                                {
                                }
                            }
                        }
                        else if (lvl > prevLevel)
                        {
                            levelArray.Add(lvl);
                            retstr += "<ul>";
                        }
                        else
                        {
                            if (levelArray.IndexOf(lvl) == -1)
                            {
                                // starting level was level 2, so this confuses the system
                                retstr += "<ul>";
                                levelArray.Add(lvl);
                            }
                        }

                        prevLevel = lvl;

                        wrdlst = Strings.Mid(tmpstr, Strings.InStr(tmpstr, ":") + 2);
                        defn   = Strings.Mid(wrdlst, Strings.InStr(wrdlst, "--") + 3);
                        if (Strings.InStr(wrdlst, "--") == 0)
                        {
                            continue;
                        }
                        wrdlst = Strings.Left(wrdlst, Strings.InStr(wrdlst, "--") - 1);
                        Wnlib.SynSet tmpss = new Wnlib.SynSet();
                        tmpss.defn    = defn;
                        tmpss.hereiam = -1;
                        wrdlst        = formatWrdDefn(wrdlst, tmpss);

                        retstr += "<li>" + Constants.vbTab + Strings.Left(tmpstr, Strings.InStr(tmpstr, ":") + 1) + " " + wrdlst + "</li>";
                        continue;
                    }
                }
            }

            //If thirdindentflag Then
            //    retstr += "</ul>" ' close the third indent
            //    thirdindentflag = False
            //End If
            //If secondindentflag Then
            //    retstr += "</ul>" ' close the second indent
            //    secondindentflag = False
            //End If
            //If firstindentflag Then
            //    retstr += "</ul>" ' close the first indent
            //    firstindentflag = False
            //End If
            // collapse all open levels
            if (prevLevel > 0)
            {
                int inc = 0;

                for (inc = levelArray.Count; inc >= 0; inc += -1)
                {
                    //levelArray.RemoveAt(levelArray.IndexOf(inc))
                    try
                    {
                        levelArray.RemoveAt(levelArray.Count - 1);
                        retstr += "</ul>";
                    }
                    catch
                    {
                    }
                }

                prevLevel = 0;
            }

            return(retstr);
        }
Beispiel #21
0
 public int Add(SynSet item)
 {
     isDirty = true;
     return(List.Add(item));
 }
Beispiel #22
0
		public int Add(SynSet item)
		{
			isDirty = true;
			return List.Add(item);
		}
Beispiel #23
0
		/// <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();
		}
Beispiel #24
0
 public void Insert(int index, SynSet item)
 {
     List.Insert(index, item);
 }
Beispiel #25
0
		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;
						}
					}
				}
			}
		}
Beispiel #26
0
 public void Remove(SynSet item)
 {
     isDirty = true;
     List.Remove(item);
 }
        void Add_WordSenses(SynSet fromSS, SynSet toSS, int depth)
        {
            SynWord[toSS.hereiam] = toSS.words[0].word;
            if (fromSS != null)
                DepthMatrix[GetKey(fromSS.hereiam , toSS.hereiam)] = 1;
            if (!Distance.ContainsKey(toSS.hereiam))
            { 
                Distance[toSS.hereiam] = depth; 
            }
            else
            {
                int bestDepth = (int)Distance[toSS.hereiam];

                if (bestDepth > depth)
                    Distance[toSS.hereiam] = depth;
            }            
            return;           
        }
Beispiel #28
0
 public bool Contains(SynSet item)
 {
     return(List.Contains(item));
 }
Beispiel #29
0
		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;
		}
Beispiel #30
0
 public int IndexOf(SynSet item)
 {
     return(List.IndexOf(item));
 }
Beispiel #31
0
		public void wordsFrom(SynSet s)
		{
			for (int j = 0; j < s.words.Length; j++)
			{
				Lexeme lx = s.words[j];
				//				lx.wnsns = s.sense+1;
				lexemes[lx] = true;
			}
		}
Beispiel #32
0
		internal void seealso()
		{
			/* Find all SEEALSO pointers from the searchword and print the
			   word or synset pointed to. */
			string prefix; // = "      Also See-> ";
			//WN3.0 added updated wording for verb see also
			if (pos.name == "verb")
				prefix = "      Phrasal Verb-> ";
			else
				prefix = "      Also See-> ";

			for (int i = 0; i < ptrs.Length; i++)
			{
				Pointer p = ptrs[i];
				if (p.ptp.ident == SEEALSOPTR &&
					(p.sce == 0 || (p.sce == whichword)))
				{
					SynSet cursyn = new SynSet(p.off, p.pos, "", this);
					bool svwnsnsflag = WNOpt.opt("-s").flag;
					WNOpt.opt("-s").flag = true;
					cursyn.str(prefix, "", 0,
						(p.dst == 0) ? 0 : p.dst, 0, 0);
					prefix = "; ";
				}
			}
		}
Beispiel #33
0
		void doRelList(Index idx, RelList rellist)
		{
			int i;
			bool flag;
			SynSet synptr;
			BitSet outsenses = new BitSet(300);
			prflag = true;
			for (RelList rel = rellist; rel != null; rel = rel.next)
			{
				flag = false;
				for (i = 0; i < idx.offs.Length; i++)
					if (rel.senses[i] && !outsenses[i])
					{
						flag = true;
						synptr = new SynSet(idx.offs[i], pos, "", this, i);
						synptr.strsns(i + 1);
						synptr.tracePtrs(PointerType.of("HYPERPTR"), pos, 0);
						synptr.frames.Clear(); // TDMS 03 Jul 2006 - frames get added in wordnet.cs after filtering
						// TDMS 11 Oct 2005 - build hierarchical results
						senses.Add(synptr);
						outsenses[i] = true;
					}
				if (flag)
					buf += "--------------\n";
			}
			for (i = 0; i < idx.offs.Length; i++)
				if (!outsenses[i])
				{
					synptr = new SynSet(idx.offs[i], pos, "", this, i);
					synptr.strsns(i + 1);
					synptr.tracePtrs(PointerType.of("HYPERPTR"), pos, 0);
					synptr.frames.Clear(); // TDMS 03 Jul 2006 - frames get added in wordnet.cs after filtering
					// TDMS 11 Oct 2005 - build hierarchical results
					senses.Add(synptr);
					buf += "---------------\n";
				}
		}
Beispiel #34
0
		public SynSet(int off, PartOfSpeech p, string wd, SynSet fr)
			: this(off, p, wd, fr.search, fr.sense)
		{
		}
Beispiel #35
0
        // From the WordNet Manual (http://wordnet.princeton.edu/man/wnsearch.3WN.html)
        // findtheinfo() is the primary search algorithm for use with database interface
        // applications. Search results are automatically formatted, and a pointer to the
        // text buffer is returned. All searches listed in WNHOME/include/wnconsts.h can be
        // done by findtheinfo().
        void findtheinfo()
        {
            SynSet  cursyn = null;
            Indexes ixs    = new Indexes(word, pos);
            Index   idx    = null;
            int     depth  = sch.rec ? 1 : 0;

            senses = new SynSetList();
            switch (sch.ptp.mnemonic)
            {
            case "OVERVIEW":
                WNOverview();
                break;

            case "FREQ":
                if (countSenses == null)
                {
                    countSenses = new ArrayList();
                }
                while ((idx = ixs.next()) != null)
                {
                    countSenses.Add(idx.offs.Length);
                    buf += "Sense " + countSenses.Count + ": " +
                           idx.offs.Length;
                }
                break;

            case "WNGREP":
                if (!(customgrep == null))
                {
                    strings = customgrep.wngrep(word, pos);
                }
                else
                {
                    strings = WNDB.wngrep(word, pos);
                }
                for (int wi = 0; wi < strings.Count; wi++)
                {
                    buf += (string)strings[wi] + "\n";
                }
                break;

            case "VERBGROUP":
                goto case "RELATIVES";

            case "RELATIVES":
                while ((idx = ixs.next()) != null)
                {
                    relatives(idx);
                }
                break;

            default:
                /* look at all spellings of word */
                while ((idx = ixs.next()) != null)
                {
                    /* Print extra sense msgs if looking at all senses */
                    if (whichsense == ALLSENSES)
                    {
                        buf += "\n";
                    }

                    /* Go through all of the searchword's senses in the
                     * database and perform the search requested. */
                    for (int sense = 0; sense < idx.offs.Length; sense++)
                    {
                        if (whichsense == ALLSENSES || whichsense == sense + 1)
                        {
                            prflag = false;

                            /* Determine if this synset has already been done
                             * with a different spelling. If so, skip it. */
                            for (int j = 0; j < senses.Count; j++)
                            {
                                SynSet ss = (SynSet)senses[j];
                                if (ss.hereiam == idx.offs[sense])
                                {
                                    goto skipit;
                                }
                            }
                            cursyn = new SynSet(idx, sense, this);

                            //TODO: moved senses.add(cursyn) from here to each case and handled it differently according to search - this handling needs to be verified to ensure the filter is not to limiting
                            switch (sch.ptp.mnemonic)
                            {
                            case "ANTPTR":
                                if (pos.name == "adj")
                                {
                                    cursyn.traceAdjAnt();
                                }
                                else
                                {
                                    cursyn.tracePtrs(sch.ptp, pos, depth);
                                }

                                if (cursyn.isDirty)
                                {                                                 // TDMS 25 Oct 2005 - restrict to relevant values
                                    cursyn.frames.Clear();                        // TDMS 03 Jul 2006 - frames get added in wordnet.cs after filtering
                                    senses.Add(cursyn);
                                }

                                /*
                                 *                                                                              if (cursyn.senses != null )
                                 *                                                                                      if (cursyn.senses.isDirty)
                                 *                                                                                      { // TDMS 25 Oct 2005 - restrict to relevant values
                                 *                                                                                              cursyn.frames.Clear(); // TDMS 03 Jul 2006 - frames get added in wordnet.cs after filtering
                                 *                                                                                              senses.Add(cursyn);
                                 *                                                                                      }
                                 */
                                // perform the senses restrictions based upon pos

                                /*
                                 *                                                                                      switch(pos.name) {
                                 *                                                                                              case "verb":
                                 *                                                                                                      if (cursyn.senses != null) // TDMS 25 Oct 2005 - restrict to relevant values
                                 *                                                                                                              senses.Add(cursyn);
                                 *                                                                                                      break;
                                 *
                                 *                                                                                              default:
                                 *                                                                                                      if (cursyn.senses != null && cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
                                 *                                                                                                              senses.Add(cursyn);
                                 *                                                                                                      break;
                                 *                                                                                      }
                                 */
                                break;

                            case "COORDS":
                                //eg. search for 'car', select Noun -> 'Coordinate Terms'
                                cursyn.traceCoords(PointerType.of("HYPOPTR"), pos, depth);

                                if (cursyn.isDirty)                                                 // TDMS 25 Oct 2005 - restrict to relevant values
                                {
                                    senses.Add(cursyn);
                                }

                                /*
                                 *      if (cursyn.senses != null )
                                 *              if (cursyn.senses.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
                                 *                      senses.Add(cursyn);
                                 */
                                break;

                            case "FRAMES":
                                //eg. search for 'right', select Verb -> 'Sample Sentences'
                                cursyn.strFrame(true);
                                // TDMS 03 JUL 2006 fixed relevancy check										if (cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
                                if (cursyn.isDirty)
                                {
                                    senses.Add(cursyn);
                                }

                                /*
                                 *      if (cursyn.frames.Count != 0) // TDMS 03 Jul 2006 - only add frame if there are any retrieved
                                 *              senses.Add(cursyn);
                                 */
                                break;

                            case "MERONYM":
                                //eg. search for 'car', select Noun -> 'Meronym'
                                senses.isDirty = false;
                                cursyn.tracePtrs(PointerType.of("HASMEMBERPTR"), pos, depth);
                                cursyn.tracePtrs(PointerType.of("HASSTUFFPTR"), pos, depth);
                                cursyn.tracePtrs(PointerType.of("HASPARTPTR"), pos, depth);

                                if (cursyn.isDirty)                                                 // TDMS 25 Oct 2005 - restrict to relevant values
                                {
                                    senses.Add(cursyn);
                                }

                                /*
                                 *      if (cursyn.senses != null )
                                 *              if (cursyn.senses.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
                                 *                      senses.Add(cursyn);
                                 */
                                break;

                            case "HOLONYM":
                                //eg. search for 'car', select Noun -> 'Holonyms'
                                cursyn.tracePtrs(PointerType.of("ISMEMBERPTR"), pos, depth);
                                cursyn.tracePtrs(PointerType.of("ISSTUFFPTR"), pos, depth);
                                cursyn.tracePtrs(PointerType.of("ISPARTPTR"), pos, depth);
                                //											if (cursyn.senses != null && cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
                                //												senses.Add(cursyn);
                                if (cursyn.isDirty)                                                 // TDMS 25 Oct 2005 - restrict to relevant values
                                {
                                    senses.Add(cursyn);
                                }

                                /*
                                 *                                                                              if (cursyn.senses != null )
                                 *                                                                                      if (cursyn.senses.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
                                 *                                                                                              senses.Add(cursyn);
                                 */
                                break;

                            case "HMERONYM":
                                //eg. search for 'car', select Noun -> 'Meronyms Tree'
                                cursyn.partsAll(sch.ptp);
                                if (cursyn.isDirty)                                                 // TDMS 25 Oct 2005 - restrict to relevant values
                                {
                                    senses.Add(cursyn);
                                }
                                //                                            senses.Add(SearchTrack.ssParent);

                                /*
                                 * if (cursyn.senses != null )
                                 *      if (cursyn.senses.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
                                 *              senses.Add(cursyn);
                                 */
                                //											if (cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
                                //												senses.Add(cursyn);
                                break;

                            case "HHOLONYM":
                                cursyn.partsAll(sch.ptp);
                                if (cursyn.isDirty)                                                 // TDMS 25 Oct 2005 - restrict to relevant values
                                {
                                    senses.Add(cursyn);
                                }

                                /*
                                 * if (cursyn.senses != null) // && cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
                                 *      senses.Add(cursyn);
                                 */
                                break;

                            case "SEEALSOPTR":
                                cursyn.seealso();
                                if (cursyn.isDirty)                                                 // TDMS 25 Oct 2005 - restrict to relevant values
                                {
                                    senses.Add(cursyn);
                                }

                                /*
                                 * if (cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
                                 *      senses.Add(cursyn);
                                 */
                                break;

                            case "SIMPTR":
                                goto case "HYPERPTR";

                            case "SYNS":
                                goto case "HYPERPTR";

                            case "HYPERPTR":
                                //eg. search for 'car', select Noun -> 'Synonyms/Hypernyms, ordered by estimated frequency'
                                wordsFrom(cursyn);
                                cursyn.strsns(sense + 1);
                                prflag = true;
                                cursyn.tracePtrs(sch.ptp, pos, depth);
                                if (pos.name == "adj")
                                {
                                    cursyn.tracePtrs(PointerType.of("PERTPTR"), pos, depth);
                                    cursyn.tracePtrs(PointerType.of("PPLPTR"), pos, depth);
                                }
                                else if (pos.name == "adv")
                                {
                                    cursyn.tracePtrs(PointerType.of("PERTPTR"), pos, depth);
                                }
                                if (pos.name == "verb")
                                {
                                    cursyn.strFrame(false);
                                }

                                if (cursyn.isDirty)                                                 // TDMS 25 Oct 2005 - restrict to relevant values
                                {
                                    senses.Add(cursyn);
                                }
                                //												senses.Add(cursyn);
                                break;

                            case "NOMINALIZATIONS":                                             // 26/8/05 - changed "DERIVATION" to "NOMINALIZATIONS" - this needs to be verified
                                // derivation - TDMS
                                cursyn.tracenomins(sch.ptp);
                                if (cursyn.isDirty)                                                 // TDMS 25 Oct 2005 - restrict to relevant values
                                {
                                    senses.Add(cursyn);
                                }

                                /*
                                 *                                                                              if (cursyn.sense != 0) // TDMS 25 Oct 2005 - restrict to relevant values
                                 *                                                                                      senses.Add(cursyn);
                                 */
                                break;

                            //WN3.0
                            case "PERTPTR":
                                cursyn.strsns(sense + 1);
                                prflag = true;
                                cursyn.tracePtrs(PointerType.of("PERTPTR"), pos, depth);
                                break;

                            case "CLASSIFICATION":
                                goto case "CLASS";

                            case "CLASS":
                                //eg. search for 'car', select Noun -> 'Domain Terms'
                                cursyn.traceclassif(sch.ptp, new SearchType(false, sch.ptp));
                                if (cursyn.isDirty)                                                 // TDMS 25 Oct 2005 - restrict to relevant values
                                {
                                    senses.Add(cursyn);
                                }

                                /*
                                 * if (cursyn.senses != null )
                                 *      if (cursyn.senses.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
                                 *              senses.Add(cursyn);
                                 */
                                break;

                            case "HYPOPTR":
                                //eg. search for 'car', select Noun -> 'Hyponyms'
                                cursyn.tracePtrs(sch.ptp, pos, depth);
                                if (cursyn.isDirty)                                                 // TDMS 25 Oct 2005 - restrict to relevant values
                                {
                                    senses.Add(cursyn);
                                }

                                /*
                                 *                                                                              if (cursyn.senses != null )
                                 *                                                                                      if (cursyn.senses.isDirty)
                                 *                                                                                      { // TDMS 25 Oct 2005 - restrict to relevant values
                                 *                                                                                              cursyn.frames.Clear(); // TDMS 03 Jul 2006 - frames get added in wordnet.cs after filtering
                                 *                                                                                              senses.Add(cursyn);
                                 *                                                                                      }
                                 */
                                break;

                            default:
                                cursyn.tracePtrs(sch.ptp, pos, depth);
                                if (cursyn.isDirty)                                                 // TDMS 25 Oct 2005 - restrict to relevant values
                                {
                                    senses.Add(cursyn);
                                }

                                /*
                                 *                                                                              if (cursyn.senses != null )
                                 *                                                                                      if (cursyn.senses.isDirty) // TDMS 25 Oct 2005 - restrict to relevant values
                                 *                                                                                              senses.Add(cursyn);
                                 */
                                break;
                            }
skipit:
                            ;
                        }
                    }
                }
                break;
            }
        }
Beispiel #36
0
		public SynSet(int off, PartOfSpeech p, SynSet fr)
			: this(off, p, "", fr)
		{
		}
Beispiel #37
0
 public SynSet(int off, PartOfSpeech p, string wd, SynSet fr)
     : this(off, p, wd, fr.search, fr.sense)
 {
 }
Beispiel #38
0
		/// <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);
					}
				}
			}
		}
Beispiel #39
0
        /// <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);
                    }
                }
            }
        }
Beispiel #40
0
		/// <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);
					}
				}
			}
		}
Beispiel #41
0
        /// <summary>
        /// Trace adjective antonyms.
        /// </summary>
        internal void traceAdjAnt()
        {
            SynSet        newsynptr;
            int           i, j;
            AdjSynSetType anttype = AdjSynSetType.DirectAnt;
            SynSet        simptr, antptr;
            string        similar = "        => ";

            /* This search is only applicable for ADJ synsets which have
             * either direct or indirect antonyms (not valid for pertainyms). */
            if (sstype == AdjSynSetType.DirectAnt || sstype == AdjSynSetType.IndirectAnt)
            {
                strsns(sense + 1);
                search.buf += "\n";
                /* if indirect, get cluster head */
                if (sstype == AdjSynSetType.IndirectAnt)
                {
                    anttype = AdjSynSetType.IndirectAnt;
                    i       = 0;
                    while (ptrs[i].ptp.Ident != SIMPTR)
                    {
                        i++;
                    }
                    newsynptr = new SynSet(ptrs[i].off, PartOfSpeech.of("adj"), this);
                }
                else
                {
                    newsynptr = this;
                }

                /* find antonyms - if direct, make sure that the antonym
                 * ptr we're looking at is from this word */
                for (i = 0; i < newsynptr.ptrs.Length; i++)
                {
                    if (newsynptr.ptrs[i].ptp.Ident == ANTPTR &&                     // TDMS 11 JUL 2006 // mnemonic=="ANTPTR" &&
                        ((anttype == AdjSynSetType.DirectAnt &&
                          newsynptr.ptrs[i].sce == newsynptr.whichword) ||
                         anttype == AdjSynSetType.IndirectAnt))
                    {
                        /* read the antonym's synset and print it.  if a
                         * direct antonym, print it's satellites. */
                        antptr = new SynSet(newsynptr.ptrs[i].off, PartOfSpeech.of("adj"), this);
                        search.wordsFrom(antptr);
                        // TDMS 6 Oct 2005 - build hierarchical results
                        if (this.senses == null)
                        {
                            this.senses = new SynSetList();
                        }
                        //TODO: check the ptrs reference
                        antptr.thisptr = newsynptr.ptrs[i];                          // TDMS 17 Nov 2005 - add this pointer type
                        this.senses.Add(antptr);
                        if (anttype == AdjSynSetType.DirectAnt)
                        {
                            antptr.str("", "\n", 1, 0, 1, 1);
                            for (j = 0; j < antptr.ptrs.Length; j++)
                            {
                                if (antptr.ptrs[j].ptp.Ident == SIMPTR)                                 // TDMS 11 JUL 2006 - changed to INT //.mnemonic=="SIMPTR")
                                {
                                    simptr = new SynSet(antptr.ptrs[j].off, PartOfSpeech.of("adj"), this);
                                    search.wordsFrom(simptr);
                                    simptr.str(similar, "\n", 1, 0, 0, 1);
                                    // TDMS 6 Oct 2005 - build hierarchical results
                                    if (antptr.senses == null)
                                    {
                                        antptr.senses = new SynSetList();
                                    }
                                    antptr.senses.Add(simptr);
                                }
                            }
                        }
                        else
                        {
                            antptr.strAnt("\n", anttype, 1);
                        }
                    }
                }
            }
        }
Beispiel #42
0
		/// <summary>
		/// Trace classification.
		/// </summary>
		/// <param name="ptp"></param>
		/// <param name="stp"></param>
		internal void traceclassif(PointerType ptp, SearchType stp) //,PartOfSpeech fpos)
		{
			int j;
			int idx = 0;
			//int svwnsnsflag;
			string head = "";
			int LASTTYPE = PointerType.of("CLASS").ident;
			int OVERVIEW = (LASTTYPE + 9);
			int MAXSEARCH = OVERVIEW;
			int CLASSIF_START = (MAXSEARCH + 1);
			int CLASSIF_CATEGORY = (CLASSIF_START);        /* ;c */
			int CLASSIF_USAGE = (CLASSIF_START + 1);    /* ;u */
			int CLASSIF_REGIONAL = (CLASSIF_START + 2);    /* ;r */
			int CLASSIF_END = CLASSIF_REGIONAL;
			int CLASS_START = (CLASSIF_END + 1);
			int CLASS_CATEGORY = (CLASS_START);          /* -c */
			int CLASS_USAGE = (CLASS_START + 1);      /* -u */
			int CLASS_REGIONAL = (CLASS_START + 2);      /* -r */
			int CLASS_END = CLASS_REGIONAL;
			//long prlist[1024];
			ArrayList prlist = new ArrayList();

			for (int i = 0; i < ptrs.Length; i++)
			{
				Pointer pt = ptrs[i];
				if (((pt.ptp.ident >= CLASSIF_START) &&
					(pt.ptp.ident <= CLASSIF_END) && stp.ptp.ident == PointerType.of("CLASSIFICATION").ident) ||

					((pt.ptp.ident >= CLASS_START) &&
					(pt.ptp.ident <= CLASS_END) && stp.ptp.ident == PointerType.of("CLASS").ident))
				{
					if (!search.prflag)
					{
						strsns(sense + 1);
						search.prflag = true;
					}

					SynSet cursyn = new SynSet(pt.off, pt.pos, this);
					// 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);

					for (j = 0; j < idx; j++)
					{
						if (pt.off == Convert.ToInt16(prlist[j]))
						{
							break;
						}
					}

					if (j == idx)
					{
						prlist.Add(pt.off);
						spaces("TRACEP", 0);

						if (pt.ptp.ident == CLASSIF_CATEGORY)
							head = "TOPIC->("; // WN2.1 - TDMS
						//							head = "CATEGORY->(";
						else if (pt.ptp.ident == CLASSIF_USAGE)
							head = "USAGE->(";
						else if (pt.ptp.ident == CLASSIF_REGIONAL)
							head = "REGION->(";
						else if (pt.ptp.ident == CLASS_CATEGORY)
							head = "TOPIC_TERM->("; // WN2.1 - TDMS
						//							head = "CATEGORY_TERM->(";
						else if (pt.ptp.ident == CLASS_USAGE)
							head = "USAGE_TERM->(";
						else if (pt.ptp.ident == CLASS_REGIONAL)
							head = "REGION_TERM->(";

						head += pt.pos.name;
						head += ") ";

						//svwnsnsflag = wnsnsflag;
						//wnsnsflag = 1;

						//						printsynset(head, cursyn, "\n", DEFOFF, ALLWORDS,
						//							SKIP_ANTS, SKIP_MARKER);
						cursyn.str(head, "\n", 0, 0, 0, 0);

						//wnsnsflag = svwnsnsflag;
					}
				}
			}
		}
		private MyWordInfo[] LookupCandidates(Wnlib.Index index, MyWordInfo pos )
		{						
			if (pos.Sense < 0) pos.Sense=1;						
			SynSet synset=new Wnlib.SynSet( index.offs[pos.Sense - 1 ], index.pos , index.wd, null , pos.Sense - 1);					
						
			ArrayList lexemes=new ArrayList() ;
			ArrayList synIndex=new ArrayList() ;

			foreach (Lexeme obj in synset.words)
			{
				lexemes.Add(obj) ;
				synIndex.Add(index.offs[pos.Sense - 1 ]);
			}
			
			if (index.offs.Length > 1)
			{
				if (lexemes.Count <= 1)
				{
					for(int i=0; i < index.offs.Length; i++ )
					{				
						synset=new Wnlib.SynSet( index.offs[i], index.pos, index.wd, null, i );

						foreach (Lexeme obj in synset.words)
						{
							synIndex.Add(index.offs[i]);
							lexemes.Add(obj) ;
						}
					}
				}
				else
				{
					synset=new Wnlib.SynSet( index.offs[0], index.pos, index.wd, null, 0 );
					int count=0; //get top most frequency word senses
					foreach (Lexeme obj in synset.words)
					{
						lexemes.Add(obj) ;
						synIndex.Add(index.offs[0]);
						++count;
						if (count > 4) break;
					}

				}
			}
			
			ArrayList sortedSet=new ArrayList() ;
			Hashtable trace=new Hashtable() ;
			int hasSem=0;
			for (int i = 0; i < lexemes.Count; i++)
			{				
				Lexeme word=(Lexeme)lexemes[i];				
				word.word=word.word.ToLower() ;

				int senIndex=(int)synIndex[i];
				if (senIndex != -1  && word.wnsns > 0)
				{
					word.semcor=new Wnlib.SemCor(word, senIndex);
					lexemes[i]=word;					
					++hasSem;
				}

				if (!trace.ContainsKey(word.word) )					
				{					
					if ((word.semcor != null &&  word.semcor.semcor  > 0 ) || (hasSem < 4))
					{
						trace[word.word]=1;
						sortedSet.Add(word) ;
					}
				}
				//catch
				{}
			}
			
			Lexeme[] words=(Lexeme[])sortedSet.ToArray( typeof(Lexeme) );						

			ArrayList candidates=new ArrayList();

			for( int i=0; i < words.Length; i++ )
			{
				string word=words[i].word.Replace("_", " " );				
				if( word[0] <= 'Z' ) continue;

				MyWordInfo newpos=new MyWordInfo(word, pos.Pos) ;
				newpos.Sense=words[i].wnsns;
				if (words[i].semcor != null)
					newpos.Frequency=words[i].semcor.semcor;
				else
					newpos.Frequency=0;

				candidates.Add( newpos);								
			}

			if (!trace.ContainsKey (index.wd))
				candidates.Add(pos) ;

			if (candidates.Count > 1)
			{
				CompareLexeme comparer=new CompareLexeme();
				candidates.Sort(comparer);
			}
			

			return (MyWordInfo[])candidates.ToArray( typeof(MyWordInfo) );
		}
Beispiel #44
0
		/// <summary>
		/// Trace nominalizations.
		/// </summary>
		/// <param name="ptp"></param>
		internal void tracenomins(PointerType ptp) //,PartOfSpeech fpos)
		{
			/*
						int j;
						int idx = 0;
						ArrayList prlist = new ArrayList();
			*/
			for (int i = 0; i < ptrs.Length; i++)
			{
				Pointer pt = ptrs[i];
				// TDMS 26/8/05 changed DERIVATION to NOMINALIZATIONS - verify this
				if (pt.ptp.ident == NOMINALIZATIONS && (pt.sce == 0 || pt.sce == whichword))
				{
					if (!search.prflag)
					{
						strsns(sense + 1);
						search.prflag = true;
					}
					spaces("TRACEP", 0);
					SynSet cursyn = new SynSet(pt.off, pt.pos, this);
					search.wordsFrom(cursyn);
					cursyn.str("RELATED TO-> ", "\n", 0, 0, 0, 0);
					// 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);

					cursyn.tracePtrs(ptp, cursyn.pos, 0);
					/*
										for (j = 0; j < idx; j++) 
										{
											//#ifdef FOOP
											//						if (synptr->ptroff[i] == prlist[j]) 
											//						{
											//							break;
											//						}
											//#endif
										}

										if (j == idx) 
										{
											prlist.Add(pt.off);
											spaces("TRACEP",2);
											cursyn.str("=> ","\n",1,0,0,1);
										}
					*/
				}
			}
		}