Exemple #1
0
        private string getAlgorithmAnswer(QustionAnswer ans) ///////
        {
            IEnumerable <string> keywords = _keywordServ.findAlgorithmsKeywords(_quesServ.getQuestionAlgorithm(ans.IdQuestion).Id);

            keywords = nlpService.GetSearchWords(ans.Answer, keywords);
            if (keywords.Count() < 1)
            {
                return("-1");
            }

            else if (keywords.Count() == 1)
            {
                return(_keywordServ.getAlgorithm(keywords.ElementAt(0)));
            }

            else
            {
                string algo = _keywordServ.getAlgorithm(keywords.ElementAt(0));

                for (int i = 1; i < keywords.Count(); i++)
                {
                    if (algo != _keywordServ.getAlgorithm(keywords.ElementAt(i)))
                    {
                        return("0");
                    }
                }
                return(algo);
            }
        }
Exemple #2
0
        private string getBadyPartAnswer(QustionAnswer ans)
        {
            IEnumerable <string> allKeywords = _keywordServ.findBodyPartKeywords();
            IEnumerable <string> keywords    = nlpService.GetSearchWords(ans.Answer, allKeywords);

            if (keywords.Count() < 1)
            {
                return("-1");
            }

            else if (keywords.Count() == 1)
            {
                return(_keywordServ.getBodyPart(keywords.ElementAt(0)));
            }

            else
            {
                string bodyPart = _keywordServ.getBodyPart(keywords.ElementAt(0));

                for (int i = 1; i < keywords.Count(); i++)
                {
                    if (bodyPart != _keywordServ.getBodyPart(keywords.ElementAt(i)))
                    {
                        return("0");
                    }
                }
                return(bodyPart);
            }
        }
Exemple #3
0
        public string Get(string jsonAns)
        {
            QustionAnswer questionAnswer = (QustionAnswer)JSONHelper.ToObject(jsonAns);

            questionAnswer.AnswerApproved = _ansServ.getAnswer(questionAnswer);
            //saveAnswer(ans);

            return("hh");
        }
Exemple #4
0
        public string getAnswer(QustionAnswer ans)
        {
            IEnumerable <string> keywords = null;

            int type = getQuastionType(ans);

            if (type == 1)
            { //yn
                keywords = "yes,no".Split(',');
                keywords = nlpService.GetSearchWords(ans.Answer, keywords);
                if (keywords.Count() < 1)
                {
                    return("-1");
                }
                else if (keywords.Count() > 1)
                {
                    return("0");
                }
                else
                {
                    return(keywords.ElementAt(0));
                }
            }

            else if (type == 0)
            {  // first
                int order = _quesServ.getQuestionOrder(ans.IdQuestion);

                switch (order)
                {
                case 0:
                    return(getBadyPartAnswer(ans));

                case 1:
                    keywords = "injury,illness".Split(',');
                    keywords = nlpService.GetSearchWords(ans.Answer, keywords);
                    if (keywords.Count() < 1)
                    {
                        return("-1");
                    }
                    else if (keywords.Count() > 1)
                    {
                        return("0");
                    }
                    else
                    {
                        return(keywords.ElementAt(0));
                    }

                case 2:
                    return(getAlgorithmAnswer(ans));       /////// ###### //////////
                }
            }

            return("-1");
        }
Exemple #5
0
        private int getQuastionType(QustionAnswer ans)
        {
            Question q = getQuastion(ans);

            if (q.IdAlgorithem == 0)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
Exemple #6
0
        private Question getQuastion(QustionAnswer ans)
        {
            Question[] q = _db.Question.Where(a => a.Id == ans.IdQuestion).ToArray();

            if (q.Length > 0)
            {
                return(q[0]);
            }
            else
            {
                return(null);
            }
        }
Exemple #7
0
        public Question getNextQuestion(QustionAnswer lastAns)
        {
            Question lastQuestion = getQuastion(lastAns);

            string a = getAnswer(lastAns);

            if (a == "-1")
            {
                return(lastQuestion);
            }
            else if (a == "0")
            {
                return(lastQuestion);
            }
            else
            {
                return(getNextQuestion(lastQuestion));
            }
        }
Exemple #8
0
 public void saveAnswer(QustionAnswer answer)
 {
     //  _db.QustionAnswer.Add(answer);
     //  _db.SaveChanges();
 }
Exemple #9
0
 public Question Post([FromBody] QustionAnswer answer)
 {
     answer.AnswerApproved = _ansServ.getAnswer(answer);
     _ansServ.saveAnswer(answer);
     return(_ansServ.getNextQuestion(answer));
 }