public CachedWordList GetCachedWordByPOSList(PartOfSpeech pos)
            {
                CachedWordList list = null;

                _cachedWordByPOSLists.TryGetValue(pos, out list);
                return(list);
            }
            public CachedWordList CacheWordByPOSList(PartOfSpeech pos, List <Word> words, float frequency)
            {
                CachedWordList l = new CachedWordList()
                {
                    totalFrequency = frequency, words = words
                };

                _cachedWordByPOSLists.Add(pos, l);
                return(l);
            }
Пример #3
0
            /// <summary>
            /// Gets a list of all words of a specified part of speech.
            /// First tries to retrieve a cached list of words of the part of speech.
            /// If one does not exist, it is created and cached.
            /// </summary>
            /// <param name="pos">The part of speech the words in the list will have in commons.</param>
            /// <returns>A list of words that all have the specified part of speech in common.</returns>
            public CachedWordList GetWordListByPOS(PartOfSpeech pos)
            {
                CachedWordList wordListByPOS = cachedLists.GetCachedWordByPOSList(pos);

                if (wordListByPOS == null)
                {
                    List <Word> wordList  = words.Where(wkvp => wkvp.Value.PoS == pos).Select(wkvp => wkvp.Value).ToList();
                    float       frequency = wordList.Sum(w => w.Frequency);
                    wordListByPOS = cachedLists.CacheWordByPOSList(pos, wordList, frequency);
                }
                return(wordListByPOS);
            }
            /// <summary>
            /// Gets a weighted random word by its part of speech
            /// </summary>
            /// <param name="pos">The part of speech of the random word</param>
            /// <returns>A random word of the specified part of speech</returns>
            public Word GetRandomWordByPOS(PartOfSpeech pos)
            {
                CachedWordList wordList = WordDictionary.Instance.GetWordListByPOS(pos);

                return(GetWeightedRandomWordFromList(wordList.words, wordList.totalFrequency));
            }