Summary

Class:WireMock.Matchers.SimMetricsMatcher
Assembly:WireMock.Net
File(s):C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Matchers\SimMetricsMatcher.cs
Covered lines:23
Uncovered lines:17
Coverable lines:40
Total lines:104
Line coverage:57.5%
Branch coverage:5.2%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
.ctor(...)10100100
IsMatch(...)10100100
GetStringMetricType()191919.0510
GetPatterns()10100100
GetName()10100100

File(s)

C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Matchers\SimMetricsMatcher.cs

#LineLine coverage
 1using System.Linq;
 2using JetBrains.Annotations;
 3using SimMetrics.Net;
 4using SimMetrics.Net.API;
 5using SimMetrics.Net.Metric;
 6using WireMock.Validation;
 7
 8namespace WireMock.Matchers
 9{
 10    /// <summary>
 11    /// SimMetricsMatcher
 12    /// </summary>
 13    /// <seealso cref="IStringMatcher" />
 14    public class SimMetricsMatcher : IStringMatcher
 15    {
 16        private readonly string[] _patterns;
 17        private readonly SimMetricType _simMetricType;
 18
 19        /// <summary>
 20        /// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
 21        /// </summary>
 22        /// <param name="pattern">The pattern.</param>
 23        /// <param name="simMetricType">The SimMetric Type</param>
 824        public SimMetricsMatcher([NotNull] string pattern, SimMetricType simMetricType = SimMetricType.Levenstein) : thi
 825        {
 826        }
 27
 28        /// <summary>
 29        /// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
 30        /// </summary>
 31        /// <param name="patterns">The patterns.</param>
 32        /// <param name="simMetricType">The SimMetric Type</param>
 833        public SimMetricsMatcher([NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein)
 834        {
 835            Check.NotNullOrEmpty(patterns, nameof(patterns));
 36
 837            _patterns = patterns;
 838            _simMetricType = simMetricType;
 839        }
 40
 41        /// <inheritdoc cref="IStringMatcher.IsMatch"/>
 42        public double IsMatch(string input)
 443        {
 444            IStringMetric m = GetStringMetricType();
 45
 1246            return MatchScores.ToScore(_patterns.Select(p => m.GetSimilarity(p, input)));
 447        }
 48
 49        private IStringMetric GetStringMetricType()
 450        {
 451             switch (_simMetricType)
 52            {
 53                case SimMetricType.BlockDistance:
 054                    return new BlockDistance();
 55                case SimMetricType.ChapmanLengthDeviation:
 056                    return new ChapmanLengthDeviation();
 57                case SimMetricType.CosineSimilarity:
 058                    return new CosineSimilarity();
 59                case SimMetricType.DiceSimilarity:
 060                    return new DiceSimilarity();
 61                case SimMetricType.EuclideanDistance:
 062                    return new EuclideanDistance();
 63                case SimMetricType.JaccardSimilarity:
 064                    return new JaccardSimilarity();
 65                case SimMetricType.Jaro:
 066                    return new Jaro();
 67                case SimMetricType.JaroWinkler:
 068                    return new JaroWinkler();
 69                case SimMetricType.MatchingCoefficient:
 070                    return new MatchingCoefficient();
 71                case SimMetricType.MongeElkan:
 072                    return new MongeElkan();
 73                case SimMetricType.NeedlemanWunch:
 074                    return new NeedlemanWunch();
 75                case SimMetricType.OverlapCoefficient:
 076                    return new OverlapCoefficient();
 77                case SimMetricType.QGramsDistance:
 078                    return new QGramsDistance();
 79                case SimMetricType.SmithWaterman:
 080                    return new SmithWaterman();
 81                case SimMetricType.SmithWatermanGotoh:
 082                    return new SmithWatermanGotoh();
 83                case SimMetricType.SmithWatermanGotohWindowedAffine:
 084                    return new SmithWatermanGotohWindowedAffine();
 85                case SimMetricType.ChapmanMeanLength:
 086                    return new ChapmanMeanLength();
 87                default:
 488                    return new Levenstein();
 89            }
 490        }
 91
 92        /// <inheritdoc cref="IStringMatcher.GetPatterns"/>
 93        public string[] GetPatterns()
 394        {
 395            return _patterns;
 396        }
 97
 98        /// <inheritdoc cref="IMatcher.GetName"/>
 99        public string GetName()
 1100        {
 1101            return $"SimMetricsMatcher.{_simMetricType}";
 1102        }
 103    }
 104}