/// <summary> /// This method loads a term dictionary from disk to memory /// </summary> public void loadTermDictionary() { string fileName; mainTermDictionary = new ConcurrentDictionary <string, TermInfo>(); if (Properties.Settings.Default.stemmer) { fileName = Properties.Settings.Default.postingFiles + "\\TermDictionaryStemmer.bin"; } else { fileName = Properties.Settings.Default.postingFiles + "\\TermDictionary.bin"; } using (FileStream newFileStream = new FileStream(fileName, FileMode.Open)) { BinaryReader br = new BinaryReader(newFileStream); while (br.BaseStream.Position != br.BaseStream.Length) { string term = br.ReadString(); int df = br.ReadInt32(); int cf = br.ReadInt32(); long pointer = br.ReadInt64(); string continuing = br.ReadString(); mainTermDictionary[term] = new TermInfo(); mainTermDictionary[term].df = df; mainTermDictionary[term].cf = cf; mainTermDictionary[term].postingfilepointer = pointer; string[] stringSeparators = new string[] { "&&&" }; string[] DocumentAndShowsArray = continuing.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries); if (!(DocumentAndShowsArray.Length == 1 && DocumentAndShowsArray[0].Equals(" "))) { for (int i = 0; i < DocumentAndShowsArray.Count(); i = i + 2) { mainTermDictionary[term].completion[DocumentAndShowsArray[i]] = Int32.Parse(DocumentAndShowsArray[i + 1]); } } else { mainTermDictionary[term].completion = new Dictionary <string, int>(); } } } }
/// <summary> /// This methods adds the terms from a temp dictionary generated from a single doc to a more larger temp dictionary conating all the /// term from a single file(containing many documents). /// </summary> /// <param name="uniqueDictionary">a term dictionary from a single document</param> public void addUniqueDicToMainDic(Dictionary <string, int> uniqueDictionary) { foreach (string term in uniqueDictionary.Keys) { TermInfo ti; if (mainTermDictionary.TryGetValue(term, out ti)) { ti.df++; ti.cf += uniqueDictionary[term]; } else { mainTermDictionary[term] = new TermInfo(); ti = mainTermDictionary[term]; ti.df++; ti.cf += uniqueDictionary[term]; } } }