From 90b5a581319f677f082fab075023b50dd3e6db9f Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Tue, 4 Aug 2009 16:30:56 -0700 Subject: [PATCH] sync plural5 with example code (again!) --- generators.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generators.html b/generators.html index a24ce40..46b67c2 100755 --- a/generators.html +++ b/generators.html @@ -295,14 +295,14 @@ rules = []

Wouldn’t it be grand to have a generic plural() function that parses the rules file? Get rules, check for a match, apply appropriate transformation, go to next rule. That’s all the plural() function has to do, and that’s all the plural() function should do.

[download plural5.py] -

def rules():
+
def rules(rules_filename):
     with open('plural5-rules.txt', encoding='utf-8') 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, rules_filename='plural5-rules.txt'):
-    for matches_rule, apply_rule in rules():
+    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))