Пример #1
0
        public static void Main()
        {
            //
            // Sample Input files (Input1, Input2.. Input5).
            for (int inputCount = clsConstant.ONE; inputCount <= clsConstant.SEVEN; inputCount++)
            {
                Console.WriteLine("*****************Press any key to read data from Input" + inputCount + ".txt and Display the result ********************");
                Console.ReadKey();
                ParagraphQA inputData = new ParagraphQA("Input" + inputCount);
                inputData.GetLines();

                if (inputData.lines != null && inputData.lines.Length > 0)
                {
                    inputData.GetRequiredEntities();

                    if (!inputData.isValidInput)
                    {
                        Console.WriteLine("Input Data not in proper format");
                    }
                    else
                    {
                        QASystemDriver QASinstance = new QASystemDriver();
                        QASinstance.MatchWordsInSentences(inputData);
                    }
                }
                else
                {
                    Console.WriteLine("Empty file");
                }
            }

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
Пример #2
0
        public void MatchWordsInSentences(ParagraphQA inputData)
        {
            // Get words from sentences
            SentenceMaker sf = new SentenceMaker();

            sf.SplitSentence(inputData.paragraph, clsConstant.StringSplitPattern.sentenceForm);

            foreach (var sentence in sf.sentences)
            {
                Tokenizer TSentence = new Tokenizer();
                GetTokens(TSentence, sentence);
                MatchQuestionAndAnswer(inputData, TSentence, sentence);
            }

            DisplayResult d = new DisplayResult();

            d.ShowResult(colQARank, inputData.answer);
        }
Пример #3
0
        private void MatchQuestionAndAnswer(ParagraphQA inputData, Tokenizer STokens, string sentence)
        {
            int Q_num = 0;

            foreach (var ques in inputData.questions)
            {
                // Get words from Questions
                Q_num++;
                Tokenizer Qtokens = new Tokenizer();
                GetTokens(Qtokens, ques);

                int Q_Count = CountHits(STokens, Qtokens);

                if (Q_Count > 0)
                {
                    // Split to respective Answers
                    Tokenizer AnswerList = new Tokenizer();
                    AnswerList.SplitSentence(inputData.answer, clsConstant.StringSplitPattern.wordsSeparatedBySemicolon);

                    int A_num = 0;
                    foreach (var ans in AnswerList.Tokens)
                    {
                        A_num++;

                        bool      isSubstr  = CheckIfPromisingSubstr(sentence, ans);
                        Tokenizer AnsTokens = new Tokenizer();


                        GetTokens(AnsTokens, ans);

                        int A_Count = CountHits(STokens, AnsTokens);

                        if (A_Count > 0)
                        {
                            //A_Count = isSubstr ? A_Count + 1 : A_Count;
                            CreateOrUpdateQARank(Q_num, A_num, Q_Count, A_Count, Qtokens.Tokens.Count, AnsTokens.Tokens.Count, isSubstr);
                        }
                    }
                }
            }
        }