Can somebody teach me how to make a Python trie with continuation classes?
Implement a trie (letter tree) with continuation classes to represent the regular verbal paradigm of French (regular verbs ending in -er and -ir). The program is expected to analyze conjugated verb forms and to display the ininitive form and the grammatical description(s) of this form. For example, the conjugated verb form aimerais should yield the two following analyses:
aimerais ==> aimer / conditionnel 1ère personne singulier aimerais ==> aimer / conditionnel 2ème personne singulier
I have 3 files in the same folder. I don't know how I can search for the word and put it in a tree.
# TP 2 : TRIE WITH CONTINUATION CLASS
class Trie:
def __init__(self, filename):
self.__end = False
self.__nodes = {}
def myTrie (self, filename, encoding="utf8"):
file = open(filename)
trie = self._nodes(file.readlines())
for verbes in trie:
words = verbes[:-2]
trie_trie = trie_trie.setdefault(words,self._nodes)
return trie_trie
def myTrie_suffix_er (self, filename, encoding="utf8"):
filesuffix_er = open(filename)
suffix = self._nodes(filesuffix_er.readlines().split())
suffix+="er"
for a in range(len(suffix)):
fin = self._nodes
for b in suffix[a:]:
fin = fin[b]
def myTrie_suffix_ir (self, filename, encoding="utf8"):
filesuffix_ir = open(filename)
suffix = self._nodes(filesuffix_ir.readlines().split())
suffix+="ir"
for c in range(len(suffix)):
fin = self._nodes
for d in suffix[c:]:
fin = fin[d]
ver = Trie ("suffixes-er.txt")
vir = Trie ("suffixes-er.txt")
print (ver)