예제 #1
0
        private void queryOkay_Click(object sender, RoutedEventArgs e)
        {
            string        query   = queryBox.Text;
            List <string> matches = new List <string>();

            using (Ookii.Dialogs.Wpf.ProgressDialog dial = new ProgressDialog()) {
                IDataTree queryTree = DataTreeBuilder.CreateDocumentMappedTree(baseTree);
                DataTreeBuilder.AddToDataTreeBoyerMoore(queryTree, query);

                ITreeIO tio = new TreeIO();
                foreach (String s in Directory.EnumerateFiles(documentLabel.Content.ToString()))
                {
                    IDataTree docTree = tio.LoadDataTree(s);
                    if (queryTree.CompareTo(docTree))
                    {
                        matches.Add(s);
                    }
                }
            }

            if (matches.Count > 0)
            {
                StringBuilder sb = new StringBuilder("Documents which match \"" + query + "\":");
                foreach (string s in matches)
                {
                    string s2 = System.IO.Path.GetFileName(s);
                    s2 = new string(s2.Take(s2.LastIndexOf('.')).ToArray());
                    documents.Add(s2);
                    sb.Append(" " + s2);
                }
                MessageBox.Show(sb.ToString());
            }
            else
            {
                MessageBox.Show("No documents match the query \"" + query + "\"");
            }
            queryPopup.IsOpen = false;
        }
예제 #2
0
        public static void getDocsForQuery(string contentTreeName)
        {
            Console.SetBufferSize(100, 2000);
            IIO io = new FileIO();
            IEnumerable<string> file = io.ReadSourceIterable(testpath + "TIME.QUE");
            IEnumerable<string> expectedResults = io.ReadSourceIterable(testpath + "TIME.REL");
            var resultsEnum = expectedResults.GetEnumerator();
            ITextExtractor it = new BeginMarkerExtraction(file, "*FIND");

            ITreeIO tio = new TreeIO();
            IBaseTree tree = tio.LoadBaseTree(testpath + contentTreeName);

            string query = it.FindNextContent();
            Console.WriteLine("---------------------------------");
            string queryName = Helpers.GetNameWhenFirst(query);
            Console.WriteLine("Query: " + queryName);
            query = Helpers.ConsumeName(query);

            Console.WriteLine(query);

            IDataTree queryTree = DataTreeBuilder.CreateStemmedDocumentMapTree(tree);
            DataTreeBuilder.AddToDataTreeBoyerMoore(queryTree, query);
            queryTree.PrintDataTree();

            Console.WriteLine("Expected Results: ");
            while (string.IsNullOrEmpty(resultsEnum.Current))
                resultsEnum.MoveNext();
            string expected = Helpers.ConsumeName(resultsEnum.Current);
            Console.WriteLine(expected);
            resultsEnum.MoveNext();

            expected = expected.Trim();
            string[] expectedArray = expected.Split(' ');
            double relevant = 0;
            double totalRetrieved = 0;

            Console.WriteLine("Actual Results: ");
            List<string> retrieved = new List<string>();
            foreach (String s in Directory.EnumerateFiles(testpath + @"\datatrees")) {
                IDataTree docTree = tio.LoadDataTree(s);
                if (queryTree.CompareTo(docTree)) {
                    Console.Write(" " + docTree.Name);
                    retrieved.Add(docTree.Name);
                    totalRetrieved++;
                    if (expectedArray.Contains(docTree.Name)) {
                        relevant++;
                    }

                    Console.WriteLine("Found---");
                    Console.WriteLine(docTree.Name);
                    docTree.PrintDataTree();
                    Console.WriteLine("---");
                }
                if (expectedArray.Contains(docTree.Name)) {
                    Console.WriteLine("Expected---");
                    Console.WriteLine(docTree.Name);
                    docTree.PrintDataTree();
                    Console.WriteLine("---");
                }

            }

            Console.WriteLine();
            Console.WriteLine("Precision: " + relevant + "/" + totalRetrieved);
            Console.WriteLine("Recall: " + relevant + "/" + (expectedArray.Length));
            Console.WriteLine();

            Console.WriteLine("---------------------------------");
            Thread.Sleep(10000);

            IEnumerable<string> fileAll = io.ReadSourceIterable(testpath + "TIME.ALL");
            ITextExtractor itAll = new BeginMarkerExtraction(fileAll, "*TEXT");

            //int count = 1;
            //while (itAll.HasNextContent()) {
            //    string content = itAll.FindNextContent();
            //    string name = "" + count;
            //    if (retrieved.Contains(name) || expectedArray.ToList().Contains(name)) {
            //        Console.WriteLine("------------------------------------------------------------");
            //        Console.WriteLine("------------------------------------------------------------");
            //        Console.WriteLine(name);
            //        content = Helpers.ConsumeName(content);
            //        Console.WriteLine(content);
            //        Console.WriteLine("------------------------------------------------------------");
            //        Console.WriteLine("------------------------------------------------------------");
            //    }

            //    count++;
            //}
        }