-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesperanto.py
66 lines (55 loc) · 1.7 KB
/
esperanto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Result:
def __init__(self, word, entry=""):
self.word = word
self.entry = entry
def look_up(query):
query = query.lower()
if query in dictionary:
return get_esp_result(query)
elif get_root(query) in dictionary:
return get_esp_result(get_root(query))
elif get_infinitive(query) in dictionary:
return get_esp_result(get_infinitive(query))
else:
return Result(word=query, entry="was not in the dictionary")
def print_result(result):
print("\n")
print(result)
print("\n")
def get_esp_result(query):
entry = dictionary[query]
entry = entry[0:len(entry)-1]
result = Result(word=query, entry=entry)
return result
def get_root(word):
if word[len(word) - 2:len(word)] == "jn":
return word[0:len(word)-2]
elif word[len(word) - 1] == "n":
return word[0:len(word)-1]
elif word[len(word) - 1] == "j":
return word[0:len(word)-1]
else:
return None
def get_infinitive(word):
verb_suffixes = ["as", "is", "os", "us", "u", "ant", "int", "ont", "at", "it", "ot"]
for suffix in verb_suffixes:
if word[len(word) - len(suffix):len(word)] == suffix:
return word[0:len(word)-len(suffix)] + "i"
return None
def search_english(query):
relevant_keys = []
for key, value in dictionary:
if query in value:
relevant_keys.append(key)
if relevant_keys != []:
return relevant_keys
return None
f = open('esperanto-dict.txt')
dictionary = {}
while True:
line = f.readline()
if line == "":
break
esperanto, english = line.split(" : ")
dictionary[esperanto] = english
print("Dictionary successfully read in.")