Beispiel #1
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();
        }
Beispiel #2
0
        //GraphEngineQuery graphengine_query = new GraphEngineQuery();

        public static bool DoKBQA(Query query, Parser parser)
        {
            parser.ParseAllTag(ref query);
            PatternResponse pattern_response;

            if (pattern_qa.QuestionClassify(query, out pattern_response))// || cnn_qa.QuestionClassify(query, out pattern_response))
            {
                Console.WriteLine("Start to KBQA");
                string question_topic = "";
                try
                {
                    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;

                    case KBQAEntityType.RecentMovie:
                        question_topic = "";
                        break;

                    case KBQAEntityType.IsPublish:
                        question_topic = query.carried_movie[0];
                        break;
                    }
                    //List<object> res = graphengine_query.GetGraphEngineData(question_topic, pattern_response.property, pattern_response.hop_num);
                    List <string> res = GetColumnData(pattern_response.entity_type, question_topic, pattern_response.property);
                    res = res.Distinct().ToList();
                    string answer = string.Join(",", res.ToArray());
                    if (answer.Length < 2)
                    {
                        Utils.WriteUnknow("数据库中没有相关的答案...", query.raw_query);
                    }
                    else
                    {
                        Utils.WriteMachine(answer);
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    Utils.WriteUnknow("It seems Neural Network makes a mistake", query.raw_query);
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #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()));
            }
        }