How to use the rapidfuzz.fuzz.partial_token_set_ratio function in RapidFuzz

To help you get started, we’ve selected a few RapidFuzz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OmegaK2 / PyPoE / PyPoE / cli / exporter / wiki / admin / unique.py View on Github external
mwtext = mwparserfromhell.parse(page.text())
        for mwtemplate in mwtext.filter_templates():
            if mwtemplate.name.strip().lower() == 'item':
                break
        else:
            raise Exception('Item template not found')

        console('Finding flavour text...')
        if not mwtemplate.has('flavour_text_id') and mwtemplate.has('flavour_text'):
            console('Missing flavour_text_id. Trying to find flavour text in FlavourText.dat')

            ftext = self.fuzzy_find_text(
                mwtemplate.get('flavour_text'),
                'FlavourText.dat',
                'Text',
                fuzzy_func=fuzz.partial_token_set_ratio
            )

            results = []
            for row in self.rr_english['FlavourText.dat']:
                ratio = fuzz.partial_token_set_ratio(row['Text'], ftext)
                if ratio > 90:
                    results.append({
                        'id': row['Id'],
                        'text': row['Text'],
                        'ratio': ratio,
                    })

            if len(results) == 0:
                console('No matching flavour text found.')
                text = input('Enter translated flavour text. Type None to skip item entirely.\n')
                if text == 'None':
github OmegaK2 / PyPoE / PyPoE / cli / exporter / wiki / admin / unique.py View on Github external
raise Exception('Item template not found')

        console('Finding flavour text...')
        if not mwtemplate.has('flavour_text_id') and mwtemplate.has('flavour_text'):
            console('Missing flavour_text_id. Trying to find flavour text in FlavourText.dat')

            ftext = self.fuzzy_find_text(
                mwtemplate.get('flavour_text'),
                'FlavourText.dat',
                'Text',
                fuzzy_func=fuzz.partial_token_set_ratio
            )

            results = []
            for row in self.rr_english['FlavourText.dat']:
                ratio = fuzz.partial_token_set_ratio(row['Text'], ftext)
                if ratio > 90:
                    results.append({
                        'id': row['Id'],
                        'text': row['Text'],
                        'ratio': ratio,
                    })

            if len(results) == 0:
                console('No matching flavour text found.')
                text = input('Enter translated flavour text. Type None to skip item entirely.\n')
                if text == 'None':
                    console('Skipping item %s.' % pn)
                    return
                mwtemplate.get('flavour_text').value = text
            elif len(results) >= 2:
                console('Multiple matching flavour text entries found.\n')