예제 #1
0
        public double Score(string input1, string input2, PreprocessMode preprocessMode)
        {
            var preprocessor = StringPreprocessorFactory.GetPreprocessor(preprocessMode);

            input1 = preprocessor(input1);
            input2 = preprocessor(input2);
            return(Score(input1, input2));
        }
예제 #2
0
        public static Func <string, string> GetPreprocessor(PreprocessMode mode)
        {
            switch (mode)
            {
            case PreprocessMode.Full:
                return(Default);

            case PreprocessMode.None:
                return(s => s);

            default:
                throw new InvalidOperationException($"Invalid string preprocessor mode: {mode}");
            }
        }
예제 #3
0
 /// <summary>
 /// Inconsistent substrings lead to problems in matching. This ratio
 /// uses a heuristic called "best partial" for when two strings
 /// are of noticeably different lengths.
 /// </summary>
 /// <param name="input1"></param>
 /// <param name="input2"></param>
 /// <param name="preprocessMode"></param>
 /// <returns></returns>
 public static int PartialRatio(string input1, string input2, PreprocessMode preprocessMode)
 {
     return(ScorerCache.Get <PartialRatioScorer>().Score(input1, input2, preprocessMode));
 }
예제 #4
0
 /// <summary>
 /// Find all alphanumeric tokens in the string and sort
 /// those tokens and then take ratio of resulting
 /// joined strings.
 /// </summary>
 /// <param name="input1"></param>
 /// <param name="input2"></param>
 /// <param name="preprocessMode"></param>
 /// <returns></returns>
 public static int TokenSortRatio(string input1, string input2, PreprocessMode preprocessMode)
 {
     return(ScorerCache.Get <TokenSortScorer>().Score(input1, input2, preprocessMode));
 }
예제 #5
0
 /// <summary>
 /// Splits longer string into tokens and takes the initialism and compares it to the shorter
 /// </summary>
 /// <param name="input1"></param>
 /// <param name="input2"></param>
 /// <param name="preprocessMode"></param>
 /// <returns></returns>
 public static int PartialTokenInitialismRatio(string input1, string input2, PreprocessMode preprocessMode)
 {
     return(ScorerCache.Get <PartialTokenInitialismScorer>().Score(input1, input2));
 }
예제 #6
0
 /// <summary>
 /// Calculates a weighted ratio between the different algorithms for best results
 /// </summary>
 /// <param name="input1"></param>
 /// <param name="input2"></param>
 /// <param name="preprocessMode"></param>
 /// <returns></returns>
 public static double WeightedRatio(string input1, string input2, PreprocessMode preprocessMode)
 {
     return(ScorerCache.Get <WeightedRatioScorer>().Score(input1, input2, preprocessMode));
 }
예제 #7
0
 /// <summary>
 /// Similarity ratio that attempts to determine whether one strings tokens are an abbreviation
 /// of the other strings tokens. One string must have all its characters in order in the other string
 /// to even be considered.
 /// </summary>
 /// <param name="input1"></param>
 /// <param name="input2"></param>
 /// <param name="preprocessMode"></param>
 /// <returns></returns>
 public static double PartialTokenAbbreviationRatio(string input1, string input2, PreprocessMode preprocessMode)
 {
     return(ScorerCache.Get <PartialTokenAbbreviationScorer>().Score(input1, input2, preprocessMode));
 }
예제 #8
0
 /// <summary>
 /// Splits longer string into tokens and takes the initialism and compares it to the shorter
 /// </summary>
 /// <param name="input1"></param>
 /// <param name="input2"></param>
 /// <param name="preprocessMode"></param>
 /// <returns></returns>
 public static double TokenInitialismRatio(string input1, string input2, PreprocessMode preprocessMode)
 {
     return(ScorerCache.Get <TokenInitialismScorer>().Score(input1, input2, preprocessMode));
 }
예제 #9
0
 /// <summary>
 /// Splits the strings into tokens and computes the ratio on those tokens (not the individual chars,
 /// but the strings themselves)
 /// </summary>
 /// <param name="input1"></param>
 /// <param name="input2"></param>
 /// <param name="preprocessMode"></param>
 /// <returns></returns>
 public static double PartialTokenDifferenceRatio(string input1, string input2, PreprocessMode preprocessMode)
 {
     return(ScorerCache.Get <PartialTokenDifferenceScorer>().Score(input1, input2, preprocessMode));
 }