Skip to content

Commit 5792b48

Browse files
committed
[terminolgy] add method that returns a list of section types
1 parent 67a6198 commit 5792b48

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

odml/terminology.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
CACHE_AGE = datetime.timedelta(days=14)
1919
CACHE_DIR = os.path.join(tempfile.gettempdir(), "odml.cache")
2020
FILE_MAP_FILE = os.path.join(CACHE_DIR, "odml_filemap.csv")
21+
2122
if not os.path.exists(CACHE_DIR):
2223
try:
2324
os.makedirs(CACHE_DIR)
@@ -101,6 +102,7 @@ def from_cache(term):
101102

102103
class Terminologies(dict):
103104
loading = {}
105+
types = None
104106

105107
def load(self, url="http://portal.g-node.org/odml/terminologies/v1.0/terminologies.xml"):
106108
"""
@@ -147,6 +149,21 @@ def deferred_load(self, url):
147149
self.loading[url] = threading.Thread(target=self._load, args=(url,))
148150
self.loading[url].start()
149151

152+
def empty(self):
153+
return len(self) == 0
154+
155+
def type_list(self):
156+
if self.empty():
157+
from_cache(self)
158+
if not self.types:
159+
self.types = {}
160+
for k in self.items():
161+
for s in k[1].itersections():
162+
if s.type in self.types:
163+
self.types[s.type].append((k[0], s.get_path()))
164+
else:
165+
self.types[s.type] = [(k[0], s.get_path())]
166+
return self.types
150167
terminologies = Terminologies()
151168
load = terminologies.load
152169
deferred_load = terminologies.deferred_load

0 commit comments

Comments
 (0)