Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[text analytics] replace placeholder role types with actual #17124

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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