コード例 #1
0
        public static GeneratedQuestion TreatSimpleCCSentence(SentenceInformationDto sentence, WordInformationDto subject)
        {
            if (subject.Word == null)
            {
                return(null);
            }
            var subjectWord = Helper.FindWordInList(sentence.Words, subject.Word);

            string question;
            var    answer = AnswerGenerator.GenerateAnswer(sentence, subjectWord: subjectWord);

            if (subjectWord.PartOfSpeech.ToLower() == "nnp" ||
                subjectWord.PartOfSpeech.ToLower() == "nns" ||
                subjectWord.PartOfSpeech.ToLower() == "prp" ||
                subjectWord.NamedEntityRecognition.ToLower() == "person")
            {
                question = $"{sentence.SentenceText.Replace(answer, "Who")}";
                question = Helper.TrimQuestion(question, "Who");
            }
            else
            {
                question = $"{sentence.SentenceText.Replace(answer, "Who/What")}";
                question = Helper.TrimQuestion(question, "Who/What");
            }
            return(new GeneratedQuestion {
                Answer = answer, Question = question
            });
        }
コード例 #2
0
        public static GeneratedQuestion CreateQuestionBasedOnSubject(SentenceInformationDto sentence, SentenceDependencyDto subjectFromSentence,
                                                                     WordInformationDto subject)
        {
            if (subjectFromSentence == null)
            {
                return(null);
            }
            var subjectRelationWord = Helper.FindWordInList(sentence.Words, subjectFromSentence.GovernorGloss);
            var answer = AnswerGenerator.GenerateAnswer(sentence, wordInformation: subject);

            if (subjectRelationWord.PartOfSpeech == "VBZ" ||
                subjectRelationWord.PartOfSpeech == "VBN" ||
                subjectRelationWord.PartOfSpeech == "VBD")
            {
                string question;

                if (subject.NamedEntityRecognition.ToLower() == "person" ||
                    subject.PartOfSpeech.ToLower() == "prp" ||
                    subject.PartOfSpeech.ToLower() == "nnp")
                {
                    question = sentence.SentenceText.Replace(answer, "Who");
                    question = Helper.TrimQuestion(question, "Who");
                }
                else
                {
                    question = sentence.SentenceText.Replace(answer, "What");
                    question = Helper.TrimQuestion(question, "What");
                }
                return(new GeneratedQuestion {
                    Answer = answer, Question = question
                });
            }
            if (subjectRelationWord.PartOfSpeech == "NN" ||
                subjectRelationWord.PartOfSpeech == "NNS" ||
                subjectRelationWord.PartOfSpeech == "NNP" ||
                subjectRelationWord.PartOfSpeech == "NNPS")
            {
            }

            return(null);
        }
コード例 #3
0
        public static GeneratedQuestion TreatSentenceWithNSUBJ(SentenceInformationDto sentence, SentenceDependencyDto sentenceNSUBJ,
                                                               WordInformationDto subject)
        {
            var subjectRelation = Helper.FindWordInList(sentence.Words, sentenceNSUBJ.GovernorGloss);

            var answer = AnswerGenerator.GenerateAnswer(sentence, subjectWord: subject);

            if (subjectRelation.PartOfSpeech.ToLower() == "vbz" ||
                subjectRelation.PartOfSpeech.ToLower() == "vbd" ||
                subjectRelation.PartOfSpeech.ToLower() == "vbn")
            {
                string question;
                if (SubjectIsReferingToPerson(subject))
                {
                    var questionText = sentence.SentenceText.Replace(answer, "Who ");
                    question = $"{questionText}";
                    question = Helper.TrimQuestion(question, "Who");
                    return(new GeneratedQuestion {
                        Answer = answer, Question = question
                    });
                }
                if (subject.NamedEntityRecognition.ToLower() != "o")
                {
                    var questionText = sentence.SentenceText.Replace(answer, "Which ");
                    question = $"{questionText}";
                    question = Helper.TrimQuestion(question, "Which");
                }
                else
                {
                    var questionText = sentence.SentenceText.Replace(answer, "What ");
                    question = $"{questionText}";
                    question = Helper.TrimQuestion(question, "What");
                }
                return(new GeneratedQuestion {
                    Answer = answer, Question = question
                });
            }
            return(null);
        }
コード例 #4
0
        public static GeneratedQuestion TreatDateSentence(SentenceInformationDto sentence, WordInformationDto sentenceDate,
                                                          SentenceDependencyDto subjectFromSentence)
        {
            var composedAnswer = AnswerGenerator.GenerateAnswer(sentence, subjectWord: sentenceDate);
            var sentencesCases = GetSentenceCases(sentence, sentenceDate, composedAnswer);
            var firstWord      = sentence.Words.First();
            var question       = sentence.SentenceText
                                 .Replace(sentencesCases, "");

            if (question.Contains(firstWord.Word) && !WordIsName(firstWord))
            {
                question = question.Replace(firstWord.Word, firstWord.Lemma);
            }

            if (subjectFromSentence != null)
            {
                return(GenerateQuestion(sentence, sentenceDate, subjectFromSentence));
            }

            question = $"When did {question}";
            return(new GeneratedQuestion {
                Answer = composedAnswer, Question = question
            });
        }
コード例 #5
0
        public static GeneratedQuestion TreatSimpleXCOMPSentence(SentenceInformationDto sentence, SentenceDependencyDto subjectFromRes,
                                                                 WordInformationDto subject, SentenceDependencyDto sentenceXCOMP)
        {
            var subjectPossession = Helper.GetSubjectPossession(sentence);

            var answer       = AnswerGenerator.GenerateAnswer(sentence, subjectFromRes, subjectWord: subject);
            var predicate    = sentence.Words.FirstOrDefault(w => w.Word == subjectFromRes.GovernorGloss);
            var wordInResult = sentence.Words.FirstOrDefault(w => w.Word == sentenceXCOMP.DependentGloss);

            if (wordInResult == null || predicate == null)
            {
                return(null);
            }

            var pos = wordInResult.PartOfSpeech;

            if (pos != "JJ")
            {
                return(null);
            }

            if (subjectPossession != null)
            {
                var question = $"How does {subjectPossession} {subject.Lemma} {predicate.Lemma}";
                return(new GeneratedQuestion {
                    Answer = answer, Question = question
                });
            }
            else
            {
                var question = $"How does {subject.Lemma} {predicate.Lemma}";
                return(new GeneratedQuestion {
                    Answer = answer, Question = question
                });
            }
        }
コード例 #6
0
        public static GeneratedQuestion TreatSentenceWithDOBJ(SentenceInformationDto sentence,
                                                              SentenceDependencyDto sentenceDOBJ)
        {
            var answer     = sentenceDOBJ.DependentGloss;
            var answerWord = Helper.FindWordInList(sentence.Words, answer);

            answer = AnswerGenerator.GenerateAnswer(sentence, sentenceDOBJ);
            var answerWords = answer.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var verbe       = Helper.FindWordInList(sentence.Words, sentenceDOBJ.GovernorGloss);

            var firstWord = sentence.Words.FirstOrDefault();

            if (firstWord == null)
            {
                return(null);
            }
            string question;
            var    questionText = sentence.SentenceText
                                  .Replace(firstWord.Word, firstWord.Lemma);

            foreach (var word in answerWords)
            {
                questionText = questionText.Replace($" {word}", " ");
            }


            var answerNMODOF = sentence.Dependencies.FirstOrDefault(d => d.Dep.ToLower() == "nmod:of" &&
                                                                    d.GovernorGloss == answerWord.Word);
            var nmodOfString = " ";

            if (answerNMODOF != null)
            {
                questionText = questionText.Replace(answerNMODOF.DependentGloss, "");
                nmodOfString = $" of {answerNMODOF.DependentGloss} ";
            }

            var dobjNUMMode = sentence.Dependencies.FirstOrDefault(d => d.Dep.ToLower() == "nummod" &&
                                                                   d.GovernorGloss == sentenceDOBJ.DependentGloss);

            if (dobjNUMMode != null)
            {
                if (verbe.PartOfSpeech.ToLower() == "vbd")
                {
                    questionText = questionText.Replace(verbe.Word, verbe.Lemma);
                    question     = $"How many {answerWord.Word}{nmodOfString}did {questionText}";
                    return(new GeneratedQuestion {
                        Answer = answer, Question = question
                    });
                }
                question = $"How many {answerWord.Word}{nmodOfString}{questionText}";
                return(new GeneratedQuestion {
                    Answer = answer, Question = question
                });
            }



            if (answerWord.PartOfSpeech.ToLower() == "nn" ||
                answerWord.PartOfSpeech.ToLower() == "nns")
            {
                question = TreatObjectCase(sentence, verbe, questionText);
                return(new GeneratedQuestion {
                    Answer = answer, Question = question
                });
            }

            var answerPOS = Helper.FindWordInList(sentence.Words, answerWord.Word);

            if (answerPOS.PartOfSpeech.ToLower() == "nnp" ||
                answerPOS.PartOfSpeech.ToLower() == "nn")
            {
                if (verbe.PartOfSpeech.ToLower() == "vbd")
                {
                    questionText = questionText.Replace(verbe.Word, verbe.Lemma);
                    question     = TreatPersonCase(sentence, questionText, sentenceDOBJ, answerWord, true);
                }
                else
                {
                    question = TreatPersonCase(sentence, questionText, sentenceDOBJ, answerWord);
                }
                return(new GeneratedQuestion {
                    Answer = answer, Question = question
                });
            }
            return(null);
        }
