Beispiel #1
0
 public QueryHandler(
     DataAccess dA,
     KeyWordFinder kwf,
     Func <string, string> stringOp
     )                                             //later associate results with
 {                                                 //query
     this.dA       = dA;
     this.kwf      = kwf;
     this.stringOp = stringOp;
     this.queries  = new List <Query>();
 }
Beispiel #2
0
        public static string backendCommand(string paragraph)
        {
            Func <string, string> func = new Func <string, string>((x) =>
            {
                var temp = x;
                new HTMLMessager().removeFromLine(ref temp);
                return(temp);
            });
            SentenceBoiler sb = new SentenceBoiler();
            DataAccess     dA = new DataAccessDB();
            //while (true)
            //{
            //var paragraph = Console.ReadLine();
            var sentences = paragraph.Split('.');
            var qHandler  = new QueryHandler(dA, sb, func);
            int max       = -99;

            string[] maxStrings = new string[] { "" };
            var      rString    = "";

            Console.WriteLine(sentences.Count() + " " + paragraph.Count());
            foreach (var response in qHandler.handleQuery(sentences))
            {
                string query = "";
                foreach (var block in response)
                {
                    query = block.Item1;
                    var kwList    = KeyWordFinder.handleLineKeyWords(5, block.Item1);
                    int occurance = 0;
                    foreach (string s in block.Item2)
                    {
                        foreach (string kw in kwList)
                        {
                            occurance = occurance + Regex.Matches(s, kw).Count;
                        }
                    }
                    maxStrings = occurance > max ? block.Item2 : maxStrings;    //average hits per element
                    max        = occurance > max ? occurance : max;
                }
                Console.WriteLine("Hits for query: " + "\"" + query + "\"");
                rString = rString + "Hits for query: " + "\"" + query + "\"\n";
                foreach (string s in maxStrings)
                {
                    rString = rString + s + "\n";
                    Console.WriteLine(s);
                }
                Console.WriteLine();
                //return rString + "\n";
                //}
            }
            return(rString);
        }
        static void Main(string[] args)
        {
            Func <string, string> func = new Func <string, string>((x) =>
            {
                var temp = x;
                new HTMLMessager().removeFromLine(ref temp);
                return(temp);
            });
            SentenceBoiler sb = SentenceBoiler.sentenceBoilerFactory("UserBot");
            DataAccess     dA = new DataAccessDB();

            while (true)
            {
                var      paragraph  = Console.ReadLine();
                var      sentences  = paragraph.Split('.');
                var      qHandler   = new QueryHandler(dA, sb, func);
                int      max        = -99;
                string[] maxStrings = new string[] { "" };
                foreach (var response in qHandler.handleQuery(sentences))
                {
                    string query = "";
                    foreach (var block in response)
                    {
                        query = block.Item1;
                        var kwList    = KeyWordFinder.handleLineKeyWords(5, block.Item1);
                        int occurance = 0;
                        foreach (string s in block.Item2)
                        {
                            foreach (string kw in kwList)
                            {
                                occurance = occurance + Regex.Matches(s, kw).Count;
                            }
                        }
                        maxStrings = occurance > max ? block.Item2 : maxStrings;//average hits per element
                        max        = occurance > max ? occurance : max;
                    }
                    Console.WriteLine("Hits for query: " + "\"" + query + "\"");
                    foreach (string s in maxStrings)
                    {
                        Console.WriteLine(s);
                    }
                    Console.WriteLine();
                }
            }
        }
        /* private void insertBlocksIntoDB(string filePath, List<List<Element>> blocks)
         * {
         *    foreach (List<Element> block in blocks)
         *    {
         *        int blockCount = 0;
         *        foreach (Element element in block)
         *        {
         *            if (element.name == "img")
         *            {
         *                //NEED A MEANS TO RETRIEVE ID
         *                ;//db.insertIntoImages();
         *            }
         *            else
         *            {
         *                //NEED A MEANS TO RETRIEVE ID
         *                db.insertIntoElements(filePath, blockCount, element.data);
         *            }
         ++blockCount;
         *        }
         *    }
         * }
         *
         * private void insertHREFSOIntoDB(string filePath, List<string> hrefs)
         * {
         *    foreach (string href in hrefs)
         *    {
         *        //NEED A MEANS TO RETRIEVE ID
         *        db.insertIntoHyperlinks(filePath, href);
         *    }
         * }
         *
         * public void persistData()
         * {
         *    ActiveAIDDB db = new ActiveAIDDB();
         *    db.insertIntoFiles(title, "");
         *
         *    foreach (KeyValuePair<string, ParsedCHM> pair in parsedCHMs)
         *    {
         *        insertBlocksIntoDB(pair.Key, pair.Value.blocks);
         *        insertHREFSOIntoDB(pair.Value.title, pair.Value.hrefs);
         *    }
         * }*/

        public void genModel()
        {
            List <List <string> > fileKeyWords      = new List <List <string> >();
            List <string>         responseFileNames = new List <string>();
            string response;

            foreach (var pair in parsedCHMs)
            {
                List <string> keywords = new List <string>();
                responseFileNames.Add(pair.Key);
                keywords.AddRange(KeyWordFinder.handleLineKeyWords(5, pair.Value.title));//keywords weighted by ordering in which they appear in list
                keywords.AddRange(KeyWordFinder.concatAllKeyWords(5, pair.Value.blocks, keywords));
                fileKeyWords.Add(keywords);
            }
            response = String.Join(";", responseFileNames.ToArray());
            //aggregateKeyWords(fileKeyWords)
            //Console.WriteLine(response);

            /*foreach (string keyword in keywords)
             * {
             *  Console.WriteLine(keyword);
             * }*/
        }
Beispiel #5
0
 public QueryGenerator(KeyWordFinder kwf)
 {
     this.kwf = kwf;
 }