Commit a0fdafcd authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Replace single document handling with dictionary documents handling for dbxref resolver

parent 3b7d874f
def dbxrefs_from(document):
def dbxrefs_from_documents(documents):
refs = set()
for key in documents:
return refs
def dbxrefs_from_document(document):
'''finds all dbxrefs in the document and returns a list of ids'''
refs = []
for c in document['computations']:
......@@ -7,7 +13,11 @@ def dbxrefs_from(document):
return set(refs)
def combine(document, informations):
def combine_with_documents(documents, informations):
for k in documents:
combine_with_document(documents[k], informations)
def combine_with_document(document, informations):
'''adds an information tag for each result that references a dbxref'''
for c in document['computations']:
for r in c['results']:
......@@ -15,11 +15,11 @@ args = parser.parse_args()
with open(args.input, 'r') as json_file:
j = json.load(json_file)
# extract all dbxrefs
dbxrefs = dbxref.dbxrefs_from(j)
dbxrefs = dbxref.dbxrefs_from_documents(j)
# retrieve information for dbxrefs
entries = retrieve(convert_to_dbxrefs(sorted(dbxrefs)))
# add information field to results
dbxref.combine(j, entries)
dbxref.combine_with_documents(j, entries)
# write updated json
with open(args.output, 'w') as o:
json.dump(j, o)
......@@ -25,7 +25,7 @@ class TestDbXrefs(unittest.TestCase):
'text' : 'some text'
dbxref.combine(test_data, test_information)
dbxref.combine_with_document(test_data, test_information)
self.assertTrue('text' in test_data['computations'][0]['results'][0]['informations'])
self.assertEqual(test_data['computations'][0]['results'][0]['informations']['text'], 'some text')
......@@ -36,7 +36,7 @@ class TestDbXrefs(unittest.TestCase):
with open(test_file, 'r') as f:
data = json.load(f)
# extract dbxrefs
dbxrefs = dbxref.dbxrefs_from(data)
dbxrefs = dbxref.dbxrefs_from_document(data)
# test if all expected dbxrefs were found
self.assertEqual(dbxrefs, set([
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment