Skip to main content

Transform tei xml to a simple standoff format

Project description

Flatten Tei

Reformat tei-xml files to raw text + standoff annotations in json (flatdoc)

  • flatdoc is not a standardized format
  • flatdoc is a json file containing the whole text of a document in the textfield
    • All span annotations are in 'annotations' in form of an object.
    • e.g. {"Sentence": [{'begin':0, 'end': 13}, ...], ..}

Access content of flatdoc files

Use Case: Get all Sentences of a document in flatdoc-format

  • Assuming there are Sentence annotation.
from flattentei import get_units

fn = <filename of flatdoc json file>

with open(fn) as f:
    flatdoc = json.load(f)
    sentences = get_units("Sentence", flatdoc)

Use Case: Get all Entities of a document in flatdoc-format

  • Assuming the entities are stored as Entity in the annotations field
  • (In the GSAP project ScholarlyEntitiy)
  • enrich each entity with Sentence-texts
    • They can be found in the container field for each entity
from flattentei import get_units

fn = <filename of flatdoc json file>

with open(fn) as f:
    flatdoc = json.load(f)
    entities = get_units("Entity", flatdoc, enrich_container="Sentence")


for ent in entities:
    print(f'The entity span: {ent["text"]}')
    sentence_text = ent['containers']['Sentence']['text']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flattentei-0.1.6.tar.gz (9.5 kB view details)

Uploaded Source

File details

Details for the file flattentei-0.1.6.tar.gz.

File metadata

  • Download URL: flattentei-0.1.6.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.6

File hashes

Hashes for flattentei-0.1.6.tar.gz
Algorithm Hash digest
SHA256 f69e430ca5006992d7c2c6a5517d4b71aba4739edf9902766e0ad4d2b71283c4
MD5 192d5b1f419275ee78867e92a9c1b77d
BLAKE2b-256 352363907fc527b567ba6e0522e12a70a2dcd9691291f27bcff80bf036b7d2a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page