コード例 #7
0
        public static GeneratedQuestion TreatSimpleCOPSentence(SentenceInformationDto sentence, WordInformationDto subject,
                                                               SentenceDependencyDto sentenceCOP)
        {
            var copPartOfSpeech = Helper.FindWordInList(sentence.Words, sentenceCOP.GovernorGloss).PartOfSpeech;
            var copVerbe        = Helper.FindWordInList(sentence.Words, sentenceCOP.DependentGloss);
            var baseAnswer      = Helper.FindWordInList(sentence.Words, sentenceCOP.GovernorGloss);
            var subjectWord     = Helper.FindWordInList(sentence.Words, subject.Word);

            if (MustReturnNull(subjectWord))
            {
                return(null);
            }
            var answer = AnswerGenerator.GenerateAnswer(sentence, sentenceCOP, subjectWord: subjectWord);

            var    firstWord = sentence.Words.First();
            string question;

            if (baseAnswer.NamedEntityRecognition.ToLower() == "person" && copVerbe.Lemma == "be")
            {
                return(TreatCaseWhereAnswerIsPerson(sentence, firstWord, copVerbe, answer));
            }

            if (subjectWord.PartOfSpeech.ToLower() == "nn")
            {
                return(TreatCaseWhereAnswerIsObject(sentence, answer));
            }

            if (copVerbe != null && copVerbe.Lemma == "be")
            {
                question = $"What {copVerbe.Word} {subjectWord.Word}";
                return(new GeneratedQuestion {
                    Answer = answer, Question = question
                });
            }

            if (subjectWord.NamedEntityRecognition.ToLower() == "person" ||
                subjectWord.PartOfSpeech.ToLower() == "nnp" ||
                subjectWord.PartOfSpeech.ToLower() == "nns")
            {
                question = $"{sentence.SentenceText.Replace(answer, "Who")}";
                question = Helper.TrimQuestion(question, "Who");
                return(new GeneratedQuestion {
                    Answer = answer, Question = question
                });
            }

            if (baseAnswer.NamedEntityRecognition.ToLower() == "person" ||
                baseAnswer.PartOfSpeech.ToLower() == "nnp")
            {
                return(TreatCaseWithPersonAndVerbeNot_IS_(sentence, sentenceCOP, answer));
            }

            question = copPartOfSpeech == "JJ" || copPartOfSpeech == "NNS" ?
                       $"{sentence.SentenceText.Replace(answer, "What")}" :
                       $"{sentence.SentenceText.Replace(answer, "Which")}";

            if (sentence.SentenceText + "?" == question)
            {
                return(null);
            }
            question = Helper.TrimQuestion(question, "What");
            question = Helper.TrimQuestion(question, "Which");
            return(new GeneratedQuestion {
                Answer = answer, Question = question
            });
        }