コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: rbh3/corpus
        //reset the load and gui of part 2
        private void Reset_Part2_Click(object sender, RoutedEventArgs e)
        {
            //reset GUI
            r   = null;
            p   = null;
            ind = null;
            showcatch.IsEnabled = false;
            showDic.IsEnabled   = false;
            runQuery.IsEnabled  = false;
            QueryTextBox.Clear();
            isWikiExp.IsChecked     = false;
            isSumCheck.IsChecked    = false;
            stemmcheckBox.IsChecked = false;
            //Delete Last File
            try
            {
                if (File.Exists(Results.LastFile))
                {
                    File.Delete(Results.LastFile);
                }
            }
            catch (IOException)
            {
                Debug.WriteLine("CANT DELETE!!!!!");
            }
            //Garbage Collector
            GC.Collect();
            GC.WaitForPendingFinalizers();

            //notification
            System.Windows.Forms.MessageBox.Show("The Memory is clean!", "Done!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
コード例 #2
0
        public Ranker(string path, Parser p, ReadFile r, Indexer ind, bool isStem)
        {
            this.path   = path;
            avgDL       = 0;
            k           = 1.3;
            this.isStem = isStem;
            this.r      = r;
            this.p      = p;
            this.ind    = ind;
            DocWeight   = new Dictionary <string, double>();
            Docsmaxtf   = new Dictionary <string, int>();
            docslength  = new Dictionary <string, double>();
            string file;

            //check if we can do fast loading
            if (isStem)
            {
                file = path + @"\rankerStem";
            }
            else
            {
                file = path + @"\ranker";
            }
            if (File.Exists(file))
            {
                //if File exiest loading dictionaries in order to run faster
                using (FileStream fs = new FileStream(file, FileMode.Open))
                {
                    IFormatter bf = new BinaryFormatter();
                    DocWeight  = (Dictionary <string, double>)bf.Deserialize(fs); //read object
                    Docsmaxtf  = (Dictionary <string, int>)bf.Deserialize(fs);    //read object
                    docslength = (Dictionary <string, double>)bf.Deserialize(fs); //read object
                    avgDL      = (double)bf.Deserialize(fs);
                }
            }
            else
            {
                //calculate the dictionaries in order to run- long process
                calculateWeight();
                //after calculate save it for next time
                using (FileStream fs = new FileStream(file, FileMode.Create))
                {
                    IFormatter bf = new BinaryFormatter();
                    bf.Serialize(fs, DocWeight);  //write object
                    bf.Serialize(fs, Docsmaxtf);  //write object
                    bf.Serialize(fs, docslength); //write object
                    bf.Serialize(fs, avgDL);      //write object
                }
            }
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: rbh3/corpus
        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);
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: rbh3/corpus
        private void Reset_Click(object sender, RoutedEventArgs e)
        {
            //restart gui
            Corpustextbox.IsEnabled      = true;
            CorpusFolderBrowse.IsEnabled = true;
            pathopen = "";
            Corpustextbox.Clear();
            if (ind != null)
            {
                ind.swrite.Close();
            }
            if (Directory.Exists(pathclose + "\\AfterPost"))
            {
                Directory.Delete(pathclose + "\\AfterPost", true);
            }
            ind = null;
            r   = null;
            p   = null;

            //DELETE DICTIONERY
            string s;

            if (isStem)
            {
                s = "\\CacheDic\\dicStem.txt";
            }
            else
            {
                s = "\\CacheDic\\dic.txt";
            }
            if (File.Exists(pathclose + s))
            {
                File.Delete(pathclose + s);
            }
            showDic.IsEnabled   = false;
            showcatch.IsEnabled = false;

            //Garbage Collector
            GC.Collect();
            GC.WaitForPendingFinalizers();

            //notification
            System.Windows.Forms.MessageBox.Show("The Memory is clean!", "Done!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
コード例 #5
0
        private void startButton_Click(object sender, RoutedEventArgs e)
        {
            corpusFolder   = InputPathTxt.Text;
            postingsFolder = postingsTextBox.Text;
            if (corpusFolder == "" || postingsFolder == "")
            {
                System.Windows.MessageBox.Show("Path Required!", "Error");
            }

            else
            {
                labelClock.Visibility = Visibility.Visible;
                imageClock.Visibility = Visibility.Visible;
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                System.Windows.MessageBox.Show("The process started");
                rf = new ReadFile(corpusFolder, postingsFolder, stemmer);
                rf.MainProcess();
                foreach (string lang in rf.languages)
                {
                    comboBoxLang.Items.Add(lang);
                }

                string time = (stopWatch.ElapsedMilliseconds / 1000).ToString();
                labelClock.Visibility = Visibility.Hidden;
                imageClock.Visibility = Visibility.Hidden;
                Dictionary <string, TermData> theDictionary = rf.mainDictionary;
                List <string> termList = rf.termList;
                dictionary = new Dictionary <string, int>();
                System.Windows.MessageBox.Show("Finish indexing in " + time + " seconds\n"
                                               + "number of Documents: " + rf.docsCounter + "\n"
                                               + "number of terms: " + theDictionary.Count
                                               , "Finish Inexing");

                // add the term to dictionary for show
                foreach (string term in termList)
                {
                    dictionary.Add(term, theDictionary[term].NumInCorpus);
                }
                stopWatch.Stop();
            }
        }
コード例 #6
0
        //delete all the folders and reset the class Read File
        private void resetButton_Click(object sender, RoutedEventArgs e)
        {
            //delete all files from the posting's directory
            if (postingsFolder == "")
            {
                System.Windows.MessageBox.Show("posting directory path required", "Error");
            }
            else
            {
                System.IO.DirectoryInfo di = new DirectoryInfo(postingsFolder);

                foreach (DirectoryInfo dir in di.GetDirectories())
                {
                    dir.Delete(true);
                }

                rf = null;
                System.Windows.MessageBox.Show("Reset Completed", "Error");
            }
        }
コード例 #7
0
ファイル: MainWindow.xaml.cs プロジェクト: rbh3/corpus
        //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);
            }
        }