示例#1
0
        /// <summary>
        /// Trace meronyms.
        /// </summary>
        /// <param name="pbase"></param>
        /// <param name="fpos"></param>
        /// <param name="depth"></param>
        private 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);
                    SynonymSet cursyn = new SynonymSet(pt.off, pt.pos, this, netData);
                    search.WordsFrom(cursyn);
                    cursyn.Str("=> ", "\n", 1, 0, 0, 1);
                    // 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
                    // TODO: This is adding senses incorrectly
                    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();
        }
示例#2
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.Key == "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)))
                {
                    SynonymSet cursyn      = new SynonymSet(p.off, p.pos, "", this, netData);
                    bool       svwnsnsflag = WordNetOption.Opt("-s").flag;
                    WordNetOption.Opt("-s").flag = true;
                    cursyn.Str(prefix, "", 0, (p.dst == 0) ? 0 : p.dst, 0, 0);
                    prefix = "; ";
                }
            }
        }
示例#3
0
        /// <summary>
        /// Trace nominalizations.
        /// </summary>
        /// <param name="ptp"></param>
        internal void Tracenomins(PointerType ptp)         //,PartOfSpeech fpos)
        {
            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);
                    SynonymSet cursyn = new SynonymSet(pt.off, pt.pos, this, netData);
                    search.WordsFrom(cursyn);
                    cursyn.Str("RELATED TO-> ", "\n", 0, 0, 0, 0);
                    // 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);

                    cursyn.TracePtrs(ptp, cursyn.pos, 0);
                }
            }
        }
示例#4
0
        private string[] LookupSynonyms(Index index)
        {
            // OVERVIEW: For each sense, grab the synset associated with our index.
            //           Then, add the lexemes in the synset to a list.

            ArrayList synonyms = new ArrayList(10);

            // for each sense...
            for (int s = 0; s < index.offs.Length; s++)
            {
                // read in the word and its pointers
                SynonymSet synset = new SynonymSet(index.offs[s], index.pos, index.wd, null, s, netData);

                // build a string out of the words
                for (int i = 0; i < synset.words.Length; i++)
                {
                    string word = synset.words[i].word.Replace("_", " ");

                    // if the word is capitalized, that means it's a proper noun. We don't want those.
                    if (word[0] <= 'Z')
                    {
                        continue;
                    }

                    // add it to the list if it's a different word
                    if (string.Compare(word, index.wd, true) != 0)
                    {
                        synonyms.Add(word);
                    }
                }
            }

            return((string[])synonyms.ToArray(typeof(string)));
        }
示例#5
0
文件: Index.cs 项目: envis10n/Warrens
        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);
        }
示例#6
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)
                {
                    SynonymSet psyn = new SynonymSet(pt.off, pos, this, netData);
                    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 (WordNetOption.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;
                        }
                    }
                }
            }
        }
示例#7
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.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);
                    SynonymSet cursyn = new SynonymSet(pt.off, pt.pos, this, netData);
                    search.WordsFrom(cursyn);
                    cursyn.Str("-> ", "\n", 1, 0, 0, 1);
                    cursyn.TracePtrs(ptp, cursyn.pos, depth);
                    // 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);

                    if (depth > 0)
                    {
                        depth = Depthcheck(depth);
                        cursyn.TraceCoords(ptp, cursyn.pos, depth + 1);
                        // 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);
                    }
                }
            }
        }
示例#8
0
        /// <summary>
        /// Trace adjective antonyms.
        /// </summary>
        internal void TraceAdjAnt()
        {
            SynonymSet    newsynptr;
            int           i, j;
            AdjSynSetType anttype = AdjSynSetType.DirectAnt;
            SynonymSet    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 SynonymSet(ptrs[i].off, PartOfSpeech.Of("adj"), this, netData);
                }
                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 SynonymSet(newsynptr.ptrs[i].off, PartOfSpeech.Of("adj"), this, netData);
                        search.WordsFrom(antptr);
                        // TDMS 6 Oct 2005 - build hierarchical results
                        if (senses == null)
                        {
                            senses = new List <SynonymSet>();
                        }
                        //TODO: check the ptrs reference
                        antptr.thisptr = newsynptr.ptrs[i];  // TDMS 17 Nov 2005 - add this pointer type
                        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 SynonymSet(antptr.ptrs[j].off, PartOfSpeech.Of("adj"), this, netData);
                                    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 List <SynonymSet>();
                                    }

                                    antptr.senses.Add(simptr);
                                }
                            }
                        }
                        else
                        {
                            antptr.StrAnt("\n", anttype, 1);
                        }
                    }
                }
            }
        }
示例#9
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);
                    }
                }
            }
        }
示例#10
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);
                    }
                }
            }
        }
示例#11
0
 public SynonymSet(int off, PartOfSpeech p, SynonymSet fr, WordNetData netdata)
     : this(off, p, "", fr, netdata)
 {
 }
示例#12
0
 public SynonymSet(int off, PartOfSpeech p, string wd, SynonymSet fr, WordNetData netdata)
     : this(off, p, wd, fr.search, fr.sense, netdata)
 {
 }