<s> from __future__ import absolute_import , unicode_literals <EOL> import os <EOL> import xml . etree . ElementTree as ET <EOL> import poioapi . io . graf <EOL> class Parser ( poioapi . io . graf . BaseParser ) : <EOL> def __init__ ( self , filepath ) : <EOL> self . filepath = filepath <EOL> ( self . basedirname , _ ) = os . path . splitext ( os . path . abspath ( self . filepath ) ) <EOL> self . parse ( ) <EOL> def parse ( self ) : <EOL> self . root = ET . parse ( self . filepath ) . getroot ( ) <EOL> self . documents_map = { } <EOL> self . documents = [ ] <EOL> def get_root_tiers ( self ) : <EOL> return [ poioapi . io . graf . Tier ( '<STR_LIT>' ) ] <EOL> def get_child_tiers_for_tier ( self , tier ) : <EOL> pass <EOL> def get_annotations_for_tier ( self , tier , annotation_parent = None ) : <EOL> annotations = [ ] <EOL> last_position = <NUM_LIT:0> <EOL> if tier . name == "<STR_LIT>" : <EOL> for a , annotation in enumerate ( self . root ) : <EOL> text = annotation . text <EOL> id = annotation . attrib [ "<STR_LIT:id>" ] <EOL> features = { "<STR_LIT:title>" : annotation . attrib [ "<STR_LIT:title>" ] , <EOL> "<STR_LIT:url>" : annotation . attrib [ "<STR_LIT:url>" ] } <EOL> annotations . append ( poioapi . io . graf . Annotation ( id , <EOL> None , features ) ) <EOL> if len ( annotation ) is not <NUM_LIT:0> : <EOL> text += annotation [ <NUM_LIT:0> ] . tail <EOL> self . documents_map [ id ] = ( last_position , last_position + <EOL> len ( text ) + <NUM_LIT:1> ) <EOL> self . documents . append ( text ) <EOL> last_position += len ( text ) + <NUM_LIT:1> <EOL> return annotations <EOL> def region_for_annotation ( self , annotation ) : <EOL> return self . documents_map [ annotation . id ] <EOL> def tier_has_regions ( self , tier ) : <EOL> if tier . name == '<STR_LIT>' : <EOL> return True <EOL> return False <EOL> def get_primary_data ( self ) : <EOL> """<STR_LIT>""" <EOL> primary_data = poioapi . io . graf . PrimaryData ( ) <EOL> primary_data . type = poioapi . io . graf . TEXT <EOL> primary_data . content = "<STR_LIT:\n>" . join ( self . documents ) <EOL> return primary_data </s>
