An NLP-based data pipeline that analyzes the text of Alice's Adventures in Wonderland to perform Named Entity Recognition (NER), Sentiment Analysis, Co-occurrence Analysis, and visualize character interaction networks.
This project automatically extracts characters and analyzes their relationships from textual data. By integrating coreference resolution (preprocessed), sentence tokenization, name entity recognition, and sentiment analysis, the project constructs a weighted network graph representing how characters interact and their overall emotional polarity towards each other.
The workflow is divided into three key stages:
-
Named Entity Recognition (NER) & Character Extraction
- Tokenizes raw text into sentences (
SentTokenizer.py). - Identifies candidate character names using NER (
NameEntityRecognition.py). - Filters candidates based on frequency thresholds to isolate main characters.
- Tokenizes raw text into sentences (
-
Co-occurrence & Sentiment Analysis
- Processes coreference-resolved text (
AliceInWonderland-coref) for accurate entity tracking across sentences. - Calculates co-occurrence frequency between characters within sentence boundaries.
- Computes sentiment orientation and edge weights for character relationships (
Coocurence_Sentiment.py).
- Processes coreference-resolved text (
-
Network Graph Visualization
- Renders interactive/static character relationship networks using PyVis/NetworkX (
NetworkDisplay.py).
- Renders interactive/static character relationship networks using PyVis/NetworkX (
CharacterNetwork/
├── Coref/ # Coreference resolution models/data
├── CorefText/ # Coreference-resolved text output
├── Output/ # Generated network graphs & output figures
├── TextData/ # Raw input texts (e.g., AliceInWonderland.txt)
├── FileManagement.py # Text reading/writing utilities
├── SentTokenizer.py # Sentence tokenization pipeline
├── NameEntityRecognition.py # NER & frequency filtering
├── Coocurence_Sentiment.py # Co-occurrence matrix & sentiment analysis
├── NetworkDisplay.py # Network graph rendering
├── main.py # Main execution pipeline
└── requirments.txt # Project dependencies
Ensure you have Python 3.8+ installed.
Clone this repository and set up a virtual environment:
git clone https://github.com/Bencolie/CharacterNetwork.git
cd CharacterNetwork
# Create and activate a virtual environment
python -m venv venv1
source venv1/bin/activate # On Windows: venv1\Scripts\activate
# Install required dependencies
pip install -r requirments.txtRun the full pipeline using main.py:
python main.pyThe script processes the text and generates network graphs stored in the Output/ folder, displaying:
- Nodes: Main characters identified in the story.
- Edges: Connections indicating co-occurrence frequency and sentiment polarity between pairs of characters.