private void RemoveChapterFromMaster(MasterDictionary masterDictionary, double chapterNum) { string chapterNumString = chapterNum.ToString().Replace(".", "-"); foreach (var masterDictEntry in masterDictionary.MentionedWordLocation) { foreach (var wordEntry in masterDictEntry.Value) { if (wordEntry.Key.Equals(chapterNumString)) { masterDictionary.MentionedWordLocation[masterDictEntry.Key].Remove(wordEntry.Key); } } } }
private void GenerateMasterJSON(string masterFile, MasterDictionary masterDictionary) { // Generate master dictionary JSON file logger.Info("Generating word dictionary."); File.WriteAllText(masterFile, JsonConvert.SerializeObject(masterDictionary, Formatting.Indented), System.Text.Encoding.UTF8); }
private void AddExistingChapterJSONToMasterDictionary(ChapterJSON chapterJSON, string masterFilePath) { MasterDictionary masterDictionary = new MasterDictionary(); if (File.Exists(masterFilePath)) { try { masterDictionary = JsonConvert.DeserializeObject <MasterDictionary>(File.ReadAllText(masterFilePath)); } catch { logger.Error(string.Format("Unable to open the master dictionary at {0}. Halting.", masterFilePath)); } } else { masterDictionary = new MasterDictionary { MentionedWordLocation = new SortedDictionary <string, SortedDictionary <string, List <int> > >() }; logger.Info("Created new dictionary."); } double chapterNum = chapterJSON.Chapter; logger.Info(string.Format("Formatting chapter {0}.", chapterNum)); string chapterNumString = chapterNum.ToString().Replace(".", "-"); foreach (var wordEntry in chapterJSON.MentionedWordChapterLocation) { var pageList = wordEntry.Value; var upperWord = wordEntry.Key; upperWord = AutoCorrectList(upperWord); if (masterDictionary.MentionedWordLocation.ContainsKey(upperWord)) { if (!masterDictionary.MentionedWordLocation[upperWord].ContainsKey(chapterNumString)) { // Chapter dictionary DNE! masterDictionary.MentionedWordLocation[upperWord].Add(chapterNumString, pageList); } else { foreach (var pageNum in pageList) { if (!masterDictionary.MentionedWordLocation[upperWord][chapterNumString].Contains(pageNum)) { masterDictionary.MentionedWordLocation[upperWord][chapterNumString].Add(pageNum); } } } } else { // Word DNE in dictionary var newChapterDict = new SortedDictionary <string, List <int> > { { chapterNumString, pageList } }; masterDictionary.MentionedWordLocation.Add(upperWord, newChapterDict); } } GenerateMasterJSON(masterFilePath, masterDictionary); }