예제 #1
0
def brat2bioc_entity(bratentity: BratEntity) -> BioCAnnotation:
    ann = BioCAnnotation()
    ann.id = bratentity.id
    ann.text = bratentity.text
    ann.infons['type'] = bratentity.type
    for span in bratentity.locations:
        ann.add_location(BioCLocation(span.begin, span.end - span.begin))
    return ann
 def to_bioc(self):
     entity_bioc = BioCAnnotation()
     entity_bioc.infons['type'] = self.type
     entity_bioc.text = self.text
     entity_bioc.id = str(self.id)
     location = BioCLocation(self.start, len(self.text))
     entity_bioc.add_location(location)
     return entity_bioc
예제 #3
0
 def __parse_annotation(self, tree):
     annotation = BioCAnnotation()
     annotation.id = tree.attrib['id']
     annotation.infons = self.__parse_infons(tree)
     annotation.text = tree.findtext('text')
     for child in tree.findall('location'):
         annotation.add_location(
             BioCLocation(int(child.attrib['offset']), int(child.attrib['length'])))
     return annotation
def add_annotation(triple, annotation_id):
    # initialize annotation element
    bioc_annotation = BioCAnnotation()
    # MeSH term in a tag <text> ... </text> (origininal term, searched case insensitive)
    bioc_annotation.text = triple[2]
    # generate XML structure for the annotation and add infon
    bioc_annotation.id = str(annotation_id)
    bioc_annotation.put_infon('type', 'MeSH term')
    # add location element
    bioc_location = BioCLocation()
    # add length of MeSH term
    bioc_location.length = str(triple[1])
    # add start position (offset) 
    bioc_location.offset = str(triple[0])
    bioc_annotation.add_location(bioc_location)
    return bioc_annotation
예제 #5
0
def add_annotation(triple, annotation_id):
    # initialize annotation element
    bioc_annotation = BioCAnnotation()
    # MeSH term in a tag <text> ... </text> (origininal term, searched case insensitive)
    bioc_annotation.text = triple[2]
    # generate XML structure for the annotation and add infon
    bioc_annotation.id = str(annotation_id)
    bioc_annotation.put_infon('type', 'MeSH term')
    # add location element
    bioc_location = BioCLocation()
    # add length of MeSH term
    bioc_location.length = str(triple[1])
    # add start position (offset)
    bioc_location.offset = str(triple[0])
    bioc_annotation.add_location(bioc_location)
    return bioc_annotation
예제 #6
0
 def __read_annotation(self, start_elem):
     ann = BioCAnnotation()
     ann.id = start_elem.get('id')
     while self.__has_next():
         event, elem = self.__next_event()
         if event == 'start':
             pass
         elif event == 'end':
             if elem.tag == 'text':
                 ann.text = elem.text
             elif elem.tag == 'infon':
                 ann.infons[elem.get('key')] = elem.text
             elif elem.tag == 'location':
                 ann.add_location(BioCLocation(int(elem.get('offset')), int(elem.get('length'))))
             elif elem.tag == 'annotation':
                 return ann
     raise RuntimeError("should not reach here")  # pragma: no cover