UiPath Documentation
activities
latest
false
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。
UiPath logo, featuring letters U and I in white

Document Understanding 活动

上次更新日期 2026年4月27日

使用智能表单提取程序提取基于锚点的数据

以下示例说明了如何从可能还包含手写文本的表单中提取数据。 以下用例场景说明了如何从采购订单中提取数据。

它提供了诸如“数字化文档”“数据提取作用域”“智能表单提取程序”之类的活动。您可以在UiPath.IntelligentOCR.Activities包中找到这些活动。

创建工作流

在创建以下工作流之前,需要安装以下包:

  • UiPath.DocumentProcessing.Contracts.Activities
  • UiPath.Intelligent OCR.Activities
  • UiPath.OCR.Activities
  • UiPath.OCR.Contracts
  • UiPath.WebAPI.Activities

Steps:

  1. 打开 Studio ,创建一个新“流程”

  2. “工作流设计器”中添加一个“序列”容器,将其命名为“序列 1” ,然后创建下表中显示的变量:

    表格 1. 要创建的变量

    变量类型默认值
    item字符串不适用
    classificationResultClassificationResult[]不适用
    outputFileName泛型值不适用
  3. 在第一个“序列”容器之后,在“工作流设计器”中添加另一个“序列”容器,将其命名为“序列 2” ,然后创建下表中显示的变量:

    表 2. 要创建的变量

    变量类型默认值
    text字符串不适用
    taxonomyDocumentTaxonomy不适用
    dom文档不适用
    documentPath字符串不适用
    classificationResult2ClassificationResult[]不适用
    outputFileName2泛型值不适用
  4. Add a Message Box activity inside the sequence.

    • “属性”面板中,从“按钮”下拉列表中选择“确定”选项。在“文本”字段中添加以下消息:“选择 PDF 文件”。
  5. 选中“排名最前”选项的复选框。这会将消息框置于前台。

  6. “消息框”活动之后添加“选择文件”活动。

    • “属性”面板中,向“筛选器”字段添加以下文本: Pdf files (*.pdf)|*.pdf
    • Add the documentPath variable in the SelectedFile field.
  7. “分配”活动拖动至“选择文件”活动后面。

    • Add the outputFileName2 variable in the To field.
    • 在“值”字段添加表达式 ".temp/" + Path.GetFileName(documentPath)
  8. “分配”活动之后添加“反序列化 JSON”活动。

    • Add the expression File.ReadAllText("DocumentProcessing axonomy.json") in the JSON String field.
    • In the Properties panel, select the UiPath.DocumentProcessing.Contracts.Taxonomy.DocumentTaxonomy option from the TypeArgument dropdown list.
    • Add the taxonomy variable in the JsonObject field.
  9. “反序列化 JSON”活动之后添加“数字化文档”活动。

    • In the Properties panel, add the value 1 in the DegreeOfParallelism field.
    • Add the documentPath variable in the DocumentPath field.
    • Add the dom variable in the DocumentObjectModel field.
    • Add the text variable in the DocumentText field.
    • 在活动中添加UiPath™ 文档 OCR引擎。
    • Add your API Key inside the ApiKey field.
    • Add the "https://du.uipath.com/ocr" expression in the Endpoint field.
  10. “数字化文档”活动之后添加“写入文本文件”活动。

    • Add the JsonConvert.SerializeObject(dom) expression in the Text field.
    • Add the outputFileName2 + ".dom.json" expression in the FileName field.
  11. 在“写入文本文件”活动之后添加另一个“写入文本文件”活动。

    • Add the text variable in the Text field.
    • Add the outputFileName2 + ".text.txt" expression in the FileName field.
  12. “工作流设计器”中拖动另一个“序列”容器 ,将其命名为“序列 3” ,然后创建下表中显示的变量:

    表 3. 要创建的变量

    变量类型默认值
    extractionResult提取结果不适用
    validatedResults提取结果不适用
    doubleValidatedResults提取结果不适用
    dataset数据集不适用
    iInt32不适用
  13. Add a Data Extraction Scope activity inside the Sequence3.

    • In the Properties panel, add the dom variable in the DocumentObjectModel field.
    • Add the documentPath variable in the DocumentPath field.
    • Add the text variable in the DocumentText field.
    • Add the "All.Benchmarks.Invoice" expression in the DocumentTypeId field.
    • Add the taxonomy variable in the Taxonomy field.
    • Add the extractionResult variable in the ExtractionResults field.
  14. Add an Intelligent Form Extractor activity inside the Data Extraction Scope activity.

    • Add your API Key in the ApiKey field.
  15. “数据提取作用域”活动之后添加“写入文本文件”活动。

    • Add the JsonConvert.SerializeObject(extractionResult) expression in the Text field.
    • Add the outputFileName2 + ".results.json" expression in the FileName field.
  16. “写入文本文件”活动之后添加“显示验证站点”活动。

    • Add the extractionResult variable in the AutomaticExtractionResults field.
    • Add the dom variable in the DocumentObjectModel field.
    • Add the documentPath variable in the DocumentPath field.
    • Add the text variable in the DocumentText field.
    • Add the taxonomy variable in the Taxonomy field.
    • Add the validatedResults variable in the ValidatedExtractionResults field.
  17. “显示验证站点”活动后添加“写入文本文件”活动。

    • Add the JsonConvert.SerializeObject(validatedResults) expression in the Text field.
    • Add the outputFileName2 + ".savedinVS.results.json" expression in the FileName field.
  18. 在“写入文本文件”活动之后添加另一个“写入文本文件”活动。

    • Add the JsonConvert.SerializeObject(doubleValidatedResults) expression in the Text field.
    • Add the outputFileName2 + ".doubleSavedinVS.results.json" expression in the FileName field.
  19. 运行流程。 自动化流程应打开验证站点,提取数据并进行验证,并将其存储在“输出”文件夹中。

