Hello,
I am using the example provided in the Machine Learning Studio Docs for extracting Health Entities from a given string.
The code is shown below.
My question is: what is the easiest way to convert the output result into JSON format?
from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import TextAnalyticsClient
import json
credential = AzureKeyCredential("**********************************")
endpoint="https://eastus.api.cognitive.microsoft.com/"
text_analytics_client = TextAnalyticsClient(endpoint, credential)
documents = ["Subject is taking 100mg of ibuprofen twice daily"]
poller = text_analytics_client.begin_analyze_healthcare_entities(documents)
result = poller.result()
docs = [doc for doc in result if not doc.is_error]
print("Results of Healthcare Entities Analysis:")
for idx, doc in enumerate(docs):
for entity in doc.entities:
print("Entity: {}".format(entity.text))
print("...Normalized Text: {}".format(entity.normalized_text))
print("...Category: {}".format(entity.category))
print("...Subcategory: {}".format(entity.subcategory))
print("...Offset: {}".format(entity.offset))
print("...Confidence score: {}".format(entity.confidence_score))
if entity.data_sources is not None:
print("...Data Sources:")
for data_source in entity.data_sources:
print("......Entity ID: {}".format(data_source.entity_id))
print("......Name: {}".format(data_source.name))
if entity.assertion is not None:
print("...Assertion:")
print("......Conditionality: {}".format(entity.assertion.conditionality))
print("......Certainty: {}".format(entity.assertion.certainty))
print("......Association: {}".format(entity.assertion.association))
for relation in doc.entity_relations:
print("Relation of type: {} has the following roles".format(relation.relation_type))
for role in relation.roles:
print("...Role '{}' with entity '{}'".format(role.name, role.entity.text))
print("------------------------------------------")
or upvote
which might help other community members reading this thread.