コード例 #1
0
        public void CorrectlyParse_SpecialCharacters()
        {
            var originalText = "b;\tc;\rd;\ne;\r\nf;\r\n\r\ng";
            var escapedText  = Regex.Escape(originalText);
            var expected     = new List <List <string> >
            {
                new List <string> {
                    "b"
                },
                new List <string> {
                    "c"
                },
                new List <string> {
                    "d"
                },
                new List <string> {
                    "e"
                },
                new List <string> {
                    "f"
                },
                new List <string> {
                    "g"
                }
            };
            var actual = SentencesParser.ParseSentences(originalText);

            AssertAllSentencesEqual(expected, actual, escapedText);
        }
コード例 #2
0
        public void NotReturnEmptySentence([Values("..", "...!!?", "")]
                                           string text)
        {
            var expected = new List <List <string> >();

            var actual = SentencesParser.ParseSentences(text);

            AssertAllSentencesEqual(expected, actual, text);
        }
コード例 #3
0
        public void ReturnCorrectResult_OnTextWithOneSentence_WithWordContainingApostrophe()
        {
            var text     = "it's";
            var expected = new List <List <string> > {
                new List <string> {
                    "it's"
                }
            };
            var actual = SentencesParser.ParseSentences(text);

            AssertAllSentencesEqual(expected, actual, text);
        }
コード例 #4
0
        public void ReturnCorrectResult_OnTextWithOneSentenceWithTwoWords()
        {
            var text     = "b, c";
            var expected = new List <List <string> > {
                new List <string> {
                    "b", "c"
                }
            };
            var actual = SentencesParser.ParseSentences(text);

            AssertAllSentencesEqual(expected, actual, text);
        }
コード例 #5
0
        public void CorrectlyParse_OneSentenceWithWordDelimiter(
            [Values('^', '#', '$', '-', '+', '1', '=', ' ', '\t', '\n', '\r')]
            char delimiter)
        {
            var text     = "x" + delimiter + "y";
            var expected = new List <List <string> >
            {
                new List <string> {
                    "x", "y"
                }
            };
            var actual = SentencesParser.ParseSentences(text);

            AssertAllSentencesEqual(expected, actual, text);
        }
コード例 #6
0
        public void ReturnResult_InLowerCase()
        {
            var text     = "B.C.D";
            var expected = new List <List <string> >
            {
                new List <string> {
                    "b"
                },
                new List <string> {
                    "c"
                },
                new List <string> {
                    "d"
                }
            };
            var actual = SentencesParser.ParseSentences(text);

            AssertAllSentencesEqual(expected, actual, text);
        }
コード例 #7
0
        public static void Main(string[] args)
        {
            var text      = File.ReadAllText("HarryPotterText.txt");
            var sentences = SentencesParser.ParseSentences(text);
            var frequency = FrequencyAnalysis.GetMostFrequentNextWords(sentences);

            while (true)
            {
                var rnd   = new Random();
                var count = rnd.Next(0, 40);
                Console.Write("Введите первое слово (например, harry): ");
                var beginning = Console.ReadLine();
                if (string.IsNullOrEmpty(beginning))
                {
                    return;
                }
                var phrase = TextGenerator.ContinuePhrase(frequency, beginning.ToLower(), count);
                Console.WriteLine(phrase);
            }
        }
コード例 #8
0
        public void CorrectlyParse_SentenceDelimiters()
        {
            var text     = "a.b!c?d:e;f(g)h;i";
            var expected = new List <List <string> >
            {
                new List <string> {
                    "a"
                },
                new List <string> {
                    "b"
                },
                new List <string> {
                    "c"
                },
                new List <string> {
                    "d"
                },
                new List <string> {
                    "e"
                },
                new List <string> {
                    "f"
                },
                new List <string> {
                    "g"
                },
                new List <string> {
                    "h"
                },
                new List <string> {
                    "i"
                }
            };

            var actual = SentencesParser.ParseSentences(text);

            AssertAllSentencesEqual(expected, actual, text);
        }