以下是使用Amazon Comprehend Medical API返回FILTERED值的示例代码:
import boto3
# 创建Comprehend Medical客户端
comprehend_medical = boto3.client('comprehendmedical')
# 要分析的文本内容
text = 'Patient is taking 100mg of ibuprofen once daily for headache.'
# 调用API进行文本分析
response = comprehend_medical.detect_entities_v2(Text=text)
# 提取FILTERED值
filtered_entities = [entity for entity in response['Entities'] if entity['Category'] == 'MEDICATION' and entity['Traits'][0]['Name'] == 'FILTERED']
# 打印提取的FILTERED值
for entity in filtered_entities:
print(entity['Text'])
在上面的示例中,我们首先创建了一个Comprehend Medical客户端。然后,我们定义了要分析的文本内容。接下来,我们调用detect_entities_v2方法来分析文本并获得实体的列表。
我们使用列表推导式来提取具有Category为'MEDICATION'且Traits中的第一个元素的Name为'FILTERED'的实体。最后,我们遍历提取的实体列表并打印出FILTERED值。
请注意,使用此示例代码之前,您需要正确配置AWS CLI或在代码中提供您的AWS凭证。
上一篇:Amazon Cognito:使用QR码在移动设备和Web之间进行跨登录
下一篇:Amazon Comprehend的正确AssumeRolePolicyDocument和PolicyDocument是什么?