-
Notifications
You must be signed in to change notification settings - Fork 5
/
gismu_best.py
executable file
·61 lines (46 loc) · 1.71 KB
/
gismu_best.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
61
#!/usr/bin/env python
# Lojban gismu candidate score evaluation script
# Version 0.5
# Copyright 2014 Riley Martinez-Lynch, except where
# Copyright 2012 Arnt Richard Johansen.
# Distributed under the terms of the GPL v3.
# Usage:
#
# python gismu_score.py -o scores.data uan rakan ekspekt esper predpologa mulud
# python gismu_best.py < scores.data
#
import platform
import sys
from marshal import load
from gismu_utils import GismuMatcher
def main(scores, gismus):
print >>sys.stderr, "Sorting scores..."
scores.sort(lambda x,y:cmp(y[0], x[0]))
print >>sys.stderr, ""
print >>sys.stderr, "10 first gismu candidates are:"
print >>sys.stderr, ""
for record in scores[:10]:
print >>sys.stderr, record
print >>sys.stderr, ""
print >>sys.stderr, "Excluding candidates similar to existing gismu..."
matcher = GismuMatcher(gismus)
for (score, candidate, _) in scores:
gismu = matcher.find_similar_gismu(candidate)
if gismu == None:
print >>sys.stderr, "The winner is....\n"
print candidate.upper()
print >>sys.stderr, ""
break
else:
print >>sys.stderr, \
"Candidate '%s' too much like gismu '%s'." % (candidate, gismu)
else:
print >>sys.stderr, "No suitable candidates in top 10 scores."
if __name__ == '__main__':
gismu_path = 'gismu-list.txt'
print >>sys.stderr, "Reading list of gismu... "
gismus = [line.strip() for line in file(gismu_path)]
print >>sys.stderr, "Loading scores... ",
scores = load(sys.stdin)
print >>sys.stderr, "%d scores loaded." % len(scores)
main(scores, gismus)