Skip to content

Commit 5d0c0f4

Browse files
authored
update samples to use actual role names (Azure#17124)
1 parent 0c1c5e2 commit 5d0c0f4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_analyze_healthcare_entities_async.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def analyze_healthcare_entities_async(self):
4848
# [START analyze_healthcare_entities_async]
4949
import os
5050
from azure.core.credentials import AzureKeyCredential
51-
from azure.ai.textanalytics import HealthcareEntityRelationType
51+
from azure.ai.textanalytics import HealthcareEntityRelationType, HealthcareEntityRelationRoleType
5252
from azure.ai.textanalytics.aio import TextAnalyticsClient
5353

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

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

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

sdk/textanalytics/azure-ai-textanalytics/samples/sample_analyze_healthcare_entities.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def analyze_healthcare_entities(self):
4545
# [START analyze_healthcare_entities]
4646
import os
4747
from azure.core.credentials import AzureKeyCredential
48-
from azure.ai.textanalytics import TextAnalyticsClient, HealthcareEntityRelationType
48+
from azure.ai.textanalytics import TextAnalyticsClient, HealthcareEntityRelationType, HealthcareEntityRelationRoleType
4949

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

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

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

0 commit comments

Comments
 (0)