Exemple #1
0
        public bool HasHoloMero(PointerType p, Search search)
        {
            PointerType pbase;

            if (p.Mnemonic == "HMERONYM")
            {
                pbase = PointerType.Of("HASMEMBERPTR");
            }
            else
            {
                pbase = PointerType.Of("ISMEMBERPTR");
            }

            if (offs != null)
            {
                for (int i = 0; i < offs.Length; i++)
                {
                    SynonymSet s = new SynonymSet(offs[i], PartOfSpeech.Of("noun"), "", search, 0, netData);

                    if (s.Has(pbase) || s.Has(pbase + 1) || s.Has(pbase + 2))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #2
0
        private void DoRelList(Index idx, RelationalList rellist)
        {
            int        i;
            bool       flag;
            SynonymSet synptr;
            BitSet     outsenses = new BitSet(300);

            prflag = true;
            for (RelationalList 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 SynonymSet(idx.offs[i], pos, "", this, i, netData);
                        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 SynonymSet(idx.offs[i], pos, "", this, i, netData);
                    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";
                }
            }
        }
Exemple #3
0
        // From the WordNet Manual (http://wordnet.princeton.edu/man/wnsearch.3WN.html)
        // index_lookup() finds searchstr in the index file for pos and returns a pointer
        // to the parsed entry in an Index data structure. searchstr must exactly match the
        // form of the word (lower case only, hyphens and underscores in the same places) in
        // the index file. NULL is returned if a match is not found.
        public Index(string word, PartOfSpeech partOfSpeech, WordNetData netdata)
        {
            netData = netdata;
            int j;

            if (word == "" || (!char.IsLetter(word[0]) && !char.IsNumber(word[0])))
            {
                return;
            }

            string line = netData.BinSearch(word, partOfSpeech);

            if (line == null)
            {
                return;
            }

            string[] st = line.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);

            if (st.Length >= 6)
            {
                int stI = 0;
                wd        = st[stI++];                  /* the word */
                pos       = PartOfSpeech.Of(st[stI++]); /* the part of speech */
                sense_cnt = int.Parse(st[stI++]);       /* collins count */

                int ptruse_cnt = int.Parse(st[stI++]);  /* number of pointers types */
                ptruse = new PointerType[ptruse_cnt];
                for (j = 0; j < ptruse_cnt; j++)
                {
                    ptruse[j] = PointerType.Of(st[stI++]);
                }

                int off_cnt = int.Parse(st[stI++]);
                offs         = new int[off_cnt];
                tagsense_cnt = int.Parse(st[stI++]);
                for (j = 0; j < off_cnt; j++)
                {
                    offs[j] = int.Parse(st[stI++]);
                }
            }
        }
Exemple #4
0
        internal void PartsAll(PointerType ptp)
        {
            int         hasptr  = 0;
            PointerType ptrbase = PointerType.Of((ptp.Ident == HMERONYM) ? "HASMEMBERPTR" : "ISMEMBERPTR");

            /* First, print out the MEMBER, STUFF, PART info for this synset */
            for (int i = 0; i < 3; i++)
            {
                if (Has(ptrbase + i))
                {
                    TracePtrs(ptrbase + i, PartOfSpeech.Of("noun"), i);
                    hasptr++;
                }
            }
            /* Print out MEMBER, STUFF, PART info for hypernyms on HMERONYM search only */
            if (hasptr > 0 && ptp.Ident == HMERONYM)
            {
                search.Mark();

                TraceInherit(ptrbase, PartOfSpeech.Of("noun"), 1);
            }
        }
Exemple #5
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;
            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;
            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;
                    }

                    SynonymSet cursyn = new SynonymSet(pt.off, pt.pos, this, netData);
                    // TDMS 6 Oct 2005 - build hierarchical results
                    // TODO: verify this
                    if (senses == null)
                    {
                        senses = new List <SynonymSet>();
                    }

                    cursyn.thisptr = pt;  // TDMS 17 Nov 2005 - add this pointer type
                    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
                        }
                        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
                        }
                        else if (pt.ptp.Ident == CLASS_USAGE)
                        {
                            head = "USAGE_TERM->(";
                        }
                        else if (pt.ptp.Ident == CLASS_REGIONAL)
                        {
                            head = "REGION_TERM->(";
                        }

                        head += pt.pos.Key;
                        head += ") ";
                        cursyn.Str(head, "\n", 0, 0, 0, 0);
                    }
                }
            }
        }
