Exemplo n.º 1
0
        private AnswerFeedback matchAnswers(List <WorldObject> userAnswer, List <WorldObject> systemAnswerWords, string ans)
        {
            AnswerFeedback f = matchAnswers(userAnswer, systemAnswerWords);

            f.answer = ans;
            return(f);
        }
Exemplo n.º 2
0
        public string createFeedBack(AnswerFeedback answerFeedback)
        {
            string verbalFeedback = null;

            //check sub question

            if (answerFeedback.score >= 60)
            {
                verbalFeedback = getPhrase(Pkey.goodAnswer);
            }
            else if (answerFeedback.score >= 35)
            {
                verbalFeedback = getPhrase(Pkey.partialAnswer);
            }
            else if (answerFeedback.answer != null && answerFeedback.answer.Split(' ').Length > 2)
            {
                verbalFeedback = getPhrase(Pkey.wrongAnswer);
            }
            else
            {
                verbalFeedback = getPhrase(Pkey.notAnAnswer);
            }

            answerFeedback.missingEntitis.RemoveAll(x => x.entityType == "conceptWord");

            if (answerFeedback.answersFeedbacks.Count > 0)
            {
                verbalFeedback = verbalFeedback + " " + getPhrase(Pkey.missingAnswrPart);
                verbalFeedback = verbalFeedback + " " + answerFeedback.answersFeedbacks[0];
                answerFeedback.answersFeedbacks.RemoveAt(0);
                foreach (var a in answerFeedback.answersFeedbacks)
                {
                    verbalFeedback = verbalFeedback + " " + getPhrase(Pkey.and) + " " + a;
                }
            }
            else if (answerFeedback.score < 75)
            {
                verbalFeedback = verbalFeedback + " " + Pkey.MyAnswerToQuestion;
                verbalFeedback = verbalFeedback + " " + "answerText";
            }

            return(verbalFeedback);
        }
Exemplo n.º 3
0
 public static void addAnswerOutput(string answerText, string userAnswer, AnswerFeedback feedback, string userID, string QuestionID)
 {
     try
     {
         var log = new answersLog();
         log.time            = DateTime.UtcNow;
         log.userAnswer      = userAnswer;
         log.question        = answerText;
         log.missingEntities = "";
         log.entities        = feedback.score.ToString();
         log.userID          = userID;
         log.questionID      = QuestionID;
         foreach (var e in feedback.missingEntitis)
         {
             log.missingEntities += ";" + e.entityType + "#" + e.entityValue + ";";
         }
         new DataBaseController().addAnswerLog(log);
         System.Diagnostics.Trace.TraceInformation("question:" + log.question + ",userAnswer:" + log.userAnswer + "score:" + log.entities);
     }
     catch (Exception ex)
     {
     }
 }
Exemplo n.º 4
0
        public string[] createFeedBack(AnswerFeedback answerFeedback)
        {
            string[] verbalFeedback = new string[] { };
            //check sub question
            //  studySession.CurrentSubQuestion.AnswerScore = answerFeedback.score;

            var neededFeedback = answerFeedback.answersFeedbacks.OrderByDescending(x => x.score).Take(answerFeedback.Need);

            if (neededFeedback.Where(x => x.score >= 80).Count() >= answerFeedback.Need)
            {
                verbalFeedback = getPhrase(Pkey.goodAnswer);
            }
            else if (neededFeedback.Where(x => x.score <= 80 && x.score >= 20).Count() > 0)
            {
                var entities = neededFeedback.Where(x => x.score > 60).SelectMany(x => x.missingEntitis.Where(z => isSpecialEntity(z.entityType))).Distinct();
                if (neededFeedback.Where(x => x.score >= 60).Count() >= 0)
                {
                    if (entities.Count() > 0)
                    {
                        verbalFeedback = getPhrase(Pkey.goodPartialAnswer);
                        verbalFeedback = mergeText(verbalFeedback, getPhrase(Pkey.missingAnswerEntity));
                        var EntityIter = entities.Distinct().OrderBy(x => x.entityType);
                        verbalFeedback = mergeText(verbalFeedback, mergeTextWithOr(EntityIter.Select(x => x.entityValue).ToArray()));
                    }
                    else
                    {
                        verbalFeedback = mergeText(verbalFeedback, getPhrase(Pkey.goodButNotAllAnswerParts));
                    }
                }
                else
                {
                    verbalFeedback = mergeText(verbalFeedback, getPhrase(Pkey.partialAnswer));
                }

                var partial = neededFeedback.Where(x => x.score <= 60 && x.score >= 20);
                if (partial.Count() > 0)
                {
                    verbalFeedback = mergeText(verbalFeedback, getPhrase(Pkey.MyAnswerToQuestion));
                    verbalFeedback = mergeText(verbalFeedback, mergeTextWithOr(partial.Select(x => x.answer.Trim()).ToArray()));
                }

                var empty = neededFeedback.Where(x => x.score < 20);
                if (empty.Count() > 0)
                {
                    verbalFeedback = mergeText(verbalFeedback, getPhrase(Pkey.shouldWrite));
                    verbalFeedback = mergeText(verbalFeedback, mergeTextWithOr(empty.Select(x => x.answer.Trim()).ToArray()));
                }
            }

            else
            {
                if (neededFeedback.Count() > 0)
                {
                    if (answerFeedback.answer != null && answerFeedback.answer.Split(' ').Length > 2)
                    {
                        verbalFeedback = getPhrase(Pkey.wrongAnswer);
                    }
                    else
                    {
                        verbalFeedback = getPhrase(Pkey.notAnAnswer);
                    }
                    verbalFeedback = mergeText(verbalFeedback, getPhrase(Pkey.MyAnswerToQuestion));
                    verbalFeedback = mergeText(verbalFeedback, mergeTextWithOr(neededFeedback.Select(x => x.answer.Trim()).ToArray()));
                }
            }

            var optionalAnswers = answerFeedback.answersFeedbacks.Except(neededFeedback);

            if (optionalAnswers.Any())
            {
                verbalFeedback = mergeText(verbalFeedback, "|");
                verbalFeedback = mergeText(verbalFeedback, getPhrase(Pkey.possibleAnswer));
                verbalFeedback = mergeText(verbalFeedback, mergeTextWithOr(optionalAnswers.Select(x => x.answer.Trim()).ToArray()));
            }

            return(verbalFeedback);
        }
