

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 用于自定义实体识别的实时分析 (API)
<a name="detecting-cer-real-time-api"></a>

您可以使用 Amazon Comprehend API 使用自定义模型运行实时分析。首先，创建一个终端节点来运行实时分析。创建终端节点后，您可以运行实时分析。

有关配置终端节点吞吐量以及相关成本的信息，请参阅 [使用 Amazon Comprehend 终端节点](using-endpoints.md)。

**Topics**
+ [

## 为自定义实体检测创建终端节点
](#detecting-cer-real-time-create-endpoint-api)
+ [

## 运行实时自定义实体检测
](#detecting-cer-real-time-run)

## 为自定义实体检测创建终端节点
<a name="detecting-cer-real-time-create-endpoint-api"></a>

有关与终端节点相关的成本的信息，请参阅 [使用 Amazon Comprehend 终端节点](using-endpoints.md)。

### 使用创建终端节点 AWS CLI
<a name="detecting-cer-real-time-create-endpoint-examples"></a>

要使用创建终端节点 AWS CLI，请使用以下`create-endpoint`命令：

```
$ aws comprehend create-endpoint \
> --desired-inference-units number of inference units \
> --endpoint-name endpoint name \
> --model-arn arn:aws:comprehend:region:account-id:model/example \
> --tags Key=Key,Value=Value
```

如果您的命令成功，Amazon Comprehend 将使用终端节点 ARN 进行响应：

```
{
   "EndpointArn": "Arn"
}
```

有关该命令、其参数配置以及其输出的更多信息，请参阅 AWS CLI 命令参考中的 [https://docs.aws.amazon.com/cli/latest/reference/comprehend/create-endpoint.html](https://docs.aws.amazon.com/cli/latest/reference/comprehend/create-endpoint.html)。

## 运行实时自定义实体检测
<a name="detecting-cer-real-time-run"></a>

为自定义实体识别器模型创建端点后，您可以使用该端点运行 [DetectEntities](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectEntities.html)API 操作。您可以使用 `text` 或 `bytes` 参数提供文本输入。使用 `bytes` 参数输入其他输入类型。

对于图像文件和 PDF 文件，您可以使用 `DocumentReaderConfig` 参数来覆盖默认的文本提取操作。有关更多信息，请参阅 [设置文本提取选项](idp-set-textract-options.md)。

### 使用检测文本中的实体 AWS CLI
<a name="detecting-cer-real-time-run-cli1"></a>

要检测文本中的自定义实体，请使用 `text` 参数中的输入文本运行 `detect-entities` 命令。

**Example ：使用 CLI 检测输入文本中的实体**  

```
$ aws comprehend detect-entities \
> --endpoint-arn arn \
> --language-code en \
> --text  "Andy Jassy is the CEO of Amazon."
```
如果您的命令成功，Amazon Comprehend 将使用分析进行响应。对于 Amazon Comprehend 检测到的每个实体，它都会提供实体类型、文本、位置和置信度分数。

### 使用检测半结构化文档中的实体 AWS CLI
<a name="detecting-cer-real-time-run-cli2"></a>

要 PDF、Word 或图像文件中的自定义实体，请使用 `bytes` 参数中的输入文本运行 `detect-entities` 命令。

**Example ：使用 CLI 检测图像文件中的实体**  
此示例说明如何使用 `fileb` 选项对图像字节进行 base64 编码，从而传入图像文件。有关更多信息，请参阅《 AWS Command Line Interface 用户指南》中的[二进制大型对象](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-types.html#parameter-type-blob)。  
此示例还传入名为 `config.json` 的 JSON 文件以设置文本提取选项。  

```
$ aws comprehend detect-entities \
> --endpoint-arn arn \
> --language-code en \
> --bytes fileb://image1.jpg   \
> --document-reader-config file://config.json
```
**config.json** 文件包含以下代码。  

```
 {
    "DocumentReadMode": "FORCE_DOCUMENT_READ_ACTION",
    "DocumentReadAction": "TEXTRACT_DETECT_DOCUMENT_TEXT"    
 }
```

有关命令语法的更多信息，请参阅《*Amazon Comprehend API* 参考》[DetectEntities](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectEntities.html)中的。