

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# カスタムエンティティ認識でのリアルタイム分析 (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)」を参照してくださ。