Beispiel #1
0
        public void WordCounting_CreatesArrayOfWords_Array()
        {
            WordCounting testWordCount = new WordCounting("testQueryWord", "this is a test sentence");

            string[] testSentenceArray = { "this", "is", "a", "test", "sentence" };
            CollectionAssert.AreEqual(testSentenceArray, testWordCount.ArrayFromSentence);
        }
Beispiel #2
0
 public List <ViseonHeaderModel> GetViseonElements(HtmlDocument doc)
 {
     try
     {
         var headers = new List <ViseonHeaderModel>();
         foreach (var type in ViseonStaticData.HeaderElements)
         {
             var list = doc.DocumentNode.GetElementsByTagName(type);
             foreach (var item in list)
             {
                 headers.Add(new ViseonHeaderModel()
                 {
                     HtmlTagName = item.Name,
                     Text        = item.InnerText,
                     WordCount   = WordCounting.CountWords(item.InnerText),
                 });
             }
         }
         return(headers);
     }
     catch (Exception ex)
     {
         return(new List <ViseonHeaderModel>());
     }
 }
Beispiel #3
0
 public ViseonTitleModel GetViseonElement(HtmlDocument doc)
 {
     try
     {
         var list  = doc.DocumentNode.GetElementsByTagName(ViseonStaticData.TitleElement);
         var title = list.FirstOrDefault();
         // no title found
         if (title == null)
         {
             return new ViseonTitleModel()
                    {
                        HtmlTagName = ViseonStaticData.TitleElement,
                        Text        = "", WordCount = 0
                    }
         }
         ;
         return(new ViseonTitleModel()
         {
             Text = title.InnerText,
             WordCount = WordCounting.CountWords(title.InnerText),
             HtmlTagName = ViseonStaticData.TitleElement,
             CharacterCount = title.InnerText.Length
         });
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
    static void Main()
    {
        const string t1 = "To be or not to be, that is the question.";

        Console.WriteLine(WordCounting.CountWords1(t1));

        const string t2 = "Mary had a little lamb.";

        Console.WriteLine(WordCounting.CountWords1(t2));
    }
Beispiel #5
0
        public ViseonDescriptionModel GetViseonElement(HtmlDocument doc)
        {
            try
            {
                var      list = doc.DocumentNode.GetElementsByTagName(ViseonStaticData.MetaElements);
                HtmlNode desc = null;
                foreach (var htmlNode in list)
                {
                    if (htmlNode.Attributes[ViseonStaticData.Meta.NameProp] == null)
                    {
                        continue;
                    }
                    if (!String.Equals(htmlNode.Attributes[ViseonStaticData.Meta.NameProp].Value, ViseonStaticData.MetaDescription, StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }
                    desc = htmlNode;
                    break;
                }

                // no desc
                if (desc == null)
                {
                    return new ViseonDescriptionModel()
                           {
                               HtmlTagName = ViseonStaticData.MetaDescription,
                               Text        = "",
                               WordCount   = 0
                           }
                }
                ;

                var text = desc.Attributes[ViseonStaticData.Meta.ContentProp]?.Value;
                return(new ViseonDescriptionModel()
                {
                    Text = text ?? "",
                    WordCount = text == null ? 0 : WordCounting.CountWords(text),
                    HtmlTagName = ViseonStaticData.MetaDescription,
                    CharacterCount = text?.Length ?? 0
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Beispiel #6
0
 public List <ViseonParagraphModel> GetViseonElements(HtmlDocument doc)
 {
     try
     {
         var paras  = doc.DocumentNode.GetElementsByName(ViseonStaticData.ParaElement);
         var result = new List <ViseonParagraphModel>();
         foreach (var htmlNode in paras)
         {
             result.Add(new ViseonParagraphModel()
             {
                 HtmlTagName = ViseonStaticData.ParaElement,
                 Text        = htmlNode.InnerText,
                 WordCount   = WordCounting.CountWords(htmlNode.InnerText)
             });
         }
         return(result);
     }
     catch (Exception ex)
     {
         return(new List <ViseonParagraphModel>());
     }
 }
Beispiel #7
0
        public void WordCounting_SaysNoMatches_Int()
        {
            WordCounting testWordCount = new WordCounting("hate", "I love love LOVE C Sharp");

            Assert.AreEqual(0, testWordCount.matchCounter(testWordCount.QueryWord, testWordCount.ArrayFromSentence));
        }
Beispiel #8
0
        public void WordCounting_IgnoresCase_Int()
        {
            WordCounting testWordCount = new WordCounting("love", "I love love LOVE C Sharp");

            Assert.AreEqual(3, testWordCount.matchCounter(testWordCount.QueryWord, testWordCount.ArrayFromSentence));
        }
Beispiel #9
0
        public void WordCounting_CountsWordMatches_Int()
        {
            WordCounting testWordCount = new WordCounting("love", "I love love C Sharp");

            Assert.AreEqual(2, testWordCount.matchCounter(testWordCount.QueryWord, testWordCount.ArrayFromSentence));
        }
Beispiel #10
0
 public override string ToString()
 {
     return("{" + string.Format("anchor:'{0}', length:{1}, link:'{2}'", Common.GetParaForCassDb(anchors), WordCounting.CountWords1(anchors), link) + "}");
 }
Beispiel #11
0
        public ActionResult Create(string word, string sentence)
        {
            WordCounting newCount = new WordCounting(word, sentence);

            return(View("Show", newCount));
        }