Exemple #6
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;
            SynonymSet  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 (pt.ptp.Ident) // TDMS 11 JUL 2006 - changed switch to ident
                    {
                    case PERTPTR:
                        if (fpos.Key == "adv")                                 // TDMS "adverb")
                        {
                            prefix = "Derived from ";
                        }
                        else
                        {
                            prefix = "Pertains to ";
                        }

                        prefix += pt.pos.Key + " ";

                        break;

                    case ANTPTR:                             // TDMS 26/8/05
                        if (fpos.Key == "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 SynonymSet(pt.off, pt.pos, this, netData);
                    search.WordsFrom(cursyn);

                    // TDMS 6 Oct 2005 - build hierarchical results

                    if (senses == null)
                    {
                        senses = new List <SynonymSet>();
                    }

                    cursyn.thisptr = pt;  // TDMS 17 Nov 2005 - add this pointer type
                    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.Key == "adv")                         // adverb pointing to adjective
                        {
                            cursyn.Str("     =>", "\n", 0, 0, (pos.Clss == "SATELLITE") ? 0 : 1, 1);
                        }
                        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);
                    }
                }
            }
        }
Exemple #7
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().
        private void Findtheinfo()
        {
            Indexes ixs   = new Indexes(word, pos, netData);
            int     depth = sch.rec ? 1 : 0;

            senses = new List <SynonymSet>();
            Index idx;

            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 = netData.Wngrep(word, pos);
                }

                for (int wi = 0; wi < strings.Count; wi++)
                {
                    buf += (string)strings[wi] + "\n";
                }

                break;

            case "VERBGROUP":
            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. */
                            bool skipToEnd = false;
                            for (int j = 0; j < senses.Count; j++)
                            {
                                SynonymSet ss = senses[j];
                                if (ss.hereiam == idx.offs[sense])
                                {
                                    skipToEnd = true;
                                    break;
                                }
                            }

                            if (!skipToEnd)
                            {
                                SynonymSet cursyn = new SynonymSet(idx, sense, this, netData);

                                //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.Key == "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);
                                    }
                                    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);
                                    }
                                    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);
                                    }

                                    break;

                                case "MERONYM":
                                    //eg. search for 'car', select Noun -> 'Meronym'
                                    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);
                                    }

                                    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.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);
                                    }
                                    break;

                                case "HHOLONYM":
                                    cursyn.PartsAll(sch.ptp);
                                    if (cursyn.isDirty)         // 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);
                                    }
                                    break;

                                case "SIMPTR":
                                case "SYNS":
                                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.Key == "adj")
                                    {
                                        cursyn.TracePtrs(PointerType.Of("PERTPTR"), pos, depth);
                                        cursyn.TracePtrs(PointerType.Of("PPLPTR"), pos, depth);
                                    }
                                    else if (pos.Key == "adv")
                                    {
                                        cursyn.TracePtrs(PointerType.Of("PERTPTR"), pos, depth);
                                    }

                                    if (pos.Key == "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);
                                    }
                                    break;

                                //WN3.0
                                case "PERTPTR":
                                    cursyn.Strsns(sense + 1);
                                    prflag = true;
                                    cursyn.TracePtrs(PointerType.Of("PERTPTR"), pos, depth);
                                    break;

                                case "CLASSIFICATION":
                                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);
                                    }
                                    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);
                                    }
                                    break;

                                default:
                                    cursyn.TracePtrs(sch.ptp, pos, depth);
                                    if (cursyn.isDirty)         // TDMS 25 Oct 2005 - restrict to relevant values
                                    {
                                        senses.Add(cursyn);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
                break;
            }
        }
Exemple #8
0
 public bool HasHoloMero(string s, Search search)
 {
     return(HasHoloMero(PointerType.Of(s), search));
 }