spaCy Aligner
The spacy_aligner is a custom spaCy component designed to connect entities in text and build relational graphs based on these connections. It utilizes both spaCy's powerful NLP capabilities and NetworkX for graph management, making it an excellent tool for complex entity relationship analysis in large texts.
Installation
To install spacy_aligner, you will need Python 3.7 or newer. You can install this package directly from PyPI (once uploaded) or through the repository if it is hosted on a site like GitHub.
pip install spacy_aligner
Or, if you have the source code:
git clone https://github.com/yourgithub/spacy_aligner
cd spacy_aligner
python setup.py install
Usage
Here's a quick start example to use spacy_aligner:
import spacy
from spacy_aligner.pipeline import Aligner
import json
import networkx as nx
import matplotlib.pyplot as plt
# Load external data
links = {
"PERSON": {
"Elizabeth": ["Liz", "Lizzie", "Beth", "Betsy", "Eliza"],
"William": ["Will", "Bill", "Billy", "Liam"],
}
}
# Load the spaCy model
nlp = spacy.load("en_core_web_lg")
# Add the custom pipeline component to the spaCy pipeline
nlp.add_pipe("aligner", config={"links": links})
text = """Elizabeth Jenkins went to school. She works at Mattingly Autoparts.
Liz is 20. She also goes by Lizzie. Mrs. Jenkins teaches students.
Once she completes her PhD, she will be Dr. Elizabeth P. Jenkins.
William also goes by Will.
His full name is William Mattingly."""
# Process the text
doc = nlp(text)
# Access the generated graph
G = doc._.graph
Visualization
The spacy_aligner also includes a function to visualize the relationship graph generated:
def visualize_graph(G):
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels=True, node_color='lightblue', node_size=500, edge_color='gray', linewidths=1, font_size=12)
plt.show()
visualize_graph(doc._.graph)
This function uses matplotlib to plot the graph, showing the relationships between detected entities based on the document text.
Metadata
Release files for spacy-aligner 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spacy_aligner-0.0.1.tar.gz | 3.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spacy_aligner-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.5 kB
Release files / spacy_aligner-0.0.1.tar.gz
| Download URL | spacy_aligner-0.0.1.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
98d4729a22f3f8efe7c560611a218e57085dcda133da4e25cdeff7b80eaed529
|
|
BLAKE2b-256 checksum How to use checksums |
a31bb16796df363fd6befcd6c0fe1e5563345d1a0184d081c2984e592800be33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / spacy_aligner-0.0.1-py3-none-any.whl
| Download URL | spacy_aligner-0.0.1-py3-none-any.whl |
|---|---|
| Size | 3.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b4d192a3222e357a36a147b12645783d9104993b6211643e77af506523382f5
|
|
BLAKE2b-256 checksum How to use checksums |
3838776487561688b6c5be0db030d6135eb892228f5307212d53dd1e042d1aad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|