void Build_WordData()
        {
            Opt opt = GetSearchType(WordInfo.Pos);
            if (opt == null) return;

            Search se = new Search(WordInfo.Word, true, opt.pos, opt.sch, WordInfo.Sense);
            if (se.senses != null && se.senses.Count == 0 && se.morphs.Count > 0)
            {
                IDictionaryEnumerator getEnum = se.morphs.GetEnumerator();
                while (getEnum.MoveNext())
                {
                    string morphForm = (string)getEnum.Key;
                    if ((Wnlib.Search)getEnum.Value != null)
                    {
                        se = (Wnlib.Search)getEnum.Value;
                        if (se.senses != null && se.senses.Count > 0)
                        {
                            WordInfo.Word = morphForm;
                            break;
                        }
                    }
                }
            }

            if (WordInfo.Pos == Wnlib.PartsOfSpeech.Verb)
            {
                int AA = 0;
            }

            if (se.senses != null)
                Walk(se.senses, null, 1);
            Compute_DepthMatrix();
        }
Exemple #2
0
        public List <string> WordNetExtraTerms(List <string> query)
        {
            List <string> returnedList = new List <string>();

            foreach (string term in query)
            {
                Wnlib.Search se = new Wnlib.Search(term, true, Wnlib.PartOfSpeech.of("noun"), new SearchType("DERIVATION"), 0);
                string[]     s  = Strings.Split(se.buf, Constants.vbLf);
                if (s.Length > 6)
                {
                    string at5 = s[5];
                    string at6 = s[6];
                    at5 = at5.Split(new string[] { "--" }, StringSplitOptions.RemoveEmptyEntries)[0];
                    at6 = at6.Split(new string[] { "--" }, StringSplitOptions.RemoveEmptyEntries)[0];
                    string[] arrayAt5 = at5.Split(new string[] { " ", "\t", "," }, StringSplitOptions.RemoveEmptyEntries);
                    string[] arrayAt6 = at6.Split(new string[] { " ", "=>", "\t", "," }, StringSplitOptions.RemoveEmptyEntries);
                    returnedList.AddRange(arrayAt5);
                    returnedList.AddRange(arrayAt6);
                    for (int i = 0; i < returnedList.Count; i++)
                    {
                        returnedList[i] = returnedList[i].Trim(new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' });
                    }
                }
            }
            return(returnedList);
        }
Exemple #3
0
	    static bool AddSearchFor(string s, PartOfSpeech pos, ArrayList list)
		{
			var se = new Search(s, false, pos, new SearchType(false, "OVERVIEW"), 0);
			if (se.lexemes.Count > 0)
				list.Add(se);

			return se.lexemes.Count > 0;
		}
Exemple #4
0
        bool AddSearchFor(string s,PartOfSpeech pos, ArrayList list)
        {
            Search se = new Search(s,false,pos,new SearchType(false,"OVERVIEW"),0);
            if(se.lexemes.Count > 0)
                list.Add(se);

            if(se.lexemes.Count > 0)
                return true; // results were found
            else
                return false;
        }
        static string[] GetAllDefinitionTokens(Search se)
        {
            string rels = "";
            if (se.senses[0].senses != null)
                foreach (SynSet ss in se.senses[0].senses)
                {
                    foreach (Lexeme ww in ss.words)
                        rels += " " + ww.word;
                    rels += ss.defn;
                }

            string[] toks = tokenize.Partition(rels);
            return toks;
        }
Exemple #6
0
        // TDMS 16 July 2006 - removed this method.
        // Method removed because if called externally
        // WNDBPart was not correctly constructed.
        // Calling is_defined(string searchstr,PartOfSpeech fpos)
        // correctly constructs WNDBPart.
        /*
        private static SearchSet is_defined(string word,string p)
        {
            Console.WriteLine("is_defined string, string");
            return is_defined(word,PartOfSpeech.of(p));
        }
        */
        /// <summary>
        /// Determines if a word is defined in the WordNet database and returns
        /// all possible searches of the word.
        /// </summary>
        /// <example> This sample displays a message stating whether the 
        /// word "car" exists as the part of speech "noun".
        /// <code>
        /// Wnlib.WNCommon.path = "C:\Program Files\WordNet\2.1\dict\"
        /// Dim wrd As String = "car"
        /// Dim POS As String = "noun"
        /// Dim b As Boolean = Wnlib.WNDB.is_defined(wrd, Wnlib.PartOfSpeech.of(POS)).NonEmpty.ToString
        /// 
        /// If b Then
        /// 	MessageBox.Show("The word " & wrd & " exists as a " & POS & ".")
        /// Else
        /// 	MessageBox.Show("The word " & wrd & " does not exist as a " & POS & ".")
        /// End If
        /// </code>
        /// </example>
        /// <param name="searchstr">The word to search for</param>
        /// <param name="fpos">Part of Speech (noun, verb, adjective, adverb)</param>
        /// <returns>A SearchSet or null if the word does not exist in the dictionary</returns>
        public static SearchSet is_defined(string searchstr,PartOfSpeech fpos)
        {
            Indexes ixs = new Indexes(searchstr,fpos);
            Index index;
            int i;
            int CLASS =          22;	/* - */
            int LASTTYPE =	CLASS;

            Search s = new Search(searchstr,fpos,new SearchType(false,"FREQ"),0);
            SearchSet retval = new SearchSet();
            while ((index=ixs.next())!=null)
            {
                retval=retval+"SIMPTR"+"FREQ"+"SYNS"+"WNGREP"+"OVERVIEW"; // added WNGREP - TDMS
                for (i=0;i<index.ptruse.Length;i++)
                {
                    PointerType pt = index.ptruse[i];
            //					retval=retval+pt;

                    // WN2.1 - TDMS
                    if (pt.ident <= LASTTYPE) {
                        retval = retval + pt;
                    } else if (pt.mnemonic == "INSTANCE") {
                        retval = retval + "HYPERPTR";
                    } else if (pt.mnemonic == "INSTANCES") {
                        retval = retval + "HYPOPTR";
                    }

                    // WN2.1 - TDMS
                    if (pt.mnemonic == "SIMPTR") {
                        retval = retval + "ANTPTR";
                    }

                    if (fpos.name=="noun")
                    {
                        /* set generic HOLONYM and/or MERONYM bit if necessary */
                        if (pt>="ISMEMBERPTR" && pt<="ISPARTPTR")
                            retval=retval+"HOLONYM";
                        else if (pt>="HASMEMBERPTR" && pt<="HASPARTPTR")
                            retval=retval+"MERONYM";
                    }
            // WN2.1 - TDMS					else if (fpos.name=="adj" && pt.mnemonic=="SIMPTR")
            //						retval=retval+"ANTPTR";
                }
                if (fpos.name=="noun")
                {
                    retval=retval+"RELATIVES";
                    if (index.HasHoloMero("HMERONYM",s))
                        retval=retval+"HMERONYM";
                    if (index.HasHoloMero("HHOLONYM",s))
                        retval=retval+"HHOLONYM";
                    if (retval["HYPERPTR"])
                        retval = retval+"COORDS";
                }
                else if (fpos.name=="verb")
                    retval=retval+"RELATIVES"+"FRAMES"; // added frames - TDMS
            }
            return retval;
        }
Exemple #7
0
        // TDMS 16 July 2006 - removed this method.
        // Method removed because if called externally
        // WNDBPart was not correctly constructed.
        // Calling is_defined(string searchstr,PartOfSpeech fpos)
        // correctly constructs WNDBPart.

        /*
         *              private static SearchSet is_defined(string word,string p)
         *              {
         *                      Console.WriteLine("is_defined string, string");
         *                      return is_defined(word,PartOfSpeech.of(p));
         *              }
         */

        /// <summary>
        /// Determines if a word is defined in the WordNet database and returns
        /// all possible searches of the word.
        /// </summary>
        /// <example> This sample displays a message stating whether the
        /// word "car" exists as the part of speech "noun".
        /// <code>
        /// Wnlib.WNCommon.path = "C:\Program Files\WordNet\2.1\dict\"
        /// Dim wrd As String = "car"
        /// Dim POS As String = "noun"
        /// Dim b As Boolean = Wnlib.WNDB.is_defined(wrd, Wnlib.PartOfSpeech.of(POS)).NonEmpty.ToString
        ///
        /// If b Then
        ///     MessageBox.Show("The word " &amp; wrd &amp; " exists as a " &amp; POS &amp; ".")
        /// Else
        ///     MessageBox.Show("The word " &amp; wrd &amp; " does not exist as a " &amp; POS &amp; ".")
        /// End If
        /// </code>
        /// </example>
        /// <param name="searchstr">The word to search for</param>
        /// <param name="fpos">Part of Speech (noun, verb, adjective, adverb)</param>
        /// <returns>A SearchSet or null if the word does not exist in the dictionary</returns>
        public static SearchSet is_defined(string searchstr, PartOfSpeech fpos)
        {
            Indexes ixs = new Indexes(searchstr, fpos);
            Index   index;
            int     i;
            int     CLASS    = 22;      /* - */
            int     LASTTYPE = CLASS;

            Search    s      = new Search(searchstr, fpos, new SearchType(false, "FREQ"), 0);
            SearchSet retval = new SearchSet();

            while ((index = ixs.next()) != null)
            {
                retval = retval + "SIMPTR" + "FREQ" + "SYNS" + "WNGREP" + "OVERVIEW";                 // added WNGREP - TDMS
                for (i = 0; i < index.ptruse.Length; i++)
                {
                    PointerType pt = index.ptruse[i];
                    //					retval=retval+pt;

                    // WN2.1 - TDMS
                    if (pt.ident <= LASTTYPE)
                    {
                        retval = retval + pt;
                    }
                    else if (pt.mnemonic == "INSTANCE")
                    {
                        retval = retval + "HYPERPTR";
                    }
                    else if (pt.mnemonic == "INSTANCES")
                    {
                        retval = retval + "HYPOPTR";
                    }

                    // WN2.1 - TDMS
                    if (pt.mnemonic == "SIMPTR")
                    {
                        retval = retval + "ANTPTR";
                    }

                    if (fpos.name == "noun")
                    {
                        /* set generic HOLONYM and/or MERONYM bit if necessary */
                        if (pt >= "ISMEMBERPTR" && pt <= "ISPARTPTR")
                        {
                            retval = retval + "HOLONYM";
                        }
                        else if (pt >= "HASMEMBERPTR" && pt <= "HASPARTPTR")
                        {
                            retval = retval + "MERONYM";
                        }
                    }
                    // WN2.1 - TDMS					else if (fpos.name=="adj" && pt.mnemonic=="SIMPTR")
                    //						retval=retval+"ANTPTR";
                }
                if (fpos.name == "noun")
                {
                    retval = retval + "RELATIVES";
                    if (index.HasHoloMero("HMERONYM", s))
                    {
                        retval = retval + "HMERONYM";
                    }
                    if (index.HasHoloMero("HHOLONYM", s))
                    {
                        retval = retval + "HHOLONYM";
                    }
                    if (retval["HYPERPTR"])
                    {
                        retval = retval + "COORDS";
                    }
                }
                else if (fpos.name == "verb")
                {
                    retval = retval + "RELATIVES" + "FRAMES";                     // added frames - TDMS
                }
            }
            return(retval);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="word"></param>
        /// <param name="senseIndex"></param>
        /// <param name="relatenessSearchTypes"></param>
        /// <returns></returns>
        public static string[][] GetRelatednessGlosses(string word, int senseNumber, Opt[] relatednessTypes)
        {
            string[][] relations = new string[relatednessTypes.Length + 1][];

            for (int i = 0; i < relatednessTypes.Length; i++)
            {
                Opt relateness = relatednessTypes[i];
                Search se = new Search(word, true, relateness.pos, relateness.sch, senseNumber);//								
                if (se.senses != null && se.senses.Count > 0)
                {
                    if (relations[0] == null)
                        relations[0] = GetSynsetDefinition(se.senses[0]);
                    if (se.senses[0].senses != null)
                        relations[i + 1] = GetAllDefinitionTokens(se);

                }
                else relations[i + 1] = null;
            }

            return relations;
        }
Exemple #9
0
		/// <summary>
		/// Performs a search based on the parameters setup
		/// in the Search constructor.
		/// </summary>
		/// <param name="m">Specify if morphs should be searched</param>
		/// <param name="p">The Part Of Speech to perform the search on</param>
		public void do_search(bool m, string p)
		{
			if (parts == null)
				parts = new Hashtable();
			Search s = new Search(word, PartOfSpeech.of(p), sch, whichsense);
			s.do_search(m);
			parts[p] = s;
			buf += s.buf;
		}
Exemple #10
0
 public bool HasHoloMero(string s, Search search)
 {
     return(HasHoloMero(PointerType.of(s), search));
 }
Exemple #11
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;
		}
Exemple #12
0
		/// <summary>
		/// Performs a search based on the parameters setup
		/// in the Search constructor.
		/// </summary>
		/// <param name="doMorphs">Specifies whether to perform a search on morphs.  
		/// This parameter is retrieved in the first
		/// call from do_search(bool m, string p).  If morph searching is specified
		/// and a morph is found, then on a recursive call to this method
		/// morphing will be turned off to prevent unnecessary morph searching.</param>
		internal void do_search(bool doMorphs)
		{
			findtheinfo();
			if (buf.Length > 0)
				buf = "\n" + sch.label + " of " + pos.name + " " + word + "\n" + buf;
			if (!doMorphs)
				return;
			morphs = new Hashtable();
			MorphStr st = new MorphStr(word, pos);
			string morphword;

			// if there are morphs then perform iterative searches
			// on each morph, filling the morph tree in the search
			// object.
			while ((morphword = st.next()) != null)
			{
				Search s = new Search(morphword, pos, sch, whichsense);
				s.do_search(false);
				// Fill the morphlist - eg. if verb relations of 'drunk' are requested, none are directly 
				// found, but the morph 'drink' will have results.  The morph hashtable will be populated 
				// into the search results and should be iterated instead of the returned synset if the 
				// morphs are non-empty
				morphs[morphword] = s;
				buf += s.buf;
			}
		}
Exemple #13
0
		public bool HasHoloMero(string s, Search search)
		{
			return HasHoloMero(PointerType.of(s), search);
		}
Exemple #14
0
		public SynSet(Index idx, int sens, Search sch)
			: this(idx.SynsetOffsets[sens], idx.PartOfSpeech, idx.Wd, sch, sens)
		{
		}
Exemple #15
0
 public SynSet(Index idx, int sens, Search sch) : this(idx.offs[sens], idx.pos, idx.wd, sch, sens)
 {
 }
		public SynSet(Index idx, int sens, Search sch)
			: this(idx.offs[sens], idx.pos, idx.wd, sch, sens)
		{
		}
		} // for serialization

		public SynSet(int offset, PartOfSpeech p, string wd, Search sch, int sens)
		{
			pos = p;
			hereiam = offset;
			search = sch;
			sense = sens;
			StreamReader f = WNDB.data(p);
			f.DiscardBufferedData();
			//f.BaseStream.Seek(off,SeekOrigin.Begin);
			f.BaseStream.Position = offset;
			string rec = f.ReadLine();
			//string str;
			if (!rec.StartsWith(offset.ToString("D8")))
			{
				Console.WriteLine("Error reading " + p.name + " file! " + offset + ": " + rec);
				WNDB.reopen(p);
				f = WNDB.data(p);
				f.DiscardBufferedData();
				//f.BaseStream.Seek(off, SeekOrigin.Begin);
				f.BaseStream.Position = offset;
				rec = f.ReadLine();
				//if (!rec.StartsWith(off.ToString("D8")))
				//    str = "";
				//else
				//    Console.WriteLine("Recovered...");
			}
			Parse(rec, pos, wd);
		}