frhyme

guess the last phonemes of a French word
git clone https://a3nm.net/git/frhyme/
Log | Files | Refs | README

commit 87c740896784f74f58495a0dff3de29e576a1dc2
parent 7b5acb5f891130182002b1949baf758fd4aac8f1
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Tue, 13 Mar 2012 14:37:54 +0100

do not hardcode 5

Diffstat:
frhyme.py | 27++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/frhyme.py b/frhyme.py @@ -44,17 +44,22 @@ def nbest(l, t): l.reverse() return l -def lookup(key): - """Return pronunciations for key""" - if key.rstrip() == '': - raise ValueError # TODO this is debug - return nbest(do_lookup(trie, key[::-1] + ' '), 5) +def lookup(key, n): + """Return n top pronunciations for key""" + return nbest(do_lookup(trie, key[::-1] + ' '), n) + +def wrap_lookup(line, n): + pprint(lookup(line.lower().strip(), n)) if __name__ == '__main__': - while True: - line = sys.stdin.readline() - if not line: - break - line = line.lower().lstrip().rstrip() - pprint(lookup(line)) + n = int(sys.argv[1]) + if len(sys.argv) > 2: + for arg in sys.argv[2:]: + wrap_lookup(arg, n) + else: + while True: + line = sys.stdin.readline() + if not line: + break + wrap_lookup(line, n)