示例#1
0
    def test_match(self):
        parse = charts.Type()

        text = 'CLAIMING - Thoroughbred'
        result = parse.match(text)

        self.assertEqual(result['race_type'], 1)
        self.assertEqual(result['race_for'], 'Thoroughbred')
示例#2
0
    def test_spaces_match(self):
        parse = charts.Info()
        text = 'ALBUQUERQ UE - July 24, 2019 - Race 1'

        info = parse.match(text)

        self.assertEqual(result['track_name'], 'ALBUQUERQUE')
        self.assertEqual(result['track_date'], 'July 24, 2019')
        self.assertEqual(result['track_race_number'], 1)
        self.assertEqual(parse.race, '')
示例#3
0
    def test_match(self):
        parse = charts.Age()

        text = 'FOR REGISTERED NEW MEXICO BRED FILLIES AND MARES THREE YEARS OLD AND UPWARD WHICH HAVE NOT WON'
        result = parse.match(text)

        self.assertEqual(result['age'], 2)
        self.assertEqual(
            parse.race,
            'FOR REGISTERED NEW MEXICO BRED FILLIES AND MARES WHICH HAVE NOT WON'
        )
示例#4
0
    def test_match(self):
        parse = charts.Desc()

        text = 'FOR REGISTERED NEW MEXICO BRED THREE YEAR OLDS AND UPWARD WHICH HAVE NEVER WON TWO RACES. Three'

        info = parse.match(text)

        self.assertEqual(
            info['race_desc'],
            'FOR REGISTERED NEW MEXICO BRED THREE YEAR OLDS AND UPWARD WHICH HAVE NEVER WON TWO RACES.'
        )
        self.assertEqual(parse.race, 'Three')
示例#5
0
    def test_match(self):
        text = 'Three Year Olds, 120 lbs.; Older, 123 lbs. Claiming Price $6,250 (Maiden, Claiming, Or Starter Races'

        parse = charts.WeightInfo()
        result = parse.match(text)

        self.assertIn({
            'desc': 'Three Year Olds',
            'weight': '120'
        }, result['weight_info'])
        self.assertIn({
            'desc': 'Older',
            'weight': '123'
        }, result['weight_info'])
示例#6
0
    def test_match(self):
        text = """FOR REGISTERED NEW MEXICO BRED FILLIES AND MARES THREE YEARS OLD AND UPWARD WHICH HAVE NOT WON 
TWO RACES SINCE JANUARY 24, 2019 OR WHICH HAVE NEVER WON FOUR RACES. Three Year Olds, 120 lbs.; Older, 123"""

        parse = charts.Registered()
        info = parse.match(text)
        print(info)
        self.assertEqual(info['registered'], True)
        text = parse.race
        self.assertEqual(
            text,
            """FOR FILLIES AND MARES THREE YEARS OLD AND UPWARD WHICH HAVE NOT WON 
TWO RACES SINCE JANUARY 24, 2019 OR WHICH HAVE NEVER WON FOUR RACES. Three Year Olds, 120 lbs.; Older, 123"""
        )

        parse = charts.Sex()
        parse.match(text)
        text = parse.race
        self.assertEqual(
            text, """FOR THREE YEARS OLD AND UPWARD WHICH HAVE NOT WON 
TWO RACES SINCE JANUARY 24, 2019 OR WHICH HAVE NEVER WON FOUR RACES. Three Year Olds, 120 lbs.; Older, 123"""
        )

        parse = charts.Age()
        parse.match(text)
        text = parse.race
        self.assertEqual(
            text, """FOR WHICH HAVE NOT WON 
TWO RACES SINCE JANUARY 24, 2019 OR WHICH HAVE NEVER WON FOUR RACES. Three Year Olds, 120 lbs.; Older, 123"""
        )

        parse = charts.Desc()
        info = parse.match(text)

        print(info)
        self.assertEqual(
            result['race_desc'],
            'FOR WHICH HAVE NOT WON TWO RACES SINCE JANUARY 24, 2019 OR WHICH HAVE NEVER WON FOUR RACES.'
        )
        self.assertEqual(parse.race,
                         """Three Year Olds, 120 lbs.; Older, 123""")
示例#7
0
def guess_graph(text=None, handle=""):
    seed = base64.b64encode(os.urandom(8)).decode("ascii")

    GraphGenerator = RandomGraph(seed)
    style = None
    layout = None

    if text:
        numbers = [
            int(s) for s in text.split() if s.isdigit() and int(s) < 1024
        ]
        if numbers:
            N = random.choice(numbers)
            print(f"recognized {N} nodes")
        else:
            N = None

        key, certainty = match(text, synonyms.keys())
        gen = lambda: synonyms[key](GraphGenerator, N=N)

        styleKey, styleCertainty = match(text, styles_all)

        if styleCertainty >= 80:
            print(f"regocnized style: {styleKey} ({styleCertainty})")
            style = styleKey

        layoutKey, layoutCertainty = match(text, layouts_all)

        if layoutCertainty >= 80:
            print(f"recognized layout: {layoutKey} ({layoutCertainty})")
            layout = layoutKey

    if not text or certainty < 20:
        gen = GraphGenerator.randomGraph
        certainty = 0
        key = "n/a"

    folder = os.path.join(absdir, "answers")
    path, details = createPlot(gen,
                               folder,
                               seed,
                               comment="'{text}' -> {key} ({certainty}%)",
                               style=style,
                               layout=layout)

    print(key, "({}%)".format(certainty))

    print(details["template"].format(**details))

    name = details["name"]
    if handle and handle[0] != "@":
        handle = "@" + handle

    if certainty < 50:
        answer = "{handle} I am not sure what you mean, but I drew a {graph} for you! ({N} nodes)"
    elif certainty < 80:
        answer = "{handle} I think you mentioned a {graph}, I drew it for you. ({N} nodes)"
    else:
        answer = "{handle} here is a picture of the {graph} you're interested in! ({N} nodes)"
    answer = answer.format(handle=handle, graph=name, N=details["N"]).strip()

    return path, answer