コード例 #1
0
        public StringMatchingFilterDialog(StringMatching existingFilter)
        {
            m_existingFilter = existingFilter;
            InitializeComponent();

            TxtUserInput.Text = m_existingFilter.MatchText;
            switch (m_existingFilter.MatchMode)
            {
            case StringMatchingMode.Exact:
                rdoExact.Checked = true;
                break;

            case StringMatchingMode.StartsWith:
                RdoStartsWith.Checked = true;
                break;

            case StringMatchingMode.Contains:
                rdoContains.Checked = true;
                break;

            case StringMatchingMode.EndsWith:
                rdoEndsWith.Checked = true;
                break;

            case StringMatchingMode.Regex:
                rdoRegex.Checked = true;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #2
0
        public void Matches_with_valid_regexes_should_return_true()
        {
            var input   = "Hello";
            var pattern = "[A-Za-z]*";

            StringMatching.MatchesPattern(input, pattern).Should().BeTrue();
        }
コード例 #3
0
        public void Patterns_that_do_not_match_input_should_return_false()
        {
            var input   = "Hello";
            var pattern = "^[a]*$";

            StringMatching.MatchesPattern(input, pattern).Should().BeFalse();
        }
コード例 #4
0
        public void Exact_text_match_with_no_special_characters_should_return_true()
        {
            var input   = "Hello";
            var pattern = "Hello";

            StringMatching.MatchesPattern(input, pattern).Should().BeTrue();
        }
コード例 #5
0
        public void Pattern_matching_is_case_insensitive()
        {
            var input   = "HELLO";
            var pattern = "[a-z]*";

            StringMatching.MatchesPattern(input, pattern).Should().BeTrue();
        }
コード例 #6
0
        public void Should_return_true_if_strings_exactly_match()
        {
            var input   = "Hello";
            var matches = "Hello";

            StringMatching.Matches(input, matches).Should().BeTrue();
        }
コード例 #7
0
        public void Matches_should_be_case_insensitive()
        {
            var input           = "Hello";
            var ignoreCaseMatch = "HELLO";

            StringMatching.Matches(input, ignoreCaseMatch).Should().BeTrue();
        }
コード例 #8
0
        public void Should_return_false_if_strings_dont_exactly_match()
        {
            var input       = "Hello";
            var doesntMatch = "Bye";

            StringMatching.Matches(input, doesntMatch).Should().BeFalse();
        }
コード例 #9
0
        public void Non_matching_text_with_no_special_characters_should_return_false()
        {
            var input   = "Hello";
            var pattern = "Goodbye";

            StringMatching.MatchesPattern(input, pattern).Should().BeFalse();
        }
コード例 #10
0
        public IMessageAssertions SummaryIs(string shouldMatch)
        {
            if (!StringMatching.Matches(_message.Summary, shouldMatch))
            {
                ThrowMatchException(nameof(_message.Summary), shouldMatch, _message.Summary);
            }

            return(this);
        }
コード例 #11
0
        public IMessageAssertions TextIs(string shouldMatch)
        {
            if (!StringMatching.Matches(_message.Text, shouldMatch))
            {
                ThrowMatchException(nameof(_message.Text), shouldMatch, _message.Text);
            }

            return(this);
        }
コード例 #12
0
        public void Pattern_matching_is_case_insensitive()
        {
            var input   = "HELLO";
            var pattern = "[a-z]*";

            var result = StringMatching.MatchesPatternWithGroups(input, pattern);

            result.doesMatch.Should().BeTrue();
        }
コード例 #13
0
        public void Patterns_that_do_not_match_input_should_return_false()
        {
            var input   = "Hello";
            var pattern = "^[a]*$";

            var result = StringMatching.MatchesPatternWithGroups(input, pattern);

            result.doesMatch.Should().BeFalse();
        }
コード例 #14
0
        public void Matches_with_valid_regexes_should_return_true()
        {
            var input   = "Hello";
            var pattern = "[A-Za-z]*";

            var result = StringMatching.MatchesPatternWithGroups(input, pattern);

            result.doesMatch.Should().BeTrue();
        }
コード例 #15
0
        public void Non_matching_text_with_no_special_characters_should_return_false()
        {
            var input   = "Hello";
            var pattern = "Goodbye";

            var result = StringMatching.MatchesPatternWithGroups(input, pattern);

            result.doesMatch.Should().BeFalse();
        }
コード例 #16
0
        public IMessageAssertions TextLike(string pattern)
        {
            if (!StringMatching.MatchesPattern(_message.Text, pattern))
            {
                ThrowPatternException(nameof(_message.Text), pattern, _message.Text);
            }

            return(this);
        }
コード例 #17
0
        public IActivityAssertions TypeLike(string activityTypePattern)
        {
            if (!StringMatching.MatchesPattern(_activity.Type, activityTypePattern))
            {
                ThrowPatternException(nameof(_activity.Type), activityTypePattern, _activity.Type);
            }

            return(this);
        }
コード例 #18
0
        public IActivityAssertions TypeIs(string activityType)
        {
            if (!StringMatching.Matches(_activity.Type, activityType))
            {
                ThrowMatchException(nameof(_activity.Type), activityType, _activity.Type);
            }

            return(this);
        }
コード例 #19
0
        public IMessageAssertions SummaryLike(string pattern)
        {
            if (!StringMatching.MatchesPattern(_message.Summary, pattern))
            {
                ThrowPatternException(nameof(_message.Summary), pattern, _message.Summary);
            }

            return(this);
        }
コード例 #20
0
        public IActivityAssertions IdIs(string id)
        {
            if (!StringMatching.Matches(_activity.Id, id))
            {
                ThrowMatchException(nameof(_activity.Id), id, _activity.Id);
            }

            return(this);
        }
コード例 #21
0
        public IActivityAssertions IdLike(string idPattern)
        {
            if (!StringMatching.MatchesPattern(_activity.Id, idPattern))
            {
                ThrowPatternException(nameof(_activity.Id), idPattern, _activity.Id);
            }

            return(this);
        }
コード例 #22
0
        public IActivityAssertions ChannelIdIs(string channelId)
        {
            if (!StringMatching.Matches(_activity.ChannelId, channelId))
            {
                ThrowMatchException(nameof(_activity.ChannelId), channelId, _activity.ChannelId);
            }

            return(this);
        }
コード例 #23
0
        public void Matching_pattern_with_groupings_should_return_the_matched_groups()
        {
            var input   = "hello";
            var pattern = "([a-z]*)";

            var result = StringMatching.MatchesPatternWithGroups(input, pattern);

            result.doesMatch.Should().BeTrue();
            result.matches.Should().Contain(input);
        }
コード例 #24
0
        public void Exact_text_match_with_no_special_characters_should_return_true_with_no_matches()
        {
            var input   = "Hello";
            var pattern = "Hello";

            var result = StringMatching.MatchesPatternWithGroups(input, pattern);

            result.doesMatch.Should().BeTrue();
            result.matches.Should().BeEmpty();
        }
コード例 #25
0
        public void Multiple_matching_groups_should_all_be_returned()
        {
            var input   = "hello";
            var pattern = "^([a-z])([a-z]*)$";

            var result = StringMatching.MatchesPatternWithGroups(input, pattern);

            result.doesMatch.Should().BeTrue();
            result.matches.Should().Contain("h");
            result.matches.Should().Contain("ello");
        }
コード例 #26
0
        /// <summary>
        /// Wyznaczanie minimalnego szablonu
        /// </summary>
        /// <param name="text">Napis do namalowania</param>
        /// <param name="indexes">Tablica zawierająca indeksy "punktów przyłozenia" początku szablonu</param>
        /// <returns>Długość szablonu</returns>
        public static int MinPattern(string text, out int[] indexes)
        {
            int[]      P                      = StringMatching.ComputeP(text);
            int        textLength             = text.Length;
            int        shortestPatternLength  = textLength;
            List <int> shortestPatternMatches = new List <int>()
            {
                0
            };

            foreach (int prefixLength in P.Where(x => x > 0).Distinct().OrderByDescending(x => x))
            {
                //if (shortestPatternLength < textLength && shortestPatternLength <= 2 * prefixLength)
                //{
                //    // Using "tip 2"
                //    shortestPatternLength = prefixLength;
                //    shortestPatternMatches = null;
                //}
                //else
                //{
                // Check if the pattern matches
                string     prefix  = text.Substring(0, prefixLength);
                int[]      prefixP = StringMatching.ComputeP(prefix);
                List <int> matches = StringMatching.KMP(text, prefix, prefixP);

                bool patternMatches = IsPattern(text, prefix, matches);
                if (patternMatches)
                {
                    shortestPatternLength  = prefixLength;
                    shortestPatternMatches = matches;
                }
                //}
            }

            if (shortestPatternMatches == null)
            {
                string prefix = text.Substring(0, shortestPatternLength);
                shortestPatternMatches = StringMatching.KMP(text, prefix, StringMatching.ComputeP(prefix));
            }

            indexes = shortestPatternMatches.ToArray();
            return(shortestPatternLength);
        }
コード例 #27
0
        private void BtnDone_Click(object sender, EventArgs e)
        {
            if (rdoRegex.Checked)
            {
                try
                {
                    Regex r = new Regex(TxtUserInput.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("Not a valid Regex");
                    return;
                }
            }

            if (rdoExact.Checked)
            {
                ResultFilter = new StringMatching(StringMatchingMode.Exact, TxtUserInput.Text);
            }
            else if (RdoStartsWith.Checked)
            {
                ResultFilter = new StringMatching(StringMatchingMode.StartsWith, TxtUserInput.Text);
            }
            else if (rdoContains.Checked)
            {
                ResultFilter = new StringMatching(StringMatchingMode.Contains, TxtUserInput.Text);
            }
            else if (rdoEndsWith.Checked)
            {
                ResultFilter = new StringMatching(StringMatchingMode.EndsWith, TxtUserInput.Text);
            }
            else if (rdoRegex.Checked)
            {
                ResultFilter = new StringMatching(StringMatchingMode.Regex, TxtUserInput.Text);
            }
            else
            {
                MessageBox.Show("Not a valid mode");
                return;
            }

            DialogResult = DialogResult.OK;
        }
コード例 #28
0
        /// <summary>
        /// Badanie równoważności cyklicznej z wykorzystaniem algorytmu KMP
        /// </summary>
        /// <param name="text1">Pierwszy badany tekst</param>
        /// <param name="text2">Drugi badany tekst</param>
        /// <returns>
        /// Jeśli teksty nie są cyklicznie równoważne zwraca null
        /// Jeśli teksty są cyklicznie równoważne zwraca liczbę znaków,
        ///    które trzeba przenieść z początku pierwszego tekstu na koniec aby uzyskać drugi tekst
        /// </returns>
        public static int?CyclicEquivalenceKMP(string text1, string text2)
        {
            int n = text1.Length;

            if (n != text2.Length)
            {
                return(null);
            }

            if (text1 == text2)
            {
                return(0);
            }

            int[] P = StringMatching.ComputeP(text1 + text2);
            if (P.Last() == 0)
            {
                return(null);
            }
            return(P.Last());
        }
コード例 #29
0
 /// <summary>Find the best approximate match for <paramref name="words"/> in <paramref name="text"/>. Also takes into account the <paramref name="words"/>'s distance from the beginning.</summary>
 /// <param name="cReplace">Cost of replace operation. Default is 1.</param>
 /// <param name="cInsert">Cost of insert operation. Default is 1.</param>
 /// <param name="cDelete">Cost of delete operation. Default is 1.</param>
 public static StrMatch WordMatch(this string text, string[] words, int cReplace, int cInsert, int cDelete) => StringMatching.WordMatch(text, words, cReplace, cInsert, cDelete);
コード例 #30
0
 public static int EditDistance(this string from, string to) => StringMatching.EditDistance(from, to);