Ejemplo n.º 1
0
        public static PredictionDictionary Load(BinaryReader reader)
        {
            var wordCount = reader.ReadInt32();

            var wordListLength      = reader.ReadInt32();
            var wordList            = new List <WordEntry>(wordListLength);
            var wordIndexDictionary = new Dictionary <string, int>(wordListLength);

            for (var wordIndex = 0; wordIndex < wordListLength; wordIndex++)
            {
                var entry = WordEntry.Read(reader);
                wordList.Add(entry);
                wordIndexDictionary.Add(entry.Word, wordIndex);
            }

            var dictionaryListCount = reader.ReadInt32();

            var dictionaryList = new List <DictionaryEntry>(dictionaryListCount);

            for (var index = 0; index < dictionaryListCount; index++)
            {
                var entry = DictionaryEntry.Read(reader);
                dictionaryList.Add(entry);
            }

            var dictionary = new PredictionDictionary {
                _wordCount = wordCount, _dictionaryList = dictionaryList, _wordList = wordList, _wordIndexDictionary = wordIndexDictionary
            };

            return(dictionary);
        }
Ejemplo n.º 2
0
        int AddIndexWord(string word)
        {
            var normalisedWord = word.ToLowerInvariant();

            int index;

            if (_wordIndexDictionary.TryGetValue(normalisedWord, out index))
            {
                var entry = _wordList[index];
                if (entry.UseCount != byte.MaxValue)
                {
                    entry.UseCount++;
                }
            }
            else
            {
                index = _wordIndexDictionary.Count;

                var entry = new WordEntry {
                    Word = normalisedWord, UseCount = 1
                };
                _wordList.Add(entry);
                _wordIndexDictionary.Add(word, index);
            }

            return(index);
        }
Ejemplo n.º 3
0
        internal static WordEntry Read(BinaryReader reader)
        {
            var word     = reader.ReadString();
            var useCount = reader.ReadByte();
            var entry    = new WordEntry {
                Word = word, UseCount = useCount
            };

            return(entry);
        }