Skip to content

Commit 133d885

Browse files
committed
[terminology] add some docstrings
1 parent e80d75d commit 133d885

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

odml/terminology.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828

2929

3030
def open_file_map():
31+
"""
32+
Opens the file_map file stored in the cache that maps the filenames to the urls of the
33+
respective terminolgies.
34+
"""
3135
file_map = {}
3236
if not os.path.exists(FILE_MAP_FILE):
3337
return file_map
@@ -41,7 +45,7 @@ def open_file_map():
4145

4246
def cache_load(url):
4347
"""
44-
load the url and store it in a temporary cache directory
48+
Load the url and store it in a temporary cache directory
4549
subsequent requests for this url will use the cached version
4650
"""
4751
filename = md5(url.encode()).hexdigest() + '__' + os.path.basename(url)
@@ -64,12 +68,18 @@ def cache_load(url):
6468

6569

6670
def cached_files():
71+
"""
72+
Returns a list of all locally cached files.
73+
"""
6774
filelist = [ f for f in os.listdir(CACHE_DIR) if \
6875
(f.endswith(".xml") and os.path.isfile(os.path.join(CACHE_DIR, f)))]
6976
return filelist
7077

7178

7279
def show_cache():
80+
"""
81+
Show all locally cached files. Just for display.
82+
"""
7383
print("terminology %s \t updated"%(19*" "))
7484
print(60*"-")
7585
files = cached_files()
@@ -85,6 +95,9 @@ def show_cache():
8595

8696

8797
def clear_cache():
98+
"""
99+
Clears the cache, i.e. deletes all locally stored files. Does not remove the cache folder, though.
100+
"""
88101
filelist = cached_files();
89102
for f in filelist:
90103
os.remove(os.path.join(CACHE_DIR, f))
@@ -93,6 +106,10 @@ def clear_cache():
93106

94107

95108
def from_cache(term):
109+
"""
110+
Fills the terminology with the definitions stored in the cache.
111+
"""
112+
assert isinstance(term, Terminologies)
96113
file_list = cached_files();
97114
file_map = open_file_map();
98115
for f in file_map:
@@ -150,9 +167,15 @@ def deferred_load(self, url):
150167
self.loading[url].start()
151168

152169
def empty(self):
170+
"""
171+
Tells whether there are no terminolgies stored.
172+
"""
153173
return len(self) == 0
154174

155175
def type_list(self):
176+
"""
177+
returns a dict of all types stored in the cache together with the terminologies it is defined in.
178+
"""
156179
if self.empty():
157180
from_cache(self)
158181
if not self.types:
@@ -240,7 +263,7 @@ def get_section_by_type(section_type, pattern=None, relaxed=False):
240263
if __name__ == "__main__":
241264
from IPython import embed
242265
print ("Terminologies!")
266+
# from_cache(terminologies)
243267
# t.load('http://portal.g-node.org/odml/terminologies/v1.0/terminologies.xml')
244-
embed()
245268
# t.load('http://portal.g-node.org/odml/terminologies/v1.0/analysis/power_spectrum.xml')
246-
269+
embed()

0 commit comments

Comments
 (0)