-
Notifications
You must be signed in to change notification settings - Fork 1
/
sexes.py
52 lines (42 loc) · 1.61 KB
/
sexes.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
from namespace_registry import NamespaceRegistry as ns
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
class Sex:
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
def __init__(self, label):
self.label = label
self.IRI = get_sex_IRI(label)
self.count = 0
def __str__(self):
return f"Sex(label:{self.label}, IRI:{self.IRI}, count:{self.count})"
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
class Sexes:
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
def __init__(self):
self.sex_dic = dict()
f_in = open("data_in/cellosaurus.txt")
while True:
line = f_in.readline()
if line == "": break
line = line.rstrip()
if line.startswith("SX "):
label = line[5:]
if label not in self.sex_dic: self.sex_dic[label] = Sex(label)
rec = self.sex_dic[label]
rec.count += 1
f_in.close()
def keys(self):
return self.sex_dic.keys()
def get(self, k):
return self.sex_dic.get(k)
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_sex_IRI(label):
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
prefix = ns.cello.pfx
name = label.title().replace(" ", "").replace("(", "").replace(")", "").replace("/","").replace("-","")
return prefix + ":" + name
# = = = = = = = = = = = = = = = = = = = = = = = = = = = =
if __name__ == '__main__':
# = = = = = = = = = = = = = = = = = = = = = = = = = = = =
sexes = Sexes()
for k in sexes.keys():
print(sexes.get(k))