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

方法

根据“提取文档数据”活动的“生成数据类型”设置,使用文档数据输出方法访问提取的字段值。

提取文档数据”活动中的“生成数据类型”设置决定文档数据输出类型:

  1. “生成数据”True时,文档数据输出为IDocumentData<ExtractorType>
  2. “生成数据”False时,文档数据输出为IDocumentData<DictionaryData>

IDocumentData<DictionaryData> 类型允许您使用某些方法检索和修改字段值。您还可以在“验证站点”中更改文档类型。

You can work with this output in two ways:

  • The lower-level Get/Set methods documented on this page, which return raw extraction objects such as ResultsDataPoint and ResultsValue.
  • The strongly-typed Handler property, which exposes an ExtractionResultHandler navigator for a fluent, typed way to read and edit fields, tables, and field groups.

The following sections show the available members for DocumentData.Data.

备注:

fieldIdOrName参数既被视为字段的标识符,也被视为字段名称。

Handler

Returns an ExtractionResultHandler — the strongly-typed V1 navigator over the extraction result. It provides a fluent, typed alternative to the Get/Set methods for reading and editing fields, tables, and field groups.

语法

Handler
Handler

返回值

The navigator over the document's extraction result.

示例

The following example shows how to use the property:

var handler = DocumentData.Data.Handler;
// Read a basic field value through the navigator.
string invoiceDate = handler.GetSimpleField("InvoiceDate")?.Value?.Value;
var handler = DocumentData.Data.Handler;
// Read a basic field value through the navigator.
string invoiceDate = handler.GetSimpleField("InvoiceDate")?.Value?.Value;

GetFields()

返回某一文档类型中字段的所有信息,表格字段除外。

语法

GetFields()
GetFields()

返回值

包含所有字段及其关联的提取值的数组。

示例

The following example shows how to use the method:

ResultsDataPoint[] allFields = DocumentData.Data.GetFields()
ResultsDataPoint[] allFields = DocumentData.Data.GetFields()

GetField(string)

根据给定的字段 ID 或名称返回所有字段信息。

语法

GetField(string fieldIdOrName)
GetField(string fieldIdOrName)

参数

  • fieldIdOrName String : 要检索或设置的字段的 ID 或名称。此方法首先使用 ID 搜索匹配项。如果未找到匹配项,则使用与字段名称相同的值进行搜索。

    您可以通过以下方式发现字段 ID 和名称:

    • 导航至项目的“构建”部分。为示例文档选择“文档类型管理器” 。进入“字段” ,然后为相关字段选择“高级设置”

    • 打开“验证站点”,在“文档类型”下,搜索已存在的字段名称。
    • 如果您使用的是 Document Understanding API,则可以使用发现服务中的 API 来检索字段名称和 ID。访问“使用发现 API”,检查可用的 API 调用。

返回值

该字段及其关联的提取值。

示例

The following example shows how to use the method, when the desired field ID or name is vendor:

ResultsDataPoint vendorData = DocumentData.Data.GetField("vendor");
ResultsDataPoint vendorData = DocumentData.Data.GetField("vendor");

GetFieldValue(string)

根据给定的字段 ID 或名称,返回第一个字段值。

语法

GetFieldValue(string fieldIdOrName)
GetFieldValue(string fieldIdOrName)

参数

  • fieldIdOrName字符串要检索或设置的字段的 ID 或名称。此方法首先使用 ID 搜索匹配项。如果未找到匹配项,则使用与字段名称相同的值进行搜索。

    您可以通过以下方式发现字段 ID 和名称:

    • 导航至项目的“构建”部分。为示例文档选择“文档类型管理器” 。进入“字段” ,然后为相关字段选择“高级设置”

    • 打开“验证站点”,在“文档类型”下,搜索已存在的字段名称。
    • 如果您使用的是 Document Understanding API,则可以使用发现服务中的 API 来检索字段名称和 ID。访问“使用发现 API”,检查可用的 API 调用。

返回值

为提取结果中的字段报告的值。

异常

如果未找到 fieldIdOrName,则会引发以下异常:未找到 Field {FieldIDOrName}

示例

The following example shows how to use the method, when the field ID or name is vendor:

ResultsValue fieldValue = DocumentData.Data.GetFieldValue("vendor");
    // stores the value of the fieldValue object in a string variable
    string value = fieldValue.Value;
    // stores the confidence of the fieldValue object in a float variable
    float confidence = fieldValue.Confidence;
ResultsValue fieldValue = DocumentData.Data.GetFieldValue("vendor");
    // stores the value of the fieldValue object in a string variable
    string value = fieldValue.Value;
    // stores the confidence of the fieldValue object in a float variable
    float confidence = fieldValue.Confidence;

GetFieldValue(string, int)

根据给定的字段 ID 或名称以及字段 index 返回字段值,以从值数组中返回特定值。

此方法适用于简单字段。

语法

GetFieldValue(string fieldIdOrName, int index)
GetFieldValue(string fieldIdOrName, int index)

