renamed and added comment for vim at end of file
[regelmatige-werkwoorden.git] / verb.py
blobbe287616bf71471712aba5571902dda9f5bdb96c
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 """
5 simple conjugation of regular dutch verbs
6 http://www.dutchgrammar.com/en/?n=Verbs.01
7 """
9 from optparse import OptionParser
11 class Verbum:
12 """generic verb methods"""
13 def __init__(self, werkwoord):
14 self.werkwoord = werkwoord
16 def extract_stam(self):
17 """extracts the stem of the verb. only takes 3 rules into account."""
18 # een stam eindigt nooit op twee dezelfe medeklinkers
19 if self.werkwoord[-3] == self.werkwoord[-4]:
20 self.stam = self.werkwoord[:-3]
22 # de stam van een -iën werkwoord eindigt op `ie'
23 elif self.werkwoord[-4:] == "iën":
24 self.stam = self.werkwoord[:-3] + "e"
26 # een stam eindigt nooit op v of z
27 elif self.werkwoord[-3] == "v":
28 self.stam = self.werkwoord[:-3] + "f"
29 elif self.werkwoord[-3] == "z":
30 self.stam = self.werkwoord[:-3] + "s"
32 else:
33 self.stam = self.werkwoord[:-2]
35 def to_string(self):
36 """writes out the conjugation to stdout"""
37 # this would take a list of words as an argument.
38 # it would then write out `pronomen - word' list.
39 # the Verbum class would have the pronomen as attributes.
40 pass
42 class Presens(Verbum):
43 """takes a verb and conjugates it in the present tense"""
44 def schrijven(self):
45 """writes out the conjugated verb to stdout"""
46 pronomen_singularis = ["ik", "jij/je", "u", "hij/zij/ze"]
47 pronomen_pluralis = ["wij/we", "jullie", "zij/ze"]
49 for pronom in pronomen_singularis:
50 if pronom == "ik":
51 print "%s\t%s()" % (pronom, self.stam)
52 else:
53 print "%s\t%s(%s)" % (pronom, self.stam, "t")
55 for pronom in pronomen_pluralis:
56 # bug re rule #1, try `pakken'
57 print "%s\t%s(%s)" % (pronom, self.stam, "en")
59 if __name__ == "__main__":
60 gui = OptionParser()
61 gui.add_option("-w", "--werkwoord", action="store", dest="werkwoord")
62 (options, args) = gui.parse_args()
63 verbum = Presens(options.werkwoord)
65 # simple sanity checks, the word `t' is not a verb :)
66 try:
67 verbum.werkwoord[-4]
68 except IndexError:
69 gui.error("option -w, the verb needs more letters")
70 if verbum.werkwoord[-4:] != "iën":
71 if verbum.werkwoord[-2:] != "en":
72 gui.error("option -w: the ending of the verb must be \"-en\"")
74 verbum.extract_stam()
75 verbum.schrijven()
77 # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4