private void LoadDic_Click(object sender, RoutedEventArgs e) { //open new file OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Dictionary File|*.dicx"; dlg.Title = "Open a Dictionary File"; dlg.ShowDialog(); if (dlg.FileName != "") // If the file name is not an empty string ,open it. { if (ind == null) //if its not after a full run { pathclose = @".\"; ind = new Indexer(pathclose, isStem); } using (FileStream fs = new FileStream(dlg.FileName, FileMode.Open)) { IFormatter bf = new BinaryFormatter(); ind.dic = (Dictionary <string, DicRecord>)bf.Deserialize(fs);//read object } ind.writeTextDic(); showDic.IsEnabled = true; //notify when finished System.Windows.Forms.MessageBox.Show("Dictionary Loaded!", "Done!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { return; } }
private void StartEngine() { //Delete Exists Directory if (Directory.Exists(pathclose + @"\AfterPost")) { Directory.Delete(pathclose + @"\AfterPost", true); } if (Directory.Exists(pathclose + @"\tempPost")) { Directory.Delete(pathclose + @"\tempPost", true); } /* if (Directory.Exists(pathclose + @"\CacheDic")) * Directory.Delete(pathclose + @"\CacheDic", true);*/ //initlizing reader,parser,indexer r = new ReadFile(pathopen); p = new Parser(pathopen + @"\stop_words.txt", isStem); ind = new Indexer(pathclose, isStem); //For program timing DateTime start = DateTime.Now; for (int i = 0; i < r.files.Count; i++) { Debug.WriteLine(i); //return dictionary<DocNO, TEXT> d = r.ProccessDocs(r.files[i]); foreach (string s in d.Keys) { //Parse DOC Dictionary <string, termInfo> docdic = p.Parse(d[s]); //make temp Post file ind.tempPosting(docdic, s.Trim(' '), p.maxterm, p.maxtf); } } StreamWriter sw = new StreamWriter(pathopen + @"\docsMap.txt"); sw.WriteLine(r.sb.ToString()); sw.Close(); ind.tempPost(); //Write the last dictionary p.clearSteam(); // cleans the stemmers dictionary ind.mergefile(); // merge and split ind.writeTextDic(); // WriteDic For show TimeSpan ts3 = DateTime.Now - start; //The requested popup of this run System.Windows.Forms.MessageBox.Show("Number Of Docs Indexed : " + ind.TotalDoc + "\nTime Of Running : " + ts3.TotalSeconds + "\nIndex Size[bytes] : " + ind.PostSize + "\nCache Size[bytes] : " + ind.cacheSize, "Done!", MessageBoxButtons.OK, MessageBoxIcon.Information); }
//Load all files of part 2-corpus, stop words, cache, dictionary ,posting and rank private void Load2_click(object sender, RoutedEventArgs e) { //Folder Chooser var dlg = new FolderBrowserDialog(); System.Windows.Forms.DialogResult result = dlg.ShowDialog(this.GetIWin32Window()); //change the source path if (dlg.SelectedPath != "") { pathopen = dlg.SelectedPath; pathclose = dlg.SelectedPath; //init all the first part objects ind = new Indexer(pathclose, isStem); p = new Parser(pathopen + @"\stop_words.txt", isStem); r = new ReadFile(pathopen + @"\corpus\"); string dic; string cache; if (isStem)//check if stem { dic = pathclose + @"\CacheDic\dicStem.dicx"; cache = pathclose + @"\CacheDic\cacheStem.chex"; } else { dic = pathclose + @"\CacheDic\dic.dicx"; cache = pathclose + @"\CacheDic\cache.chex"; } try { //load dic using (FileStream fs = new FileStream(dic, FileMode.Open)) { IFormatter bf = new BinaryFormatter(); ind.dic = (Dictionary <string, DicRecord>)bf.Deserialize(fs);//read object } //load cache using (FileStream fs = new FileStream(cache, FileMode.Open)) { IFormatter bf = new BinaryFormatter(); ind.cache = (Dictionary <string, List <PostingInfo> >)bf.Deserialize(fs);//read object } } catch (IOException) { //cant find load and cache files in currect folder System.Windows.Forms.MessageBox.Show("Files Missing, can't Load", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //for vieiwing ind.writeTextChache(); showcatch.IsEnabled = true; ind.writeTextDic(); showDic.IsEnabled = true; //new ranker and load the dictionaries of the class if the file exists in the selected folder rank = new Ranker(pathclose, p, r, ind, isStem); searcher = new Searcher(p, ind, rank, pathopen); //open the run btn runQuery.IsEnabled = true; //notify when finished System.Windows.Forms.MessageBox.Show("Ready To search!!", "Done!", MessageBoxButtons.OK, MessageBoxIcon.Information); } }