|
From: <fri...@us...> - 2008-12-24 13:40:43
|
Revision: 9642
http://zaf.svn.sourceforge.net/zaf/?rev=9642&view=rev
Author: friedelwolff
Date: 2008-12-24 13:40:35 +0000 (Wed, 24 Dec 2008)
Log Message:
-----------
Rewrite verb_rules to accept **kwargs and work with Affix and AffixGroup objects directly
Modified Paths:
--------------
trunk/dict/zu/hunspell/zu_aff.py
Modified: trunk/dict/zu/hunspell/zu_aff.py
===================================================================
--- trunk/dict/zu/hunspell/zu_aff.py 2008-12-24 11:57:35 UTC (rev 9641)
+++ trunk/dict/zu/hunspell/zu_aff.py 2008-12-24 13:40:35 UTC (rev 9642)
@@ -139,7 +139,7 @@
prefix = re.sub(r"[aeiou]([aeiou])", r"\1", prefix)
return prefix
-def verb_rules(prefix):
+def verb_rules(group, **kwargs):
"""Generate the necessary rules to prepend the given prefix to a verb
It receives a string with the already built (complete) prefix and
@@ -147,65 +147,70 @@
consequence of vowel verbs are taken into account here, and no users of
this function need to take vowel verbs into account.
"""
- changed = []
+ if isinstance(group, basestring):
+ #old API - this is actually the prefix
+ prefix = group
+ #Let's make a temporary group to work with
+ group = AffixGroup(flag="tmp", suffix=False)
+ else:
+ prefix = kwargs.pop('prefix')
#normal verb starting on consonant:
- changed.append(["0", prefix, "[^y]"])
- #monosyllabic verbs: in the dictionary in imperative form, e.g. yidla
- changed.append(["yi", prefix, "yi"])
+ group.add_rule(affix=prefix, condition="[^aeiou]", **kwargs)
- #now for the complicated part: verbs starting on vowels. (e.g. yakha)
+ #now for the complicated part: verbs starting on vowels. (e.g. akha)
if prefix[-1] == 'u':
#the 'u' always needs to be removed, we probably need a 'w'
prefix = prefix[0:-1]
#if the original prefix ended on 'wu', we don't want to add
#another 'w' as this will result in 'ww'
if len(prefix) > 0 and prefix[-1] == 'w':
- changed.append(["y", prefix, "y[ae]"])
+ group.add_rule(affix=prefix, condition="[ae]", **kwargs)
else:
- changed.append(["y", prefix + 'w', "y[ae]"])
+ group.add_rule(affix=prefix + 'w', condition="[ae]", **kwargs)
if len(prefix) == 0:
#if prefix == 'u' before 'o' we change to 'w' as above
- changed.append(["y", 'w', "yo"])
+ group.add_rule(affix='w', condition="o", **kwargs)
else:
#for a prefix ending on 'u' before 'o' we simply remove the 'u'
#without adding 'w', e.g. lu + osa -> losa
- changed.append(["y", prefix, "yo"])
- return changed
+ group.add_rule(affix=prefix, condition="o", **kwargs)
+ return group.rules
if prefix[-1] == 'i':
#if the complete prefix is 'i' before a vowel verb, we can
#ignore it, as it is simply the same as the imperative form
#example: i + enza = yenza
#
- #otherwise, change 'i' to 'y'
if len(prefix) > 1:
prefix = prefix[0:-1]
- changed.append(["y", prefix, "y[^i]"])
- #changed.append(["y", prefix, "y"])
- #TODO: this just made the "yi", prefix "yi" rule (above) unnecessary
- return changed
+ group.add_rule(affix=prefix, condition="[aeiou]", **kwargs)
+ else:
+ #otherwise, change 'i' to 'y'
+ group.add_rule(affix="y", condition="[aeiou]", **kwargs)
+ return group.rules
if prefix[-1] == 'a':
prefix = prefix[0:-1]
- changed.append(["y", prefix, "y[^i]"])
- #changed.append(["y", prefix, "y"])
- #TODO: this just made the "yi", prefix "yi" rule (above) unnecessary
- return changed
+ #prefix could now be "", which is probably ok:
+ # amadoda enza lokhu
+ group.add_rule(affix=prefix, condition="[aeiou]", **kwargs)
+ return group.rules
if prefix == "o":
#Although other prefixes can end on 'o' ('zo' or 'yo'), these
#are only used with consonant verbs and not with monosyllabics.
#TODO: verify if others are possible
- #TODO: verify if 'zo' and 'yo' are only used before consonants
- return changed
+ return group.rules
if prefix[-1] == "e":
#TODO: situative e- and be- should be handled (entirely thrown away?).
#We can probably just generate them, and duplicate handling should take
#care of them. Then we need to handle relatives with ending on e.
pass
- return changed
+ return group.rules
################################################################################
for i in concords:
+# A_rules.extend(verb_rules(i)) #XXX:DONE
+
A_rules.extend(verb_rules(i+"nga"))
A_rules.extend(verb_rules(i+"sa"))
@@ -242,6 +247,7 @@
#Mode specific ones:
for i in subject_morphemes:
+# a_rules.extend(verb_rules(i+"ya"))#XXX:DONE
#TODO: be- and se- forms
#Negative future tenses:
@@ -328,8 +334,13 @@
# flag, cross_product, type = rule_set[0]
# group = aff.add_group(suffix=type=="SFX", cross_product=cross_product, flag=flag)
# for rule in rule_set[1:]:
-# strip, affix, condition = rule
-# group.add_rule(strip=strip, affix=affix, condition=condition)
+# if isinstance(rule, Affix):
+# group.add_rule(rule)
+# else:
+# strip, affix, condition = rule
+# group.add_rule(strip=strip, affix=affix, condition=condition)
+# print aff.hunspell()
+# exit()
main_subjects = aff.add_group(suffix=False, flag="B")
# This group will contain all the major subject morphemes
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|