### Install spacyfishing Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Install the spacyfishing library using pip. ```bash pip install spacyfishing ``` -------------------------------- ### Install spacyfishing for development Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Clone the repository and install dependencies for development. ```bash git clone https://github.com/Lucaterre/spacyfishing.git virtualenv --python=/usr/bin/python3.8 venv source venv/bin/activate pip install -r requirements_dev.txt ``` -------------------------------- ### Simple spaCy Fishing Example Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Process text with spaCy and add the entityfishing component to link entities to Wikidata. ```Python import spacy text_en = "Victor Hugo and Honoré de Balzac are French writers who lived in Paris." nlp_model_en = spacy.load("en_core_web_sm") nlp_model_en.add_pipe("entityfishing") doc_en = nlp_model_en(text_en) for ent in doc_en.ents: print((ent.text, ent.label_, ent._.kb_qid, ent._.url_wikidata, ent._.nerd_score)) ``` -------------------------------- ### Visualize Entities with displaCy Source: https://context7.com/lucaterre/spacyfishing/llms.txt Utilize spaCy's displaCy visualizer to render identified entities with their associated Wikidata links. This example configures custom colors and entity types for visualization and shows how to serve the visualization locally or render it as an HTML string. ```python import spacy nlp = spacy.load("fr_core_news_sm") nlp.add_pipe("entityfishing", config={"language": "fr"}) text = "La bataille d'El-Alamein en Égypte oppose Bernard Montgomery à Erwin Rommel." doc = nlp(text) # Configure visualization options options = { "ents": ["MISC", "LOC", "PER"], "colors": {"LOC": "#82e0aa", "PER": "#85c1e9", "MISC": "#f0b27a"} } # Build manual render data with Wikidata links params = { "text": doc.text, "ents": [ { "start": ent.start_char, "end": ent.end_char, "label": ent.label_, "kb_id": ent._.kb_qid, "kb_url": ent._.url_wikidata } for ent in doc.ents ], "title": None } # Serve visualization on localhost:5000 spacy.displacy.serve(params, style="ent", manual=True, options=options) # Or render to HTML string html = spacy.displacy.render(params, style="ent", manual=True, options=options) print(html[:200]) ``` -------------------------------- ### Entity Fishing API Response Example Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Provides an example of the JSON structure returned by the Entity Fishing API, detailing entities found, their offsets, confidence scores, and associated metadata. ```json { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "Austria", "page_id": 707451 }, { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "Member states of the Three Seas Initiative", "page_id": 68227939 }, { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "Nuclear-free zones", "page_id": 14674730 }, { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "Member states of the European Union", "page_id": 30410535 }, { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "Central European countries", "page_id": 51861632 }, { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "German-speaking countries and territories", "page_id": 39933497 }, { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "States and territories established in 1955", "page_id": 22462860 }, { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "Western European countries", "page_id": 51863690 }, { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "Federal constitutional republics", "page_id": 23861362 } ], "entities": [ { "rawName": "Austria", "offsetStart": 0, "offsetEnd": 1, "confidence_score": 0.2677, "wikipediaExternalRef": 26964606, "wikidataId": "Q40", "domains": [ "Atomic_Physic", "Engineering", "Geology", "Oceanography", "Earth" ] }, { "rawName": "Russian", "offsetStart": 60, "offsetEnd": 61, "confidence_score": 0.1155, "wikipediaExternalRef": 25431, "wikidataId": "Q7737", "domains": [ "Sociology", "Geology", "Artisanship" ] }, { "rawName": "German", "offsetStart": 66, "offsetEnd": 67, "confidence_score": 0.101, "wikipediaExternalRef": 11884, "wikidataId": "Q188", "domains": [ "Sociology" ] } ] } ``` -------------------------------- ### Example entity-fishing JSON response Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md A sample JSON structure returned by the entity-fishing service containing disambiguation data and entity extractions. ```json { "disambiguation_text_service": { "software": "entity-fishing", "version": "0.0.5", "date": "2022-07-07T15:48:33.476Z", "runtime": 249, "nbest": false, "text": "Austria invaded and fought the Serbian army at the Battle of Cer and \n Battle of Kolubara beginning on 12 August. \n\nThe army, led by general Paul von Hindenburg \n defeated Russia in a series of battles collectively known as the First Battle of Tannenberg \n (17 August – 2 September). But the failed Russian invasion, causing the fresh German troops to move to the east, \n allowed the tactical Allied victory at the First Battle of the Marne.", "language": { "lang": "en", "conf": 0.0 }, "global_categories": [ { "weight": 0.009443334100703546, "source": "wikipedia-en", "category": "Recipients of the Military Merit Cross (Mecklenburg-Schwerin), 1st class", "page_id": 39385183 }, { "weight": 0.009443334100703546, "source": "wikipedia-en", "category": "Grand Crosses of the Military Order of Maria Theresa", "page_id": 55441477 }, { "weight": 0.009443333466718216, "source": "wikipedia-en", "category": "Military alliances involving France", "page_id": 29038771 } ], "entities": [ { "rawName": "Serbian", "offsetStart": 5, "offsetEnd": 6, "confidence_score": 0.3606, "wikipediaExternalRef": 75595, "wikidataId": "Q9299", "domains": [ "Sociology", "Statistics" ] }, { "rawName": "the Battle of Cer", "offsetStart": 8, "offsetEnd": 12, "confidence_score": 0.3998, "wikipediaExternalRef": 1614762, "wikidataId": "Q697748", "domains": [ "Military" ] }, { "rawName": "Kolubara", "offsetStart": 16, "offsetEnd": 17, "confidence_score": 0.4793, "wikipediaExternalRef": 2167279, "wikidataId": "Q682699", "domains": [ "Military" ] }, { "rawName": "12 August", "offsetStart": 19, "offsetEnd": 21, "confidence_score": 0.4162, "wikipediaExternalRef": 1491, "wikidataId": "Q2777", "domains": [ "Geology", "Oceanography", "Earth" ] }, { "rawName": "Paul von Hindenburg", "offsetStart": 29, "offsetEnd": 32, "confidence_score": 0.9742, "wikipediaExternalRef": 40548, "wikidataId": "Q2667", "domains": [ "Administration", "Medicine" ] }, { "rawName": "Russia", "offsetStart": 34, "offsetEnd": 35, "confidence_score": 0.3562, "wikipediaExternalRef": 25391, "wikidataId": "Q159", "domains": [ "Administration", "Geology", "Economy" ] }, { "rawName": "Tannenberg", "offsetStart": 47, "offsetEnd": 48, "confidence_score": 0.4878, "wikipediaExternalRef": 60142, "wikidataId": "Q153858", "domains": [ "Astronomy", "Administration" ] }, { "rawName": "Allied", "offsetStart": 78, "offsetEnd": 79, "confidence_score": 0.3726, "wikipediaExternalRef": 2198871, "wikidataId": "Q215669", "domains": [ "Administration" ] } ] }, "disambiguation_terms_service": { "software": "entity-fishing", "version": "0.0.5", "date": "2022-07-07T15:48:33.628Z", "runtime": 74, "nbest": false, "shortText": "Austria Serbian the Battle of Cer Kolubara 12 August Paul von Hindenburg Russia Tannenberg 17 August – 2 September Russian German Allied the First Battle of the Marne", "language": { "lang": "en", "conf": 0.0 }, "global_categories": [ { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "Current member states of the United Nations", "page_id": 69812040 }, { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "Countries in Europe", "page_id": 37691805 }, { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "Landlocked countries", "page_id": 3046541 }, { "weight": 0.050363090951538694, "source": "wikipedia-en", "category": "Member states of the Union for the Mediterranean", "page_id": 25468207 } ] } } ``` -------------------------------- ### Get Extra Wikidata Information Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Configure the entityfishing component to retrieve additional information from Wikidata, such as descriptions and standardized terms. ```Python import spacy text_en = "Victor Hugo and Honoré de Balzac are French writers who lived in Paris." nlp_model_en = spacy.load("en_core_web_sm") # specify configuration: nlp_model_en.add_pipe("entityfishing", config={"extra_info": True}) doc_en = nlp_model_en(text_en) ``` -------------------------------- ### Use a Custom Entity-Fishing Server Source: https://context7.com/lucaterre/spacyfishing/llms.txt Initializes a spaCy pipeline with a custom entity-fishing server instance. ```python import spacy nlp = spacy.load("en_core_web_sm") ``` -------------------------------- ### Visualize Named Entities with displaCy Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Use displaCy's manual serving option to visualize named entities and their Wikidata links. Ensure the 'entityfishing' pipe is added to the spaCy model with the correct language configuration. ```python import spacy text_fr = "La bataille d'El-Alamein en Égypte oppose la 8e armée britannique dirigée par Bernard Montgomery aux divisions d'Erwin Rommel." nlp_model_fr = spacy.load("fr_core_news_sm") nlp_model_fr.add_pipe("entityfishing", config={"language": "fr"}) doc_fr = nlp_model_fr(text_fr) options = { "ents": ["MISC", "LOC", "PER"], "colors": {"LOC": "#82e0aa", "PER": "#85c1e9", "MISC": "#f0b27a"} } params = {"text": doc_fr.text, "ents": [{"start": ent.start_char, "end": ent.end_char, "label": ent.label_, "kb_id": ent._.kb_qid, "kb_url": ent._.url_wikidata} for ent in doc_fr.ents], "title": None} spacy.displacy.serve(params, style="ent", manual=True, options=options) ``` -------------------------------- ### Download spaCy language model Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Download a pre-trained spaCy language model for NER tasks. ```bash python -m spacy download en_core_web_sm ``` -------------------------------- ### Configure entityfishing component Source: https://context7.com/lucaterre/spacyfishing/llms.txt Customize the API endpoint, language, and retrieval depth by passing a configuration dictionary to the pipeline component. ```python import spacy nlp = spacy.load("en_core_web_sm") # Add entityfishing with custom configuration nlp.add_pipe("entityfishing", config={ "api_ef_base": "https://cloud.science-miner.com/nerd/service", # API endpoint URL "language": "en", # Language code for disambiguation resources "extra_info": False, # Whether to fetch extended entity information "filter_statements": [], # Filter specific Wikidata property IDs "verbose": False # Enable logging messages }) doc = nlp("Albert Einstein developed the theory of relativity in Berlin.") for ent in doc.ents: print(f"{ent.text}: {ent._.kb_qid} (score: {ent._.nerd_score})") ``` -------------------------------- ### Retrieve extra entity information Source: https://context7.com/lucaterre/spacyfishing/llms.txt Enable extra_info in the configuration to fetch metadata like descriptions and cross-references. ```python import spacy nlp = spacy.load("en_core_web_sm") ``` -------------------------------- ### Enable extra information retrieval Source: https://context7.com/lucaterre/spacyfishing/llms.txt Configures the entity-fishing pipe to retrieve additional entity metadata such as descriptions and source information. ```python nlp.add_pipe("entityfishing", config={"extra_info": True}) text = "Victor Hugo and Honoré de Balzac are French writers who lived in Paris." doc = nlp(text) for ent in doc.ents: print(f"Entity: {ent.text}") print(f" QID: {ent._.kb_qid}") print(f" Normalized Term: {ent._.normal_term}") print(f" Description Source: {ent._.src_description}") print(f" Description: {ent._.description[:100] if ent._.description else 'N/A'}...") print(f" Other IDs count: {len(ent._.other_ids) if ent._.other_ids else 0}") print() ``` -------------------------------- ### Entity Fishing API Configuration Parameters Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Details the configuration parameters available for the entity-fishing API, including base URL, language, and options for extra information and filtering. ```APIDOC ## Configuration Parameters ### Description These parameters can be used to configure the behavior of the entity-fishing API. ### Parameters * **api_ef_base** : URL of the entity-fishing API endpoint. Default endpoint is set to Science-Miner server. * **language** : Specify language of KB resources for entity-fishing API. Defaults to "en". * **extra_info** : Get extra Wikidata information about an entity from service "concept look-up" of entity-fishing API as a short Wikipedia description, a normalised term, others KB ids. Defaults to false. * **filter_statements** : If `extra_info` set to True, filter other KB ids in output eg. ['P214', 'P244' ...]. Defaults to an empty list. * **verbose** : display logging messages. Defaults to False. ``` -------------------------------- ### Entity Fishing API Configuration Parameters Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Lists and describes the configuration parameters available for the Entity Fishing API, such as base URL, language, and extra information retrieval. ```text - api_ef_base : URL of the entity-fishing API endpoint. Default endpoint is set to Science-Miner server. - language : Specify language of KB resources for entity-fishing API. Defaults to "en". - extra_info : Get extra Wikidata information about an entity from service "concept look-up" of entity-fishing API as a short Wikipedia description, a normalised term, others KB ids. Defaults to false. - filter_statements : If `extra_info` set to `True`, filter other KB ids in output eg. ['P214', 'P244' ...]. Defaults to an empty list. - verbose : display logging messages. Defaults to False. ``` -------------------------------- ### Configure Local Entity Fishing Server Source: https://context7.com/lucaterre/spacyfishing/llms.txt Configure the entityfishing component to use a local or custom API endpoint. Includes enabling verbose logging for debugging. ```python nlp.add_pipe("entityfishing", config={ "api_ef_base": "http://localhost:8090/service", # Local server "language": "en", "verbose": True # Enable logging for debugging }) ``` -------------------------------- ### Check Connection Status to Custom Server Source: https://context7.com/lucaterre/spacyfishing/llms.txt After processing text, check the metadata for the connection status to the entity-fishing service. Handles successful connections and displays entity QIDs, or reports connection failures with status codes and reasons. ```python text = "The Eiffel Tower is located in Paris, France." doc = nlp(text) # Check metadata for connection status metadata = doc._.metadata.get("disambiguation_text_service", {}) if metadata.get("ok"): print("Successfully connected to custom server") for ent in doc.ents: print(f"{ent.text}: {ent._.kb_qid}") else: print(f"Connection failed: {metadata.get('status_code')} - {metadata.get('reason')}") ``` -------------------------------- ### Accessing Entity Fishing API Metadata Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Demonstrates how to access the raw response and metadata from the entity-fishing API within a document object. ```APIDOC ## Accessing Entity Fishing API Metadata ### Description The entity-fishing API response for a metadata query can be accessed using the following attributes on a document object. ### Attributes * **Doc extensions**: ``` doc._.annotations : entity-fishing API's raw response (disambiguisation service using text or terms in query). doc._.metadata : Raw information about request and response from the entity-fishing API (disambiguisation service using text or terms in query). ``` ### Request Example ```python doc._.metadata ``` ### Response Example ```json { "disambiguation_text_service": { "status_code": 200, "reason": "OK", "ok": true, "encoding": "utf-8" }, "disambiguation_terms_service": { "status_code": 200, "reason": "OK", "ok": true, "encoding": "utf-8" } } ``` ``` -------------------------------- ### Process documents in batches Source: https://context7.com/lucaterre/spacyfishing/llms.txt Use nlp.pipe() to process multiple documents efficiently, which batches API requests for improved performance. ```python import spacy nlp = spacy.load("en_core_web_sm") nlp.add_pipe("entityfishing") # Multiple texts to process texts = [ "Victor Hugo and Honoré de Balzac are French writers who lived in Paris.", "Momofuko Ando is Taiwanese Japanese Business Magnate that invented instant ramen.", "Marie Curie won the Nobel Prize for her work on radioactivity." ] # Process documents in batches (batch_size controls API request batching) docs = nlp.pipe(texts, batch_size=128) for doc in docs: print(f"Document: {doc.text[:50]}...") for ent in doc.ents: print(f" {ent.text}: {ent._.kb_qid} ({ent._.url_wikidata})") print() ``` -------------------------------- ### Accessing Entity Fishing API Metadata Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Demonstrates how to access the metadata response from the Entity Fishing API, which includes status codes and service information. ```python doc._.metadata ``` -------------------------------- ### Access Span Extensions for Entity Information Source: https://context7.com/lucaterre/spacyfishing/llms.txt Demonstrates how to access various span extensions provided by the entityfishing component, including default and extra information when enabled. Requires loading a spaCy model and adding the entityfishing pipe with `extra_info=True`. ```python import spacy nlp = spacy.load("en_core_web_sm") nlp.add_pipe("entityfishing", config={"extra_info": True}) doc = nlp("Leonardo da Vinci painted the Mona Lisa in Florence.") for ent in doc.ents: print(f"=== {ent.text} ===") # Default extensions (always available) print(f"kb_qid: {ent._.kb_qid}") # Wikidata QID (e.g., 'Q762') print(f"url_wikidata: {ent._.url_wikidata}") # Full Wikidata URL print(f"wikipedia_page_ref: {ent._.wikipedia_page_ref}") # Wikipedia page ID print(f"nerd_score: {ent._.nerd_score}") # Disambiguation confidence (0-1) # Extra extensions (when extra_info=True) print(f"normal_term: {ent._.normal_term}") # Normalized entity name print(f"description: {ent._.description[:80] if ent._.description else None}...") print(f"src_description: {ent._.src_description}") # Source KB (e.g., 'wikipedia-en') print(f"other_ids: {len(ent._.other_ids) if ent._.other_ids else 0} identifiers") print() ``` -------------------------------- ### Configure Multi-Language Support Source: https://context7.com/lucaterre/spacyfishing/llms.txt Sets the language parameter to match the specific spaCy model being used for entity disambiguation. ```python import spacy # Load French spaCy model nlp_fr = spacy.load("fr_core_news_sm") # Configure entityfishing for French nlp_fr.add_pipe("entityfishing", config={"language": "fr"}) text_fr = "La bataille d'El-Alamein en Égypte oppose la 8e armée britannique dirigée par Bernard Montgomery aux divisions d'Erwin Rommel." doc_fr = nlp_fr(text_fr) for ent in doc_fr.ents: print(f"{ent.text} ({ent.label_}): {ent._.kb_qid} - {ent._.url_wikidata}") ``` -------------------------------- ### Access entity description and metadata Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Iterate over entities in a spaCy document to print custom attributes like description, source, and other IDs. ```python for ent in doc_en.ents: print((ent.text, ent.label_, ent._.kb_qid, ent._.normal_term, ent._.description, ent._.src_description, ent._.other_ids)) ``` -------------------------------- ### Doc Extensions for Entity Fishing API Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Details the available extensions for the 'Doc' object when using the Entity Fishing API, including raw response and metadata access. ```text * **Doc** extensions: ``` doc._.annotations : entity-fishing API's raw response (disambiguisation service using text or terms in query). doc._.metadata : Raw information about request and response from the entity-fishing API (disambiguisation service using text or terms in query). ``` ``` -------------------------------- ### Access Raw API Responses Source: https://context7.com/lucaterre/spacyfishing/llms.txt Retrieves full API annotations and request metadata from the document extensions for debugging purposes. ```python import spacy import json nlp = spacy.load("en_core_web_sm") nlp.add_pipe("entityfishing") text = "Austria invaded Serbia at the Battle of Cer. Paul von Hindenburg defeated Russia." doc = nlp(text) # Access raw API annotations print("=== Disambiguation Text Service Response ===") if "disambiguation_text_service" in doc._.annotations: response = doc._.annotations["disambiguation_text_service"] print(f"Software: {response.get('software')}") print(f"Version: {response.get('version')}") print(f"Runtime: {response.get('runtime')}ms") print(f"Language detected: {response.get('language', {}).get('lang')}") print(f"Entities found: {len(response.get('entities', []))}") # Access request metadata print("\n=== Request Metadata ===") metadata = doc._.metadata.get("disambiguation_text_service", {}) print(f"Status Code: {metadata.get('status_code')}") print(f"OK: {metadata.get('ok')}") print(f"Encoding: {metadata.get('encoding')}") # Access global categories from API response if "global_categories" in doc._.annotations.get("disambiguation_text_service", {}): print("\n=== Top Global Categories ===") categories = doc._.annotations["disambiguation_text_service"]["global_categories"][:3] for cat in categories: print(f" {cat['category']} (weight: {cat['weight']:.4f})") ``` -------------------------------- ### Accessing raw entity-fishing annotations Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Retrieve the raw response object from the spaCy doc extension. ```python doc._.annotations ``` -------------------------------- ### Configure Entity Fishing API Endpoint Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Specify the URL of the entity-fishing API endpoint in the spaCy pipeline configuration. This is useful for using recent Wikidata dumps or improving performance. ```python nlp.add_pipe("entityfishing", config={\"api_ef_base\": \"\"}) ``` -------------------------------- ### Batch Processing with spaCy Fishing Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Process multiple texts efficiently using spaCy's pipe method with the entityfishing component. ```Python import spacy texts_en = [ "Victor Hugo and Honoré de Balzac are French writers who lived in Paris.", "Momofuko Ando is Taiwanese Japanese Business Magnate that invented instant ramen." ] nlp_model_en = spacy.load("en_core_web_sm") nlp_model_en.add_pipe("entityfishing") # set number of documents to be processed at once via batch_size docs_en = nlp_model_en.pipe(texts_en, batch_size=128) for doc_en in docs_en: for ent in doc_en.ents: print((ent.text, ent.label_, ent._.kb_qid, ent._.url_wikidata, ent._.nerd_score)) ``` -------------------------------- ### Entity Fishing API Span Extensions Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Explains the available extensions for span objects when using the entity-fishing API, including default and extra attributes. ```APIDOC ## Span Extensions ### Description These extensions provide additional information about entities identified within a span of text. ### Default Extensions * **span._.kb_qid** : Wikidata identifier (QID). * **span._.url_wikidata** : URL to Wikidata ressource. * **span._.wikipedia_page_ref** : Identifier of the Wikipedia concept. * **span._.nerd_score** : Selection confidence score for the disambiguated entity. ### Extra Extensions (if `extra_info` set to `True`) * **span._.description** : Short concept definition from Wikipedia with wikicode. * **span._.src_description** : The name of the Wikipedia KB from which the definition comes from (eg. wikipedia-en). * **span._.normal_term** : The normalised term name. * **span._.other_ids** : Other statements in the KB related to a Wikipedia concept. ``` -------------------------------- ### Add entityfishing to a spaCy pipeline Source: https://context7.com/lucaterre/spacyfishing/llms.txt Integrate the entityfishing component into a spaCy pipeline to enable automatic entity linking to Wikidata. ```python import spacy # Load a pre-trained spaCy model with NER capabilities nlp = spacy.load("en_core_web_sm") # Add the entityfishing component to the pipeline nlp.add_pipe("entityfishing") # Process text - entities are now linked to Wikidata text = "Victor Hugo and Honoré de Balzac are French writers who lived in Paris." doc = nlp(text) # Access linked entity information for ent in doc.ents: print(f"Entity: {ent.text}") print(f" Label: {ent.label_}") print(f" Wikidata QID: {ent._.kb_qid}") print(f" Wikidata URL: {ent._.url_wikidata}") print(f" Confidence Score: {ent._.nerd_score}") print() ``` -------------------------------- ### Use Entity Fishing in French Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Configure entityfishing to process text in a different language, such as French. This involves loading the appropriate spaCy model for the target language and specifying the language code in the component configuration. ```Python import spacy text_fr = "La bataille d'El-Alamein en Égypte oppose la 8e armée britannique dirigée par Bernard Montgomery aux divisions d'Erwin Rommel." nlp_model_fr = spacy.load("fr_core_news_sm") nlp_model_fr.add_pipe("entityfishing", config={"language": "fr"}) doc_fr = nlp_model_fr(text_fr) for ent in doc_fr.ents: print((ent.text, ent.label_, ent._.kb_qid, ent._.url_wikidata)) ``` -------------------------------- ### Filter Identifiers with Entity Fishing Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Configure entityfishing to filter specific identifiers like VIAF and Library of Congress. This helps in obtaining a more readable and relevant output by selecting only desired external knowledge base IDs. ```Python import spacy text_en = "Victor Hugo and Honoré de Balzac are French writers who lived in Paris." nlp_model_en = spacy.load("en_core_web_sm") # specify configuration: nlp_model_en.add_pipe("entityfishing", config={"extra_info": True, "filter_statements":['P214', 'P244']}) doc_en = nlp_model_en(text_en) # Access to description with ent._.description: for ent in doc_en.ents: print((ent.text, ent.label_, ent._.kb_qid, ent._.other_ids)) ``` -------------------------------- ### Entity Fishing API Response Structure Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Illustrates the structure of a typical response from the Entity Fishing API, showing service status and encoding details. ```json { "disambiguation_text_service": { "status_code": 200, "reason": "OK", "ok": true, "encoding": "utf-8" }, "disambiguation_terms_service": { "status_code": 200, "reason": "OK", "ok": true, "encoding": "utf-8" } } ``` -------------------------------- ### Span Extensions for Entity Fishing API Source: https://github.com/lucaterre/spacyfishing/blob/main/README.md Outlines the default and extra extensions available for the 'Span' object when using the Entity Fishing API, providing access to entity identifiers, scores, and descriptions. ```text * **Span** extensions: ``` default extensions ------------------ span._.kb_qid : Wikidata identifier (QID). span._.url_wikidata : URL to Wikidata ressource. span._.wikipedia_page_ref : Identifier of the Wikipedia concept. span._.nerd_score : Selection confidence score for the disambiguated entity. extra extensions (if `extra_info` set to `True`) ---------------------------------------------- span._.description : Short concept definition from Wikipedia with wikicode. span._.src_description : The name of the Wikipedia KB from which the definition comes from (eg. wikipedia-en). span._.normal_term : The normalised term name. span._.other_ids : Other statements in the KB related to a Wikipedia concept. ``` ``` -------------------------------- ### Filter Knowledge Base Identifiers Source: https://context7.com/lucaterre/spacyfishing/llms.txt Limits the retrieved cross-references to specific property IDs using the filter_statements configuration. ```python import spacy nlp = spacy.load("en_core_web_sm") # Filter to only retrieve VIAF (P214) and Library of Congress (P244) identifiers nlp.add_pipe("entityfishing", config={ "extra_info": True, "filter_statements": ["P214", "P244"] }) text = "Victor Hugo and Honoré de Balzac are French writers who lived in Paris." doc = nlp(text) for ent in doc.ents: print(f"{ent.text} ({ent._.kb_qid}):") if ent._.other_ids: for id_info in ent._.other_ids: print(f" {id_info['propertyName']}: {id_info['value']}") print() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.