-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTable.py
81 lines (63 loc) · 2.48 KB
/
Table.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Software distributed under a Creative Commons Attribution-ShareAlike 3.0 Unported license. This allows you to adapt, copy, distribute and transmit the work while crediting the author of the original work and sharing under the same or similar license.
Full legal text of this license can be found on http://creativecommons.org/licenses/by-sa/3.0/legalcode
"""
class Table():
def __init__(self, id):
self.lexems = {}
self.exists = True
self.id = id
def delete(self):
"""This function marks this table as deleted"""
self.exists = False
return True
def exist(self):
"""Checks if this table is deleted or not"""
return self.exists
def add(self, lex):
"""Adds lex to this table.
Returns the position of the lex if everything went OK. Otherwise, it returns False"""
if not lex in self.lexems:
self.lexems[lex] = ''
return self.getPos(lex)
else:
return self.getPos(lex)
def setType(self, lex, type):
"""Sets the type of lex.
Returns True if everything went OK. Otherwise, returns False"""
if lex in self.lexems:
self.lexems[lex] = type
return True
else:
return False
def getType(self, lex):
"Returns the type of lex"
return self.lexems[lex]
def contains(self, lex):
"Checks if lex is in the table or not"
return self.lexems.has_key[lex]
def write(self, path):
"Writes the contents of this table to the file pointed to by path"
if self.exist():
f = open(path, 'a')
f.write('--------------------| Tabla' + str(self.id) + ' |--------------------\n')
f.write('----------------------------------------------------\n')
for e in self.lexems.keys():
f.write('\t' + str(e))
if self.lexems[e] != '':
f.write(' (' + self.lexems[e] + ')')
f.write('\n')
f.write('\n\n\n')
f.close()
return True
else:
return False
def getPos(self, lex):
"returns the ID of lex or False if lex is not in this table"
i = 0
for e in self.lexems.keys():
if e == lex:
break
else:
i = i + 1
return False if i == len(self.lexems) else i