Exemplo n.º 1
0
        private static void TestColumnTableQA()
        {
            Parser        parser     = new Parser();
            PatternBased  pattern_qa = new PatternBased();
            List <string> questions  = new List <string>
            {
                //"肯尼思·洛纳根导演过哪些电影", // 肯尼思·洛纳根 splited
                //"你的名字是哪个国家拍的", // 你的名字 in NER, but 你的名字。in CellID
                //"十二怒汉是讲什么的", // have no 十二怒汉
                //"活着是讲什么的",
                //"你的名字。是讲什么的", // the period
                //"赌神是讲什么的",
                //"天下无贼是谁导演的",
                //"林家栋拍过什么电影",  //拍 act? direct?
                //"大话西游之大圣娶亲是什么时候拍的",
                //"有木有徐克的",
                //"美人鱼上映了吗",
                //"绝世高手上映了吗",
                //"建军大业什么时候上映的",  //there is no 建军大业 in OSearch
                "我想看张艺谋导演的电影",
                "有什么类型的电影呢",
                "战狼什么时候上映的",  //there is no 建军大业 in OSearch
                "最近有什么好电影"
            };

            foreach (string question in questions)
            {
                Query query = new Query(question);
                parser.PosTagging(ref query);
                Console.WriteLine("Question:" + question);
                Console.WriteLine("Answer:");
                Console.WriteLine(KBQA.DoKBQA(query, parser));
                Console.WriteLine();
            }
        }
Exemplo n.º 2
0
        private static void TestPatternBased(string question_filename, string output_filename)
        {
            StreamReader sr    = new StreamReader(question_filename);
            PatternBased pb    = new PatternBased();
            StreamWriter sw    = new StreamWriter(output_filename);
            Parser       parse = new Parser();

            while (!sr.EndOfStream)
            {
                PatternResponse pr       = new PatternResponse();
                string          line     = sr.ReadLine();
                string          question = line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries)[0];
                Query           query    = new Query(question);
                parse.PosTagging(ref query);
                if (pb.QuestionClassify(query, out pr))
                {
                    sw.Write(question);
                    sw.Write('\t');
                    sw.WriteLine(pr.property);
                }
                else
                {
                    sw.WriteLine(question);
                }
            }
            sw.Flush();
            sw.Close();
        }
Exemplo n.º 3
0
        private static void TestGraphEngineQA()
        {
            //string question = "肯尼思·洛纳根导演过哪些电影"; // 肯尼思·洛纳根 splited
            //string question = "你的名字是哪个国家拍的"; // 你的名字 in NER, but 你的名字。in CellID
            //string question = "十二怒汉是讲什么的"; // have no 十二怒汉
            //string question = "活着是讲什么的";
            //string question = "你的名字。是讲什么的"; // the period
            //string question = "赌神是讲什么的";
            //string question = "天下无贼是谁导演的";
            string question = "林家栋拍过什么电影";  //拍 act? direct?
            //string question = "大话西游之大圣娶亲是什么时候拍的";
            //string question = "有木有徐克的";
            Parser           parser            = new Parser();
            GraphEngineQuery graphengine_query = new GraphEngineQuery();
            PatternBased     pattern_qa        = new PatternBased();
            Query            query             = new Query(question);

            parser.PosTagging(ref query);
            parser.ParseAllTag(ref query);

            PatternResponse pattern_response;

            if (pattern_qa.QuestionClassify(query, out pattern_response))
            {
                string question_topic = "";
                switch (pattern_response.entity_type)
                {
                case KBQAEntityType.Movie:
                    question_topic = query.carried_movie[0];
                    break;

                case KBQAEntityType.Celebrity:
                    question_topic = (query.carried_artist.Count > 0) ? query.carried_artist[0] : query.carried_director[0];
                    break;
                }
                List <object> res = graphengine_query.GetGraphEngineData(question_topic, pattern_response.property, pattern_response.hop_num);
                Utils.WriteMachine(string.Join(",", res.ToArray()));
            }
        }