summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJoern Hees <dev@joernhees.de>2014-12-08 17:01:02 +0100
committerJoern Hees <dev@joernhees.de>2014-12-08 17:08:19 +0100
commit8e78708e0dd3a36d8e54796f78fd27957255b47a (patch)
tree0e3bcbab69765e2e3a2f3646fd5f81ebc818d0e7 /examples
parentb29e0b08b8171e33a9da25a5b7287fdce5ce229b (diff)
downloadrdflib-8e78708e0dd3a36d8e54796f78fd27957255b47a.tar.gz
minor: code style guides
Diffstat (limited to 'examples')
-rw-r--r--examples/graph_digest_benchmark.py50
1 files changed, 27 insertions, 23 deletions
diff --git a/examples/graph_digest_benchmark.py b/examples/graph_digest_benchmark.py
index c7c374f8..d987cf18 100644
--- a/examples/graph_digest_benchmark.py
+++ b/examples/graph_digest_benchmark.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
'''
-This benchmark will produce graph digests for all of the
+This benchmark will produce graph digests for all of the
downloadable ontologies available in Bioportal.
'''
@@ -25,36 +25,38 @@ select distinct ?ontology ?title ?download where {
metadata:links ?links.
?links metadata:Ontology ?download.
filter(regex(?download, "/download"))
-}
+}
'''
stat_cols = [
'id',
'ontology',
'download_url',
- 'tree_depth',
- 'color_count',
- 'individuations',
+ 'tree_depth',
+ 'color_count',
+ 'individuations',
'prunings',
- 'initial_color_count',
- 'adjacent_nodes',
- 'initial_coloring_runtime',
- 'triple_count',
+ 'initial_color_count',
+ 'adjacent_nodes',
+ 'initial_coloring_runtime',
+ 'triple_count',
'graph_digest',
'to_hash_runtime',
'canonicalize_triples_runtime',
'error',
- ]
+ ]
+
def files_benchmark(ontologies, output_file, threads):
w = open(output_file, 'w')
- writer = csv.DictWriter(w,stat_cols)
+ writer = csv.DictWriter(w, stat_cols)
writer.writeheader()
tasks = Queue()
finished_tasks = Queue()
dl_lock = Semaphore(4)
task_count = len(ontologies)
- def worker(q,finished_tasks, dl_lock):
+
+ def worker(q, finished_tasks, dl_lock):
try:
while True:
stats = q.get()
@@ -73,13 +75,13 @@ def files_benchmark(ontologies, output_file, threads):
pass
for i in range(int(threads)):
print "Starting worker", i
- t = Process(target=worker, args=[tasks,finished_tasks, dl_lock])
+ t = Process(target=worker, args=[tasks, finished_tasks, dl_lock])
t.daemon = True
t.start()
for download in ontologies:
stats = defaultdict(str)
stats.update({
- "id":download.split("/")[-1].split(".")[0],
+ "id": download.split("/")[-1].split(".")[0],
"ontology": download.split("/")[-1].split(".")[0],
"download_url": download
})
@@ -88,27 +90,29 @@ def files_benchmark(ontologies, output_file, threads):
written_tasks = 0
while written_tasks < task_count:
stats = finished_tasks.get()
- #print "Writing", stats['ontology']
+ # print "Writing", stats['ontology']
writer.writerow(stats)
w.flush()
written_tasks += 1
+
def bioportal_benchmark(apikey, output_file, threads):
metadata = Namespace("http://data.bioontology.org/metadata/")
- url = 'http://data.bioontology.org/ontologies?apikey=%s'%apikey
+ url = 'http://data.bioontology.org/ontologies?apikey=%s' % apikey
ontology_graph = Graph()
print url
ontology_list_json = urlopen(url).read()
ontology_graph.parse(StringIO(unicode(ontology_list_json)), format="json-ld")
ontologies = ontology_graph.query(bioportal_query)
w = open(output_file, 'w')
- writer = csv.DictWriter(w,stat_cols)
+ writer = csv.DictWriter(w, stat_cols)
writer.writeheader()
tasks = Queue()
finished_tasks = Queue()
dl_lock = Semaphore(4)
task_count = len(ontologies)
- def worker(q,finished_tasks, dl_lock):
+
+ def worker(q, finished_tasks, dl_lock):
try:
while True:
stats = q.get()
@@ -116,7 +120,7 @@ def bioportal_benchmark(apikey, output_file, threads):
try:
try:
dl_lock.acquire()
- og.load(stats['download_url']+"?apikey=%s"%apikey)
+ og.load(stats['download_url'] + "?apikey=%s" % apikey)
finally:
dl_lock.release()
print stats['ontology'], stats['id']
@@ -131,13 +135,13 @@ def bioportal_benchmark(apikey, output_file, threads):
pass
for i in range(int(threads)):
print "Starting worker", i
- t = Process(target=worker, args=[tasks,finished_tasks, dl_lock])
+ t = Process(target=worker, args=[tasks, finished_tasks, dl_lock])
t.daemon = True
t.start()
for ontology, title, download in ontologies:
stats = defaultdict(str)
stats.update({
- "id":ontology,
+ "id": ontology,
"ontology": title,
"download_url": download
})
@@ -146,13 +150,13 @@ def bioportal_benchmark(apikey, output_file, threads):
written_tasks = 0
while written_tasks < task_count:
stats = finished_tasks.get()
- #print "Writing", stats['ontology']
+ # print "Writing", stats['ontology']
writer.writerow(stats)
w.flush()
written_tasks += 1
if __name__ == '__main__':
if len(sys.argv) > 4:
- files_benchmark(sys.argv[1:-2],sys.argv[-2],sys.argv[-1])
+ files_benchmark(sys.argv[1:-2], sys.argv[-2], sys.argv[-1])
else:
bioportal_benchmark(sys.argv[1], sys.argv[2], sys.argv[3])