# tex2net
[](https://github.com/jtaca/tex2net/actions)
[](https://pypi.org/project/tex2net)
[](LICENSE)
[](https://pypi.org/project/tex2net)
## 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:
```bash
pip install tex2net
```
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:
```bash
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:
```python
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.
## 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.
## 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:
graphql
Copy
@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.
Raw data
{
"_id": null,
"home_page": null,
"name": "tex2net",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "knowledge-graph, NLP, unstructured-data, slm",
"author": "jtaca",
"author_email": "jtaca <joaotiagoaparicio@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/35/f7/092bf1a14f73691813cef17b8f8f5bdc8a39a6a47d343c8bec5675e44245/tex2net-1.34.tar.gz",
"platform": null,
"description": "# tex2net\n\n[](https://github.com/jtaca/tex2net/actions)\n[](https://pypi.org/project/tex2net)\n[](LICENSE)\n[](https://pypi.org/project/tex2net)\n\n## Overview\n\n**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.\n\n## Features\n\n- **Text Preprocessing & Entity Extraction:** Extract characters from text using spaCy's Named Entity Recognition.\n- **Graph Construction:** Build directed graphs representing character interactions, annotated with actions and sentence IDs.\n- **Node Merging:** Combine nodes with similar character names for consistency.\n- **Text Rewriting & Summarization:** Use T5 models to rephrase or summarize text, emphasizing clear character-verb-character structures.\n- **Network Analysis:** Compute centrality measures, detect communities, analyze temporal relationships, and more.\n- **Visualization:** Create both static (Matplotlib) and interactive (Pyvis) visualizations for in-depth narrative analysis.\n\n## Installation\n\nInstall the package via pip:\n\n```bash\npip install tex2net\n\n```\n\nMake sure you have all the required dependencies. You can also install them using the provided requirements.txt if needed. You may need to run:\n\n```bash\npip install --upgrade typing_extensions\npython -m spacy download en_core_web_lg\n```\n\n\n\n\n## Usage Example\n\nBelow is an example of how to use tex2net to create a character graph from sample text:\n\n```python\n\nimport tex2net\n\n# Sample text data (this could be text from a novel, article, or LaTeX file)\ntext_data = \"\"\"\nAlice was discussing ideas with Bob. Later, Bob met Charlie.\n\"\"\"\n\n# Create a character graph from the text data\ngraph, characters, relationships = tex2net.create_character_graph(text_data)\n\n# Optionally, join similar nodes to merge duplicate character entries\njoined_graph = tex2net.join_similar_nodes(graph, characters)\n\ntex2net.visualize_directed_graph(joined_graph, title=\"Character Relationships Directed Graph\")\n\n\n```\nFor more complex text the create_character_graph_llm_chunked function can be used. \n\nFor longer texts use create_character_graph_llm_long_text.\n\n\n\nMore functions are instantiated in example_usage.ipynb.\n\n\n## Contributing\n\nContributions 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.\n\n## License\n\nThis project is licensed under the GPL-3.0 License.\n\n---\n\nHappy storytelling and network exploring!\n\nCitation\n\nIf you find tex2net helpful in your academic or professional work, please cite the following paper:\n\ngraphql\nCopy\n@inproceedings{aparicio2023tex2net,\n title={tex2net: A Package for Storytelling Using Network Models},\n author={Aparicio, Joao Tiago and Arsenio, Elisabete and Henriques, Rui},\n booktitle={Proceedings of the 41st ACM International Conference on Design of Communication},\n pages={119--125},\n year={2023}\n}\n\nor \n\nAparicio, 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).\n\nYou can find the paper at ACM Digital Library: https://dl.acm.org/doi/pdf/10.1145/3615335.3623022.\n\n\n\n",
"bugtrack_url": null,
"license": "GPL-3",
"summary": "Build charachter graphs from text.",
"version": "1.34",
"project_urls": {
"Source": "https://github.com/jtaca/tex2net",
"Tracker": "https://github.com/jtaca/tex2net/issues"
},
"split_keywords": [
"knowledge-graph",
" nlp",
" unstructured-data",
" slm"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "3d39bff523e265e729f8e90f12ffab136898359d2c94afce17c3f9df01fbd7fe",
"md5": "b9c666b104682a83d71e95dedb0fbde9",
"sha256": "ed6450afbf60760aafc1f3f839dce6c3789e3b4598daa3711c77fe089f7de02a"
},
"downloads": -1,
"filename": "tex2net-1.34-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b9c666b104682a83d71e95dedb0fbde9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 26542,
"upload_time": "2025-03-28T23:43:01",
"upload_time_iso_8601": "2025-03-28T23:43:01.792132Z",
"url": "https://files.pythonhosted.org/packages/3d/39/bff523e265e729f8e90f12ffab136898359d2c94afce17c3f9df01fbd7fe/tex2net-1.34-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "35f7092bf1a14f73691813cef17b8f8f5bdc8a39a6a47d343c8bec5675e44245",
"md5": "e00d5c0e012fbe704bae54984ded06de",
"sha256": "af8cff740fc1b4519d17d7545cf04f35e066f0f2f230d5fc582dd5c834cd8253"
},
"downloads": -1,
"filename": "tex2net-1.34.tar.gz",
"has_sig": false,
"md5_digest": "e00d5c0e012fbe704bae54984ded06de",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 26756,
"upload_time": "2025-03-28T23:43:03",
"upload_time_iso_8601": "2025-03-28T23:43:03.611772Z",
"url": "https://files.pythonhosted.org/packages/35/f7/092bf1a14f73691813cef17b8f8f5bdc8a39a6a47d343c8bec5675e44245/tex2net-1.34.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-03-28 23:43:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jtaca",
"github_project": "tex2net",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "tex2net"
}