Exemplo n.º 1
0
        private static void TestGraphEngineQuery()
        {
            GraphEngineQuery graphengine_query = new GraphEngineQuery();
            List <object>    res = graphengine_query.GetGraphEngineData("墨攻", "PublishDate", 0);

            Console.WriteLine(string.Join(",", res.ToArray()));
            Console.WriteLine();
            res = graphengine_query.GetGraphEngineData("墨攻", "Rating", 0);
            Console.WriteLine(string.Join(",", res.ToArray()));
            Console.WriteLine();
            res = graphengine_query.GetGraphEngineData("墨攻", "Genres", 0);
            Console.WriteLine(string.Join(",", res.ToArray()));
            Console.WriteLine();
            res = graphengine_query.GetGraphEngineData("墨攻", "Country", 0);
            Console.WriteLine(string.Join(",", res.ToArray()));
            Console.WriteLine();
            res = graphengine_query.GetGraphEngineData("墨攻", "Description", 0);
            Console.WriteLine(string.Join(",", res.ToArray()));
            Console.WriteLine();
            res = graphengine_query.GetGraphEngineData("墨攻", "Artists:Name", 1);
            Console.WriteLine(string.Join(",", res.ToArray()));
            Console.WriteLine();
            res = graphengine_query.GetGraphEngineData("墨攻", "Directors:Name", 1);
            Console.WriteLine(string.Join(",", res.ToArray()));
            Console.WriteLine();
            res = graphengine_query.GetGraphEngineData("刘德华", "Act:Name", 1);
            Console.WriteLine(string.Join(",", res.ToArray()));
            Console.WriteLine();
            res = graphengine_query.GetGraphEngineData("张艺谋", "Direct:Name", 1);
            Console.WriteLine(string.Join(",", res.ToArray()));
        }
Exemplo n.º 2
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()));
            }
        }