fuzzywuzzy.process.extractOne

Here are the examples of the python api fuzzywuzzy.process.extractOne taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

14 Examples 7

Example 1

Project: fuzzywuzzy
License: View license
Source File: test_fuzzywuzzy.py
    def testWithCutoff2(self):
        choices = [
            "new york mets vs chicago cubs",
            "chicago cubs at new york mets",
            "atlanta braves vs pittsbugh pirates",
            "new york yankees vs boston red sox"
        ]

        query = "new york mets vs chicago cubs"
        # Only find 100-score cases
        res = process.extractOne(query, choices, score_cutoff=100)
        self.assertTrue(res is not None)
        best_match, score = res
        self.assertTrue(best_match is choices[0])

Example 2

Project: fuzzywuzzy
License: View license
Source File: test_fuzzywuzzy.py
    def testWithProcessor(self):
        events = [
            ["chicago cubs vs new york mets", "CitiField", "2011-05-11", "8pm"],
            ["new york yankees vs boston red sox", "Fenway Park", "2011-05-11", "8pm"],
            ["atlanta braves vs pittsburgh pirates", "PNC Park", "2011-05-11", "8pm"],
        ]
        query = "new york mets vs chicago cubs"

        best = process.extractOne(query, events, processor=lambda event: event[0])
        self.assertEqual(best[0], events[0])

Example 3

Project: fuzzywuzzy
License: View license
Source File: test_fuzzywuzzy.py
    def testWithCutoff(self):
        choices = [
            "new york mets vs chicago cubs",
            "chicago cubs at new york mets",
            "atlanta braves vs pittsbugh pirates",
            "new york yankees vs boston red sox"
        ]

        query = "los angeles dodgers vs san francisco giants"

        # in this situation, this is an event that does not exist in the list
        # we don't want to randomly match to something, so we use a reasonable cutoff

        best = process.extractOne(query, choices, score_cutoff=50)
        self.assertTrue(best is None)

Example 4

Project: fuzzywuzzy
License: View license
Source File: test_fuzzywuzzy.py
Function: test_empty_strings
    def testEmptyStrings(self):
        choices = [
            "",
            "new york mets vs chicago cubs",
            "new york yankees vs boston red sox",
            "",
            ""
        ]

        query = "new york mets at chicago cubs"

        best = process.extractOne(query, choices)
        self.assertEqual(best[0], choices[1])

Example 5

Project: fuzzywuzzy
License: View license
Source File: test_fuzzywuzzy.py
Function: testnullstrings
    def testNullStrings(self):
        choices = [
            None,
            "new york mets vs chicago cubs",
            "new york yankees vs boston red sox",
            None,
            None
        ]

        query = "new york mets at chicago cubs"

        best = process.extractOne(query, choices)
        self.assertEqual(best[0], choices[1])

Example 6

Project: fuzzywuzzy
License: View license
Source File: test_fuzzywuzzy.py
Function: test_simple_match
    def test_simplematch(self):
        basic_string = 'a, b'
        match_strings = ['a, b']

        result = process.extractOne(basic_string, match_strings, scorer=fuzz.ratio)
        part_result = process.extractOne(basic_string, match_strings, scorer=fuzz.partial_ratio)

        self.assertEqual(result, ('a, b', 100))
        self.assertEqual(part_result, ('a, b', 100))

Example 7

Project: fuzzywuzzy
License: View license
Source File: test_fuzzywuzzy_pytest.py
def test_process_warning(capsys):
    """Check that a string reduced to 0 by processor logs a warning to stderr"""

    query = ':::::::'
    choices = [':::::::']

    _ = process.extractOne(query, choices)

    out, err = capsys.readouterr()

    outstr = ("WARNING:root:Applied processor reduces "
              "input query to empty string, "
              "all comparisons will have score 0. "
              "[Query: ':::::::']\n")

    assert err == outstr

Example 8

Project: ledger-autosync
License: View license
Source File: ledgerwrap.py
    def get_account_by_payee(self, payee, exclude):
        fuzzed_payee = process.extractOne(payee, self.payees)[0]

        q = self.journal.query("--real payee '%s'" % (clean_payee(fuzzed_payee)))
        accts = [p.account for p in q]
        accts_filtered = [a for a in accts if a.fullname() != exclude]
        if accts_filtered:
            return str(accts_filtered[-1])
        else:
            return None

Example 9

Project: 1pass
License: View license
Source File: keychain.py
Function: item
    def item(self, name, fuzzy_threshold=100):
        """
        Extract a password from an unlocked Keychain using fuzzy
        matching. ``fuzzy_threshold`` can be an integer between 0 and
        100, where 100 is an exact match.
        """
        match = process.extractOne(
            name,
            self._items.keys(),
            score_cutoff=(fuzzy_threshold-1),
        )
        if match:
            exact_name = match[0]
            item = self._items[exact_name]
            item.decrypt_with(self)
            return item
        else:
            return None

Example 10

Project: fuzzywuzzy
License: View license
Source File: test_fuzzywuzzy.py
    def testGetBestChoice1(self):
        query = "new york mets at atlanta braves"
        best = process.extractOne(query, self.baseball_strings)
        self.assertEqual(best[0], "braves vs mets")

Example 11

Project: fuzzywuzzy
License: View license
Source File: test_fuzzywuzzy.py
    def testGetBestChoice2(self):
        query = "philadelphia phillies at atlanta braves"
        best = process.extractOne(query, self.baseball_strings)
        self.assertEqual(best[0], self.baseball_strings[2])

Example 12

Project: fuzzywuzzy
License: View license
Source File: test_fuzzywuzzy.py
    def testGetBestChoice3(self):
        query = "atlanta braves at philadelphia phillies"
        best = process.extractOne(query, self.baseball_strings)
        self.assertEqual(best[0], self.baseball_strings[2])

Example 13

Project: fuzzywuzzy
License: View license
Source File: test_fuzzywuzzy.py
    def testGetBestChoice4(self):
        query = "chicago cubs vs new york mets"
        best = process.extractOne(query, self.baseball_strings)
        self.assertEqual(best[0], self.baseball_strings[0])

Example 14

Project: fuzzywuzzy
License: View license
Source File: test_fuzzywuzzy.py
    def testWithScorer(self):
        choices = [
            "new york mets vs chicago cubs",
            "chicago cubs at new york mets",
            "atlanta braves vs pittsbugh pirates",
            "new york yankees vs boston red sox"
        ]

        choices_dict = {
            1: "new york mets vs chicago cubs",
            2: "chicago cubs vs chicago white sox",
            3: "philladelphia phillies vs atlanta braves",
            4: "braves vs mets"
        }

        # in this hypothetical example we care about ordering, so we use quick ratio
        query = "new york mets at chicago cubs"
        scorer = fuzz.QRatio

        # first, as an example, the normal way would select the "more
        # 'complete' match of choices[1]"

        best = process.extractOne(query, choices)
        self.assertEqual(best[0], choices[1])

        # now, use the custom scorer

        best = process.extractOne(query, choices, scorer=scorer)
        self.assertEqual(best[0], choices[0])

        best = process.extractOne(query, choices_dict)
        self.assertEqual(best[0], choices_dict[1])