I need to run Named Entity Recognition of Text Analysis using Python.
Here's my code which I've sourced from here.
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential
key = "snip"
endpoint = "https://centralindia.cognitiveservices.azure.com/text/analytics/v3.1/entities/recognition/general"
def authenticate_client():
ta_credential = AzureKeyCredential(key)
text_analytics_client = TextAnalyticsClient(
endpoint=endpoint,
credential=ta_credential)
return text_analytics_client
client = authenticate_client()
def entity_recognition_example(client):
try:
documents = ["I had a wonderful trip to Seattle last week."]
result = client.recognize_entities(documents = documents)[0]
print("Named Entities:\n")
for entity in result.entities:
print("\tText: \t", entity.text, "\tCategory: \t", entity.category, "\tSubCategory: \t", entity.subcategory,
"\n\tConfidence Score: \t", round(entity.confidence_score, 2), "\tLength: \t", entity.length, "\tOffset: \t", entity.offset, "\n")
except Exception as err:
print("Encountered exception. {}".format(err))
entity_recognition_example(client)
This gives me the error: Encountered exception. <urllib3.connection.HTTPSConnection object at 0x000001D0BD6A26A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed
I'm not sure how to write the endpoint, this page says I have to follow this format: https://<your-custom-subdomain>.cognitiveservices.azure.com/text/analytics/v3.1/entities/recognition/general. Not sure what to put in place of "<your-custom-subdomain>"