|
from keys import endpoint, key |
|
|
|
|
|
from azure.ai.textanalytics import TextAnalyticsClient |
|
from azure.core.credentials import AzureKeyCredential |
|
|
|
|
|
def authenticate_client(): |
|
ta_credential = AzureKeyCredential(key) |
|
text_analytics_client = TextAnalyticsClient( |
|
endpoint=endpoint, |
|
credential=ta_credential) |
|
return text_analytics_client |
|
|
|
client = authenticate_client() |
|
|
|
|
|
def replace_original_text_with_entities(original_text:str): |
|
try: |
|
result = client.recognize_entities(documents = [original_text])[0] |
|
|
|
for entity in result.entities: |
|
|
|
|
|
original_text= original_text.replace( |
|
entity.text, |
|
entity.text+ f' ({entity.category}) ' |
|
) |
|
return original_text |
|
|
|
except Exception as err: |
|
|
|
print("Encountered exception. {}".format(err)) |
|
return original_text |
|
|