Metadata-Version: 2.1
Name: spacy-lancedb-linker
Version: 0.1.0
Summary: spaCy pipeline component for ANN Entity Linking using LanceDB
Home-page: https://guitton.co/
License: Apache-2.0
Keywords: spacy,spacy-pipeline,entity-linking,ann,lancedb
Author: Louis Guitton
Author-email: admin@guitton.co
Requires-Python: >=3.12,<4.0
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: lancedb (>=0.13.0,<0.14.0)
Requires-Dist: pydantic (>=2.9.2,<3.0.0)
Requires-Dist: sentence-transformers (>=3.1.1,<4.0.0)
Requires-Dist: spacy (>=3.7.6,<4.0.0)
Requires-Dist: tantivy (>=0.22.0,<0.23.0)
Project-URL: Documentation, https://guitton.co/
Project-URL: Repository, https://github.com/louisguitton/spacy-lancedb-linker
Description-Content-Type: text/markdown

# spacy-lancedb-linker

> spaCy pipeline component for ANN Entity Linking using LanceDB

## Installation

```python
pip install spacy-lancedb-linker
```

## Usage

```python
import spacy

from spacy_lancedb_linker.kb import AnnKnowledgeBase
from spacy_lancedb_linker.linker import AnnLinker  # noqa
from spacy_lancedb_linker.types import Alias, Entity

nlp = spacy.load("en_core_web_md")
kb = AnnKnowledgeBase(uri="data/sample-lancedb")
kb.add_entities(
    [
        Entity(**entity)
        for entity in [
            {
                "entity_id": "a3",
                "name": "Natural language processing",
                "description": "Natural language processing (NLP) is a subfield of linguistics, computer science, information engineering, and artificial intelligence concerned with the interactions between computers and human (natural) languages, in particular how to program computers to process and analyze large amounts of natural language data.",
            },
            {
                "entity_id": "a4",
                "name": "Neuro-linguistic programming",
                "description": "Neuro-linguistic programming (NLP) is a pseudoscientific approach to communication, personal development, and psychotherapy created by Richard Bandler and John Grinder in California, United States in the 1970s.",
            },
        ]
    ]
)
kb.add_aliases(
    [
        Alias(**alias)
        for alias in [
            {"alias": "NLP", "entities": ["a3", "a4"], "probabilities": [0.5, 0.5]},
            {
                "alias": "Natural language processing",
                "entities": ["a3"],
                "probabilities": [1.0],
            },
            {
                "alias": "Neuro-linguistic programming",
                "entities": ["a4"],
                "probabilities": [1.0],
            },
        ]
    ]
)

ann_linker = nlp.add_pipe("ann_linker", last=True)
ann_linker.set_kb(kb)

doc = nlp("NLP is a subset of machine learn.")

print(doc.ents[0].kb_id_)
print(doc.ents[0]._.alias_candidates)
print(doc.ents[0]._.kb_candidates)
```

## Test

```python
poetry install
poetry shell
poetry run pytest
```

## TODO

- setup trusted publisher github action https://medium.com/@blackary/publishing-a-python-package-from-github-to-pypi-in-2024-a6fb8635d45d

Other

- docs?
- more Github actions?
- add docker https://matt.sh/python-project-structure-2024#_living-with-pyproject.toml
- test coverage
- test across python versions
- use collections, itertools, more-itertools, boltons, sortedcontainers, diskcache, peewee, httpx, loguru, orjson

