Skip to main content

The text2story package

The text2story main package contains the main classes and methods for the T2S pipeline: from text to formal representation to visualization or other representation.

  • Relation to Brat2Viz

The Text2Story package is a generalization of Brat2Viz and should in fact contain all the funcionalities and variants of the T2S project output.

Table of Contents

  1. Getting Start.
  2. The Framework Structure.
  3. The Annotators.
  4. Installation.
  5. The Web App.

1. Getting Started

The main goal of the text2story is to extract narrative from raw text. The narrative components comprise events, the participants (or participants) in the events, and the time expressions.

  • Event: Eventuality that happens or occurs or state or circumstance that is temporally relevant
  • Time: Temporal expressions that represent units of time.
  • Participants: Named entities, or participants, that play an important role in the event or state.

These elements relate to each other by some relations, like Semantic Role Links and Objectal Links.

  • Objectal Links: It states how two discourse entities are referentially related to one another. For instance, there is the "identity" objectal link, which links entities that refer to the same referents, and there is the "part of" objectal link, which links a referent that is part of another.
  • Semantic Role Links: The identification of the way an entity is involved/participates in an eventuality. For instance, there is the "agent" semantic role link, in which an event is linked to a participant that intentionally caused it.

A simple code to perform the extraction of the narrative elements, and the two type of relations described above is like the following.

import text2story as t2s # Import the package

t2s.load("en") # Load the pipelines for the English language

text = 'On Friday morning, Max Healthcare, which runs 10 private hospitals around Delhi, put out an "SOS" message, saying it had less than an hour\'s supply remaining at two of its sites. The shortage was later resolved.'

doc = t2s.Narrative('en', text, '2020-05-30')

doc.extract_participants() # Extraction done with all tools.
doc.extract_participants('spacy', 'nltk') # Extraction done with the SPACY and NLTK tools.
doc.extract_participants('srl') # Extraction done with just the SRL tool.

doc.extract_times() # Extraction done with all tools 

doc.extract_events() # Extraction of events with all tools
doc.extract_semantic_role_link() # Extraction of semantic role links with all tools (should be done after extracting events since most semantic relations are between an participant and an event)
doc.extract_objectal_links()# Extraction of objectal links with all tools (should be done after extracting participants because objectal links are between participants)

ann_str = doc.ISO_annotation() # Outputs ISO annotation in .ann format (txt) in a file called 'annotations.ann'
with open('annotations.ann', "w") as fd:
    fd.write(ann_str)

2. Framework Structure

.
│   README.md
|   env.yml
│   requirements.txt
|
└──Text2Story
      └──core
      │   │   annotator.py (META-annotator)
      │   │   entity_structures.py (ParticipantEntity, TimexEntity and EventEntity classes)
      │   |   exceptions.py (Exceptions raised by the package)
      │   |   link_structures.py (TemporalLink, AspectualLink, SubordinationLink, SemanticRoleLink and ObjectalLink classes)
      │   |   narrative.py (Narrative class)
      │   |   utils.py (Utility functions)
      │
      └───readers (tools to support the reading of some specific kind of annotated corpus)
      |   | read.py (Abstract class: defines the structure of a reader)
      |   | TokenCorpus (Internal representation of a token, its annotations and relations)
      |   | read_brat.py (it reads annotated file of type supported the BRAT annotation tool)
      |   | read_ecb.py (it processes ecb+ corpus format)
      |   | read_framenet.py (it processes Framenet corpus format)
      |   | read_propbank.py (it processes Propbank corpus format)  
      └───annotators (tools supported by the package to do the extractions)
      |   |   NLTK
      |   │   PY_HEIDELTIME
      |   |   BERTNERPT
      |   |   LUSA
      |   |   MAVERICK
      |   |   DBPEDIA
      |   |   SPACY
      |   |   SRL
      └───experiments
      |   |   evaluation.py (it performs batch evaluation of narrative corpora)
      |   |   metrics.py (it implements some specific metrics, like relaxed recall and relaxed precision)
      |   |   stats.py (it counts some narrative elements, and produce some stats of the narrative corpora)
      └───visualization
      |   |   brat2viz: a module that converts a BRAT annotation file to visual representations, like  Message Sequence Chart (MSC) and (Knowledge Graph) KG
      |   |   viz: a module that contain bubble_tikz.py, a class dedicate to build Bubble diagrams
      
