示例#1
0
        private static void TestCNNBased(string question_filename, string output_filename)
        {
            StreamReader sr    = new StreamReader(question_filename);
            CNNBased     cb    = new CNNBased();
            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 (cb.QuestionClassify(query, out pr))
                {
                    sw.Write(question);
                    sw.Write('\t');
                    sw.WriteLine(pr.property);
                }
                else
                {
                    sw.WriteLine(question);
                }
            }
            sw.Flush();
            sw.Close();
        }
示例#2
0
        // classify a query based on CNN
        public bool QuestionClassify(Query query, out PatternResponse pattern_response)
        {
            pattern_response = new PatternResponse();
            string postagged_query = query.postagged_query;
            int    tf_class        = GetTensorFlowServingResponse(postagged_query);

            if (tf_class != -1 && tf_class != 0)
            {
                pattern_response = new PatternResponse(query, class2pattern[tf_class]);
                return(true);
            }
            return(false);
        }
示例#3
0
        // classify a query based on pattern
        public bool QuestionClassify(Query query, out PatternResponse pattern_response)
        {
            pattern_response = new PatternResponse();
            string postagged_query = query.postagged_query;

            foreach (Pattern pattern in patterns)
            {
                Match match = pattern.regex_pattern.Match(postagged_query);
                if (match.Success)
                {
                    pattern_response = new PatternResponse(query, pattern);
                    return(true);
                }
            }
            return(false);
        }