### Using the get() Method with Fuzzy Matching Source: https://context7.com/pysnippet/fuzzymap/llms.txt Demonstrates the `get()` method's behavior with FuzzyMap, including fuzzy matching and returning a default value when no match is found. ```python from fuzzymap import FuzzyMap data = FuzzyMap({ 'Barcelona FC': {'stadium': 'Camp Nou'}, 'Bayern Munich': {'stadium': 'Allianz Arena'}, }) # Fuzzy get with match result = data.get('FC Barcelona', default={'stadium': 'Unknown'}) # Returns: {'stadium': 'Camp Nou'} # Get with no match returns default result = data.get('Unknown Team', default={'stadium': 'Unknown'}) # Returns: {'stadium': 'Unknown'} # Get without default returns None result = data.get('Unknown Team') # Returns: None ``` -------------------------------- ### Initialize and Access FuzzyMap Source: https://context7.com/pysnippet/fuzzymap/llms.txt Demonstrates initializing FuzzyMap with a dictionary and accessing values using both exact and similar keys. Non-matching keys return None. ```python from fuzzymap import FuzzyMap # Initialize with a dictionary data = FuzzyMap({ 'SK Rapid Wien - First Vienna FC': {'w1': 1.97, 'x': 2.3, 'w2': 8.2}, 'Bourj FC - Nejmeh SC Beirut': {'w1': 32, 'x': 12, 'w2': 1.05}, }) # Access with exact key result = data['SK Rapid Wien - First Vienna FC'] # Returns: {'w1': 1.97, 'x': 2.3, 'w2': 8.2} # Access with similar key (fuzzy matching) result = data['Rapid Wien - First Vienna'] # Returns: {'w1': 1.97, 'x': 2.3, 'w2': 8.2} # Another fuzzy match example result = data['Al Bourj - Al Nejmeh'] # Returns: {'w1': 32, 'x': 12, 'w2': 1.05} # Non-matching key returns None result = data['Some Completely Different Key'] # Returns: None ``` -------------------------------- ### Match keys across data sources using FuzzyMap Source: https://github.com/pysnippet/fuzzymap/blob/master/README.md Demonstrates using FuzzyMap to resolve inconsistent game names between two data sources by mapping keys based on similarity. ```python from fuzzymap import FuzzyMap source_1 = { 'Rapid Wien - First Vienna': {'w1': 1.93, 'x': 2.32, 'w2': 7.44}, 'Al Bourj - Al Nejmeh': {'w1': 26, 'x': 11.5, 'w2': 1.05}, # hundreds of other games' data } source_2 = FuzzyMap({ 'Bourj FC - Nejmeh SC Beirut': {'w1': 32, 'x': 12, 'w2': 1.05}, 'SK Rapid Wien - First Vienna FC': {'w1': 1.97, 'x': 2.3, 'w2': 8.2}, # hundreds of other games' data }) for game, odds1 in source_1.items(): odds2 = source_2[game] # odds1 = {"w1": 1.93, "x": 2.32, "w2": 7.44} # odds2 = {"w1": 1.97, "x": 2.3, "w2": 8.2} handle_fork(odds1, odds2) ``` -------------------------------- ### Configure FuzzyMap Similarity Ratio Source: https://context7.com/pysnippet/fuzzymap/llms.txt Shows how to adjust the `ratio` attribute to control the minimum similarity percentage for fuzzy matches. Lower values are more lenient, higher values are stricter. ```python from fuzzymap import FuzzyMap data = FuzzyMap({ 'Manchester United FC': {'league': 'Premier League'}, 'Real Madrid CF': {'league': 'La Liga'}, }) # Default ratio (60) - strict matching result = data['Man Utd'] # Returns: None (similarity below threshold) # Lower the ratio for more lenient matching data.ratio = 30 result = data['Man Utd'] # Returns: {'league': 'Premier League'} # Increase ratio for stricter matching data.ratio = 90 result = data['Manchester United'] # Returns: None (requires higher similarity) data.ratio = 60 result = data['Manchester United'] # Returns: {'league': 'Premier League'} ``` -------------------------------- ### Fuzzy Key Setting in FuzzyMap Source: https://context7.com/pysnippet/fuzzymap/llms.txt Illustrates how FuzzyMap uses fuzzy matching when setting values, updating existing similar keys rather than creating new entries. ```python from fuzzymap import FuzzyMap data = FuzzyMap({ 'SK Rapid Wien - First Vienna FC': {'w1': 1.97, 'x': 2.3, 'w2': 8.2}, }) # Setting with a similar key updates the existing entry data['Rapid Wien - First Vienna'] = {'w1': 2.0, 'x': 2.5, 'w2': 8.0} # The original key's value is updated print(data['SK Rapid Wien - First Vienna FC']) # Returns: {'w1': 2.0, 'x': 2.5, 'w2': 8.0} # Only one key exists in the dictionary print(len(data)) # Returns: 1 ``` -------------------------------- ### Cross-Source Data Matching with FuzzyMap Source: https://context7.com/pysnippet/fuzzymap/llms.txt Illustrates a primary use case of FuzzyMap for matching data across different sources that have varying naming conventions for the same entities. ```python from fuzzymap import FuzzyMap # Data from source 1 (bookmaker A) source_1 = { 'Rapid Wien - First Vienna': {'w1': 1.93, 'x': 2.32, 'w2': 7.44}, 'Al Bourj - Al Nejmeh': {'w1': 26, 'x': 11.5, 'w2': 1.05}, } # Data from source 2 (bookmaker B) - different naming convention source_2 = FuzzyMap({ 'Bourj FC - Nejmeh SC Beirut': {'w1': 32, 'x': 12, 'w2': 1.05}, 'SK Rapid Wien - First Vienna FC': {'w1': 1.97, 'x': 2.3, 'w2': 8.2}, }) # Match games across sources for game, odds_1 in source_1.items(): odds_2 = source_2[game] if odds_2: print(f"Game: {game}") print(f" Source 1 odds: {odds_1}") print(f" Source 2 odds: {odds_2}") # Calculate potential arbitrage implied_prob = (1/odds_1['w1']) + (1/odds_2['w2']) if implied_prob < 1: print(f" Potential arbitrage opportunity!") # Output: # Game: Rapid Wien - First Vienna ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.