Example #1
0
        public void FilterStopWordsTest_basic()
        {
            string input          = "I am a person and a man";
            string expectedResult = "person man";

            AnalyseModel model = new AnalyseModel();

            Assert.AreEqual(expectedResult, model.RemoveStopWords(input));
        }
Example #2
0
        public void FilterStopWordsTest_input_is_empty()
        {
            string input          = string.Empty;
            string expectedResult = string.Empty;

            AnalyseModel model = new AnalyseModel();

            Assert.AreEqual(expectedResult, model.RemoveStopWords(input));
        }
Example #3
0
        public void FilterStopWordsTest_input_have_empty_space()
        {
            string input          = "I    AM     A person    aNd    A    man";
            string expectedResult = "person man";

            AnalyseModel model = new AnalyseModel();

            Assert.AreEqual(expectedResult, model.RemoveStopWords(input));
        }
Example #4
0
        public ActionResult Index(AnalyseModel model)
        {
            string content = string.Empty;

            model.InvalidMessage = string.Empty;

            #region Validate input
            if (model.IsAnyOptionSelected == false)
            {
                model.InvalidMessage = "Please check at least one of the checkbox";
            }
            else if (string.IsNullOrWhiteSpace(model.Input))
            {
                model.InvalidMessage = "Please enter text or url";
            }
            else if (Uri.TryCreate(model.Input, UriKind.Absolute, out Uri uri))
            {
                content = GetHtmlText(uri);

                if (string.IsNullOrEmpty(content))
                {
                    model.InvalidMessage = "The URL you enter could not be access";
                }
            }
            else
            {
                content = model.Input;
            }
            #endregion

            if (string.IsNullOrEmpty(model.InvalidMessage))
            {
                model.IsValid = true;

                if (model.FilterStopsWordsFlag)
                {
                    content = model.RemoveStopWords(content);
                }

                if (model.CalNumOfOccuranceOfWordsFlag)
                {
                    model.OccuranceOfWordsTable = model.GetOccuranceWordTable(HttpUtility.HtmlEncode(content));
                }

                if (model.CalNumOfOccuranceOfWordsListedInMetaTagsFlag)
                {
                    model.OccuranceOfWordsInMetaTagsTable = model.GetOccuranceWordInMetaTagTable(content);
                }

                if (model.CalNumOfOccuranceOfExternalLinksFlag)
                {
                    model.OccuranceOfExternalLinksTable = model.GetOccuranceExternalLinkTable(content);
                }
            }

            return(View(model));
        }