Exemple #1
0
        //adds scanned words to list
        private static List <string> AddTextToList(string myTextInput)
        {
            List <string> fileWords = new List <string>();

            string myText = myTextInput;

            myText.Replace(Environment.NewLine, " ");


            myText = StopWords.RemoveStopwords(myText); //removes stopwords

            // remove numbers, punctuation & special characters from each line and make lower case
            String aText = Regex.Replace(myText, "[^a-zA-Z\\s+]", ""); //replace punctuations and numbers with blank space

            aText = aText.ToLower();

            String[] words = aText.Split(' '); //Splitting a line into an array of words

            foreach (string word in words)
            {
                if (word != "")
                {
                    fileWords.Add(word);
                }
            }

            return(fileWords);
        }
Exemple #2
0
        private void searchButton_Click(object sender, EventArgs e)
        {
            PorterStemmer stemmer     = new PorterStemmer();               // instantiate a PorterStemmer object to stem words from files
            string        stemmedWord = stemmer.StemWord(searchWord.Text); //stems the word before searching

            fileList.Text   = " ";
            filesFound.Text = " ";

            List <string> files = new List <string>();
            bool          found = false;

            if (thread.IsAlive)
            {
                MessageBox.Show("The index is currently busy. Please try again later"); //message shown if index building is in progress
            }
            else
            {
                foreach (var item in index.internalIndex)
                {
                    string newItem = StopWords.RemoveStopwords(item.Key);

                    if (newItem == stemmedWord)
                    {
                        found           = true;
                        filesFound.Text = item.Value.Count.ToString();

                        foreach (var folderName in item.Value.Keys)
                        {
                            files.Add(folderName);
                        }
                    }
                }

                foreach (var file in files)
                {
                    fileList.Text += file + "\r\n";
                }
                if (!found)
                {
                    filesFound.Text = "0";
                    fileList.Text   = "No results found";
                }
            }
        }