请访问以下链接,将该示例下载为ZIP格式的文件:示例

定义分类

您已经创建了工作流,定义了所有变量并自定义了所有活动。现在是时候定义分类了。请访问加载分类,了解有关定义自己的分类的信息。

创建分类,以便能够从发票中提取信息。您应该专注于创建“发票”文档类型,其中包含下表中显示的字段:

表 4. 发票文档类型字段

字段类型
发票编号Text
小计Number
销售税Number
总计Number

图 1. 包含前面提到的字段的已完成分类的概览

包含前面提到的字段的已完成分类的概览

创建模板

现在可以为提取流程创建模板。请访问加载分类,了解如何创建模板。

对于本示例,使用以下值配置模板:

  • 文档类型:发票。
  • 模板名称: Invoice-example。
  • 模板文档:选择目标文件。
  • OCR 引擎:Microsoft OCR。
  • 语言:英语。
  • 配置文件: 扫描。
  • 规模:1。

图 2. 显示模板配置的动图示例

显示模板配置的动图示例

在模板中设置锚点

当您需要从文档中提取精确信息时,锚点是一项非常特殊且有用的功能。 通过使用锚点定义提取区域,您可以期望数据提取具有较高的准确性。

定义分类并创建模板后,您可以使用锚点开始配置模板,这意味着在框中定义提取区域,并且使用锚点定义框位置。

在开始将锚点添加到模板之前,请查看以下列表,以获取一些建议:

  • 锚框应尽可能大(高度、宽度),以覆盖任何类型的发票编号(长、短、大字体等)。
  • 一个提取区域可以根据需要具有任意数量的锚点,但只能将一个锚点定义为主锚点(第一个)。
  • 使用由多个并排单词组成的锚点。
  • 主锚点应尽可能靠近提取区域。
  • 提取区域和主锚点的位置在模板中是固定的,即使应用于不同的文档也是如此。 唯一可以改变的是主锚点和次要锚点之间的距离。

让我们继续配置模板,看看如何使用锚点提取数据。

  1. 设置提取区域:
    • 在“验证站点”右侧的区域中,选择“选择模式”

    • 选择“锚点”

    • 开始选择所需的区域。

      备注:

      主锚点应包含两个或三个单词,以便在提取过程中获得更高的准确性和更好的结果。

      标记锚点时,通过按 CTRL 键并选择所需字词来选择多个字词。

  2. 设置主锚点:
    1. 当仍处于“锚点”选择模式时,选择所需的区域作为主锚点。
    2. 选择所需字段的“提取值”
  3. 设置次要锚点:
    1. 确保您仍处于“锚点”选择模式,并激活主锚点选择。
    2. 为次要锚点选择新区域。
    3. 为所需字段选择“选项” ,然后选择“更改提取的值”

重复此过程,直到完成所有提取区域的定义并添加所有锚点。 完成后,保存模板。

  • 创建工作流
  • 定义分类
  • 创建模板
  • 在模板中设置锚点

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新