### Customizing Scorer and Preprocessor - C# Source: https://github.com/jakebayer/fuzzysharp/blob/master/README.md Demonstrates overriding the default scoring and preprocessing functions. The example shows how to use a specific scorer like `DefaultRatioScorer` and bypass string manipulation by passing `s => s` as the preprocessor. This allows for fine-grained control over matching logic. ```csharp Process.ExtractOne("cowboys", new[] { "Atlanta Falcons", "New York Jets", "New York Giants", "Dallas Cowboys" }, s => s, ScorerCache.Get()); (string: Dallas Cowboys, score: 57, index: 3) ``` -------------------------------- ### Process.ExtractTop - Get Top N String Matches Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Retrieves the top N most similar matches from a given collection, sorted by their similarity scores in descending order. This FuzzySharp function takes a limit parameter to specify the number of results, defaulting to 5 if not provided. ```csharp using FuzzySharp; // Get top 3 matches var results = Process.ExtractTop("goolge", new[] { "google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }, limit: 3); // Returns: [(string: google, score: 83, index: 0), (string: googleplus, score: 75, index: 5), (string: plexoogl, score: 43, index: 7)] // Default limit is 5 if not specified var results2 = Process.ExtractTop("test query", new[] { "item1", "item2", "item3", "item4", "item5", "item6" }); // Returns top 5 matches ``` -------------------------------- ### FuzzySharp Process with Custom Extraction Logic Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Demonstrates how to use the Process class with custom logic for extracting string representations from complex objects. This allows matching based on specific properties or elements within objects, such as matching based on the first element of a string array representing an event. ```csharp var events = new[] { new[] { "chicago cubs vs new york mets", "CitiField", "2011-05-11", "8pm" }, new[] { "new york yankees vs boston red sox", "Fenway Park", "2011-05-11", "8pm" }, new[] { "atlanta braves vs pittsburgh pirates", "PNC Park", "2011-05-11", "8pm" }, }; var query = new[] { "new york mets vs chicago cubs", "CitiField", "2017-03-19", "8pm" }; var best = Process.ExtractOne(query, events, strings => strings[0]); best: (value: { "chicago cubs vs new york mets", "CitiField", "2011-05-11", "8pm" }, score: 95, index: 0) ``` -------------------------------- ### Fuzz.TokenInitialismRatio: Acronym and Initialism Matching (C#) Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Compares a potential acronym or initialism against a longer phrase by extracting the first letters of each word. It provides scores from 0 to 100 and includes a partial version for better matching in longer texts. ```csharp using FuzzySharp; // Perfect initialism match int score1 = Fuzz.TokenInitialismRatio("NASA", "National Aeronautics Space Administration"); // Returns: 100 // Close initialism match (missing 'and') int score2 = Fuzz.TokenInitialismRatio("NASA", "National Aeronautics and Space Administration"); // Returns: 89 // Partial match in longer context int score3 = Fuzz.TokenInitialismRatio("NASA", "National Aeronautics Space Administration, Kennedy Space Center, Cape Canaveral, Florida 32899"); // Returns: 53 // Use partial version for better results in long text int score4 = Fuzz.PartialTokenInitialismRatio("NASA", "National Aeronautics Space Administration, Kennedy Space Center, Cape Canaveral, Florida 32899"); // Returns: 100 ``` -------------------------------- ### Retrieve Scorers Using ScorerCache Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Demonstrates how to efficiently retrieve instances of different scorers (e.g., DefaultRatioScorer, PartialRatioScorer, TokenSetScorer) using the ScorerCache. This approach ensures that only one instance of each scorer is created and reused, optimizing performance by avoiding repeated instantiation. ```csharp var ratio = ScorerCache.Get(); var partialRatio = ScorerCache.Get(); var tokenSet = ScorerCache.Get(); var partialTokenSet = ScorerCache.Get(); var tokenSort = ScorerCache.Get(); var partialTokenSort = ScorerCache.Get(); var tokenAbbreviation = ScorerCache.Get(); var partialTokenAbbreviation = ScorerCache.Get(); var weighted = ScorerCache.Get(); ``` -------------------------------- ### Efficient Scorer Instance Management with ScorerCache (C#) Source: https://context7.com/jakebayer/fuzzysharp/llms.txt This C# code demonstrates the use of `ScorerCache` in FuzzySharp for efficient management of scoring algorithm instances. It shows how to retrieve cached singleton instances of various scorers, avoiding repeated instantiation overhead, and then use these cached scorers with `Process` methods for performance-critical applications. ```csharp using FuzzySharp.SimilarityRatio; using FuzzySharp.SimilarityRatio.Scorer.StrategySensitive; using FuzzySharp.SimilarityRatio.Scorer.Composite; // Get cached scorer instances var ratio = ScorerCache.Get(); var partialRatio = ScorerCache.Get(); var tokenSet = ScorerCache.Get(); var partialTokenSet = ScorerCache.Get(); var tokenSort = ScorerCache.Get(); var partialTokenSort = ScorerCache.Get(); var tokenAbbreviation = ScorerCache.Get(); var partialTokenAbbreviation = ScorerCache.Get(); var weighted = ScorerCache.Get(); // Use cached scorer with Process methods var customResult = Process.ExtractOne("test", new[] { "test1", "test2", "test3" }, s => s, ratio); // Avoids creating new scorer instances ``` -------------------------------- ### Custom String Preprocessing - C# Source: https://github.com/jakebayer/fuzzysharp/blob/master/README.md Shows how to customize the string preprocessing step to handle different character sets or avoid string alterations. By passing a lambda function like `(s) => s`, the original strings are used directly in the similarity algorithm, preserving characters like accents. ```csharp var query = "strng"; var choices = new [] { "stríng", "stráng", "stréng" }; var results = Process.ExtractAll(query, choices, (s) => s); // The results will include matches with accented characters because the default preprocessor is bypassed. ``` -------------------------------- ### FuzzySharp Process.ExtractTop Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Retrieves the top N best matching strings from a list of choices for a given query string. It allows specifying a limit for the number of results. This is useful when you need a few of the closest matches, not just the single best one. ```csharp Process.ExtractTop("goolge", new[] { "google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }, limit: 3); [(string: google, score: 83, index: 0), (string: googleplus, score: 75, index: 5), (string: plexoogl, score: 43, index: 7)] ``` -------------------------------- ### FuzzySharp Token Initialism Ratio Calculation Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Calculates the token initialism ratio similarity between two strings. This method compares the initial letters of words in the strings. It's particularly useful for matching acronyms against their full names. ```csharp Fuzz.TokenInitialismRatio("NASA", "National Aeronautics and Space Administration"); 89 Fuzz.TokenInitialismRatio("NASA", "National Aeronautics Space Administration"); 100 Fuzz.TokenInitialismRatio("NASA", "National Aeronautics Space Administration, Kennedy Space Center, Cape Canaveral, Florida 32899"); 53 Fuzz.PartialTokenInitialismRatio("NASA", "National Aeronautics Space Administration, Kennedy Space Center, Cape Canaveral, Florida 32899"); 100 ``` -------------------------------- ### FuzzySharp Process.ExtractAll Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Extracts all matching strings from a list of choices for a given query string, optionally applying a score cutoff. This method returns all potential matches that meet a minimum similarity threshold, providing a comprehensive set of results. ```csharp Process.ExtractAll("goolge", new [] {"google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }) [(string: google, score: 83, index: 0), (string: bing, score: 22, index: 1), (string: facebook, score: 29, index: 2), (string: linkedin, score: 29, index: 3), (string: twitter, score: 15, index: 4), (string: googleplus, score: 75, index: 5), (string: bingnews, score: 29, index: 6), (string: plexoogl, score: 43, index: 7)] // score cutoff Process.ExtractAll("goolge", new[] { "google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }, cutoff: 40) [(string: google, score: 83, index: 0), (string: googleplus, score: 75, index: 5), (string: plexoogl, score: 43, index: 7)] ``` -------------------------------- ### Fuzz.TokenSetRatio: Duplicate-Tolerant Word Matching (C#) Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Compares strings based on the intersection and remainder of their token sets, making it robust against repeated words. It also offers a partial version for substring matching scenarios. Scores range from 0 to 100. ```csharp using FuzzySharp; // Handles redundant words int score1 = Fuzz.TokenSetRatio("fuzzy was a bear", "fuzzy fuzzy fuzzy bear"); // Returns: 100 // Also available as partial version int score2 = Fuzz.PartialTokenSetRatio("fuzzy was a bear", "fuzzy fuzzy fuzzy bear"); // Returns: 100 // Works with different word orders and duplicates int score3 = Fuzz.TokenSetRatio("new york mets vs atlanta braves", "atlanta braves vs new york mets", PreprocessMode.Full); // Returns: 100 ``` -------------------------------- ### Process.ExtractAll Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Returns all choices with their similarity scores, optionally filtered by a minimum score threshold. This provides a comprehensive view of all potential matches. ```APIDOC ## Process.ExtractAll ### Description Returns all choices with their similarity scores, optionally filtered by a minimum score threshold. ### Method `Process.ExtractAll(string query, IEnumerable choices, int cutoff = 0, Func preprocessor = null)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp using FuzzySharp; // Get all results var results1 = Process.ExtractAll("goolge", new[] { "google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }); // Returns: [(string: google, score: 83, index: 0), (string: bing, score: 22, index: 1), (string: facebook, score: 29, index: 2), (string: linkedin, score: 29, index: 3), (string: twitter, score: 15, index: 4), (string: googleplus, score: 75, index: 5), (string: bingnews, score: 29, index: 6), (string: plexoogl, score: 43, index: 7)] // Filter with score cutoff var results2 = Process.ExtractAll("goolge", new[] { "google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }, cutoff: 40); // Returns: [(string: google, score: 83, index: 0), (string: googleplus, score: 75, index: 5), (string: plexoogl, score: 43, index: 7)] ``` ### Response #### Success Response (200) A list of objects, each containing a matching string, its score, and its index. #### Response Example ```json [ { "value": "google", "score": 83, "index": 0 }, { "value": "bing", "score": 22, "index": 1 }, { "value": "facebook", "score": 29, "index": 2 } ] ``` ``` -------------------------------- ### Fuzz.PartialRatio: Substring Matching (C#) Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Compares strings using a 'best partial' heuristic, suitable for finding matches when one string is a substring of another. It returns an integer score from 0 to 100, indicating the similarity of the best matching substring. ```csharp using FuzzySharp; // Find substring match int score1 = Fuzz.PartialRatio("similar", "somewhresimlrbetweenthisstring"); // Returns: 71 // Perfect partial match int score2 = Fuzz.PartialRatio("new york mets", "the wonderful new york mets"); // Returns: 100 // Handles complex substrings int score3 = Fuzz.PartialRatio("kaution", "kdeffxxxiban:de1110010060046666666datum:16.11.17zeit:01:12uft0000899999tan076601testd.-20-maisonette-z4-jobas-hagkautionauszug"); // Returns: 100 ``` -------------------------------- ### FuzzySharp Process.ExtractOne Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Finds the single best matching string from a list of choices for a given query string. It uses a default scoring and processing method but can be customized. This is ideal for finding the most likely match in a small set of options. ```csharp Process.ExtractOne("cowboys", new[] { "Atlanta Falcons", "New York Jets", "New York Giants", "Dallas Cowboys" }) (string: Dallas Cowboys, score: 90, index: 3) ``` ```csharp Process.ExtractOne("cowboys", new[] { "Atlanta Falcons", "New York Jets", "New York Giants", "Dallas Cowboys" }, s => s, ScorerCache.Get()); (string: Dallas Cowboys, score: 57, index: 3) ``` -------------------------------- ### Fuzz.TokenSortRatio: Order-Independent Word Matching (C#) Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Compares strings by tokenizing them into words, sorting the words alphabetically, and then calculating the similarity. This method is insensitive to word order differences. It also has a partial version available. Scores range from 0 to 100. ```csharp using FuzzySharp; // Ignores word order int score1 = Fuzz.TokenSortRatio("order words out of", " words out of order"); // Returns: 100 // Also available as partial version int score2 = Fuzz.PartialTokenSortRatio("order words out of", " words out of order"); // Returns: 100 // Works with case-insensitive mode int score3 = Fuzz.TokenSortRatio("New York Mets", "mets york new", PreprocessMode.Full); // Returns: 100 ``` -------------------------------- ### Process.ExtractTop Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Returns the top N most similar matches from a collection, sorted by similarity score in descending order. This is useful when you need a ranked list of potential matches. ```APIDOC ## Process.ExtractTop ### Description Returns the top N most similar matches from a collection, sorted by similarity score in descending order. ### Method `Process.ExtractTop(string query, IEnumerable choices, int limit = 5, Func preprocessor = null)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp using FuzzySharp; // Get top 3 matches var results = Process.ExtractTop("goolge", new[] { "google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }, limit: 3); // Returns: [(string: google, score: 83, index: 0), (string: googleplus, score: 75, index: 5), (string: plexoogl, score: 43, index: 7)] // Default limit is 5 if not specified var results2 = Process.ExtractTop("test query", new[] { "item1", "item2", "item3", "item4", "item5", "item6" }); // Returns top 5 matches ``` ### Response #### Success Response (200) A list of objects, each containing a matching string, its score, and its index, sorted by score. #### Response Example ```json [ { "value": "google", "score": 83, "index": 0 }, { "value": "googleplus", "score": 75, "index": 5 }, { "value": "plexoogl", "score": 43, "index": 7 } ] ``` ``` -------------------------------- ### Process.ExtractOne Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Searches through a collection of choices and returns the single best matching item with its similarity score and index. Useful for finding the most relevant item in a list. ```APIDOC ## Process.ExtractOne ### Description Searches through a collection of choices and returns the single best matching item with its similarity score and index. ### Method `Process.ExtractOne(string query, IEnumerable choices, Func preprocessor = null, IScorer scorer = null)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp using FuzzySharp; // Find best match in array var result1 = Process.ExtractOne("cowboys", new[] { "Atlanta Falcons", "New York Jets", "New York Giants", "Dallas Cowboys" }); // Returns: (string: Dallas Cowboys, score: 90, index: 3) // Custom scoring with specific scorer var result2 = Process.ExtractOne("cowboys", new[] { "Atlanta Falcons", "New York Jets", "New York Giants", "Dallas Cowboys" }, s => s, ScorerCache.Get()); // Returns: (string: Dallas Cowboys, score: 57, index: 3) // Works with typos var result3 = Process.ExtractOne("goolge", new[] { "google", "bing", "facebook", "linkedin" }); // Returns: (string: google, score: 83, index: 0) ``` ### Response #### Success Response (200) An object containing the best matching string, its score, and its index. #### Response Example ```json { "value": "Dallas Cowboys", "score": 90, "index": 3 } ``` ``` -------------------------------- ### Fuzz.WeightedRatio Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Automatically combines multiple algorithms using weighted ratios to produce the best overall similarity score for any input pair. It's suitable for general-purpose string comparison. ```APIDOC ## Fuzz.WeightedRatio ### Description Automatically combines multiple algorithms using weighted ratios to produce the best overall similarity score for any input pair. ### Method `Fuzz.WeightedRatio(string str1, string str2, PreprocessMode mode = PreprocessMode.Fast)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp using FuzzySharp; using FuzzySharp.PreProcess; // Intelligent scoring for general use int score1 = Fuzz.WeightedRatio("The quick brown fox jimps ofver the small lazy dog", "the quick brown fox jumps over the small lazy dog"); // Returns: 95 // Handles identical strings int score2 = Fuzz.WeightedRatio("new york mets", "new york mets"); // Returns: 100 // Works with case-insensitive mode int score3 = Fuzz.WeightedRatio("NEW YORK METS", "new york mets", PreprocessMode.Full); // Returns: 100 // Partial matches int score4 = Fuzz.WeightedRatio("new york mets", "the wonderful new york mets"); // Returns: 90 ``` ### Response #### Success Response (200) An integer representing the similarity score. #### Response Example ```json { "score": 95 } ``` ``` -------------------------------- ### FuzzySharp Process.ExtractSorted Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Extracts all matching strings from a list of choices for a given query string and sorts them by score in descending order. This method is useful when you need all possible matches, ordered from best to worst. ```csharp Process.ExtractSorted("goolge", new [] {"google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }) [(string: google, score: 83, index: 0), (string: googleplus, score: 75, index: 5), (string: plexoogl, score: 43, index: 7), (string: facebook, score: 29, index: 2), (string: linkedin, score: 29, index: 3), (string: bingnews, score: 29, index: 6), (string: bing, score: 22, index: 1), (string: twitter, score: 15, index: 4)] ``` -------------------------------- ### Process.ExtractSorted Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Returns all matching choices sorted from highest to lowest similarity score, with an optional score cutoff. This is useful for displaying a ranked list of all possible matches above a certain quality threshold. ```APIDOC ## Process.ExtractSorted ### Description Returns all matching choices sorted from highest to lowest similarity score, with optional score cutoff. ### Method `Process.ExtractSorted(string query, IEnumerable choices, int cutoff = 0, Func preprocessor = null)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp using FuzzySharp; // Get all results sorted by score var results = Process.ExtractSorted("goolge", new[] { "google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }); // Returns: [(string: google, score: 83, index: 0), (string: googleplus, score: 75, index: 5), (string: plexoogl, score: 43, index: 7), (string: facebook, score: 29, index: 2), (string: linkedin, score: 29, index: 3), (string: bingnews, score: 29, index: 6), (string: bing, score: 22, index: 1), (string: twitter, score: 15, index: 4)] ``` ### Response #### Success Response (200) A list of objects, each containing a matching string, its score, and its index, sorted by score in descending order. #### Response Example ```json [ { "value": "google", "score": 83, "index": 0 }, { "value": "googleplus", "score": 75, "index": 5 }, { "value": "plexoogl", "score": 43, "index": 7 } ] ``` ``` -------------------------------- ### Fuzz.WeightedRatio - Smart Combined Scoring for String Similarity Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Automatically combines multiple string similarity algorithms using weighted ratios to provide an optimal overall score for any input pair. It relies on the FuzzySharp library and optionally accepts a PreprocessMode. Returns an integer similarity score. ```csharp using FuzzySharp; using FuzzySharp.PreProcess; // Intelligent scoring for general use int score1 = Fuzz.WeightedRatio("The quick brown fox jimps ofver the small lazy dog", "the quick brown fox jumps over the small lazy dog"); // Returns: 95 // Handles identical strings int score2 = Fuzz.WeightedRatio("new york mets", "new york mets"); // Returns: 100 // Works with case-insensitive mode int score3 = Fuzz.WeightedRatio("NEW YORK METS", "new york mets", PreprocessMode.Full); // Returns: 100 // Partial matches int score4 = Fuzz.WeightedRatio("new york mets", "the wonderful new york mets"); // Returns: 90 ``` -------------------------------- ### FuzzySharp Token Abbreviation Ratio Calculation Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Calculates the token abbreviation ratio similarity between two strings, optionally using full preprocessing. This method is designed to handle abbreviations and shorter forms of words effectively, comparing them against longer, more complete versions. ```csharp Fuzz.TokenAbbreviationRatio("bl 420", "Baseline section 420", PreprocessMode.Full); 40 Fuzz.PartialTokenAbbreviationRatio("bl 420", "Baseline section 420", PreprocessMode.Full); 50 ``` -------------------------------- ### FuzzySharp Token Set Ratio Calculation Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Calculates the token set ratio similarity between two strings. This method compares the intersection and difference of token sets, making it robust against duplicate words and differences in word order. It's useful for comparing phrases with varying word counts. ```csharp Fuzz.TokenSetRatio("fuzzy was a bear", "fuzzy fuzzy fuzzy bear") 100 Fuzz.PartialTokenSetRatio("fuzzy was a bear", "fuzzy fuzzy fuzzy bear") 100 ``` -------------------------------- ### FuzzySharp Partial Ratio Calculation Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Calculates the partial ratio similarity between two strings. This method is useful when one string is a substring of another, finding the best matching substring. It's more forgiving than the simple ratio for partial matches. ```csharp Fuzz.PartialRatio("similar", "somewhresimlrbetweenthisstring") 71 ``` -------------------------------- ### FuzzySharp Simple Ratio Calculation Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Calculates the simple ratio similarity between two strings. This is a basic comparison that may not account for word order or partial matches effectively. It's suitable for straightforward string similarity checks. ```csharp Fuzz.Ratio("mysmilarstring","myawfullysimilarstirng") 72 Fuzz.Ratio("mysmilarstring","mysimilarstring") 97 ``` -------------------------------- ### Fuzz.Ratio: Basic Levenshtein Similarity Score (C#) Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Calculates the basic Levenshtein distance ratio between two strings. It is case-sensitive by default but can be made case-insensitive using the PreprocessMode.Full option. Returns an integer score from 0 to 100. ```csharp using FuzzySharp; // Basic similarity comparison int score1 = Fuzz.Ratio("mysmilarstring", "myawfullysimilarstirng"); // Returns: 72 int score2 = Fuzz.Ratio("mysmilarstring", "mysimilarstring"); // Returns: 97 // Case-sensitive by default int score3 = Fuzz.Ratio("Hello World", "hello world"); // Returns: 73 // Case-insensitive with preprocessing int score4 = Fuzz.Ratio("Hello World", "hello world", PreprocessMode.Full); // Returns: 100 ``` -------------------------------- ### FuzzySharp Weighted Ratio Calculation Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Calculates the weighted ratio similarity between two strings. This method combines multiple scoring strategies (like partial and token sort ratios) with weights to provide a more nuanced similarity score. It's useful for complex comparisons where different aspects of similarity are important. ```csharp Fuzz.WeightedRatio("The quick brown fox jimps ofver the small lazy dog", "the quick brown fox jumps over the small lazy dog") 95 ``` -------------------------------- ### Fuzz.TokenAbbreviationRatio - Detect String Abbreviations Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Determines if tokens in one string are abbreviations of tokens in another, ensuring order is maintained. It utilizes the FuzzySharp library and requires a PreprocessMode for customization. The function returns an integer score representing the similarity. ```csharp using FuzzySharp; using FuzzySharp.PreProcess; // Detect abbreviations int score1 = Fuzz.TokenAbbreviationRatio("bl 420", "Baseline section 420", PreprocessMode.Full); // Returns: 40 // Partial version for better matching int score2 = Fuzz.PartialTokenAbbreviationRatio("bl 420", "Baseline section 420", PreprocessMode.Full); // Returns: 50 ``` -------------------------------- ### FuzzySharp Token Sort Ratio Calculation Source: https://github.com/jakebayer/fuzzysharp/blob/master/FuzzySharp/README.md Calculates the token sort ratio similarity between two strings. This method tokenizes the strings, sorts the tokens alphabetically, and then compares them. It's effective for strings where word order differs but the words themselves are the same. ```csharp Fuzz.TokenSortRatio("order words out of"," words out of order") 100 Fuzz.PartialTokenSortRatio("order words out of"," words out of order") 100 ``` -------------------------------- ### Extract Matches from Complex Objects using Custom Property (C#) Source: https://context7.com/jakebayer/fuzzysharp/llms.txt This snippet demonstrates how to extract matches from complex objects in C# by specifying a custom property or computed string for comparison. It uses the `Process.ExtractOne` method with a lambda expression to target a specific element within the complex data structure. ```csharp using FuzzySharp; // Define complex objects var events = new[] { new[] { "chicago cubs vs new york mets", "CitiField", "2011-05-11", "8pm" }, new[] { "new york yankees vs boston red sox", "Fenway Park", "2011-05-11", "8pm" }, new[] { "atlanta braves vs pittsburgh pirates", "PNC Park", "2011-05-11", "8pm" } }; var query = new[] { "new york mets vs chicago cubs", "CitiField", "2017-03-19", "8pm" }; // Extract by comparing first element (index 0) of each array var best = Process.ExtractOne(query, events, strings => strings[0]); // Returns: (value: { "chicago cubs vs new york mets", "CitiField", "2011-05-11", "8pm" }, score: 95, index: 0) ``` -------------------------------- ### Fuzz.TokenAbbreviationRatio Source: https://context7.com/jakebayer/fuzzysharp/llms.txt Determines if one string's tokens are abbreviations of another, ensuring characters appear in order. This is useful for matching patterns where abbreviations are common. ```APIDOC ## Fuzz.TokenAbbreviationRatio ### Description Determines whether one string's tokens are abbreviations of another string's tokens, requiring characters to appear in order. ### Method `Fuzz.TokenAbbreviationRatio(string str1, string str2, PreprocessMode mode = PreprocessMode.Fast)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp using FuzzySharp; using FuzzySharp.PreProcess; // Detect abbreviations int score1 = Fuzz.TokenAbbreviationRatio("bl 420", "Baseline section 420", PreprocessMode.Full); // Returns: 40 // Partial version for better matching int score2 = Fuzz.PartialTokenAbbreviationRatio("bl 420", "Baseline section 420", PreprocessMode.Full); // Returns: 50 ``` ### Response #### Success Response (200) An integer representing the similarity score. #### Response Example ```json { "score": 40 } ``` ``` -------------------------------- ### Custom String Preprocessing for International Characters (C#) Source: https://context7.com/jakebayer/fuzzysharp/llms.txt This C# snippet illustrates how to provide custom string preprocessing for non-English languages to preserve special characters. By specifying a custom preprocessor function, you can override the default behavior of FuzzySharp, which typically removes non-alphanumeric characters and lowercases strings. ```csharp using FuzzySharp; // Preserve accented characters var query = "strng"; var choices = new[] { "stríng", "stráng", "stréng" }; // Use identity function to skip default preprocessing var results = Process.ExtractAll(query, choices, (s) => s); // Compares strings without stripping accented characters // Default preprocessing removes non-alphanumeric var resultsDefault = Process.ExtractAll(query, choices); // Uses PreprocessMode.Full which lowercases and removes special chars ``` -------------------------------- ### Extract Single Best Match - C# Source: https://github.com/jakebayer/fuzzysharp/blob/master/README.md Extracts the single best matching string from a list of choices using default scoring. Returns the best match along with its score and index. This is useful for finding the most similar string to a query. ```csharp Process.ExtractOne("cowboys", new[] { "Atlanta Falcons", "New York Jets", "New York Giants", "Dallas Cowboys"}) (string: Dallas Cowboys, score: 90, index: 3) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.