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); }
public static PredictionDictionary Create(IPredictionEnvironment environment) { PredictionDictionary dictionary; try { using (var stream = environment.OpenDynamicDictionaryCache()) { if (stream != null) { dictionary = Load(stream); } else { dictionary = null; } } } catch { dictionary = null; } if (dictionary == null) { dictionary = new PredictionDictionary(); var history = environment.GetHistoryText(); dictionary.AddRawPhrases(history); using (var stream = environment.CreateDynamicDictionaryCache()) { dictionary.Save(stream); } } return(dictionary); }