Skip to content

Commit

Permalink
update samples to use actual role names (#17124)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft authored Mar 5, 2021
1 parent 0c1c5e2 commit 5d0c0f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def analyze_healthcare_entities_async(self):
# [START analyze_healthcare_entities_async]
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import HealthcareEntityRelationType
from azure.ai.textanalytics import HealthcareEntityRelationType, HealthcareEntityRelationRoleType
from azure.ai.textanalytics.aio import TextAnalyticsClient

endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
Expand Down Expand Up @@ -115,8 +115,8 @@ async def analyze_healthcare_entities_async(self):
for relation in dosage_of_medication_relations:
# The DosageOfMedication relation should only contain the dosage and medication roles

dosage_role = next(filter(lambda x: x.name == "Attribute", relation.roles))
medication_role = next(filter(lambda x: x.name == "Entity", relation.roles))
dosage_role = next(filter(lambda x: x.name == HealthcareEntityRelationRoleType.DOSAGE, relation.roles))
medication_role = next(filter(lambda x: x.name == HealthcareEntityRelationRoleType.MEDICATION, relation.roles))

try:
dosage_value = int(re.findall(r"\d+", dosage_role.entity.text)[0]) # we find the numbers in the dosage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def analyze_healthcare_entities(self):
# [START analyze_healthcare_entities]
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import TextAnalyticsClient, HealthcareEntityRelationType
from azure.ai.textanalytics import TextAnalyticsClient, HealthcareEntityRelationType, HealthcareEntityRelationRoleType

endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
Expand Down Expand Up @@ -111,8 +111,8 @@ def analyze_healthcare_entities(self):
for relation in dosage_of_medication_relations:
# The DosageOfMedication relation should only contain the dosage and medication roles

dosage_role = next(filter(lambda x: x.name == "Attribute", relation.roles))
medication_role = next(filter(lambda x: x.name == "Entity", relation.roles))
dosage_role = next(filter(lambda x: x.name == HealthcareEntityRelationRoleType.DOSAGE, relation.roles))
medication_role = next(filter(lambda x: x.name == HealthcareEntityRelationRoleType.MEDICATION, relation.roles))

try:
dosage_value = int(re.findall(r"\d+", dosage_role.entity.text)[0]) # we find the numbers in the dosage
Expand Down

0 comments on commit 5d0c0f4

Please sign in to comment.