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(); } }
public void Matches_with_valid_regexes_should_return_true() { var input = "Hello"; var pattern = "[A-Za-z]*"; StringMatching.MatchesPattern(input, pattern).Should().BeTrue(); }
public void Patterns_that_do_not_match_input_should_return_false() { var input = "Hello"; var pattern = "^[a]*$"; StringMatching.MatchesPattern(input, pattern).Should().BeFalse(); }
public void Exact_text_match_with_no_special_characters_should_return_true() { var input = "Hello"; var pattern = "Hello"; StringMatching.MatchesPattern(input, pattern).Should().BeTrue(); }
public void Pattern_matching_is_case_insensitive() { var input = "HELLO"; var pattern = "[a-z]*"; StringMatching.MatchesPattern(input, pattern).Should().BeTrue(); }
public void Should_return_true_if_strings_exactly_match() { var input = "Hello"; var matches = "Hello"; StringMatching.Matches(input, matches).Should().BeTrue(); }
public void Matches_should_be_case_insensitive() { var input = "Hello"; var ignoreCaseMatch = "HELLO"; StringMatching.Matches(input, ignoreCaseMatch).Should().BeTrue(); }
public void Should_return_false_if_strings_dont_exactly_match() { var input = "Hello"; var doesntMatch = "Bye"; StringMatching.Matches(input, doesntMatch).Should().BeFalse(); }
public void Non_matching_text_with_no_special_characters_should_return_false() { var input = "Hello"; var pattern = "Goodbye"; StringMatching.MatchesPattern(input, pattern).Should().BeFalse(); }
public IMessageAssertions SummaryIs(string shouldMatch) { if (!StringMatching.Matches(_message.Summary, shouldMatch)) { ThrowMatchException(nameof(_message.Summary), shouldMatch, _message.Summary); } return(this); }
public IMessageAssertions TextIs(string shouldMatch) { if (!StringMatching.Matches(_message.Text, shouldMatch)) { ThrowMatchException(nameof(_message.Text), shouldMatch, _message.Text); } return(this); }
public void Pattern_matching_is_case_insensitive() { var input = "HELLO"; var pattern = "[a-z]*"; var result = StringMatching.MatchesPatternWithGroups(input, pattern); result.doesMatch.Should().BeTrue(); }
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(); }
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(); }
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(); }
public IMessageAssertions TextLike(string pattern) { if (!StringMatching.MatchesPattern(_message.Text, pattern)) { ThrowPatternException(nameof(_message.Text), pattern, _message.Text); } return(this); }
public IActivityAssertions TypeLike(string activityTypePattern) { if (!StringMatching.MatchesPattern(_activity.Type, activityTypePattern)) { ThrowPatternException(nameof(_activity.Type), activityTypePattern, _activity.Type); } return(this); }
public IActivityAssertions TypeIs(string activityType) { if (!StringMatching.Matches(_activity.Type, activityType)) { ThrowMatchException(nameof(_activity.Type), activityType, _activity.Type); } return(this); }
public IMessageAssertions SummaryLike(string pattern) { if (!StringMatching.MatchesPattern(_message.Summary, pattern)) { ThrowPatternException(nameof(_message.Summary), pattern, _message.Summary); } return(this); }
public IActivityAssertions IdIs(string id) { if (!StringMatching.Matches(_activity.Id, id)) { ThrowMatchException(nameof(_activity.Id), id, _activity.Id); } return(this); }
public IActivityAssertions IdLike(string idPattern) { if (!StringMatching.MatchesPattern(_activity.Id, idPattern)) { ThrowPatternException(nameof(_activity.Id), idPattern, _activity.Id); } return(this); }
public IActivityAssertions ChannelIdIs(string channelId) { if (!StringMatching.Matches(_activity.ChannelId, channelId)) { ThrowMatchException(nameof(_activity.ChannelId), channelId, _activity.ChannelId); } return(this); }
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); }
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(); }
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"); }
/// <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); }
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; }
/// <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()); }
/// <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);
public static int EditDistance(this string from, string to) => StringMatching.EditDistance(from, to);