File size: 6,297 Bytes
6b45f1e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from mpbench import score as S
T = lambda *a, **k: dict(type='text', answers=list(a), **k)
N = lambda a, **k: dict(type='number', answer=a, **k)
C = lambda name, opt=(), **args: dict(type='tool', call=dict(name=name, arguments=args), optional=list(opt))
CAP = dict(reject=['Sydney', 'Melbourne', 'Perth'])
cases = [
('William Shakespere wrote it.', T('Shakespeare'), 1), ('shakespeare', T('William Shakespeare', 'Shakespeare'), 1),
('It was Shakspeare', T('Shakespeare'), 1), ('Iran', T('Iraq'), 0), ('Iraq.', T('Iraq'), 1),
('Austria', T('Australia'), 0), ('Australa', T('Australia'), 1), ('Algeria', T('Nigeria'), 0), ('Slovenia', T('Slovakia'), 0),
('The capital is Canberra.', T('Canberra', **CAP), 1), ('Canbera', T('Canberra', **CAP), 1),
("It isn't Canberra", T('Canberra'), 0), ("It is not Canberra.", T('Canberra'), 0),
('Not Sydney but Canberra', T('Canberra', **CAP), 1), ('Sydney. Or maybe Canberra', T('Canberra', **CAP), 0),
('Canberra, Sydney, Melbourne, Perth', T('Canberra', **CAP), 0), ('Canberra, not Sydney', T('Canberra', **CAP), 1),
("São Paulo", T('Sao Paulo'), 1), ('the Pacific Ocean', T('Pacific'), 1), ('photosynthesys', T('photosynthesis'), 1),
('eight', T('8'), 1), ('There are 18.', T('8'), 0), ('In nineteen', T('19'), 1), ('It has two moons', T('2'), 1),
('0.5', N('1/2'), 1), ('.50', N('1/2'), 1), ('one half', N('1/2'), 1), ('The answer is 1/2.', N('0.5'), 1),
('one and a bit', N('2'), 0), ('3 + 4 = 7', N('7'), 1), ('3 + 4 = 8', N('7'), 0), ('1,274', N('1274'), 1), ('1274.', N('1274'), 1),
('twenty-three', N('23'), 1), ('two thousand and six', N('2006'), 1), ('one hundred and five', N('105'), 1),
('three million', N('3000000'), 1), ('-4', N('-4'), 1), ('−4', N('-4'), 1), ('4', N('-4'), 0), ('0.33', N('1/3'), 1),
('0.3', N('1/3'), 0), ('1 1/2', N('3/2'), 1), ('about 330', N('333', relative_tolerance=0.02), 1),
('The answer is 12. I used 3 steps', N('12'), 1), ('First 5, then 9', N('9'), 1), ('', N('0'), 0), ('1/0', N('0'), 0),
('{"name":"get_weather","arguments":{"city":"paris"}}', C('get_weather', city='Paris'), 1),
('Sure: {"tool":"add","args":{"b":5,"a":"2"}} done', C('add', a=2, b='5'), 1),
('add(b=5, a=2)', C('add', a=2, b=5), 1), ('{"name":"add","arguments":{"a":2}}', C('add', a=2, b=5), 0),
('{"name":"add","arguments":{"a":2,"b":5,"c":1}}', C('add', a=2, b=5), 0),
('{"name":"add","arguments":{"a":2,"b":5,"c":1}}', C('add', ('c',), a=2, b=5), 1),
('{"name":"w","arguments":{"city":"NYC"}}', C('w', city={'any': ['New York', 'NYC']}), 1),
('{"name":"a"}{"name":"b"}', C('a'), 0), ('no call here', C('a'), 0),
('{"type":"function","function":{"name":"t","arguments":"{\\"on\\":true}"}}', C('t', on=True), 1),
("I'd eat soup and get some rest", dict(type='ideas', ideas=[['rest', 'sleep'], ['soup', 'fluids', 'water']]), 1),
("Just rest", dict(type='ideas', ideas=[['rest', 'sleep'], ['soup', 'fluids']]), 0),
("Just rest", dict(type='ideas', need=1, ideas=[['rest', 'sleep'], ['soup', 'fluids']]), 1),
]
cases += [
('{"name":"calc","arguments":{"expression":"418+27"}}', C('calc', expression={'any': ['418*27', '27*418']}), 0),
('{"name":"calc","arguments":{"expression":"418 x 27"}}', C('calc', expression={'any': ['418*27', '27*418']}), 1),
('{"name":"v","arguments":{"percent":"30%"}}', C('v', percent=30), 1),
('{"name":"v","arguments":{"percent":"1e99999999"}}', C('v', percent=30), 0),
('recieve', T('receive', exact=True), 0), ('It is spelled receive.', T('receive', exact=True), 1),
('seperate', T('separate', exact=True), 0), ('definately', T('definitely', exact=True), 0),
('5, 6, 7, 8, 9', T('8'), 0), ('There are 8.', T('8'), 1), ('1:59:30', T('1:59:30'), 1),
('The answer is 5 + 3 = 8.', N('8'), 1),
("Don't click links", dict(type='ideas', ideas=[['links', 'sender']]), 1),
('This is fine, hello!', dict(type='ideas', question='hi', ideas=[['this']]), 1),
]
P = lambda *checks: dict(type='html', checks=list(checks))
NAVY = P(dict(colour='background', family='dark blue'))
cases += [
('<body style="background:#000000">x</body>', NAVY, 0), ('<body style="background:#003366">x</body>', NAVY, 1),
('<body bgcolor="navy">x</body>', NAVY, 1), ('<body style="background: navy">x</body>', NAVY, 1),
('<style>body{background-color: rgb(0, 0, 90)}</style>', NAVY, 1), ('<body style="background: blue">x</body>', NAVY, 0),
('<input value="Join">', P(dict(any=[dict(tag='input', attrs={'value': 'join'})])), 1),
]
cases += [
('recieve', dict(type='ideas', exact=True, ideas=[['receive']]), 0),
('receive', dict(type='ideas', exact=True, ideas=[['receive']]), 1),
('water or cola', T('water', reject=['cola']), 0), ('Water, not cola', T('water', reject=['cola']), 1),
('An elephant is bigger than a mouse.', T('elephant', reject=['mouse']), 1),
]
cases += [('is fire hot or cold ? answer :', T('hot', question='Is fire hot or cold?'), 0)]
cases += [
('419, 246, 137 or 469.', N('469'), 0), ('15, 5, 10, 10, 15, 10, 15', N('10'), 0), ('1 × 1 × 1 × 1 × 1', N('1'), 0),
('469 is the largest.', N('469'), 1), ('From left to right: 5 + 37 = 42. Then 42 + 30 = 72. The answer is 72.', N('72'), 1),
('11 × $2 = $22, then $40 - $22 = $18. The answer is $18.', N('18'), 1), ('16/3', N('16/3'), 1), ('1,274', N('1274'), 1),
('World War II ended in 1945, and the two most recent are in 2026 and 2028.', T('1945'), 1),
('The only even prime number is 2, because 2 × 2 = 4 and 2 × 4 = 8.', T('2'), 1), ('It is 1, 2 or 3.', T('2'), 0),
('It means something extra.', T('mean', 'stingy'), 0), ('I love the wind. I love the sea. I love the wind. I love the sea. I love the wind. I love the sea.', dict(type='ideas', ideas=[['sea']]), 0),
]
cases += [
('455. 190 is the smallest, so 455 is the bigger one.', N('455'), 1), ('Which one? The answer is one.', N('1'), 1),
('one apple and two pears make three fruits', N('3'), 1),
('-16 = -5x + 9', N('-5'), 0), ('5x + 9 = -16, so 5x = -25 and x = -5.', N('-5'), 1), ('x = 17', N('17'), 1),
]
known = S.known_words([t for _, t, _ in cases])
bad = [(o, t, want) for o, t, want in cases if S.score(o, t, known) != float(want)]
for b in bad:
print('FAIL', b)
print(f'{len(cases) - len(bad)}/{len(cases)} scorer tests pass')
sys.exit(bool(bad))
|