Last active
August 28, 2020 16:48
-
-
Save godelfin/595f88aac30645fe30acc6ee29a27b10 to your computer and use it in GitHub Desktop.
WDW Dining Item Matching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def filter_items(match_a: MenuItem, match_b: MenuItem) -> bool: | |
| """ | |
| Filter items which are possible matches using three scoring methods. | |
| :param match_a: | |
| :param match_b: | |
| :return: | |
| """ | |
| ratio_score, partial_score, token_set_score = score_items(match_a, match_b) | |
| if ratio_score > 90: | |
| return True | |
| elif token_set_score > 85 and (ratio_score + partial_score > 120): | |
| return True | |
| elif ratio_score > 85 and partial_score > 85: | |
| return True | |
| elif ratio_score > 77 and partial_score > 77 and token_set_score > 80: | |
| return True | |
| else: | |
| return False | |
| def item_price_name(item: MenuItem) -> str: | |
| prices = ' '.join(['{} ({})'.format(i.value, i.type) if i.type else i.value for i in item.prices]) | |
| return item.name + ' ' + prices if prices else item.name | |
| def _ratio(item_a: MenuItem, item_b: MenuItem) -> int: | |
| return fuzz.ratio(item_price_name(item_a), item_price_name(item_b)) | |
| def _partial_ratio(item_a: MenuItem, item_b: MenuItem) -> int: | |
| return fuzz.partial_ratio(item_price_name(item_a), item_price_name(item_b)) | |
| def _token_set_ratio(item_a: MenuItem, item_b: MenuItem) -> int: | |
| return fuzz.token_set_ratio(item_price_name(item_a), item_price_name(item_b)) | |
| def score_items(item_a: MenuItem, item_b: MenuItem) -> ItemScore: | |
| return ItemScore((_ratio(item_a, item_b), _partial_ratio(item_a, item_b), _token_set_ratio(item_a, item_b))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment