コード例 #1
0
        private void searchBtn_Click(object sender, EventArgs e)
        {
            List <int[]> searchResults = StringSearch.searchReadings(project.readings, searchBox.Text);
            //project.readings list items in corresponding index to searchResults indexes
            List <SearchResult>    resultsBoxData   = new List <SearchResult>();
            List <HighlightResult> highlightBoxData = new List <HighlightResult>();

            for (int i = 0; i < searchResults.Count; i++)
            {
                resultsBoxData.Add(new SearchResult(project.readings.ElementAt(i), searchResults.ElementAt(i), searchBox.Text));
                List <int[]>  highlightResults1 = StringSearch.searchHighlights(project.readings.ElementAt(i), searchBox.Text); //in same order as r.highlights (correspond)
                List <String> highlightsText    = StringSearch.getHighlightsText();                                             //works since searchHighlights() was just called which updates the current highlightsText object in StringSearch
                for (int j = 0; j < highlightResults1.Count; j++)
                {
                    if (highlightResults1.ElementAt(j).Count() != 0 && searchResults.ElementAt(i).Count() != 0)
                    {
                        highlightBoxData.Add(new HighlightResult(project.readings.ElementAt(i), highlightsText.ElementAt(j), highlightResults1.ElementAt(j), searchBox.Text, project.readings.ElementAt(i).highlights.ElementAt(j)));
                    }
                }
            }

            textSearchResultsListBox.DataSource    = resultsBoxData;
            textSearchResultsListBox.DisplayMember = "displayString";
            textSearchResultsListBox.ValueMember   = "readingId";

            highlightResults.DataSource    = highlightBoxData;
            highlightResults.DisplayMember = "displayString";
            highlightResults.ValueMember   = "readingId";
        }
コード例 #2
0
        public void stringTest()
        {
            String path        = @"..\\..\\warpeace.txt";
            String strToSearch = "";

            //StringSearch tester = new StringSearch();

            if (!File.Exists(path))
            {
                // Create the file.
                using (FileStream fs = File.Create(path))
                {
                    Byte[] info =
                        new UTF8Encoding(true).GetBytes("This is some text in the file.");

                    // Add some information to the file.
                    fs.Write(info, 0, info.Length);
                }
            }

            // Open the stream and read it back.
            using (StreamReader sr = File.OpenText(path))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                {
                    strToSearch += s;
                }
                //Console.WriteLine(strToSearch);
            }

            Console.WriteLine("Done Reading File");

            String pat = "war";

            //algorithmToTest, String, pattern
            Console.WriteLine("Using indexOf: ");
            Console.WriteLine("Elapsed Time: " + StringSearch.Test(1, strToSearch, pat));

            Console.WriteLine("Using BM: ");
            Console.WriteLine("Elapsed Time: " + StringSearch.Test(2, strToSearch, pat));

            Console.WriteLine("Using KMP: ");
            Console.WriteLine("Elapsed Time: " + StringSearch.Test(3, strToSearch, pat));

            Console.WriteLine("Using RK: ");
            Console.WriteLine("Elapsed Time: " + StringSearch.Test(4, strToSearch, pat));
        }