└── Webapp
      |  backend.py
      |  main.py
      |  session_state.py
      |  input_phase.py
      |  output_phase.py

3. The Annotators

All annotators have the same interface: they implement a function called 'extract_' followed by the name of the particular extraction. E.g., if they are extracting participants, then they implement a function named 'extract_participants', with two arguments: the language of text and the text itself.

Extractions Interface Supporting tools
Participant extract_participants(lang, text, url(optional for DBPedia)) SPACY, NLTK , SRL, BERTNERPT, LUSA
Timexs extract_timexs(lang, text, publication_time) PY_HEIDELTIME, LUSA
Event extract_events(lang, text) SRL, LUSA
SemanticLink extract_semantic_role_link(lang, text) SRL
ObjectalLink extract_objectal_links(lang, text) Maverick

To change some model used in the supported tools, just go to text2story/annotators/ANNOTATOR_TO_BE_CHANGED and change the model in the file: __init__.py.

To add a new tool, add a folder to text2story/annotators with the name of the annotator all capitalized (just a convention; useful to avoid name colisions). In that folder, create a file called '__init__.py' and there implement a function load() and the desired extraction functions. The function load() should load the pipeline to some variable defined by you, so that, every time we do an extraction, we don't need to load the pipeline all over again. (Implement it, even if your annotator doesn't load anything. Leave it with an empty body.)

In the text2story.annotators.__init__.py file, add a call to the load() function, and to the extract functions. (See the already implemented tools for guidance.)

PS: Don't forget to normalize the labels to our semantic framework!

4. Installation

4.1 Linux / Ubuntu

The installation requires graphviz software, the latex suite and the software poppler to convert pdf to png. In Linux, to install these software open a terminal and type the following commands:

sudo apt-get install graphviz libgraphviz-dev texlive-latex-base  texlive-latex-extra poppler-utils

After that, create a virtual enviroment using venv or other tool of your preference. For instance, using the following command in the prompt line:

$ python3 -m venv venv

Then, activate the virtual enviroment in the prompt line. Like, the following command:

$ source venv/bin/activate

After that, you are ready to install

4.2 Windows

First, make sure you have Microsoft C++ Build Tools. Then install graphviz software by download one suitable version in this link. Next, install the latex-suite like these tutorial explains. Then, install Popple packed for windows, which you download here.

Finnally, you can install text2story using pip. If it did not recognize the graphviz installation, then you can use the following command for pip (tested in pip == 21.1.1).

pip install text2story  --global-option=build_ext --global-option="-IC:\Program Files\Graphviz\include" --global-option="-LC:\Program Files\Graphviz\lib\"

For newer version of pip (tested in pip == 23.1.2), you can type the following command:

pip install --use-pep517  --config-setting="--global-option=build_ext"  --config-setting="--global-option=-IC:\Program Files\Graphviz\include" --config-setting="--global-option=-LC:\Program Files\Graphviz\lib"

Web App

#### Web app
```ssh
python backend.py
streamlit run main.py

and a page on your browser will open!

Metadata

Release files for text2story 1.6.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for text2story 1.6.11
File Size Uploaded Provenance Actions
text2story-1.6.11.tar.gz 1.4 MB Without provenance Details for text2story-1.6.11.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for text2story 1.6.11
File Interpreter ABI Platform Actions
text2story-1.6.11-py3-none-any.whl Python 3 none any Details for text2story-1.6.11-py3-none-any.whl

Total release size: 2.8 MB

Release files / text2story-1.6.11.tar.gz

Download URL text2story-1.6.11.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
7878708cbdade4f0d83616a5d7b914dde4253c806eb19a41024cbb1062d06d9c
BLAKE2b-256 checksum
How to use checksums
cadd8aa8bd5df3bae95eb2015fa34d119ac42e253155e8965c74390e10d0718c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Release files / text2story-1.6.11-py3-none-any.whl

Download URL text2story-1.6.11-py3-none-any.whl
Size 1.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
df02e943b90db378e6877562fb9cea703ef1595f4b68a3cf886daefa4e760ab8
BLAKE2b-256 checksum
How to use checksums
5bf1d07653a4d163eea17e1033219c2278231739e6f426c00d7808c82041e696
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Security for text2story 1.6.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.6.11 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page