Exemplo n.º 1
0
        /// <summary>
        /// Find all first-level synonyms
        /// </summary>
        /// <param name="word">The word to look up</param>
        /// <returns>A list of all synonyms for all senses, and how many of each</returns>
        public static Dictionary<string, double> GetSynonyms(WordNetInterface iface, string word, WordNetAccess.PartOfSpeech part, SynonymLevel level, double scalePower, out List<WordNetAccess.PartOfSpeech> partsFound)
        {
            Dictionary<string, double> retVal = new Dictionary<string, double>();
            partsFound = new List<WordNetAccess.PartOfSpeech>();
            List<Index> indices = iface.GetIndex(word.ToLower(), part);
            foreach (Index index in indices)
            {
                partsFound.Add(index.DbPartOfSpeech);
                List<string> fileNames = iface.FileTools.GetDBaseForType(index.DbPartOfSpeech);
                foreach (long synSetOffset in index.SynSetsOffsets)
                {
                    List<string> synwords;
                    if (level == SynonymLevel.OneFull)
                        synwords = GetDefinitionSynonyms(synSetOffset, fileNames[0]);
                    else if (level == SynonymLevel.OnePartials)
                        synwords = GetPartialDefinitionSynonyms(synSetOffset, fileNames[0]);
                    else
                        synwords = GetDoublePartialDefinitionSynonyms(synSetOffset, fileNames[0]);
                    foreach (string synword in synwords)
                    {
                        string hiword = synword.ToUpper();
                        double count = 0;
                        retVal.TryGetValue(hiword, out count);
                        retVal[hiword] = count + 1;
                    }
                }
            }

            return CountsToSynonyms(word, scalePower, retVal);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Find all first-level synonyms
        /// </summary>
        /// <param name="word">The word to look up</param>
        /// <returns>A list of all synonyms for all senses, and how many of each</returns>
        public static Dictionary <string, double> GetSynonyms(WordNetInterface iface, string word, WordNetAccess.PartOfSpeech part, SynonymLevel level, double scalePower, out List <WordNetAccess.PartOfSpeech> partsFound)
        {
            Dictionary <string, double> retVal = new Dictionary <string, double>();

            partsFound = new List <WordNetAccess.PartOfSpeech>();
            List <Index> indices = iface.GetIndex(word.ToLower(), part);

            foreach (Index index in indices)
            {
                partsFound.Add(index.DbPartOfSpeech);
                List <string> fileNames = iface.FileTools.GetDBaseForType(index.DbPartOfSpeech);
                foreach (long synSetOffset in index.SynSetsOffsets)
                {
                    List <string> synwords;
                    if (level == SynonymLevel.OneFull)
                    {
                        synwords = GetDefinitionSynonyms(synSetOffset, fileNames[0]);
                    }
                    else if (level == SynonymLevel.OnePartials)
                    {
                        synwords = GetPartialDefinitionSynonyms(synSetOffset, fileNames[0]);
                    }
                    else
                    {
                        synwords = GetDoublePartialDefinitionSynonyms(synSetOffset, fileNames[0]);
                    }
                    foreach (string synword in synwords)
                    {
                        string hiword = synword.ToUpper();
                        double count  = 0;
                        retVal.TryGetValue(hiword, out count);
                        retVal[hiword] = count + 1;
                    }
                }
            }

            return(CountsToSynonyms(word, scalePower, retVal));
        }