Given a list of ddlite Documents with PubTator/CDR annotations,
extract a dictionary of annotations by type.
annotations = defaultdict(list)
for a in doc.attribs["root"].xpath(".//annotation"):
// Relation annotations
if len(a.xpath("./infon[@key="relation"]")) > 0:
type = a.xpath("./infon[@key="relation"]/text()")[0]
types = a.xpath("./infon[@key != "relation"]/@key")
mesh_ids = a.xpath("./infon[@key != "relation"]/text()")
annotations[type].append(PubtatorRelation(types=types, mesh_ids=mesh_ids))
// Mention annotations
else:
txt = a.xpath("./text/text()")[0]