-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·60 lines (46 loc) · 1.46 KB
/
main.py
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
#!/usr/bin/python -OO
# -*- coding: utf-8 -*-
import argparse
import re
import sys
import lib.ek as ek
import lib.cmu as cmu
import lib.wik as wik
parser = argparse.ArgumentParser()
parser.add_argument('-r', '--rebuild', action='store_true', help='rebuild databases')
args = parser.parse_args()
engine = wik
engine.load(do_insert=args.rebuild)
line = ['--------'] * 4
right = [['English', 'IPA', 'machine', 'human']]
wrong = [['English', 'IPA', 'machine', 'human']]
right.apppend(line)
wrogn.append(line)
total = 0
for line in sys.stdin:
wordlist = re.split(r'\s+', line)
# remove the empty strings
wordlist = filter(None, wordlist)
# If this results in a blank line,
# then we just loop again
if len(wordlist) < 2:
continue
# This is the reference set
eka_real = wordlist[1]
word = engine.prepare(wordlist[0])
# This is our generated set
eka_test = engine.to_eka(word)
engine_test = engine.to_middleware(word).values()[0] if eka_test else ''
if eka_test == eka_real:
right.append([word, engine_test, eka_real, eka_test])
else:
if not eka_test: eka_test = ''
wrong.append([word, engine_test, eka_real, eka_test])
total += 1
print "\n\nResults: " + str( 100 * len(right) / total) + "% correct\n\n"
print "Wrong List:"
for line in wrong:
print ''.join(['{:20}'.format(x) for x in line])
print "\n\n\nRight List:"
for line in right:
print ''.join(['{:20}'.format(x) for x in line])