예제 #1
0
        // start the run in a separate thread
        private void Start_Click(object sender, RoutedEventArgs e)
        {
            reset.IsEnabled = true;
            readfile        = new ReadFile();
            Start.IsEnabled = false;
            stem            = checkBox.IsChecked.Value;
            Start.Content   = "Running...";
            Thread readFromFolderThread = new Thread(delegate()
            {
                DoEverything();
            });

            readFromFolderThread.Start();

            stem = checkBox.IsChecked.Value;
        }
예제 #2
0
        private void reset_button(object sender, RoutedEventArgs e)
        {
            resetPressed = true;
            if (readfile != null)
            {
                readfile.resetReadFile();
            }
            if (indexer != null)
            {
                indexer.resetIndexer();
            }
            Start.Content = "START";
            StatsTextBlock.Items.Clear();
            readfile = new ReadFile();
            indexer  = null;

            if (File.Exists(PostingsPath + @"\DocPostings.txt"))
            {
                File.Delete(PostingsPath + @"\DocPostings.txt");
            }
            if (File.Exists(PostingsPath + @"\TermPostings.txt"))
            {
                File.Delete(PostingsPath + @"\TermPostings.txt");
            }
            if (File.Exists(PostingsPath + @"\DocPostingsStemming.txt"))
            {
                File.Delete(PostingsPath + @"\DocPostingsStemming.txt");
            }
            if (File.Exists(PostingsPath + @"\TermPostingsStemming.txt"))
            {
                File.Delete(PostingsPath + @"\TermPostingsStemming.txt");
            }

            stop();
            if (postingsPathOn && dataPathOn)
            {
                selectQueryFile.IsEnabled    = false;
                QueryEntry.IsEnabled         = false;
                Start.IsEnabled              = true;
                save_result_button.IsEnabled = false;
            }
        }
예제 #3
0
        // the function that runs readfile, parser, indexer and postings
        private void DoEverything()
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                Start.Content = "Parsing...";
            }));
            Stopwatch mainwatch = new Stopwatch();

            mainwatch.Start();

            readfile.readFilesFromFolder(DataSetPath, stem);// read the files and parse

            if (resetPressed)
            {
                stop();
                return;
            }
            indexer = new Indexer();
            TimeSpan readfileTime = readfile.stopwatch.Elapsed;
            int      docCount     = readfile.documents.Count;

            this.Dispatcher.Invoke((Action)(() =>
            {
                Start.Content = "Indexing Terms...";
                StatsTextBlock.Items.Clear();
                StatsTextBlock.Items.Add("Read file + Parse Time : " + readfileTime);
                StatsTextBlock.Items.Add("Number of documents parsed: " + docCount);
                StatsTextBlock.Items.Add("Total Time so far: " + readfileTime);
            }));



            indexer.createTermAndDictionaries(readfile.documents);//creates the dictionaries (inverted index)


            TimeSpan indexerTime = indexer.stopwatch1.Elapsed;

            readfile = null;
            int termsCount = indexer.sortedTermDictionary.Count;

            if (resetPressed)
            {
                stop();
                return;
            }
            this.Dispatcher.Invoke((Action)(() =>
            {
                Start.Content = "Creating postings...";

                StatsTextBlock.Items.Clear();
                StatsTextBlock.Items.Add("Read file + Parse Time : " + readfileTime);
                StatsTextBlock.Items.Add("Number of documents parsed: " + docCount);
                StatsTextBlock.Items.Add("inverted Index Creation Time : " + indexerTime);

                StatsTextBlock.Items.Add("Number of terms indexed : " + termsCount);

                StatsTextBlock.Items.Add("Total Time so far: " + (readfileTime + indexerTime));
            }));


            Stopwatch lastmainwatch = new Stopwatch();

            lastmainwatch.Start();

            // writes the documents postings file
            string Stemming = "";

            if (stem)
            {
                Stemming = "Stemming";
            }
            using (StreamWriter sw = File.AppendText(@PostingsPath + @"\DocPostings" + Stemming + ".txt"))
            {
                string json = JsonConvert.SerializeObject(indexer.docDictionary, Formatting.Indented);

                sw.Write(json);
            }


            this.Dispatcher.Invoke((Action)(() =>
            {
                Start.Content = "Creating postings...";


                StatsTextBlock.Items.Clear();
                StatsTextBlock.Items.Add("Read file + Parse Time : " + readfileTime);
                StatsTextBlock.Items.Add("Number of documents parsed: " + docCount);
                StatsTextBlock.Items.Add("inverted Index Creation Time : " + indexerTime);
                StatsTextBlock.Items.Add("Number of terms indexed : " + termsCount);
                StatsTextBlock.Items.Add("Documents postings created.");
                StatsTextBlock.Items.Add("Total Time so far : " + (readfileTime + indexerTime + lastmainwatch.Elapsed));
            }));
            indexer.docDictionary.Clear();

            if (resetPressed)
            {
                stop();
                return;
            }


            // writes the terms postings file
            indexer.CreateTermsPostings(@PostingsPath, stem);


            indexer.sortedTermDictionary.Clear();

            // the text file from which the inverted index is loaded and showed


            indexer  = null;
            readfile = null;
            this.Dispatcher.Invoke((Action)(() =>
            {
                StatsTextBlock.Items.Clear();
                StatsTextBlock.Items.Add("Read file + Parse Time : " + readfileTime);
                StatsTextBlock.Items.Add("Number of documents parsed: " + docCount);
                StatsTextBlock.Items.Add("inverted Index Creation Time : " + indexerTime);
                StatsTextBlock.Items.Add("Number of terms indexed : " + termsCount);
                StatsTextBlock.Items.Add("Documents postings created.");
                StatsTextBlock.Items.Add("Terms postings created.");
                StatsTextBlock.Items.Add("Posting Files creation Time: " + lastmainwatch.Elapsed.ToString());
                StatsTextBlock.Items.Add("Total Time  : " + (mainwatch.Elapsed));
                if (File.Exists(@PostingsPath + @"\TermPostings.txt"))
                {
                    ReadTermsPostingsButton.IsEnabled = true;
                }
                ShowInvertedIndex.IsEnabled = true;
            }));

            if (resetPressed)
            {
                stop();
                return;
            }

            this.Dispatcher.Invoke((Action)(() =>
            {
                Start.Content = "START (press RESET)";
            }));
            lastmainwatch.Stop();
        }