haspirater

detect aspirated 'h' in French words
git clone https://a3nm.net/git/haspirater/
Log | Files | Refs | README

commit 7e4b18bf9ab421d22b00b9e8f29db4817c74390a
parent 1f5dc55eafd2f633f85eb5fd41cb04e3fb399e19
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Mon, 18 Feb 2013 19:51:17 +0100

fix buildtrie.py to use __name__

Diffstat:
buildtrie.py | 23++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/buildtrie.py b/buildtrie.py @@ -12,8 +12,6 @@ import sys def empty_node(): return [{}, {}] -trie = empty_node() - def insert(trie, key, val): """Insert val for key in trie""" values, children = trie @@ -29,14 +27,17 @@ def insert(trie, key, val): # recurse return insert(children[key[0]], key[1:], val) -for line in sys.stdin.readlines(): - line = line.split() - value = line[0] - word = line[1].lower() if len(line) == 2 else '' - # a trailing space is used to mark termination of the word - # this is useful in cases where a prefix of a word is a complete, - # different word with a different value - insert(trie, word+' ', value) +if __name__ == '__main__': + trie = empty_node() + + for line in sys.stdin.readlines(): + line = line.split() + value = line[0] + word = line[1].lower() if len(line) == 2 else '' + # a trailing space is used to mark termination of the word + # this is useful in cases where a prefix of a word is a complete, + # different word with a different value + insert(trie, word+' ', value) -print(json.dumps(trie)) + print(json.dumps(trie))