Exemplo n.º 5
0
        public AnswerFeedback matchAnswers(ISubQuestion subquestion, string answer)
        {
            if (subquestion != null && answer != null)
            {
                var questionAnlize = new List <WorldObject>();
                if (subquestion.questionText != null)
                {
                    questionAnlize = Nlp.Analize(subquestion.questionText); //TODO : fix double computing
                }
                var            userAnswer = Nlp.Analize(answer, subquestion.questionText);
                AnswerFeedback feedback   = new AnswerFeedback();
                feedback.answer = answer;
                if (subquestion.answerText.Contains("|"))
                {
                    foreach (var ans in subquestion.answerText.Split('|'))
                    {
                        if (ans.Trim() != "")
                        {
                            var systemAnswerWords = Nlp.Analize(ans).Except(questionAnlize);
                            var f = matchAnswers(userAnswer, systemAnswerWords.ToList(), ans);
                            feedback.addFeedback(f);
                        }
                    }

                    var feedbacks = feedback.answersFeedbacks;

                    if (feedbacks.Count == 0)
                    {
                        throw new Exception(subquestion.answerText);
                    }

                    var flags = subquestion.flags;



                    if (flags == null || flags.Trim() == "" || flags.Trim() == "needAll")
                    {
                        feedback.Need  = feedback.answersFeedbacks.Count;
                        feedback.score = (int)feedback.answersFeedbacks.Average(x => x.score);
                    }
                    else
                    {
                        int numberInt;

                        var numberStr = flags.Replace("need", "");
                        int.TryParse(numberStr, out numberInt);
                        numberInt     = numberInt == 0 ? feedbacks.Count : numberInt;
                        feedback.Need = numberInt;
                        feedbacks.Sort((x, y) => y.score - x.score);
                        feedbacks = feedbacks.GetRange(0, numberInt);
                        foreach (var f in feedbacks)
                        {
                            feedback.score = (int)feedbacks.Average(x => x.score);
                        }
                        //feedback.answersFeedbacks = feedbacks;
                    }
                }
                else
                {
                    var systemAnswer = Nlp.Analize(subquestion.answerText).Except(questionAnlize);
                    var f            = matchAnswers(userAnswer, systemAnswer.ToList());
                    f.answer = subquestion.answerText;
                    feedback.addFeedback(f);
                    feedback.Need = 1;
                }


                if (feedback == null)
                {
                    feedback = new AnswerFeedback();
                }



                return(feedback);
            }
            else
            {
                return(new AnswerFeedback());
            }
        }
Exemplo n.º 6
0
        public AnswerFeedback matchAnswers(List <WorldObject> userAnswer, List <WorldObject> systemAnswer)
        {
            if (userAnswer != null && systemAnswer != null)
            {
                var userEntities          = userAnswer.Distinct();
                var systemEntities        = systemAnswer.Distinct();
                var systemEntitisFiltered = systemAnswer.Where(o => o is EntityObject);
                if (systemEntitisFiltered.Count() >= 1)
                {
                    systemEntities = systemEntitisFiltered;
                }
                var feedback = new AnswerFeedback();

                if (systemAnswer.Count() != 0)
                {
                    foreach (var se in systemEntities)
                    {
                        var found = false;


                        foreach (var ue in userEntities)
                        {
                            if (se.GetType() == ue.GetType())
                            {
                                var a = se.Word.Equals(ue.Word);
                                var b = se.Negat == ue.Negat;


                                if (se.Word.Equals(ue.Word) && se.Negat == ue.Negat)
                                {
                                    Double d = 100.0 / systemEntities.Count();

                                    feedback.score += (int)Math.Ceiling(d);

                                    found = true;
                                    break;
                                }
                            }
                        }

                        if (!found)
                        {
                            feedback.missingEntitis.Add(se.Entity);
                        }
                        else
                        {
                            feedback.foundEntitis.Add(se.Entity);
                        }
                    }
                }
                else
                {
                    feedback.score = 100;
                }

                return(feedback);
            }
            else if (userAnswer == null && systemAnswer != null)
            {
                var fe = new AnswerFeedback();
                fe.score = 0;
                return(fe);
            }
            else
            {
                var fe = new AnswerFeedback();
                fe.score = 100;
                return(fe);
            }
        }
 public string[] createFeedBack(AnswerFeedback answerFeedback)
 {
     return(messageComposer.createFeedBack(answerFeedback));
 }