Example #1
0
        /// <summary>
        /// Find only those synonyms which unambiguously mean the same thing
        /// </summary>
        public static List <string> GetExactSynonyms(WordNetInterface iface, string word, WordNetAccess.PartOfSpeech part)
        {
            List <Index> indices = iface.FileTools.GetIndex(word.ToLower(), part);

            if (indices.Count != 1)
            {
                return(null);    // ambiguous or none
            }
            Index index = indices[0];

            if (index.SynSetsOffsets.Count != 1)
            {
                return(null);    // ambiguous
            }
            List <string> fileNames    = iface.FileTools.GetDBaseForType(index.DbPartOfSpeech);
            long          synSetOffset = index.SynSetsOffsets[0];

            List <string> synwords = GetDefinitionSynonyms(synSetOffset, fileNames[0]);

            if (synwords.Count == 0)
            {
                return(null);
            }

            return(synwords);
        }
Example #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));
        }
        /// <summary>
        /// Returns a list of the Index objects stored in the cache corresponding to the given string and part(s) of speech
        /// </summary>
        /// <param name="word">The string to use as a key</param>
        /// <param name="part">The part of speech limitations</param>
        /// <returns>The Index objects</returns>
        public List <Index> GetIndex(string word, WordNetAccess.PartOfSpeech part)
        {
            if (word.Length == 0)
            {
                return(new List <Index>());
            }

            word = WordNetInterface.EncodeWord(word);

            // search in the file
            List <Index>  result        = new List <Index>();
            List <string> fileListIndex = GetIndexForType(part);

            for (int i = 0; i < fileListIndex.Count; i++)
            {
                long offset = FastSearch(word, fileListIndex[i], IndexFile.Tokenizer);
                if (offset > 0)
                {
                    Index index = ParseIndexAt(offset, fileListIndex[i]);
                    result.Add(index);
                }
            }
            return(result);
        }
        /// <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);
        }
        /// <summary>
        /// Find only those synonyms which unambiguously mean the same thing
        /// </summary>
        public static List<string> GetExactSynonyms(WordNetInterface iface, string word, WordNetAccess.PartOfSpeech part)
        {
            List<Index> indices = iface.FileTools.GetIndex(word.ToLower(), part);
            if (indices.Count != 1)
                return null;    // ambiguous or none

            Index index = indices[0];
            if (index.SynSetsOffsets.Count != 1)
                return null;    // ambiguous

            List<string> fileNames = iface.FileTools.GetDBaseForType(index.DbPartOfSpeech);
            long synSetOffset = index.SynSetsOffsets[0];

            List<string> synwords = GetDefinitionSynonyms(synSetOffset, fileNames[0]);
            if (synwords.Count == 0)
                return null;

            return synwords;
        }