Skip to main content

A spaCy component for connecting entities and building relational graphs in text.

Project description

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.

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

spacy_aligner-0.0.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

spacy_aligner-0.0.1-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file spacy_aligner-0.0.1.tar.gz.

File metadata

  • Download URL: spacy_aligner-0.0.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for spacy_aligner-0.0.1.tar.gz
Algorithm Hash digest
SHA256 98d4729a22f3f8efe7c560611a218e57085dcda133da4e25cdeff7b80eaed529
MD5 eff4c6b4e9f4b406e590a93e46705c73
BLAKE2b-256 a31bb16796df363fd6befcd6c0fe1e5563345d1a0184d081c2984e592800be33

See more details on using hashes here.

File details

Details for the file spacy_aligner-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for spacy_aligner-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b4d192a3222e357a36a147b12645783d9104993b6211643e77af506523382f5
MD5 d80e679f5b0f9bfa036bdce63cf7648e
BLAKE2b-256 3838776487561688b6c5be0db030d6135eb892228f5307212d53dd1e042d1aad

See more details on using hashes here.

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