参数

  • fieldIdOrName字符串要检索或设置的字段的 ID 或名称。此方法首先使用 ID 搜索匹配项。如果未找到匹配项,则使用与字段名称相同的值进行搜索。

    您可以通过以下方式发现字段 ID 和名称:

    • 导航至项目的“构建”部分。为示例文档选择“文档类型管理器” 。进入“字段” ,然后为相关字段选择“高级设置”

    • 打开“验证站点”,在“文档类型”下,搜索已存在的字段名称。
    • 如果您使用的是 Document Understanding API,则可以使用发现服务中的 API 来检索字段名称和 ID。访问“使用发现 API”,检查可用的 API 调用。
  • index整型:特定值的索引。

返回值

为提取结果中的字段报告的值。

异常

  • 如果未找到 fieldIdOrName,则会引发以下异常:未找到 Field {fieldIdOrName}
  • 如果未找到 index,则会引发以下异常:Index is out of range

示例

The following example shows how to use the method, where field ID is vendor, and the index for the desired value is 2:

ResultsValue fieldValue = DocumentData.Data.GetFieldValue("vendor", 2);
    // store the retrieved value in a string variable
    string value = fieldValue.Value;
    // retrieve and store the confidence level of the field value
    float confidence = fieldValue.Confidence
ResultsValue fieldValue = DocumentData.Data.GetFieldValue("vendor", 2);
    // store the retrieved value in a string variable
    string value = fieldValue.Value;
    // retrieve and store the confidence level of the field value
    float confidence = fieldValue.Confidence

GetFieldValues(string)

根据给定的字段 ID 或名称,返回文档类型中字段的所有值。

此方法不仅适用于多值字段,还适用于提取模型提供替代值的字段。这意味着一个字段可以具有多个替代值,即使它本质上不是多值字段。

语法

GetFieldValues(string fieldIdOrName)
GetFieldValues(string fieldIdOrName)

参数

  • fieldIdOrName字符串要检索或设置的字段的 ID 或名称。此方法首先使用 ID 搜索匹配项。如果未找到匹配项,则使用与字段名称相同的值进行搜索。

    您可以通过以下方式发现字段 ID 和名称:

    • 导航至项目的“构建”部分。为示例文档选择“文档类型管理器” 。进入“字段” ,然后为相关字段选择“高级设置”

    • 打开“验证站点”,在“文档类型”下,搜索已存在的字段名称。
    • 如果您使用的是 Document Understanding API,则可以使用发现服务中的 API 来检索字段名称和 ID。访问“使用发现 API”,检查可用的 API 调用。

返回值

为提取结果中的字段报告的值的数组。

异常

如果未找到 fieldIdOrName,则会引发以下异常:未找到 Field {fieldIdOrName}

示例

The following example shows how to use the method, where field ID is vendor:

ResultsValue[] fieldValues = DocumentData.Data.GetFieldValues("vendor");
ResultsValue[] fieldValues = DocumentData.Data.GetFieldValues("vendor");

GetTables()

返回某一文档类型中所有表格中的所有字段信息。

语法

GetTables()
GetTables()

返回值

以数组形式提取的表格字段,其中包含一个或多个结果表格值(以分别支持单值表和多值表)。每个值都有一个结果表格单元格数组。每个单元格都有一个结果值数组,这是用于简单字段的标准值对象。

示例

The following example shows how to use the method:

ResultsTable[] tableValues = DocumentData.Data.GetTables();
ResultsTable[] tableValues = DocumentData.Data.GetTables();

GetTable(string)

根据给定 ID,返回表格中某一文档类型的所有字段信息。

语法

GetTable(string tableID)
GetTable(string tableID)

参数

  • tableID String : 要检索的表格的 ID。您可以通过导航至项目的“构建”部分找到表格 ID。为示例文档选择“文档类型管理器” 。进入“字段” ,然后为相关表格字段选择“高级设置”

返回值

已提取的表格字段,其中包含一个或多个结果表格值(以分别支持单值表和多值表)。每个值都有一个结果表格单元格数组。每个单元格都有一个结果值数组,这是用于简单字段的标准值对象。

示例

The following example shows how to use the method, where table ID is prices:

var tableValues = DocumentData.Data.GetTable("prices");
var tableValues = DocumentData.Data.GetTable("prices");

SetFieldValue(string, ResultsValue)

使用指定值覆盖由字段 ID 标识的整个值数组。

语法

SetFieldValue(string fieldID, ResultsValue value)
SetFieldValue(string fieldID, ResultsValue value)

参数

  • fieldIdOrName字符串要检索或设置的字段的 ID 或名称。此方法首先使用 ID 搜索匹配项。如果未找到匹配项,则使用与字段名称相同的值进行搜索。

    您可以通过以下方式发现字段 ID 和名称:

    • 导航至项目的“构建”部分。为示例文档选择“文档类型管理器” 。进入“字段” ,然后为相关字段选择“高级设置”

    • 打开“验证站点”,在“文档类型”下,搜索已存在的字段名称。
    • 如果您使用的是 Document Understanding API,则可以使用发现服务中的 API 来检索字段名称和 ID。访问“使用发现 API”,检查可用的 API 调用。
  • value “结果值” :要为字段设置的值。

