Exemplo n.º 1
0
        private WordInfo GetMorphInfo(ArrayList morphinfos, string morph)
        {
            // Attempt to find the morph string in the list.
            // NOTE: Since the list should never get very large, a selection search will work just fine
            foreach (WordInfo morphinfo in morphinfos)
            {
                if (morphinfo.text == morph)
                {
                    return(morphinfo);
                }
            }

            // if not found, create a new one
            WordInfo wordinfo = new WordInfo
            {
                text        = morph,
                senseCounts = new int[enums.Length]
            };

            return((WordInfo)morphinfos[morphinfos.Add(wordinfo)]);
        }
Exemplo n.º 2
0
        private WordInfo LookupWordMorphs(string word)
        {
            // OVERVIEW: This functions only gets called when the word was not found with
            //           an exact match. So, enumerate all the parts of speech, then enumerate
            //           all of the word's morphs in each category. Perform a lookup on each
            //           morph and save the morph/strength/part-of-speech data sets. Finally,
            //           loop over all the data sets and then pick the strongest one.

            ArrayList wordinfos = new ArrayList();

            // for each part of speech...
            for (int i = 0; i < enums.Length; i++)
            {
                // get a valid part of speech
                PartsOfSpeech pos = enums[i];
                if (pos == PartsOfSpeech.None)
                {
                    continue;
                }

                // generate morph list
                Morph  morphs = new Morph(word, PartOfSpeech.Of(pos), netData);
                string morph;
                while ((morph = morphs.Next()) != null)
                {
                    // get an index to a synset collection
                    Index index = new Index(morph, PartOfSpeech.Of(pos), netData);

                    // none found?
                    if (index == null)
                    {
                        continue;
                    }

                    // save the wordinfo
                    WordInfo wordinfo = GetMorphInfo(wordinfos, morph);
                    wordinfo.senseCounts[i] = index.sense_cnt;
                }
            }

            // search the wordinfo list for the best match
            WordInfo bestWordInfo = new WordInfo();
            int      maxStrength  = 0;

            foreach (WordInfo wordinfo in wordinfos)
            {
                // for each part of speech...
                int maxSenseCount = 0;
                int strength      = 0;
                for (int i = 0; i < enums.Length; i++)
                {
                    // get a valid part of speech
                    PartsOfSpeech pos = enums[i];
                    if (pos == PartsOfSpeech.None)
                    {
                        continue;
                    }

                    // determine part of speech and strength
                    strength += wordinfo.senseCounts[i];
                    if (wordinfo.senseCounts[i] > maxSenseCount)
                    {
                        maxSenseCount         = wordinfo.senseCounts[i];
                        wordinfo.partOfSpeech = pos;
                    }
                }

                // best match?
                if (strength > maxStrength)
                {
                    maxStrength  = strength;
                    bestWordInfo = wordinfo;
                }
            }

            return(bestWordInfo);
        }