Code to filter document with respect to the presence of a specific annotation:
def filter_by_annotation(annotated_docs, pymedext_docs, filters):
docs = []
index = 0
for d in annotated_docs:
document_added = False
for a in d['annotations']:
if a['type'] in filters:
if(not document_added):
docs.append(pymedext_docs[index])
document_added = True
index += 1
return docs
Code to filter document with respect to the presence of a specific annotation: