spacy-lancedb-linker


Namespacy-lancedb-linker JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://guitton.co/
SummaryspaCy pipeline component for ANN Entity Linking using LanceDB
upload_time2024-09-22 20:04:07
maintainerNone
docs_urlNone
authorLouis Guitton
requires_python<4.0,>=3.12
licenseApache-2.0
keywords spacy spacy-pipeline entity-linking ann lancedb
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # spacy-lancedb-linker

> spaCy pipeline component for ANN Entity Linking using LanceDB

## Installation

```sh
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

```sh
poetry install
poetry shell
poetry run pytest
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://guitton.co/",
    "name": "spacy-lancedb-linker",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.12",
    "maintainer_email": null,
    "keywords": "spacy, spacy-pipeline, entity-linking, ann, lancedb",
    "author": "Louis Guitton",
    "author_email": "admin@guitton.co",
    "download_url": "https://files.pythonhosted.org/packages/a4/dc/a247c5a20b3a715124a4913527b1e5a4979c58a1b632b3cea25ae923d6d5/spacy_lancedb_linker-0.1.2.tar.gz",
    "platform": null,
    "description": "# spacy-lancedb-linker\n\n> spaCy pipeline component for ANN Entity Linking using LanceDB\n\n## Installation\n\n```sh\npip install spacy-lancedb-linker\n```\n\n## Usage\n\n```python\nimport spacy\n\nfrom spacy_lancedb_linker.kb import AnnKnowledgeBase\nfrom spacy_lancedb_linker.linker import AnnLinker  # noqa\nfrom spacy_lancedb_linker.types import Alias, Entity\n\nnlp = spacy.load(\"en_core_web_md\")\nkb = AnnKnowledgeBase(uri=\"data/sample-lancedb\")\nkb.add_entities(\n    [\n        Entity(**entity)\n        for entity in [\n            {\n                \"entity_id\": \"a3\",\n                \"name\": \"Natural language processing\",\n                \"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.\",\n            },\n            {\n                \"entity_id\": \"a4\",\n                \"name\": \"Neuro-linguistic programming\",\n                \"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.\",\n            },\n        ]\n    ]\n)\nkb.add_aliases(\n    [\n        Alias(**alias)\n        for alias in [\n            {\"alias\": \"NLP\", \"entities\": [\"a3\", \"a4\"], \"probabilities\": [0.5, 0.5]},\n            {\n                \"alias\": \"Natural language processing\",\n                \"entities\": [\"a3\"],\n                \"probabilities\": [1.0],\n            },\n            {\n                \"alias\": \"Neuro-linguistic programming\",\n                \"entities\": [\"a4\"],\n                \"probabilities\": [1.0],\n            },\n        ]\n    ]\n)\n\nann_linker = nlp.add_pipe(\"ann_linker\", last=True)\nann_linker.set_kb(kb)\n\ndoc = nlp(\"NLP is a subset of machine learn.\")\n\nprint(doc.ents[0].kb_id_)\nprint(doc.ents[0]._.alias_candidates)\nprint(doc.ents[0]._.kb_candidates)\n```\n\n## Test\n\n```sh\npoetry install\npoetry shell\npoetry run pytest\n```\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "spaCy pipeline component for ANN Entity Linking using LanceDB",
    "version": "0.1.2",
    "project_urls": {
        "Documentation": "https://guitton.co/",
        "Homepage": "https://guitton.co/",
        "Repository": "https://github.com/louisguitton/spacy-lancedb-linker"
    },
    "split_keywords": [
        "spacy",
        " spacy-pipeline",
        " entity-linking",
        " ann",
        " lancedb"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0ca295bb64536c19876ac99710cf911212fea4b629905f8918e3d29f3221b592",
                "md5": "e20b57e054334a99513ecd2efbb70f5a",
                "sha256": "dcc3dd3dc8fc3e60ad9e6a726f58083be09ec96bcaed4b5584b14fd9044de308"
            },
            "downloads": -1,
            "filename": "spacy_lancedb_linker-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e20b57e054334a99513ecd2efbb70f5a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.12",
            "size": 10721,
            "upload_time": "2024-09-22T20:04:05",
            "upload_time_iso_8601": "2024-09-22T20:04:05.849051Z",
            "url": "https://files.pythonhosted.org/packages/0c/a2/95bb64536c19876ac99710cf911212fea4b629905f8918e3d29f3221b592/spacy_lancedb_linker-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a4dca247c5a20b3a715124a4913527b1e5a4979c58a1b632b3cea25ae923d6d5",
                "md5": "6081fb8db4bc74d190d215d891357947",
                "sha256": "bd2a4a80d6e4a62102b61ea07252fcf9ac168075a6f8c14b18e11466b7518a77"
            },
            "downloads": -1,
            "filename": "spacy_lancedb_linker-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "6081fb8db4bc74d190d215d891357947",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.12",
            "size": 10039,
            "upload_time": "2024-09-22T20:04:07",
            "upload_time_iso_8601": "2024-09-22T20:04:07.812245Z",
            "url": "https://files.pythonhosted.org/packages/a4/dc/a247c5a20b3a715124a4913527b1e5a4979c58a1b632b3cea25ae923d6d5/spacy_lancedb_linker-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-22 20:04:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "louisguitton",
    "github_project": "spacy-lancedb-linker",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "spacy-lancedb-linker"
}
        
Elapsed time: 4.08668s