示例#1
0
        public void GetRepeatedWordsTests()
        {
            _smartTextBox = new SmartTextBoxImpl();
            _text         = "נתחיל מבדיקה בה אין אף מילה אשר חוזרת על עצמה עצמה יותר יותר יותר יותר מפעם אחת.";
            IDictionary <string, int> wordList = _smartTextBox.GetRepeatedWords(_text);

            Assert.IsTrue(wordList["עצמה"] == 2);
            Assert.IsTrue(wordList["יותר"] == 4);
            Assert.IsTrue(wordList["אין"] == 1);
            Assert.IsTrue(wordList["אחת"] == 1);

            for (int i = 0; i < 10; i++)
            {
                _text = _text + " הלילה אף אחד לא יושב פה, ";
                if (i % 2 == 0)
                {
                    _text = _text + " במקום זוגי ";
                }
                if (i % 3 == 0)
                {
                    _text = _text + " עם שלישיה ";
                }
            }
            _text    = _text + "לא יכול להפסיק לזוז";
            wordList = _smartTextBox.GetRepeatedWords(_text);

            Assert.IsTrue(wordList["לא"] == 11);
            Assert.IsTrue(wordList["הלילה"] == 10);
            Assert.IsTrue(wordList["לזוז"] == 1);
            Assert.IsTrue(wordList["זוגי"] == 5);
            Assert.IsTrue(wordList["שלישיה"] == 4);
        }
示例#2
0
        public ActionResult AnalyzeAnswer(string questionNumber)
        {
            try
            {
                int tmpQuestNumber = 1;

                if (questionNumber != null)
                {
                    string[] tmpStringArray = questionNumber.Split(' ');

                    tmpQuestNumber = Int32.Parse(tmpStringArray.Last());

                    if (tmpStringArray.Length > 4)
                    {
                        return(RedirectToAction("FinalAnswerSubmit", new
                        {
                            questionNumber = tmpQuestNumber,
                            textContent = Request.Form["TextBoxArea"]
                        }));
                    }
                }


                string input           = Request.Form["TextBoxArea"];
                int    numOfWords      = _smartTextBox.GetNumberOfWords(input);
                int    numOfConnectors = _smartTextBox.GetNumberOfConnectors(input);
                IDictionary <string, int> repeatedWords = _smartTextBox.GetRepeatedWords(input);

                string repeatedWordsString = "";
                foreach (var word in repeatedWords)
                {
                    if (word.Value >= 2 && _smartTextBox.IsConnector(word.Key))
                    {
                        repeatedWordsString = repeatedWordsString + "השתמשת במילה " + word.Key + " " + word.Value + " פעמים, אולי תרצה להשתמש במילה אחרת כמו " + _smartTextBox.SuggestAlternativeWord(word.Key) + ". ";
                    }
                    if (word.Value >= 2 && _smartTextBox.IsConnector((word.Key).Substring(1)))
                    {
                        repeatedWordsString = repeatedWordsString + "השתמשת במילה " + (word.Key).Substring(1) + " " + word.Value + " פעמים, אולי תרצה להשתמש במילה אחרת כמו " + _smartTextBox.SuggestAlternativeWord((word.Key).Substring(1)) + ". ";
                    }
                }



                smartView.QuestionNumber = tmpQuestNumber;

                string userid = User.Identity.GetUserId();

                foreach (var std in _studentService.All().Include(x => x.Homeworks))
                {
                    if (std.ApplicationUserId.Equals(userid))
                    {
                        student = std;
                        break;
                    }
                }

                string tmpName = (string)Session["textName"];
                textGuid = _textService.All().Where(t => t.Name == tmpName).FirstOrDefault().Id;

                List <Homework> AllStudentHW = _homeworkService.All().Where(x => x.Text.Id == textGuid).ToList();

                Homework hw = AllStudentHW.First();

                List <Question> tmpQuestionsList = _homeworkService.All().Include(x => x.Questions.Select(q => q.Policy)).Where(x => x.Id == hw.Id).FirstOrDefault().Questions.ToList();
                smartView.question  = tmpQuestionsList.Where(x => x.Question_Number == tmpQuestNumber).FirstOrDefault();
                smartView.Questions = tmpQuestionsList;

                if (smartView.question == null)
                {
                    return(RedirectToAction("Index"));
                }
                if (smartView.question.Policy != null)
                {
                    _policy = smartView.question.Policy;
                }



                TempData["NumberOfWords"]          = numOfWords;
                TempData["NumberOfConnectorWords"] = numOfConnectors;
                TempData["Answer"]           = input;
                TempData["AlternativeWords"] = repeatedWordsString;

                string tmpCounter = "";
                if (numOfConnectors > _policy.MaxConnectors)
                {
                    tmpCounter = "הכנסת " + numOfConnectors + " מילות קישור, אבל מותר לכל היותר " + _policy.MaxConnectors + " מילות קישור.";
                }
                if (numOfConnectors < _policy.MinConnectors)
                {
                    tmpCounter = tmpCounter + " הכנסת " + numOfConnectors + " מילות קישור, אבל עלייך להכניס לכל הפחות " + _policy.MinConnectors + " מילות קישור.";
                }
                if (numOfWords > _policy.MaxWords)
                {
                    tmpCounter = tmpCounter + " הכנסת " + numOfWords + " מילים, אבל מותר לכל היותר " + _policy.MaxWords + " מילים.";
                }
                if (numOfWords < _policy.MinWords)
                {
                    tmpCounter = tmpCounter + " הכנסת " + numOfWords + " מילים, אבל עלייך להכניס לכל הפחות " + _policy.MinWords + " מילים.";
                }
                TempData["toManyConnectors"] = tmpCounter;

                if (smartView.question.Suggested_Openings.Count == 0)
                {
                    SuggestedOpening noSuggOpen  = new SuggestedOpening("אין משפטי פתיחה לשאלה זו");
                    SuggestedOpening noSuggOpen2 = new SuggestedOpening("התשובה לשאלה נמצאת בגוף השאלה");
                    smartView.question.Suggested_Openings.Add(noSuggOpen);
                    smartView.question.Suggested_Openings.Add(noSuggOpen2);
                }

                List <int> SmartViewQuestionsNumbers = new List <int>();

                List <QuestionAnswer> QuestionsAnswered = _answerService.All().Where(x => x.Homework_Id == hw.Id && x.Student_Id == student.Id).SelectMany(x => x.questionAnswers).ToList();


                smartView.CompleteQuestions = QuestionsAnswered;

                if (QuestionsAnswered.Count() == 0)
                {
                    smartView.CompleteQuestions = new List <QuestionAnswer>();

                    SmartViewQuestionsNumbers.Add(-1);

                    smartView.CompleteQuestionsNumbers = SmartViewQuestionsNumbers;

                    Session["percentage"] = 0;
                }
                else
                {
                    int k = 0;

                    foreach (var QuestAns in QuestionsAnswered)
                    {
                        SmartViewQuestionsNumbers.Add(QuestAns.Of_Question.Question_Number);
                        k++;
                    }
                    smartView.CompleteQuestionsNumbers = SmartViewQuestionsNumbers;
                    Session["percentage"] = (k / smartView.Questions.Count * 100);
                }
                return(View("QuestionsView", smartView));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Index"));
            }
        }