An annotated sentence consists of annotated tokens, which can be tokens, tokens with annotations, or stand-alone annotations. Annotations can be attached to tokens or entered independently with token span information in the form of begin-end (end is inclusive, ids start with 1). Annotated tokens are separated by one or more space characters. Annotations are separated by a single / (slash) character. Each annotation type is defined by the field position in the list of annotations. Annotations for a specific annotation type can be skippped (empty field or explicitly indicated by a single _ (underscore) character as annotation value). Annotations are either span annotations or relation annotations. Relation annotations are defined by the annotation value (relation name) and the span id (annotated token id) of its head (ids are starting from 1) separated by a : (colon) character. Relations can only be connected to span annotations (never tokens) and are always connected to the annotation type directly in front of the relation annotation (hence, relation annotations must always occur after a non-empty span annotation). Head span ids are referring to the span annotation with the given id and the same annotation type (field). Relation annotations of the same type for the same span annotation (i.e. multiple heads) can be accumulated with ; (semicolon).
word1/span11/span21 word2//span22 word3/span12 ... word1/span11/rel1:3/span2/rel2:2 word2/_/_/span22 word3/span12 ... word1 word2 word3 word4 word5 /1-2/span1/rel1:7;rel2:8 /3-3/span2 /4-5/span3 ...
Generate annotated sentence with spacy:
python -c "import spacy; nlp=spacy.load('en_core_web_sm'); doc=nlp('Angela Merkel lives in Berlin.'); print(' '.join(['/'.join([t.text, t.pos_, f'{t.dep_}:{t.head.i+1 if t.head.i != t.i else 0}', t.tag_, t.lemma_, t.ent_type_]) for t in doc]) + ' ' + ' '.join(['/'.join([f'/{e.start+1}-{e.end}/////', e.text.replace(' ','_'), e.label_, e.kb_id_]) for e in doc.ents]))"
Install spacy and spacy model beforehand:
pip install -U spacy
python -m spacy download en_core_web_sm
Help for modifying the brat layout can be found here: http://brat.nlplab.org/embed.html.
This website was built using: