frhyme

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

commit b128dd33ca4bc59fa37f379d9d28f5c392e07008
parent 331f09ff77a02525b3972c8ef0a9e39d5539094c
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Tue, 13 Mar 2012 15:51:15 +0100

make NBEST optional

Diffstat:
README | 7++++---
frhyme.py | 8++++++--
2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/README b/README @@ -35,9 +35,10 @@ To avoid licensing headaches, and because the data file is quite big, no pronunciation data is included, you have to generate it yourself. See section 3. Once you have pronunciation data ready in frhyme.json, you can either run -frhyme.py NBEST, giving one word per line in stdin and getting the NBEST top -pronunciations on stdout, or you can import it in a Python file and call -frhyme.lookup(word, NBEST) which returns the NBEST top pronunciations. +frhyme.py [NBEST], giving one word per line in stdin and getting the NBEST top +pronunciations on stdout (default is 5), or you can import it in a Python file +and call frhyme.lookup(word, NBEST) which returns the NBEST top pronunciations +(default is 5). The pronunciations returned are annotated with a confidence score (the number of occurrences in the training data). They should be sensible up to the longest diff --git a/frhyme.py b/frhyme.py @@ -8,6 +8,8 @@ import json import sys from pprint import pprint +DEFAULT_NBEST=5 + f = open(os.path.join(os.path.dirname( os.path.realpath(__file__)), 'frhyme.json')) trie = json.load(f) @@ -43,7 +45,7 @@ def nbest(l, t): l.reverse() return l -def lookup(key, n): +def lookup(key, n=DEFAULT_NBEST): """Return n top pronunciations for key""" return nbest(do_lookup(trie, key[::-1] + ' '), n) @@ -51,7 +53,9 @@ def wrap_lookup(line, n): pprint(lookup(line.lower().strip(), n)) if __name__ == '__main__': - n = int(sys.argv[1]) + n = DEFAULT_NBEST + if len(sys.argv) >= 2: + n = int(sys.argv[1]) if len(sys.argv) > 2: for arg in sys.argv[2:]: wrap_lookup(arg, n)