fixed numbering, fixed file() typo, take rules file as an argument in plural5.py

This commit is contained in:
Mark Pilgrim
2009-07-09 01:42:21 -04:00
parent d07bb6397c
commit f67581298a
2 changed files with 13 additions and 12 deletions
+4 -4
View File
@@ -14,14 +14,14 @@ def build_match_and_apply_functions(pattern, search, replace):
return re.sub(search, replace, word)
return [matches_rule, apply_rule]
def rules():
with open('plural5-rules.txt') as pattern_file:
def rules(rules_filename):
with open(rules_filename) as pattern_file:
for line in pattern_file:
pattern, search, replace = line.split(None, 3)
yield build_match_and_apply_functions(pattern, search, replace)
def plural(noun):
for matches_rule, apply_rule in rules():
def plural(noun, rules_filename='plural5-rules.txt'):
for matches_rule, apply_rule in rules(rules_filename):
if matches_rule(noun):
return apply_rule(noun)
raise ValueError('no matching rule for {0}'.format(noun))