Esempio n. 1
0
    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])
Esempio n. 2
0
    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])
Esempio n. 3
0
    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.assertIsNone(best)

        # however if we had no cutoff, something would get returned

        best = process.extractOne(query, choices)
        self.assertIsNotNone(best)
Esempio n. 4
0
    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.assertIsNone(best)

        # however if we had no cutoff, something would get returned

        best = process.extractOne(query, choices)
        self.assertIsNotNone(best)
Esempio n. 5
0
    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"
        processor = lambda event: event[0]

        best = process.extractOne(query, events, processor=processor)
        self.assertEqual(best[0], events[0])
Esempio n. 6
0
    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"
        ]

        # in this hypothetical example we care about ordering, so we use quick ratio
        query = "new york mets at chicago cubs"
        scorer = 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])
Esempio n. 7
0
    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"
        ]

        # in this hypothetical example we care about ordering, so we use quick ratio
        query = "new york mets at chicago cubs"
        scorer = 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])
Esempio n. 8
0
    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"
        processor = lambda event: event[0]

        best = process.extractOne(query, events, processor=processor)
        self.assertEqual(best[0], events[0])
Esempio n. 9
0
 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])
Esempio n. 10
0
 def testGetBestChoice3(self):
     query = "atlanta braves at philadelphia phillies"
     best = process.extractOne(query, self.baseball_strings)
     self.assertEqual(best[0], self.baseball_strings[2])
Esempio n. 11
0
 def testGetBestChoice1(self):
     query = "new york mets at atlanta braves"
     best = process.extractOne(query, self.baseball_strings)
     self.assertEqual(best[0], "braves vs mets")
Esempio n. 12
0
 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])
Esempio n. 13
0
 def testGetBestChoice3(self):
     query = "atlanta braves at philadelphia phillies"
     best = process.extractOne(query, self.baseball_strings)
     self.assertEqual(best[0], self.baseball_strings[2])
Esempio n. 14
0
 def testGetBestChoice1(self):
     query = "new york mets at atlanta braves"
     best = process.extractOne(query, self.baseball_strings)
     self.assertEqual(best[0], "braves vs mets")