【问题标题】:Textractor python library - Is there a way to export key values in reading order to csv?Textractor python library - 有没有办法将键值按阅读顺序导出到 csv?
【发布时间】:2022-11-11 06:00:54
【问题描述】:

我目前正在尝试使用 texttractor python 库 (https://github.com/aws-samples/amazon-textract-textractor/) 使用 Amazon Textract 处理 pdf。

我已经能够调用 API 并使用库返回结果,但导出键值似乎没有任何特定的逻辑顺序。

我正在尝试处理一个多页申请表,它有多个字段具有相同的键(例如是/否),并希望使用该顺序来识别哪个属于哪个问题。

下面的脚本:

from textractor import Textractor
from textractor.data.constants import TextractFeatures

extractor = Textractor(profile_name="default")
document = extractor.start_document_analysis(
    file_source=("Application Form trimmed.pdf"),
    features=[TextractFeatures.FORMS],
    s3_upload_path="s3://textractbucket2/"
)
document.export_kv_to_csv(
    include_kv=True,
    include_checkboxes=True,
    filepath="async_kv.csv"
) 

【问题讨论】:

  • pdf很少按顺序编写,注释更少,因此作者添加一个然后另一个然后转到顶部添加一个。就像封面页可能是添加到小说的最后一页或索引的一半。 PDF 在运行时逐页构建以重新排序为页面顺序,但页面内容不必自上而下跟随,因为激光打印机可以简单地在旋转的页面鼓上旋转而没有任何问题

标签: python amazon-textract


【解决方案1】:

版本 1.0.16 (pip install amazon-textract-textractor==1.0.16) 应该解决这个问题。实体按其页面排序,然后是 Y、X 坐标,这应保留键和值的顺序。

但是,根据您的问题数量,查询可能更合适(并且更便宜)。你可以“问”多达 15 个这样的问题:

from textractor import Textractor
from textractor.data.constants import TextractFeatures

extractor = Textractor(profile_name="default")
document = extractor.start_document_analysis(
    file_source=("Application Form trimmed.pdf"),
    features=[TextractFeatures.QUERIES],
    queries=[
        "What is X?",
        "What is Y?",
        # Up to 15 questions here
    ],
    s3_upload_path="s3://textractbucket2/"
)

print(document.queries)

有关详细信息,请参阅文档:https://aws-samples.github.io/amazon-textract-textractor/notebooks/using_queries.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    • 2016-02-18
    • 1970-01-01
    • 2022-01-04
    相关资源
    最近更新 更多