Esempio n. 1
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;

                            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;
            }
        }
Esempio n. 2
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";
                    }
                }
            }
        }
Esempio n. 3
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);
        }