如何将 Textract 的输出输入 给Comprehend Medical

0

【以下的问题经过翻译处理】 我正在尝试修改 https://github.com/aws-samples/amazon-textract-enhancer/blob/master/functions/detect-text-postprocess-page.py 的代码。

我想能够将textract分析的结果传送到comprehend medicalAPI中。

我尝试解读代码,但是我不是python专家。

你有什么好的方法来解决这个问题吗?

profile picture
EXPERTE
gefragt vor 8 Monaten43 Aufrufe
1 Antwort
0

【以下的回答经过翻译处理】 这里有个链接,其中包含一个简单的Python代码,它接受一个图像,使用Textract,并将其输入到Amazon Comprehend Medical。请查找“医疗文档自然语言处理”部分。

https://aws.amazon.com/blogs/machine-learning/automatically-extract-text-and-structured-data-from-documents-with-amazon-textract/

在此示例中,使用Amazon Textract提取以下文档中的文本。然后,您使用Amazon Comprehend Medical提取医疗实体,例如医疗条件,药物,剂量,强度和受保护健康信息(PHI)。

该链接提供的Python代码如下:

import boto3

# Document
s3BucketName = "ki-textract-demo-docs"
documentName = "medical-notes.png"

# Amazon Textract client
textract = boto3.client('textract')

# Call Amazon Textract
response = textract.detect_document_text(
    Document={
        'S3Object': {
            'Bucket': s3BucketName,
            'Name': documentName
        }
    })

#print(response)

# Print text
print("\nText\n========")
text = ""
for item in response["Blocks"]:
    if item["BlockType"] == "LINE":
        print ('\033[94m' +  item["Text"] + '\033[0m')
        text = text + " " + item["Text"]

# Amazon Comprehend client
comprehend = boto3.client('comprehendmedical')

# Detect medical entities
entities =  comprehend.detect_entities(Text=text)
print("\nMidical Entities\n========")
for entity in entities["Entities"]:
    print("- {}".format(entity["Text"]))
    print ("   Type: {}".format(entity["Type"]))
    print ("   Category: {}".format(entity["Category"]))
    if(entity["Traits"]):
        print("   Traits:")
        for trait in entity["Traits"]:
            print ("    - {}".format(trait["Name"]))
    print("\n")

希望这可以帮助你,

profile picture
EXPERTE
beantwortet vor 8 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen

Relevanter Inhalt