Skip to main content

No project description provided

Project description

Text2Story main 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.

Structure

.
│   README.md
|   env.yml
│   requirements.txt
|
└──Text2Story
      └──core
      │   │   annotator.py (META-annotator)
      │   │   entity_structures.py (ActorEntity, 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)
      │   
      └───annotators (tools supported by the package to do the extractions)
      |   |   NLTK
      |   │   PY_HEIDELTIME
      |   |   SPACY
|
└── Webapp
      |  backend.py
      |  main.py
      |  session_state.py
      |  input_phase.py
      |  output_phase.py

Classes

Entity classes

  • ActorEntity 🟢

    • attributes
      • text : str
      • character_span : (int, int)
      • value : str
      • type : str
      • individuation : str (HARDCODED)
      • involvement : str (HARDCODED)
  • TimexEntity 🟢

    • attributes
      • text : str
      • character_span : (int, int)
      • value : str
      • type : str
      • temporal_function : boolean (HARDCODED)
      • anchor_time : str (HARDCODED)
  • EventEntity 🟢

    • attributes
      • text : str
      • character_span : str
      • event_class : str (HARDCODED)
      • polarity : str (HARDCODED)
      • factuality : str (HARDCODED)
      • tense : str (HARDCODED)

Link classes

  • TemporalLink 🔴

  • AspectualLink 🔴

  • SubordinationLink 🔴

  • SemanticRoleLink 🟢

    • attributes
      • type : str
      • actor : str
      • event : str
  • ObjectalLink 🟢

    • attributes
      • type : str (HARDCODED)
      • arg1 : str
      • arg2 : str

Other classes

  • Narrative

    • attributes
      • lang : str 🟢
      • text : str 🟢
      • publication_time : str 🟢
      • actors : {str -> ActorEntity} 🟢
      • timex : {str -> TimexEntity} 🟢
      • events : {str -> EventEntity} 🟢
      • tlinks : 🔴
      • ref_rels : 🔴
      • obj_links : {str -> SemanticRoleLink} 🟢
      • sem_links : {str -> ObjectalLink} 🟢
    • methods
      • extract_actors: given a list of tools to do the extraction with, updates self.actors and returns it 🟢
      • extract_times: given a list of tools to do the extraction with, updates self.timexs and returns it 🟢
      • extract_events: given a list of tools to do the extraction with, updates self.events and returns it 🟢
      • extract_semantic_role_links: given a list of tools to do the extraction with, finds semantic role links between extracted actors (self.actors) and events (self.events), updates self.sem_links and returns it. 🟢
      • extract_objectal_links: given a list of tools to do the extraction with, updates self.obj_links and returns it 🟢
      • tempsort_events: given two or more events (spans?), outputs the temporal relationship between them. Output ISO dictionary. 🔴
      • ISO_annotation: returns ISO annotation in .ann format 🟢
      • import_ISO_annotation: imports ISO annotation from file (may not be trivial, because of the organization by type) 🔴
      • drs: outputs list with drs formulae (txt) 🔴
      • compare_annotations: compare ISO annotation given with the one here (should annotation be an attribute) 🔴
  • drs 🔴

    • attributes
      • drs: list with text or structure with formulae
    • methods
      • msc: plot msc
      • kowledge_graph: plot knowledge_graph
      • icons: plot icon strip
      • pretty_print:

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 actors, then they implement a function named 'extract_actors', with two arguments: the language of text and the text itself.

Extractions Interface Supporting tools
Actor extract_actors(lang, text) SPACY, NLTK
Timexs extract_timexs(lang, text, publication_time) PY_HEIDELTIME
ObjectalLink extract_objectal_links(lang, text, publication_time) ALLENNLP
Event extract_events(lang, text, publication_time) ALLENNLP
SemanticLink extract_semantic_role_link(lang, text, publication_time) ALLENNLP

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.)

And it should be done.

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

Usage

Installation

The installation requires graphviz software.

Terminal

import text2story as t2s # Import the package

t2s.start() # Load the pipelines

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_actors() # Extraction done with all tools.
doc.extract_actors('spacy', 'nltk') # Extraction done with the SPACY and NLTK tools.
doc.extract_actors('allennlp') # Extraction done with just the ALLENNLP tool.

doc.extract_times() # Extraction done with all tools (same as specifying 'py_heideltime', since we have just one tool to extract timexs)

doc.extract_objectal_links() # Extraction of objectal links from the text with all tools (needs to be done after extracting actors, since it requires actors to make the co-reference resolution)

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 actor and an event)

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)

Web app

python backend.py
streamlit run main.py

and a page on your browser will open!

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

text2story-1.2.21.tar.gz (534.2 kB view details)

Uploaded Source

Built Distribution

text2story-1.2.21-py3-none-any.whl (551.1 kB view details)

Uploaded Python 3

File details

Details for the file text2story-1.2.21.tar.gz.

File metadata

  • Download URL: text2story-1.2.21.tar.gz
  • Upload date:
  • Size: 534.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for text2story-1.2.21.tar.gz
Algorithm Hash digest
SHA256 3b0a9b799c1a308339700e928b6c8480b546ca0c2de9e4aab74a5b3cdd6d7e0d
MD5 0db4ff9039e06caf8f68569b4b752036
BLAKE2b-256 885437f08b1520b11502addf0727f93a5e625385346c23545c8c4eac9f951a67

See more details on using hashes here.

Provenance

File details

Details for the file text2story-1.2.21-py3-none-any.whl.

File metadata

  • Download URL: text2story-1.2.21-py3-none-any.whl
  • Upload date:
  • Size: 551.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for text2story-1.2.21-py3-none-any.whl
Algorithm Hash digest
SHA256 f2b157ed02b41c1d5fb4638472cb0c0b3f8d242c89edf508b353a58002d99850
MD5 a5738a6ab370d43ba10d52e1c3139801
BLAKE2b-256 0641639389bf62722b3bbd255570d5408063fef026a3070d910d15fc0d5ab457

See more details on using hashes here.

Provenance

Supported by

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