Skip to main content

Build character graphs from text.

Project description

tex2net

Build Status PyPI version License Python Versions

Overview

tex2net is a Python library designed to convert narrative texts into interactive network graphs that visualize character interactions. The library leverages Natural Language Processing (NLP) with spaCy, text rewriting and summarization using Transformer models (T5), network analysis with NetworkX, and interactive visualization with Pyvis and Matplotlib. This tool is perfect for researchers, data scientists, and digital humanities scholars looking to explore complex narrative structures.

Features

  • Text Preprocessing & Entity Extraction: Extract characters from text using spaCy's Named Entity Recognition.
  • Graph Construction: Build directed graphs representing character interactions, annotated with actions and sentence IDs.
  • Node Merging: Combine nodes with similar character names for consistency.
  • Text Rewriting & Summarization: Use T5 models to rephrase or summarize text, emphasizing clear character-verb-character structures.
  • Network Analysis: Compute centrality measures, detect communities, analyze temporal relationships, and more.
  • Visualization: Create both static (Matplotlib) and interactive (Pyvis) visualizations for in-depth narrative analysis.

Installation

Install the package via pip:

pip install tex2net

tex2net currently supports Python 3.10 and newer.

Make sure you have all the required dependencies. You can also install them using the provided requirements.txt if needed. You may need to run:

pip install --upgrade typing_extensions
python -m spacy download en_core_web_lg

Usage Example

Below is an example of how to use tex2net to create a character graph from sample text:

import tex2net

# Sample text data (this could be text from a novel, article, or LaTeX file)
text_data = """
Alice was discussing ideas with Bob. Later, Bob met Charlie.
"""

# Create a character graph from the text data
graph, characters, relationships = tex2net.create_character_graph(text_data)

# Optionally, join similar nodes to merge duplicate character entries
joined_graph = tex2net.join_similar_nodes(graph, characters)

tex2net.visualize_directed_graph(joined_graph, title="Character Relationships Directed Graph")

For more complex text the create_character_graph_llm_chunked function can be used.

For longer texts use create_character_graph_llm_long_text.

More functions are instantiated in example_usage.ipynb.

Gallery and GitHub Pages showcase

This repository now includes a static gallery in docs/index.html together with generated example assets in docs/generated.

To rebuild the gallery locally:

python scripts/build_gallery.py

The Pages workflow in .github/workflows/pages.yml rebuilds and publishes the gallery automatically.

Contributing

Contributions are welcome! Feel free to submit pull requests or open issues to improve the functionality of this library. Please follow the code style and add tests for any new features.

Release process

Releases are published to PyPI with GitHub Actions and PyPI Trusted Publishing.

  1. Update the version in pyproject.toml.
  2. Merge the change into main.
  3. Create and push a version tag such as v1.41.
  4. Wait for the Release tex2net to PyPI workflow to finish.

The publishing job expects a GitHub environment named pypi and a matching Trusted Publisher entry on PyPI for this repository and workflow file.

License

This project is licensed under the GPL-3.0 License.


Happy storytelling and network exploring!

Citation

If you find tex2net helpful in your academic or professional work, please cite the following paper:

@inproceedings{aparicio2023tex2net,
  title={tex2net: A Package for Storytelling Using Network Models},
  author={Aparicio, Joao Tiago and Arsenio, Elisabete and Henriques, Rui},
  booktitle={Proceedings of the 41st ACM International Conference on Design of Communication},
  pages={119--125},
  year={2023}
}

or

Aparicio, J. T., Arsenio, E., & Henriques, R. (2023, October). tex2net: A Package for Storytelling Using Network Models. In Proceedings of the 41st ACM International Conference on Design of Communication (pp. 119-125).

You can find the paper at ACM Digital Library: https://dl.acm.org/doi/pdf/10.1145/3615335.3623022.

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

tex2net-1.41.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tex2net-1.41-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file tex2net-1.41.tar.gz.

File metadata

  • Download URL: tex2net-1.41.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tex2net-1.41.tar.gz
Algorithm Hash digest
SHA256 0f42ffb738b87672cd0b5503283122d6b264fec8d38f0987eb3811be4cfcdfac
MD5 b4672199bee098fcb71ae8c772e2fc8c
BLAKE2b-256 04e8d4f00ce4d3373e33d3aa3d3f1d384372908e7b723ccf90d02e2903218197

See more details on using hashes here.

Provenance

The following attestation bundles were made for tex2net-1.41.tar.gz:

Publisher: release.yml on jtaca/tex2net

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tex2net-1.41-py3-none-any.whl.

File metadata

  • Download URL: tex2net-1.41-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tex2net-1.41-py3-none-any.whl
Algorithm Hash digest
SHA256 f68a0632353648aae889b2b9105187a56f485117456c238f8cb4b3a340cbe9bf
MD5 dff0ad2604b85f1ff92ddad1815e2d1a
BLAKE2b-256 85ae43f8c92f660e5d25f496c302468c417240528e679e558ab54c15e957011a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tex2net-1.41-py3-none-any.whl:

Publisher: release.yml on jtaca/tex2net

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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