UiPath Documentation
activities
latest
false
Document Understanding 活动
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。

Document Understanding 编码自动化 API(预览版)

用于“Document Understanding”活动包的编码自动化 API,涵盖文档分类、数据提取和验证工件。

UiPath.DocumentUnderstanding.Activities

编码工作流 API,用于对文档进行分类、提取结构化数据以及创建和检索文档验证工件。这些 API 在设计编码自动化时可用。有关编码自动化以及如何使用 API 设计自动化的简介,请参阅编码自动化

  • 服务访问者: du (类型IDocumentUnderstandingService
  • 所需的包: "UiPath.DocumentUnderstanding.Activities": "*"依赖项中的project.json

自动导入的命名空间

安装 Document Understanding 包后,以下命名空间将自动在编码工作流中可用:

  • UiPath.DocumentUnderstanding.Activities.Api
  • UiPath.Platform.ResourceHandling
  • UiPath.DocumentProcessing.Contracts.Actions
  • UiPath.IntelligentOCR.StudioWeb.Activities.DataExtraction
  • UiPath.IntelligentOCR.StudioWeb.Activities.DocumentClassification

服务概述

du 服务将每个 Document Understanding 操作公开为直接方法调用。没有可打开的连接或作用域。直接在服务访问器上调用方法:

var extracted = du.ExtractDocumentData(@"C:\invoices\invoice.pdf", "Invoices", "Production", "invoice");
var extracted = du.ExtractDocumentData(@"C:\invoices\invoice.pdf", "Invoices", "Production", "invoice");

该服务在 Studio Web 中对“分类文档”“提取文档数据”“创建文档验证工件”“检索文档验证工件”活动进行镜像。

项目版本或标签

projectVersionOrTag参数映射到 Studio 的单个“版本”下拉列表。传递版本名称(例如 v3)或标签(例如 ProductionStaginglive)。运行时将解析与项目匹配的类型。对于预定义项目,使用 Production

通用参数

  • timeoutMs (Int) - 分类和提取超时(以毫秒为单位)。默认为 3600000(1 小时)。
  • docType (String) - 文档类型 ID。对于具有多种文档类型的项目,请传递文档类型名称;对于每个版本只有一个提取程序的 IXP 样式项目,请传递空字符串。

分类

DocumentData ClassifyDocument(string documentPath, string projectName, string projectVersionOrTag, int timeoutMs = 3600000)

根据 Document Understanding 项目对本地文件路径中的文档进行分类。返回一个“文档数据”对象,包括预测的文档类型。

DocumentData ClassifyDocument(IResource file, string projectName, string projectVersionOrTag, int timeoutMs = 3600000)

对提供的文档资源进行分类。接受任何IResource ,例如存在路径获取本地文件或文件夹活动的输出。

数据提取

IDocumentData<DictionaryData> ExtractDocumentData(string documentPath, string projectName, string projectVersionOrTag, string docType, int timeoutMs = 3600000)

从本地文件路径下的文档中提取结构化数据。将提取的字段返回为IDocumentData<DictionaryData>

IDocumentData<DictionaryData> ExtractDocumentData(IResource file, string projectName, string projectVersionOrTag, string docType, int timeoutMs = 3600000)

从提供的文档资源中提取结构化数据。

IDocumentData<DictionaryData> ExtractDocumentData(DocumentData classifiedDocument, string projectName, string projectVersionOrTag, string docType = null, int timeoutMs = 3600000)

从已使用 ClassifyDocument 分类的文档中提取结构化数据,这避免了将文件重新数字化。当 docTypenull 时,它派生自已分类文档的文档类型。

验证工件

ContentValidationData CreateDocumentValidationArtifacts(IDocumentData<DictionaryData> automaticExtractionResults, string orchestratorFolderName, string orchestratorBucketName = null)

将提取结果上传到 Orchestrator 存储并返回ContentValidationData句柄。使用该句柄创建验证操作,或稍后使用 RetrieveDocumentValidationArtifacts 检索结果。当 orchestratorBucketNamenull 时,系统将使用默认存储桶。

IDocumentData<DictionaryData> RetrieveDocumentValidationArtifacts(ContentValidationData contentValidationData, object completedAppAction = null, bool removeDataFromStorage = false, bool returnAutomaticExtractionResults = false)

从存储中检索已验证的提取结果。当 removeDataFromStoragetrue 时,表示存储工件将在检索后删除。当 returnAutomaticExtractionResultstrue 时,将返回原始自动提取结果,而不是经过验证的结果。

与活动的关系

编码 API 和 Document Understanding XAML 活动在同一 Runtime 上运行,因此编码工作流可实现与“提取文档数据”“分类文档”活动相同的分类、提取和验证工件行为。区别在于调用形式:该服务接受纯文件路径或IResource输入,并直接返回文档数据对象,您可以使用普通try / catch ,而不是“出错时继续”活动选项。

常见模式

先分类,然后提取

此模式对文档进行分类,然后重用分类结果来提取数据,从而避免了再次将文件数字化。

[Workflow]
public void Execute()
{
    var classified = du.ClassifyDocument(@"C:\docs\file.pdf", "MyProject", "Production");
    Log($"Document type: {classified.DocumentType.DisplayName}");

    // Reuses the classified document, so the file is not digitized again.
    var extracted = du.ExtractDocumentData(classified, "MyProject", "Production");
}
[Workflow]
public void Execute()
{
    var classified = du.ClassifyDocument(@"C:\docs\file.pdf", "MyProject", "Production");
    Log($"Document type: {classified.DocumentType.DisplayName}");

    // Reuses the classified document, so the file is not digitized again.
    var extracted = du.ExtractDocumentData(classified, "MyProject", "Production");
}

为包含验证控件的应用程序任务提取和准备数据

此模式会提取数据,将数据作为验证工件上传到存储以供在应用程序任务中查看,并在操作完成后检索已验证的结果。

[Workflow]
public void Execute()
{
    var extracted = du.ExtractDocumentData(@"C:\docs\invoice.pdf", "Invoices", "Production", "invoice");

    // Upload the results so they can be reviewed in Action Center.
    var artifacts = du.CreateDocumentValidationArtifacts(extracted, "Shared");

    // After the Action Center validation action completes, retrieve the validated results.
    var validated = du.RetrieveDocumentValidationArtifacts(artifacts, removeDataFromStorage: true);
}
[Workflow]
public void Execute()
{
    var extracted = du.ExtractDocumentData(@"C:\docs\invoice.pdf", "Invoices", "Production", "invoice");

    // Upload the results so they can be reviewed in Action Center.
    var artifacts = du.CreateDocumentValidationArtifacts(extracted, "Shared");

    // After the Action Center validation action completes, retrieve the validated results.
    var validated = du.RetrieveDocumentValidationArtifacts(artifacts, removeDataFromStorage: true);
}

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新