异常

如果未找到 fieldID,则会引发以下异常:未找到 Field {FieldIDOrName}

示例

The following example shows how to use the method, where we first create the field value using the ResultsValue.CreateWithNoReference helper method. The helper method takes the following parameters:

  • 第一个参数表示值。
  • 第二个参数表示置信度。
  • 第三个参数表示 OCR 的可信度。

创建 taxValue 字段值对象后,我们将 tax 字段可能预先存在的值(如果有)替换为仅包含 taxValue 对象的新数组。在本例中,由于我们使用 SetFieldValuetax 字段将采用新值 10

var taxValue = ResultsValue.CreateWithNoReference("10", 1, 1);
documentData.Data.SetFieldValue("tax", taxValue);
var taxValue = ResultsValue.CreateWithNoReference("10", 1, 1);
documentData.Data.SetFieldValue("tax", taxValue);

SetFieldValue(string, ResultsValue, int)

根据给定的字段 ID 或名称,并根据字段索引设置字段值。

此方法适用于简单字段。

语法

SetFieldValue(string fieldID, ResultsValue value, int index)
SetFieldValue(string fieldID, ResultsValue value, int index)

参数

  • fieldIdOrName字符串要检索或设置的字段的 ID 或名称。此方法首先使用 ID 搜索匹配项。如果未找到匹配项,则使用与字段名称相同的值进行搜索。

    您可以通过以下方式发现字段 ID 和名称:

    • 导航至项目的“构建”部分。为示例文档选择“文档类型管理器” 。进入“字段” ,然后为相关字段选择“高级设置”

    • 打开“验证站点”,在“文档类型”下,搜索已存在的字段名称。
    • 如果您使用的是 Document Understanding API,则可以使用发现服务中的 API 来检索字段名称和 ID。访问“使用发现 API”,检查可用的 API 调用。
  • value “结果值” :要为字段设置的值。

  • index整型:特定值的索引。

异常

  • 如果未找到 fieldID,则会引发以下异常:未找到 Field {FieldIDOrName}
  • 如果未找到 index,则会引发以下异常:Index is out of range

示例

The following example shows how to use the method, where we first create the field value using the ResultsValue.CreateWithNoReference helper method. The helper method takes the following parameters:

  • 第一个参数表示值数组。
  • 第二个参数表示置信度。
  • 第三个参数表示 OCR 的可信度。

创建 taxValue 字段值对象后,我们继续将此新 taxValue 对象替换 tax 字段数组索引 1 处的值。在此处,SetFieldValue 方法用于替换索引 1 处的值。

var taxValue = ResultsValue.CreateWithNoReference("10", 1, 1);
documentData.Data.SetFieldValue("tax", new [] {taxValue}, 1);
var taxValue = ResultsValue.CreateWithNoReference("10", 1, 1);
documentData.Data.SetFieldValue("tax", new [] {taxValue}, 1);

SetFieldValues(string, ResultsValue[])

对于给定的字段 ID 或名称,将整个值数组替换为另一个指定的值数组。

语法

SetFieldValues(string fieldID, ResultsValue[] values)
SetFieldValues(string fieldID, ResultsValue[] values)

参数

  • fieldIdOrName字符串要检索或设置的字段的 ID 或名称。此方法首先使用 ID 搜索匹配项。如果未找到匹配项,则使用与字段名称相同的值进行搜索。

    您可以通过以下方式发现字段 ID 和名称:

    • 导航至项目的“构建”部分。为示例文档选择“文档类型管理器” 。进入“字段” ,然后为相关字段选择“高级设置”

    • 打开“验证站点”,在“文档类型”下,搜索已存在的字段名称。
    • 如果您使用的是 Document Understanding API,则可以使用发现服务中的 API 来检索字段名称和 ID。访问“使用发现 API”,检查可用的 API 调用。
  • values结果值[]:要为字段设置的值数组。

异常

如果未找到 fieldID,则会引发以下异常:未找到 Field {FieldIDOrName}

示例

The following example shows how to use this method, where we first create two field value objects using the ResultsValue.CreateWithNoReference helper method : total1 and total2. The helper method accepts three parameters:

  1. 第一个参数表示实际值。
  2. 第二个参数表示置信度值。
  3. 第三个参数表示 OCR 置信度值。

创建这些字段值后,我们将名为 Total Amount 字段的值替换为包含 total1total2 的数组。

var total1 = ResultsValue.CreateWithNoReference("100", 1, 1);
    var total2 = ResultsValue.CreateWithNoReference("200", 1, 1);
    documentData.Data.SetFieldValues("Total Amount", new []{total1, total2});
var total1 = ResultsValue.CreateWithNoReference("100", 1, 1);
    var total2 = ResultsValue.CreateWithNoReference("200", 1, 1);
    documentData.Data.SetFieldValues("Total Amount", new []{total1, total2});

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新