diff --git a/FuzzySharp/Extractor/ResultExtractor.cs b/FuzzySharp/Extractor/ResultExtractor.cs index 66b7168..8abe608 100644 --- a/FuzzySharp/Extractor/ResultExtractor.cs +++ b/FuzzySharp/Extractor/ResultExtractor.cs @@ -8,13 +8,12 @@ namespace FuzzySharp.Extractor { public static class ResultExtractor { - public static IEnumerable> ExtractWithoutOrder(T query, IEnumerable choices, Func processor, IRatioScorer scorer, int cutoff = 0) + public static IEnumerable> ExtractWithoutOrder(string query, IEnumerable choices, Func processor, IRatioScorer scorer, int cutoff = 0) { int index = 0; - var processedQuery = processor(query); foreach (var choice in choices) { - int score = scorer.Score(processedQuery, processor(choice)); + int score = scorer.Score(query, processor(choice)); if (score >= cutoff) { yield return new ExtractedResult(choice, score, index); @@ -23,17 +22,37 @@ public static IEnumerable> ExtractWithoutOrder(T query, IE } } + + public static IEnumerable> ExtractWithoutOrder(T query, IEnumerable choices, Func processor, IRatioScorer scorer, int cutoff = 0) + { + return ExtractWithoutOrder(processor(query), choices, processor, scorer, cutoff); + } + public static ExtractedResult ExtractOne(T query, IEnumerable choices, Func processor, IRatioScorer calculator, int cutoff = 0) { return ExtractWithoutOrder(query, choices, processor, calculator, cutoff).Max(); } + public static ExtractedResult ExtractOne(string query, IEnumerable choices, Func processor, IRatioScorer calculator, int cutoff = 0) + { + return ExtractWithoutOrder(query, choices, processor, calculator, cutoff).Max(); + } public static IEnumerable> ExtractSorted(T query, IEnumerable choices, Func processor, IRatioScorer calculator, int cutoff = 0) { return ExtractWithoutOrder(query, choices, processor, calculator, cutoff).OrderByDescending(r => r.Score); } + + public static IEnumerable> ExtractSorted(string query, IEnumerable choices, Func processor, IRatioScorer calculator, int cutoff = 0) + { + return ExtractWithoutOrder(query, choices, processor, calculator, cutoff).OrderByDescending(r => r.Score); + } public static IEnumerable> ExtractTop(T query, IEnumerable choices, Func processor, IRatioScorer calculator, int limit, int cutoff = 0) + { + return ExtractWithoutOrder(query, choices, processor, calculator, cutoff).MaxN(limit).Reverse(); + } + + public static IEnumerable> ExtractTop(string query, IEnumerable choices, Func processor, IRatioScorer calculator, int limit, int cutoff = 0) { return ExtractWithoutOrder(query, choices, processor, calculator, cutoff).MaxN(limit).Reverse(); } diff --git a/FuzzySharp/Process.cs b/FuzzySharp/Process.cs index dbc5caf..e8b749b 100644 --- a/FuzzySharp/Process.cs +++ b/FuzzySharp/Process.cs @@ -36,6 +36,27 @@ public static IEnumerable> ExtractAll( return ResultExtractor.ExtractWithoutOrder(query, choices, processor, scorer, cutoff); } + /// + /// Creates a list of ExtractedResult which contain all the choices with + /// their corresponding score where higher is more similar + /// + /// + /// + /// + /// + /// + /// + public static IEnumerable> ExtractAll( + string query, + IEnumerable choices, + Func processor, + IRatioScorer scorer = null, + int cutoff = 0) + { + if (scorer == null) scorer = s_defaultScorer; + return ResultExtractor.ExtractWithoutOrder(query, choices, processor, scorer, cutoff); + } + /// /// Creates a list of ExtractedResult which contain all the choices with /// their corresponding score where higher is more similar @@ -84,6 +105,30 @@ public static IEnumerable> ExtractTop( } + /// + /// Creates a sorted list of ExtractedResult which contain the + /// top limit most similar choices + /// + /// + /// + /// + /// + /// + /// + /// + public static IEnumerable> ExtractTop( + string query, + IEnumerable choices, + Func processor, + IRatioScorer scorer = null, + int limit = 5, + int cutoff = 0) + { + if (scorer == null) scorer = s_defaultScorer; + return ResultExtractor.ExtractTop(query, choices, processor, scorer, limit, cutoff); + } + + /// /// Creates a sorted list of ExtractedResult which contain the /// top limit most similar choices @@ -130,6 +175,26 @@ public static IEnumerable> ExtractSorted( return ResultExtractor.ExtractSorted(query, choices, processor, scorer, cutoff); } + /// + /// Creates a sorted list of ExtractedResult with the closest matches first + /// + /// + /// + /// + /// + /// + /// + public static IEnumerable> ExtractSorted( + string query, + IEnumerable choices, + Func processor, + IRatioScorer scorer = null, + int cutoff = 0) + { + if (scorer == null) scorer = s_defaultScorer; + return ResultExtractor.ExtractSorted(query, choices, processor, scorer, cutoff); + } + /// /// Creates a sorted list of ExtractedResult with the closest matches first /// @@ -173,6 +238,26 @@ public static ExtractedResult ExtractOne( return ResultExtractor.ExtractOne(query, choices, processor, scorer, cutoff); } + /// + /// Find the single best match above a score in a list of choices. + /// + /// + /// + /// + /// + /// + /// + public static ExtractedResult ExtractOne( + string query, + IEnumerable choices, + Func processor, + IRatioScorer scorer = null, + int cutoff = 0) + { + if (scorer == null) scorer = s_defaultScorer; + return ResultExtractor.ExtractOne(query, choices, processor, scorer, cutoff); + } + /// /// Find the single best match above a score in a list of choices. ///