-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel.py
executable file
·52 lines (50 loc) · 1.23 KB
/
label.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
class Label(object):
def __init__(self, name):
self.name = name.replace(".","_")
def __repr__(self):
return self.name
class LabelManager(object):
def __init__(self):
self.nameDict = dict()
self.label_num = 0
self.labelDict = dict()
def new(self, LN, name = None):
if name != None:
if type(name) is list:
pass
else:
name = [name]
for n in name:
if self.hasLabel(n):
LN.addLabel(self.getLabel(n))
else:
LN.addLabel(self.addLabel(n))
return LN
self.label_num += 1
ID = "L"+str(self.label_num)
while ID in self.nameDict:
self.label_num += 1
ID = "L"+str(self.label_num)
LN.addLabel(self.addLabel(ID))
return LN
def delete(self, name):
LN = self.nameDict.pop(str(name))
LN.label = []
"""def search(self, name):
return self.nameDict[str(name)]
"""
def getLabel(self, name):
return self.nameDict[name]
def hasLabel(self, name):
return self.nameDict.has_key(name)
def addLabel(self, name):
l = Label(name)
self.nameDict[name] = l
return l
def useLabel(self, LN, label):
if not self.labelDict.has_key(LN):
self.labelDict[LN] = {}
self.labelDict[LN][label] = True
return
def replace(labelA, labelB):
pass