

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

# Amazon Comprehend API を使用する
<a name="using-the-api"></a>

Amazon Comprehend API では、リアルタイム (同期) 分析を実行するオペレーションと、非同期分析ジョブを開始および管理するオペレーションを実行することができます。

Amazon Comprehend API オペレータは直接使用ことも、あるいは CLI または SDK を使用して間接的に使用することもできます。この章の例では、CLI、Python SDK、および Java SDK を使用しています。

 AWS CLI および Python の例を実行するには、 をインストールする必要があります AWS CLI。詳細については、「[AWS Command Line Interface (AWS CLI) のセットアップ](setting-up.md#setup-awscli)」を参照してください。

Java の例を実行するには、 AWS SDK for Javaをインストールする必要があります。SDK for Java をインストールする手順については、[AWS 「SDK for Java のセットアップ](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/setup.html)」を参照してください。

**Topics**
+ [AWS SDK での Amazon Comprehend の使用](sdk-general-information-section.md)
+ [API を使用したリアルタイムの分析](using-api-sync.md)
+ [API を使用した非同期分析ジョブ](api-async.md)

# AWS SDK での Amazon Comprehend の使用
<a name="sdk-general-information-section"></a>

AWS Software Development Kit (SDKsは、多くの一般的なプログラミング言語で使用できます。各 SDK には、デベロッパーが好みの言語でアプリケーションを簡単に構築できるようになる API、コード例、およびドキュメントが提供されています。


| SDK ドキュメント | コード例 | 
| --- | --- | 
| [AWS SDK for C\$1\$1](https://docs.aws.amazon.com/sdk-for-cpp) | [AWS SDK for C\$1\$1 コード例](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/cpp) | 
| [AWS CLI](https://docs.aws.amazon.com/cli) | [AWS CLI コード例](https://docs.aws.amazon.com/code-library/latest/ug/cli_2_code_examples.html) | 
| [AWS SDK for Go](https://docs.aws.amazon.com/sdk-for-go) | [AWS SDK for Go コード例](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/gov2) | 
| [AWS SDK for Java](https://docs.aws.amazon.com/sdk-for-java) | [AWS SDK for Java コード例](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2) | 
| [AWS SDK for JavaScript](https://docs.aws.amazon.com/sdk-for-javascript) | [AWS SDK for JavaScript コード例](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javascriptv3) | 
| [AWS SDK for Kotlin](https://docs.aws.amazon.com/sdk-for-kotlin) | [AWS SDK for Kotlin コード例](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin) | 
| [AWS SDK for .NET](https://docs.aws.amazon.com/sdk-for-net) | [AWS SDK for .NET コード例](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv3) | 
| [AWS SDK for PHP](https://docs.aws.amazon.com/sdk-for-php) | [AWS SDK for PHP コード例](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/php) | 
| [AWS Tools for PowerShell](https://docs.aws.amazon.com/powershell) | [AWS Tools for PowerShell コード例](https://docs.aws.amazon.com/code-library/latest/ug/powershell_5_code_examples.html) | 
| [AWS SDK for Python (Boto3)](https://docs.aws.amazon.com/pythonsdk) | [AWS SDK for Python (Boto3) コード例](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python) | 
| [AWS SDK for Ruby](https://docs.aws.amazon.com/sdk-for-ruby) | [AWS SDK for Ruby コード例](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/ruby) | 
| [AWS SDK for Rust](https://docs.aws.amazon.com/sdk-for-rust) | [AWS SDK for Rust コード例](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/rustv1) | 
| [AWS SDK for SAP ABAP](https://docs.aws.amazon.com/sdk-for-sapabap) | [AWS SDK for SAP ABAP コード例](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/sap-abap) | 
| [AWS SDK for Swift](https://docs.aws.amazon.com/sdk-for-swift) | [AWS SDK for Swift コード例](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/swift) | 

**可用性の例**  
必要なものが見つからなかった場合。このページの下側にある [**Provide feedback**] リンクから、コードの例をリクエストしてください。

# API を使用したリアルタイムの分析
<a name="using-api-sync"></a>

次の例は、 および AWS CLI SDKs for .NET、Java、Python を使用した AWS リアルタイム分析に Amazon Comprehend API を使用する方法を示しています。これらの例を使用して、Amazon Comprehend 非同期オペレーションについて、またご自身のアプリケーションの構成要素として説明します。

このセクションの .NET 例では [AWS SDK for .NET](https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/welcome.html) を使用します。を使用して[AWS Toolkit for Visual Studio](https://docs.aws.amazon.com/AWSToolkitVS/latest/UserGuide/welcome.html)、.NET を使用して AWS アプリケーションを開発できます。これには、アプリケーションのデプロイとサービスの管理に役立つテンプレートと AWS Explorer が含まれています。.NET 開発者の視点については AWS、[AWS .NET 開発者向けガイド](https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/welcome.html)を参照してください。

**Topics**
+ [主要言語の検出](#get-started-api-dominant-language)
+ [名前付きエンティティを検出する](#get-started-api-entities)
+ [キーフレーズの検出](#get-started-api-key-phrases)
+ [感情の判断](#get-started-api-sentiment)
+ [ターゲット感情のリアルタイム分析](#get-started-api-targeted-sentiment)
+ [構文の検出](#get-started-api-syntax)
+ [リアルタイムバッチ API](#get-started-batch)

## 主要言語の検出
<a name="get-started-api-dominant-language"></a>

テキストで使用されている主要言語を判別するには、[「DetectDominantLanguage」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectDominantLanguage.html) オペレーションを使用します。バッチ内の最大 25 件の文書から主要言語を検出するには、[「BatchDetectDominantLanguage」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectDominantLanguage.html) オペレーションを使用します。詳細については、「[リアルタイムバッチ API](#get-started-batch)」を参照してください。

**Topics**
+ [の使用 AWS Command Line Interface](#get-started-api-dominant-language-cli)
+ [AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET](#get-started-api-dominant-language-java)

### の使用 AWS Command Line Interface
<a name="get-started-api-dominant-language-cli"></a>

次の例は、 AWS CLIで `DetectDominantLanguage` オペレーションを使用する方法を示しています。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend detect-dominant-language \
    --region region \
    --text "It is raining today in Seattle."
```

Amazon Comprehend は次のように応答します。

```
{
    "Languages": [
        {
            "LanguageCode": "en",
            "Score": 0.9793661236763
        }
    ]
}
```

### AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET
<a name="get-started-api-dominant-language-java"></a>

主要言語を判別する方法を示す SDK の例については、「[AWS SDK または CLI `DetectDominantLanguage`で を使用する](example_comprehend_DetectDominantLanguage_section.md)」を参照してください。

## 名前付きエンティティを検出する
<a name="get-started-api-entities"></a>

ドキュメント内の名前付きエンティティを判別するには、[「DetectEntities」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectEntities.html) オペレーションを使用します。バッチ内の最大 25 件の文書からエンティティを検出するには、[「BatchDetectDominantLanguage」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectEntities.html) オペレーションを使用します。詳細については、「[リアルタイムバッチ API](#get-started-batch)」を参照してください。

**Topics**
+ [の使用 AWS Command Line Interface](#get-started-api-entities-cli)
+ [AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET](#get-started-api-entities-java)

### の使用 AWS Command Line Interface
<a name="get-started-api-entities-cli"></a>

次の例は、 AWS CLIを使用した `DetectEntities` オペレーションを使用する方法を示しています。入力テキストの言語を指定する必要があります。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend detect-entities \
    --region region \
    --language-code "en" \
    --text "It is raining today in Seattle."
```

Amazon Comprehend は次のように応答します。

```
{
    "Entities": [
        {
            "Text": "today",
            "Score": 0.97,
            "Type": "DATE",
            "BeginOffset": 14,
            "EndOffset": 19
        },
        {
            "Text": "Seattle",
            "Score": 0.95,
            "Type": "LOCATION",
            "BeginOffset": 23,
            "EndOffset": 30
        }
    ],
    "LanguageCode": "en"
}
```

### AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET
<a name="get-started-api-entities-java"></a>

主要言語を判別する方法を示す SDK の例については、「[AWS SDK または CLI `DetectEntities`で を使用する](example_comprehend_DetectEntities_section.md)」を参照してください。

## キーフレーズの検出
<a name="get-started-api-key-phrases"></a>

テキストで使用されている主要な名詞フレーズを判別するには、[「DetectKeyPhrases」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectKeyPhrases.html) オペレーションを使用します。バッチ内の最大 25 件の文書から主要な名詞フレーズを検出するには、[「BatchDetectDominantLanguage」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectKeyPhrases.html) オペレーションを使用します。詳細については、「[リアルタイムバッチ API](#get-started-batch)」を参照してください。

**Topics**
+ [の使用 AWS Command Line Interface](#get-started-api-key-phrases-cli)
+ [AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET](#get-started-api-key-phrases-java)

### の使用 AWS Command Line Interface
<a name="get-started-api-key-phrases-cli"></a>

次の例は、 AWS CLIで `DetectKeyPhrases` オペレーションを使用する方法を示しています。入力テキストの言語を指定する必要があります。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend detect-key-phrases \
    --region region \
    --language-code "en" \
    --text "It is raining today in Seattle."
```

Amazon Comprehend は次のように応答します。

```
{
    "LanguageCode": "en",
    "KeyPhrases": [
        {
            "Text": "today",
            "Score": 0.89,
            "BeginOffset": 14,
            "EndOffset": 19
        },
        {
            "Text": "Seattle",
            "Score": 0.91,
            "BeginOffset": 23,
            "EndOffset": 30
        }
    ]
}
```

### AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET
<a name="get-started-api-key-phrases-java"></a>

キーフレーズを検出する SDK の例については、「[AWS SDK または CLI `DetectKeyPhrases`で を使用する](example_comprehend_DetectKeyPhrases_section.md)」を参照してください。

## 感情の判断
<a name="get-started-api-sentiment"></a>

Amazon Comprehend には、感情を分析するための次の API オペレーションが用意されています。
+ [「DetectSentiment」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectSentiment.html) — ドキュメント全体の感情を判断します。
+  [「BatchDetectSentiment」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectSentiment.html) — 最大 25 件のドキュメントをまとめて全体の感情を測定します。詳細については、[リアルタイムバッチ API](#get-started-batch)を参照してください。
+  [StartSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StartSentimentDetectionJob.html) – ドキュメントのコレクション用に非同期の感情検出ジョブを開始します。
+  [ListSentimentDetectionJobs](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_ListSentimentDetectionJobs.html) — 提出した感情検出ジョブのリストを返します。
+  [DescribeSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeSentimentDetectionJob.html) — 指定された感情検出ジョブに関連するプロパティ (ステータスを含む) を取得します。
+  [StopTargetdSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StopSentimentDetectionJob.html) — 指定された進行中のターゲット感情ジョブを停止します。

**Topics**
+ [の使用 AWS Command Line Interface](#get-started-api-sentiment-cli)
+ [AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET](#get-started-api-sentiment-java)

### の使用 AWS Command Line Interface
<a name="get-started-api-sentiment-cli"></a>

次の例は、 AWS CLIで `DetectSentiment` オペレーションを使用する方法を示しています。この例では、入力テキストの言語を指定します。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend detect-sentiment \
    --region region \
    --language-code "en" \
    --text "It is raining today in Seattle."
```

 Amazon Comprehend は次のように応答します。

```
{
    "SentimentScore": {
        "Mixed": 0.014585512690246105,
        "Positive": 0.31592071056365967,
        "Neutral": 0.5985543131828308,
        "Negative": 0.07093945890665054
    },
    "Sentiment": "NEUTRAL",
    "LanguageCode": "en"
}
```

### AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET
<a name="get-started-api-sentiment-java"></a>

入力テキストの感情を決定する SDK の例については、「[AWS SDK または CLI `DetectSentiment`で を使用する](example_comprehend_DetectSentiment_section.md)」を参照してください。

## ターゲット感情のリアルタイム分析
<a name="get-started-api-targeted-sentiment"></a>

Amazon Comprehend には、ターゲット感情のリアルタイム分析のための次の API オペレーションが用意されています。
+ [DetectTargetedSentiment](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectTargetedSentiment.html) — ドキュメントに記載されているエンティティの感情を分析します。
+  [BatchDetectTargetedSentiment](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectTargetedSentiment.html) — 最大 25 件の文書のターゲット感情を一括して分析します。詳細については、[リアルタイムバッチ API](#get-started-batch)を参照してください。

分析しているテキストにターゲット感情「[エンティティタイプ](how-targeted-sentiment.md#how-targeted-sentiment-entities)」が含まれていない場合、API は空のエンティティ配列を返します。

### の使用 AWS Command Line Interface
<a name="get-started-api-targeted-sentiment-cli"></a>

次の例は、 AWS CLIで `DetectTargetedSentiment` オペレーションを使用する方法を示しています。この例では、入力テキストの言語を指定します。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend detect-targeted-sentiment \
    --region region \
    --language-code "en" \
    --text "The burger was cooked perfectly but it was cold. The service was OK."
```

 Amazon Comprehend は次のように応答します。

```
{
"Entities": [
    {
      "DescriptiveMentionIndex": [
        0
      ],
      "Mentions": [
        {
          "BeginOffset": 4,
          "EndOffset": 10,
          "Score": 1,
          "GroupScore": 1,
          "Text": "burger",
          "Type": "OTHER",
          "MentionSentiment": {
            "Sentiment": "POSITIVE",
            "SentimentScore": {
              "Mixed": 0.001515,
              "Negative": 0.000822,
              "Neutral": 0.000243,
              "Positive": 0.99742
            }
          }
        },
        {
          "BeginOffset": 36,
          "EndOffset": 38,
          "Score": 0.999843,
          "GroupScore": 0.999661,
          "Text": "it",
          "Type": "OTHER",
          "MentionSentiment": {
            "Sentiment": "NEGATIVE",
            "SentimentScore": {
              "Mixed": 0,
              "Negative": 0.999996,
              "Neutral": 0.000004,
              "Positive": 0
            }
          }
        }
      ]
    },
    {
      "DescriptiveMentionIndex": [
        0
      ],
      "Mentions": [
        {
          "BeginOffset": 53,
          "EndOffset": 60,
          "Score": 1,
          "GroupScore": 1,
          "Text": "service",
          "Type": "ATTRIBUTE",
          "MentionSentiment": {
            "Sentiment": "NEUTRAL",
            "SentimentScore": {
              "Mixed": 0.000033,
              "Negative": 0.000089,
              "Neutral": 0.993325,
              "Positive": 0.006553
            }
          }
        }
      ]
    }
  ]
}
```

## 構文の検出
<a name="get-started-api-syntax"></a>

テキストを解析して個々の単語を抽出し、各単語の品詞を決定するには、[detectSyntax](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectSyntax.html) オペレーションを使用します。バッチ内の最大 25 件の文書から構文をパースするには、[BatchDetectDominantLanguage](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectSyntax.html) オペレーションを使用します。詳細については、「[リアルタイムバッチ API](#get-started-batch)」を参照してください。

**Topics**
+ [の使用 AWS Command Line Interface。](#get-started-api-syntax-cli)
+ [AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET](#get-started-api-syntax-java)

### の使用 AWS Command Line Interface。
<a name="get-started-api-syntax-cli"></a>

次の例は、 AWS CLIで `DetectSyntax` オペレーションを使用する方法を示しています。この例では、入力テキストの言語を指定します。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend detect-syntax \
   --region region \
   --language-code "en" \
   --text "It is raining today in Seattle."
```

Amazon Comprehend は次のように応答します。

```
{
    "SyntaxTokens": [
        {
            "Text": "It",
            "EndOffset": 2,
            "BeginOffset": 0,
            "PartOfSpeech": {
                "Tag": "PRON",
                "Score": 0.8389829397201538
            },
            "TokenId": 1
        },
        {
            "Text": "is",
            "EndOffset": 5,
            "BeginOffset": 3,
            "PartOfSpeech": {
                "Tag": "AUX",
                "Score": 0.9189288020133972
            },
            "TokenId": 2
        },
        {
            "Text": "raining",
            "EndOffset": 13,
            "BeginOffset": 6,
            "PartOfSpeech": {
                "Tag": "VERB",
                "Score": 0.9977611303329468
            },
            "TokenId": 3
        },
        {
            "Text": "today",
            "EndOffset": 19,
            "BeginOffset": 14,
            "PartOfSpeech": {
                "Tag": "NOUN",
                "Score": 0.9993606209754944
            },
            "TokenId": 4
        },
        {
            "Text": "in",
            "EndOffset": 22,
            "BeginOffset": 20,
            "PartOfSpeech": {
                "Tag": "ADP",
                "Score": 0.9999061822891235
            },
            "TokenId": 5
        },
        {
            "Text": "Seattle",
            "EndOffset": 30,
            "BeginOffset": 23,
            "PartOfSpeech": {
                "Tag": "PROPN",
                "Score": 0.9940338730812073
            },
            "TokenId": 6
        },
        {
            "Text": ".",
            "EndOffset": 31,
            "BeginOffset": 30,
            "PartOfSpeech": {
                "Tag": "PUNCT",
                "Score": 0.9999997615814209
            },
            "TokenId": 7
        }
    ]
}
```

### AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET
<a name="get-started-api-syntax-java"></a>

入力テキストの構文を検出する SDK の例については、「[AWS SDK または CLI `DetectSyntax`で を使用する](example_comprehend_DetectSyntax_section.md)」 を参照してください。

## リアルタイムバッチ API
<a name="get-started-batch"></a>

Amazon Comprehend のリアルタイムバッチオペレーションを使用すると、最大 25 件のドキュメントのバッチを送信できます。バッチオペレーションを呼び出すことは、リクエスト内のドキュメントごとに単一ドキュメント API を呼び出すことと同じです。バッチ API を使用すると、アプリケーションのパフォーマンスが向上します。詳細については、「[複数ドキュメントの同期処理](concepts-processing-modes.md#how-batch)」を参照してください。

**Topics**
+ [を使用したバッチ処理 AWS CLI](#batch-cli)
+ [を使用したバッチ処理 AWS SDK for .NET](#batch-csharp)

### を使用したバッチ処理 AWS CLI
<a name="batch-cli"></a>

以下の例では、 AWS Command Line Interfaceでバッチ API オペレーションを使用する方法を示します。`BatchDetectDominantLanguage` 以外のすべての操作では、 `process.json` という名前の次のJSONファイルがインプットとして使用されます。その操作に `LanguageCode` エンティティは含まれません。

JSON ファイル (`"$$$$$$$$"`) の 3 番目のドキュメントは、バッチ処理中にエラーの原因となります。このドキュメントは、オペレーションのレスポンスに [BatchItemError](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchItemError.html) が含まれるようになっています。

```
{
   "LanguageCode": "en",
   "TextList": [
      "I have been living in Seattle for almost 4 years",
      "It is raining today in Seattle",
      "$$$$$$$$"
   ]
}
```

例は、Unix、Linux、macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

**Topics**
+ [バッチ (AWS CLI) を使用して主要言語を検出します。](#batch-dominant-language)
+ [バッチ (AWS CLI) を使用してエンティティを検出します。](#batch-entities)
+ [バッチ (AWS CLI) を使用してキーフレーズを検出します。](#batch-key-phrase)
+ [バッチ (AWS CLI) を使用して感情を検出します。](#batch-sentiment)

#### バッチ (AWS CLI) を使用して主要言語を検出します。
<a name="batch-dominant-language"></a>

[BatchDetectDominantLanguage](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectDominantLanguage.html) オペレーションは、バッチに含まれる各ドキュメントの主要言語を決定します。Amazon Comprehend が検出できる言語のリストについては、「[主要言語](how-languages.md)」を参照してください。次の AWS CLI コマンドは、 `BatchDetectDominantLanguage`オペレーションを呼び出します。

```
aws comprehend batch-detect-dominant-language \
    --endpoint endpoint \
    --region region \
    --cli-input-json file://path to input file/process.json
```

`BatchDetectDominantLanguage` オペレーションからのレスポンスは次のとおりです。

```
{
    "ResultList": [
        {
          "Index": 0,
          "Languages":[
            {
              "LanguageCode":"en",
              "Score": 0.99
            }
          ]
        },
        {
          "Index": 1
          "Languages":[
            {
              "LanguageCode":"en",
              "Score": 0.82
            }
          ]
        }
    ],
    "ErrorList": [
      {
        "Index": 2,
        "ErrorCode": "InternalServerException",
        "ErrorMessage": "Unexpected Server Error. Please try again."
      }
    ]
}
```

#### バッチ (AWS CLI) を使用してエンティティを検出します。
<a name="batch-entities"></a>

[BatchDetectEntities](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectEntities.html) オペレーションを使用して、ドキュメントのバッチに含まれるエンティティを検索します。エンティティの詳細については、「[エンティティ](how-entities.md)」を参照してください。以下の AWS CLI コマンドは、`BatchDetectEntities` オペレーションを呼び出します。

```
aws comprehend batch-detect-entities \
    --endpoint endpoint \
    --region region \
    --cli-input-json file://path to input file/process.json
```

#### バッチ (AWS CLI) を使用してキーフレーズを検出します。
<a name="batch-key-phrase"></a>

[BatchDetectKeyPhrases](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectKeyPhrases.html)オペレーションは、ドキュメントのバッチに含まれる主要な名詞フレーズを返します。次の AWS CLI コマンドは、 `BatchDetectKeyNounPhrases`オペレーションを呼び出します。

```
aws comprehend batch-detect-key-phrases
    --endpoint endpoint
    --region region
    --cli-input-json file://path to input file/process.json
```

#### バッチ (AWS CLI) を使用して感情を検出します。
<a name="batch-sentiment"></a>

[BatchDetectSentiment](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectSentiment.html) オペレーションを使用して、ドキュメントのバッチの全体的な感情を検出します。次の AWS CLI コマンドは、 `BatchDetectSentiment`オペレーションを呼び出します。

```
aws comprehend batch-detect-sentiment \
    --endpoint endpoint \
    --region region \
    --cli-input-json file://path to input file/process.json
```

### を使用したバッチ処理 AWS SDK for .NET
<a name="batch-csharp"></a>

次のサンプルプログラムは、 SDK for .NETで [BatchDetectEntities](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectEntities.html) オペレーションを使用する方法を示しています。サーバーからのレスポンスには、正常に処理された各ドキュメントの [BatchDetectEntitiesItemResult](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectEntitiesItemResult.html) オブジェクトが含まれています。ドキュメントの処理中にエラーが発生した場合は、レスポンスのエラーリストにレコードが記録されます。この例では、エラーのある各ドキュメントを取得して再送信します。

このセクションの .NET 例では [AWS SDK for .NET](https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/welcome.html) を使用します。を使用して[AWS Toolkit for Visual Studio](https://docs.aws.amazon.com/AWSToolkitVS/latest/UserGuide/welcome.html)、.NET を使用して AWS アプリケーションを開発できます。これには、アプリケーションのデプロイとサービスの管理に役立つテンプレートと AWS Explorer が含まれています。.NET 開発者の視点については AWS、[AWS .NET 開発者向けガイド](https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/welcome.html)を参照してください。

```
using System;
using System.Collections.Generic;
using Amazon.Comprehend;
using Amazon.Comprehend.Model;

namespace Comprehend
{
    class Program
    {
        // Helper method for printing properties
        static private void PrintEntity(Entity entity)
        {
            Console.WriteLine("     Text: {0}, Type: {1}, Score: {2}, BeginOffset: {3} EndOffset: {4}",
                entity.Text, entity.Type, entity.Score, entity.BeginOffset, entity.EndOffset);
        }

        static void Main(string[] args)
        {
            AmazonComprehendClient comprehendClient = new AmazonComprehendClient(Amazon.RegionEndpoint.USWest2);

            List<String> textList = new List<String>()
            {
                { "I love Seattle" },
                { "Today is Sunday" },
                { "Tomorrow is Monday" },
                { "I love Seattle" }
            };

            // Call detectEntities API
            Console.WriteLine("Calling BatchDetectEntities");
            BatchDetectEntitiesRequest batchDetectEntitiesRequest = new BatchDetectEntitiesRequest()
            {
                TextList = textList,
                LanguageCode = "en"
            };
            BatchDetectEntitiesResponse batchDetectEntitiesResponse = comprehendClient.BatchDetectEntities(batchDetectEntitiesRequest);

            foreach (BatchDetectEntitiesItemResult item in batchDetectEntitiesResponse.ResultList)
            {
                Console.WriteLine("Entities in {0}:", textList[item.Index]);
                foreach (Entity entity in item.Entities)
                    PrintEntity(entity);
            }

            // check if we need to retry failed requests
            if (batchDetectEntitiesResponse.ErrorList.Count != 0)
            {
                Console.WriteLine("Retrying Failed Requests");
                List<String> textToRetry = new List<String>();
                foreach(BatchItemError errorItem in batchDetectEntitiesResponse.ErrorList)
                    textToRetry.Add(textList[errorItem.Index]);

                batchDetectEntitiesRequest = new BatchDetectEntitiesRequest()
                {
                    TextList = textToRetry,
                    LanguageCode = "en"
                };

                batchDetectEntitiesResponse = comprehendClient.BatchDetectEntities(batchDetectEntitiesRequest);

                foreach(BatchDetectEntitiesItemResult item in batchDetectEntitiesResponse.ResultList)
                {
                    Console.WriteLine("Entities in {0}:", textList[item.Index]);
                    foreach (Entity entity in item.Entities)
                        PrintEntity(entity);
                }
            }
            Console.WriteLine("End of DetectEntities");
        }
    }
}
```

# API を使用した非同期分析ジョブ
<a name="api-async"></a>

以下の例では、 AWS CLIから Amazon Comprehend 非同期 API を使用して、分析ジョブを作成および管理しています。

**Topics**
+ [Amazon Comprehend のインサイトのための非同期分析](api-async-insights.md)
+ [ターゲット感情の非同期分析](using-api-targeted-sentiment.md)
+ [イベント検出の同期分析](get-started-api-events.md)
+ [トピックモデリングの非同期分析](get-started-topics.md)

# Amazon Comprehend のインサイトのための非同期分析
<a name="api-async-insights"></a>

以下のセクションでは、Amazon Comprehend API を使用して非同期オペレーションを実行し、Amazon Comprehend のインサイトを分析します。

**Topics**
+ [前提条件](#detect-topics-role-auth)
+ [分析の開始](#how-start-job)
+ [分析ジョブのモニタリング](#how-monitor-progress)
+ [分析結果の取得](#how-get-results)

## 前提条件
<a name="detect-topics-role-auth"></a>

ドキュメントは、UTF-8 形式のテキストファイルである必要があります。ドキュメントは 2 つの形式で送信できます。次の表に示すように、使用する形式は分析する文書のタイプによって異なります。


| 説明 | 形式 | 
| --- | --- | 
| 各ファイルには 1 つの入力ドキュメントが含まれます。これはサイズの大きいドキュメントのコレクションに最適です。 | ファイルごとに 1 文書 | 
|  入力は 1 つまたは複数のファイルです。ファイル内の各行は 1 つのドキュメントとみなされます。これは、ソーシャルメディアへの投稿など、短いドキュメントに最適です。 各行は、改行 (LF、\$1 n)、キャリッジリターン (CR、\$1r)、またはその両方 (CRLF、\$1r\$1n) で終える必要があります。行の終了に、UTF-8 の行区切り文字 (u\$12028) を使用することはできません。  | 1 行に 1 文書 | 

分析ジョブを開始するときは、入力データの S3 上の場所を指定します。URI は、呼び出す API エンドポイントと同じ AWS リージョンにある必要があります。URI は 1 つのファイルを指すものでも、データファイルのコレクションのプレフィックスでもかまいません。詳細については、[InputDataConfig](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_InputDataConfig.html) データ型を参照してください。

Amazon Comprehend には、ドキュメントコレクションと出力ファイルを含む Amazon S3 バケットへのアクセス許可を付与する必要があります。詳細については、「[バッチ操作に必要なロールベースのアクセス許可](security_iam_id-based-policy-examples.md#auth-role-permissions)」を参照してください。

## 分析の開始
<a name="how-start-job"></a>

分析ジョブを送信するには、Amazon Comprehend コンソールまたは適切な `Start*` オペレーションを使用します。
+  [StartDominantLanguageDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StartDominantLanguageDetectionJob.html) — コレクションの各ドキュメントの主要言語を検出するジョブを開始します。ドキュメントの主要言語の詳細については、「[主要言語](how-languages.md)」を参照してください。
+  [StartEntitiesDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StartEntitiesDetectionJob.html) — コレクションの各ドキュメントに含まれるエンティティを検出するジョブを開始します。エンティティの詳細については、「[エンティティ](how-entities.md)」を参照してください。
+  [StartKeyPhrasesDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StartKeyPhrasesDetectionJob.html) — コレクションの各ドキュメントに含まれるキーフレーズを検出するジョブを開始します。キーフレーズの詳細については、「[キーフレーズ](how-key-phrases.md)」を参照してください。
+  [StartPiiEntitiesDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StartPiiEntitiesDetectionJob.html) — コレクションの各ドキュメントに含まれる個人を特定できる情報 (PII) を検出するジョブを開始します。PII の詳細については、「[PII エンティティの検出](how-key-phrases.md)」を参照してください。
+  [StartSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StartSentimentDetectionJob.html) — コレクションの各文書のセンチメントを検出するジョブを開始します。センチメントの詳細については、「[感情](how-sentiment.md)」を参照してください。

## 分析ジョブのモニタリング
<a name="how-monitor-progress"></a>

`Start*` オペレーションでは、ジョブの進行状況の監視に利用できる ID が返されす。

この API を使用して進行状況を監視するには、個別ジョブの進行状況を監視するのか、複数のジョブの進行状況を監視するのかに応じて、2 つあるオペレーションのいずれかを使用します。

個別分析ジョブの進行状況を監視するには、`Describe*` オペレーションを使用します。`Start*` オペレーションによって返されるジョブ ID を指定します。`Describe*` オペレーションからのレスポンスには、ジョブのステータスを示す `JobStatus` フィールドが含まれます。

複数の分析ジョブの進行状況を監視するには、`List*` オペレーションを使用します。 `List*` オペレーションでは、Amazon Comprehend に送信したジョブのリストが返されます。レスポンスには、ジョブごとにそのステータスを示す `JobStatus` フィールドが含まれます。

ステータスフィールドが `COMPLETED` または `FAILED` に設定されている場合、そのジョブの処理は完了しています。

個別ジョブのステータスを取得するには、実行する分析で `Describe*` オペレーションを使用します。
+  [DescribeDominantLanguageDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeDominantLanguageDetectionJob.html)
+  [DescribeEntitiesDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeEntitiesDetectionJob.html)
+  [DescribeKeyPhrasesDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeKeyPhrasesDetectionJob.html)
+  [DescribePiiEntitiesDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribePiiEntitiesDetectionJob.html)
+  [DescribeSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeSentimentDetectionJob.html)

複数のジョブのステータスを取得するには、実行する分析で `List*` オペレーションを使用します。
+  [ListDominantLanguageDetectionJobs](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_ListDominantLanguageDetectionJobs.html)
+  [ListEntitiesDetectionJobs](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_ListEntitiesDetectionJobs.html)
+  [ListKeyPhrasesDetectionJobs](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_ListKeyPhrasesDetectionJobs.html)
+  [ListPiiEntitiesDetectionJobs](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_ListPiiEntitiesDetectionJobs.html)
+  [ListSentimentDetectionJobs](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_ListSentimentDetectionJobs.html)

結果を特定の条件に一致するジョブに制限するには、`List*` オペレーションの `Filter` パラメータを使用します。フィルタ条件には、ジョブ名やジョブステータス、またはジョブの送信日時を使用できます。詳細については、Amazon Comprehend API リファレンスの各 `List*` オペレーションの `Filter` パラメータを参照してください。

## 分析結果の取得
<a name="how-get-results"></a>

分析ジョブが終了すると、`Describe*` オペレーションを使用して結果の場所を取得します。ジョブのステータスが `COMPLETED` の場合、応答には出力ファイルの Amazon S3 の場所を示すフィールドを含む `OutputDataConfig` フィールドが含まれます。このファイル `output.tar.gz` は、分析の結果を含む圧縮アーカイブ形式です。

ジョブのステータスが `FAILED` の場合、 レスポンスには、ジョブが正常に完了しなかった理由を説明する `Message` フィールドが含まれます。

個別ジョブのステータスを取得するには、適切な `Describe*` オペレーションを使用します。
+  [DescribeDominantLanguageDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeDominantLanguageDetectionJob.html)
+  [DescribeEntitiesDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeEntitiesDetectionJob.html)
+  [DescribeKeyPhrasesDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeKeyPhrasesDetectionJob.html)
+  [DescribeSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeSentimentDetectionJob.html)

結果はドキュメントごとに 1 つの JSON 構造を持つ 1 つのファイルの形式で返されます。各レスポンスファイルには、ステータスフィールドが `FAILED` に設定されているジョブのエラーメッセージも含まれます。

以下の各セクションでは、2 つの入力形式の出力例を示しています。

### 主要言語の検出結果の取得
<a name="async-dominant-language"></a>

次に、主要言語を検出した分析からの出力ファイルの例を示します。入力の形式は、行ごとにドキュメント 1 つです。詳細については、[DetectDominantLanguage](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectDominantLanguage.html) オペレーションを参照してください。

```
{"File": "0_doc", "Languages": [{"LanguageCode": "en", "Score": 0.9514502286911011}, {"LanguageCode": "de", "Score": 0.02374090999364853}, {"LanguageCode": "nl", "Score": 0.003208699868991971}, "Line": 0}
{"File": "1_doc", "Languages": [{"LanguageCode": "en", "Score": 0.9822712540626526}, {"LanguageCode": "de", "Score": 0.002621392020955682}, {"LanguageCode": "es", "Score": 0.002386554144322872}], "Line": 1}
```

以下は、入力の形式がファイルごとにドキュメント 1 つの場合の分析の出力例です。

```
{"File": "small_doc", "Languages": [{"LanguageCode": "en", "Score": 0.9728053212165833}, {"LanguageCode": "de", "Score": 0.007670710328966379}, {"LanguageCode": "es", "Score": 0.0028472368139773607}]}
{"File": "huge_doc", "Languages": [{"LanguageCode": "en", "Score": 0.984955906867981}, {"LanguageCode": "de", "Score": 0.0026436643674969673}, {"LanguageCode": "fr", "Score": 0.0014206881169229746}]}
```

### エンティティ検出結果の取得
<a name="async-entities"></a>

以下は、ドキュメント内のエンティティを検出した分析からの出力ファイル例です。入力の形式は、行ごとにドキュメント 1 つです。詳細については、[DetectEntities](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectEntities.html) オペレーションを参照してください。出力には 2 つのエラーメッセージが含まれています。1 つはドキュメントが長すぎる、もう 1 つはドキュメントが UTF-8 形式ではないというエラーです。

```
{"File": "50_docs", "Line": 0, "Entities": [{"BeginOffset": 0, "EndOffset": 22, "Score": 0.9763959646224976, "Text": "Cluj-NapocaCluj-Napoca", "Type": "LOCATION"}"]}
{"File": "50_docs", "Line": 1, "Entities": [{"BeginOffset": 11, "EndOffset": 15, "Score": 0.9615424871444702, "Text": "Maat", "Type": "PERSON"}}]}
{"File": "50_docs", "Line": 2, "ErrorCode": "DOCUMENT_SIZE_EXCEEDED", "ErrorMessage": "Document size exceeds maximum size limit 102400 bytes."}
{"File": "50_docs", "Line": 3, "ErrorCode": "UNSUPPORTED_ENCODING", "ErrorMessage": "Document is not in UTF-8 format and all subsequent lines are ignored."}
```

以下は、入力の形式がファイルごとにドキュメント 1 つの場合の分析の出力例です。出力には 2 つのエラーメッセージが含まれています。1 つはドキュメントが長すぎる、もう 1 つはドキュメントが UTF-8 形式ではないというエラーです。

```
{"File": "non_utf8.txt", "ErrorCode": "UNSUPPORTED_ENCODING", "ErrorMessage": "Document is not in UTF-8 format and all subsequent line are ignored."}
{"File": "small_doc", "Entities": [{"BeginOffset": 0, "EndOffset": 4, "Score": 0.645766019821167, "Text": "Maat", "Type": "PERSON"}]}
{"File": "huge_doc", "ErrorCode": "DOCUMENT_SIZE_EXCEEDED", "ErrorMessage": "Document size exceeds size limit 102400 bytes."}
```

### キーフレーズ検出結果の取得
<a name="async-key-phrases"></a>

以下は、ドキュメント内のキーフレーズを検出した分析からの出力ファイル例です。入力の形式は、行ごとにドキュメント 1 つです。詳細については、[DetectKeyPhrases](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectKeyPhrases.html) オペレーションを参照してください。

```
{"File": "50_docs", "KeyPhrases": [{"BeginOffset": 0, "EndOffset": 22, "Score": 0.8948641419410706, "Text": "Cluj-NapocaCluj-Napoca"}, {"BeginOffset": 45, "EndOffset": 49, "Score": 0.9989854693412781, "Text": "Cluj"}], "Line": 0}            
```

以下は、入力の形式がファイルごとにドキュメント 1 つの場合の分析の出力例です。

```
{"File": "1_doc", "KeyPhrases": [{"BeginOffset": 0, "EndOffset": 22, "Score": 0.8948641419410706, "Text": "Cluj-NapocaCluj-Napoca"}, {"BeginOffset": 45, "EndOffset": 49, "Score": 0.9989854693412781, "Text": "Cluj"}]}            
```

### 個人を特定できる情報 (PII) 検出結果の取得
<a name="async-pii"></a>

以下は、ドキュメント内の PII エンティティを検出した分析ジョブからの出力ファイル例です。入力の形式は、行ごとにドキュメント 1 つです。

```
{"Entities":[{"Type":"NAME","BeginOffset":40,"EndOffset":69,"Score":0.999995},{"Type":"ADDRESS","BeginOffset":247,"EndOffset":253,"Score":0.998828},{"Type":"BANK_ACCOUNT_NUMBER","BeginOffset":406,"EndOffset":411,"Score":0.693283}],"File":"doc.txt","Line":0}
{"Entities":[{"Type":"SSN","BeginOffset":1114,"EndOffset":1124,"Score":0.999999},{"Type":"EMAIL","BeginOffset":3742,"EndOffset":3775,"Score":0.999993},{"Type":"PIN","BeginOffset":4098,"EndOffset":4102,"Score":0.999995}],"File":"doc.txt","Line":1}
```

以下は、入力の形式がファイルごとにドキュメント 1 つの場合の分析の出力例です。

```
{"Entities":[{"Type":"NAME","BeginOffset":40,"EndOffset":69,"Score":0.999995},{"Type":"ADDRESS","BeginOffset":247,"EndOffset":253,"Score":0.998828},{"Type":"BANK_ROUTING","BeginOffset":279,"EndOffset":289,"Score":0.999999}],"File":"doc.txt"}
```

### センチメント検出結果の取得
<a name="async-sentiment"></a>

以下は、ドキュメントで表されているセンチメントを検出した分析からの出力ファイル例です。1 つのドキュメントが長すぎるというエラーメッセージが含まれています。入力の形式は、行ごとにドキュメント 1 つです。詳細については、[DetectSentiment](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectSentiment.html) オペレーションを参照してください。

```
{"File": "50_docs", "Line": 0, "Sentiment": "NEUTRAL", "SentimentScore": {"Mixed": 0.002734508365392685, "Negative": 0.008935936726629734, "Neutral": 0.9841893315315247, "Positive": 0.004140198230743408}}
{"File": "50_docs", "Line": 1, "ErrorCode": "DOCUMENT_SIZE_EXCEEDED", "ErrorMessage": "Document size is exceeded maximum size limit 5120 bytes."}
{"File": "50_docs", "Line": 2, "Sentiment": "NEUTRAL", "SentimentScore": {"Mixed": 0.0023119584657251835, "Negative": 0.0029857370536774397, "Neutral": 0.9866572022438049, "Positive": 0.008045154623687267}}
```

以下は、入力の形式がファイルごとにドキュメント 1 つの場合の分析の出力例です。

```
{"File": "small_doc", "Sentiment": "NEUTRAL", "SentimentScore": {"Mixed": 0.0023450672160834074, "Negative": 0.0009663937962614, "Neutral": 0.9795311689376831, "Positive": 0.017157377675175667}}
{"File": "huge_doc", "ErrorCode": "DOCUMENT_SIZE_EXCEEDED", "ErrorMessage": "Document size is exceeds the limit of 5120 bytes."}
```

# ターゲット感情の非同期分析
<a name="using-api-targeted-sentiment"></a>

ターゲット感情のリアルタイム分析の詳細については、「[ターゲット感情のリアルタイム分析](using-api-sync.md#get-started-api-targeted-sentiment)」を参照してください。

Amazon Comprehend には、非同期のターゲット感情分析を開始および管理するための次の API オペレーションがあります。
+  [StartTargetedSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StartTargetedSentimentDetectionJob.html) – ドキュメントのコレクションに対する非同期ターゲット感情検出ジョブを開始します。
+  [ListTargetedSentimentDetectionJobs](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_ListTargetedSentimentDetectionJobs.html) – 送信されたターゲット感情検出ジョブのリストを返します。
+  [DescribeTargetedSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeTargetedSentimentDetectionJob.html) — 指定されたターゲット感情検出ジョブに関連するプロパティ (ステータスを含む) を取得します。
+  [StopTargetdSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StopTargetedSentimentDetectionJob.html) — 進行中の指定されたターゲット感情ジョブを停止します。

**Topics**
+ [開始する前に](#api-targeted-sentiment-before)
+ [を使用したターゲット感情の分析 AWS CLI](#api-targeted-sentiment-cli)

## 開始する前に
<a name="api-targeted-sentiment-before"></a>

始める前に、次の有無を確認します。
+ **入出力バケット** — 入出力に使用する Amazon S3 バケットを指定します。バケットは、呼び出す API と同じリージョンに存在している必要があります。
+ **IAM サービスロール** — 入出力バケットにアクセス許可を持つ IAM サービスロールが必要です。詳細については、「[バッチ操作に必要なロールベースのアクセス許可](security_iam_id-based-policy-examples.md#auth-role-permissions)」を参照してください。

## を使用したターゲット感情の分析 AWS CLI
<a name="api-targeted-sentiment-cli"></a>

次の例は、 AWS CLIで `StartTargetedSentimentDetectionJob` オペレーションを使用する方法を示しています。この例では、入力テキストの言語を指定します。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend start-targeted-sentiment-detection-job \
       --job-name "job name" \
       --language-code "en" \
       --cli-input-json file://path to JSON input file
```

次の例に示すように、`cli-input-json` パラメータには、リクエストデータを含む JSON ファイルへのパスを指定します。

```
{
    "InputDataConfig": {
        "S3Uri": "s3://input bucket/input path",
        "InputFormat": "ONE_DOC_PER_FILE"
    },
    "OutputDataConfig": {
        "S3Uri": "s3://output bucket/output path"
    },
    "DataAccessRoleArn": "arn:aws:iam::account ID:role/data access role"
}
```

ジョブの開始リクエストが成功すると、以下のようなレスポンスが返されます。

```
{
    "JobStatus": "SUBMITTED",
    "JobArn": "job ARN"
    "JobId": "job ID"
}
```

# イベント検出の同期分析
<a name="get-started-api-events"></a>

**Topics**
+ [開始する前に](#events-before)
+ [を使用してイベントを検出する AWS CLI](#events-cli)
+ [を使用してイベントを一覧表示する AWS CLI](#list-events)
+ [を使用してイベントを記述する AWS CLI](#describe-events)
+ [イベント検出結果を取得する](#async-events)

ドキュメントセット内のイベントを検出するには、[StartEventsDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StartEventsDetectionJob.html) を使用して非同期ジョブを開始します。

## 開始する前に
<a name="events-before"></a>

始める前に、次の有無を確認します。
+ **入出力バケット** — 入出力に使用する Amazon S3 バケットを指定します。バケットは、呼び出す API と同じリージョンに存在している必要があります。
+ **IAM サービスロール** — 入出力バケットにアクセス許可を持つ IAM サービスロールが必要です。詳細については、「[バッチ操作に必要なロールベースのアクセス許可](security_iam_id-based-policy-examples.md#auth-role-permissions)」を参照してください。

## を使用してイベントを検出する AWS CLI
<a name="events-cli"></a>

次の例は、 で [StartEventsDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StartEventsDetectionJob.html) オペレーションを使用する方法を示しています。 AWS CLI

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend start-events-detection-job \
  --region region \
  --job-name job name \
  --cli-input-json file://path to JSON input file
```

次の例に示すように、`cli-input-json` パラメータには、リクエストデータを含む JSON ファイルへのパスを指定します。

```
{
  "InputDataConfig": {
      "S3Uri": "s3://input bucket/input path",
      "InputFormat": "ONE_DOC_PER_LINE"
  },
  "OutputDataConfig": {
      "S3Uri": "s3://output bucket/output path"
  },
  "DataAccessRoleArn": "arn:aws:iam::account ID:role/data access role"
  "LanguageCode": "en",
  "TargetEventTypes": [
      "BANKRUPTCY",
      "EMPLOYMENT",
      "CORPORATE_ACQUISITION",
      "INVESTMENT_GENERAL",
      "CORPORATE_MERGER",
      "IPO",
      "RIGHTS_ISSUE",
      "SECONDARY_OFFERING",
      "SHELF_OFFERING",
      "TENDER_OFFERING",
      "STOCK_SPLIT"
  ]
}
```

イベント検出ジョブの開始リクエストが成功すると、以下のようなレスポンスが返されます。

```
{
  "JobStatus": "SUBMITTED",
  "JobId": "job ID"
}
```

## を使用してイベントを一覧表示する AWS CLI
<a name="list-events"></a>

送信したイベント検出ジョブを一覧を表示するには、[ListEventsDetectionJobs](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_ListEventsDetectionJobs.html) オペレーションを使用します。このリストには、使用された入力および出力の場所、各検出ジョブのステータスに関する情報が含まれます 例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend list-events-detection-jobs --region region 
```

レスポンスには、以下に類似した JSON が返されます。

```
{
 "EventsDetectionJobPropertiesList": [
    {
       "DataAccessRoleArn": "arn:aws:iam::account ID:role/data access role",
       "EndTime": timestamp,
       "InputDataConfig": {
          "InputFormat": "ONE_DOC_PER_LINE",
          "S3Uri": "s3://input bucket/input path"
       },
       "JobId": "job ID",
       "JobName": "job name",
       "JobStatus": "COMPLETED",
       "LanguageCode": "en",
       "Message": "message",
       "OutputDataConfig": {
          "S3Uri": "s3://output bucket/ouput path"
       },
       "SubmitTime": timestamp,
       "TargetEventTypes": [
         "BANKRUPTCY",
         "EMPLOYMENT",
         "CORPORATE_ACQUISITION",
         "INVESTMENT_GENERAL",
         "CORPORATE_MERGER",
         "IPO",
         "RIGHTS_ISSUE",
         "SECONDARY_OFFERING",
         "SHELF_OFFERING",
         "TENDER_OFFERING",
         "STOCK_SPLIT"
  ]
    }
 ],
 "NextToken": "next token"
}
```

## を使用してイベントを記述する AWS CLI
<a name="describe-events"></a>

[DescribeEventsDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeEventsDetectionJob.html) 演算を使用して、既存のジョブのステータスを取得できます。例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend describe-events-detection-job \
  --region region \
  --job-id job ID
```

レスポンスには、次のような JSON が返されます。

```
{
 "EventsDetectionJobProperties": {
    "DataAccessRoleArn": "arn:aws:iam::account ID:role/data access role",
    "EndTime": timestamp,
    "InputDataConfig": {
       "InputFormat": "ONE_DOC_PER_LINE",
       "S3Uri": "S3Uri": "s3://input bucket/input path"
    },
    "JobId": "job ID",
    "JobName": "job name",
    "JobStatus": "job status",
    "LanguageCode": "en",
    "Message": "message",
    "OutputDataConfig": {
       "S3Uri": "s3://output bucket/output path"
    },
    "SubmitTime": timestamp,
    "TargetEventTypes": [
      "BANKRUPTCY",
      "EMPLOYMENT",
      "CORPORATE_ACQUISITION",
      "INVESTMENT_GENERAL",
      "CORPORATE_MERGER",
      "IPO",
      "RIGHTS_ISSUE",
      "SECONDARY_OFFERING",
      "SHELF_OFFERING",
      "TENDER_OFFERING",
      "STOCK_SPLIT"
  ]
 }
}
```

## イベント検出結果を取得する
<a name="async-events"></a>

以下は、ドキュメントでイベントを検出した分析ジョブの出力ファイルの例です。入力の形式は、行ごとにドキュメント 1 つです。

```
{"Entities": [{"Mentions": [{"BeginOffset": 12, "EndOffset": 27, "GroupScore": 1.0, "Score": 0.916355, "Text": "over a year ago", "Type": "DATE"}]}, {"Mentions": [{"BeginOffset": 33, "EndOffset": 39, "GroupScore": 1.0, "Score": 0.996603, "Text": "Amazon", "Type": "ORGANIZATION"}]}, {"Mentions": [{"BeginOffset": 66, "EndOffset": 77, "GroupScore": 1.0, "Score": 0.999283, "Text": "Whole Foods", "Type": "ORGANIZATION"}]}], "Events": [{"Arguments": [{"EntityIndex": 2, "Role": "INVESTEE", "Score": 0.999283}, {"EntityIndex": 0, "Role": "DATE", "Score": 0.916355}, {"EntityIndex": 1, "Role": "INVESTOR", "Score": 0.996603}], "Triggers": [{"BeginOffset": 373, "EndOffset": 380, "GroupScore": 0.999984, "Score": 0.999955, "Text": "acquire", "Type": "CORPORATE_ACQUISITION"}], "Type": "CORPORATE_ACQUISITION"}, {"Arguments": [{"EntityIndex": 2, "Role": "PARTICIPANT", "Score": 0.999283}], "Triggers": [{"BeginOffset": 115, "EndOffset": 123, "GroupScore": 1.0, "Score": 0.999967, "Text": "combined", "Type": "CORPORATE_MERGER"}], "Type": "CORPORATE_MERGER"}], "File": "doc.txt", "Line": 0}
```

イベント出力ファイルの構造およびサポートされているイベントタイプの詳細については、「[Events](how-events.md)」を参照してください。

# トピックモデリングの非同期分析
<a name="get-started-topics"></a>

 ドキュメントセットでトピックを特定するには、[StartTopicsDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StartTopicsDetectionJob.html) を使用して非同期ジョブを開始します。英語またはスペイン語のドキュメントのトピックを監視できます。

**Topics**
+ [開始する前に](#topics-before)
+ [の使用 AWS Command Line Interface](#topics-cli)
+ [SDK for Python または の使用 SDK for .NET](#topic-java)

## 開始する前に
<a name="topics-before"></a>

始める前に、次の有無を確認します。
+ **入出力バケット** — 入出力に使用する Amazon S3 バケットを指定します。バケットは、呼び出す API と同じリージョンに存在している必要があります。
+ **IAM サービスロール** — 入出力バケットにアクセス許可を持つ IAM サービスロールが必要です。詳細については、「[バッチ操作に必要なロールベースのアクセス許可](security_iam_id-based-policy-examples.md#auth-role-permissions)」を参照してください。

## の使用 AWS Command Line Interface
<a name="topics-cli"></a>

次の例は、 で `StartTopicsDetectionJob`オペレーションを使用する方法を示しています。 AWS CLI

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend start-topics-detection-job \
                --number-of-topics topics to return \
                --job-name "job name" \
                --region region \
                --cli-input-json file://path to JSON input file
```

次の例に示すように、`cli-input-json` パラメータには、リクエストデータを含む JSON ファイルへのパスを指定します。

```
{
    "InputDataConfig": {
        "S3Uri": "s3://input bucket/input path",
        "InputFormat": "ONE_DOC_PER_FILE"
    },
    "OutputDataConfig": {
        "S3Uri": "s3://output bucket/output path"
    },
    "DataAccessRoleArn": "arn:aws:iam::account ID:role/data access role"
}
```

トピック検出ジョブの開始リクエストが成功すると、以下のようなレスポンスが返されます。

```
{
    "JobStatus": "SUBMITTED",
    "JobId": "job ID"
}
```

送信したトピック検出ジョブを一覧表示するには、[ListEventsDetectionJobs](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_ListTopicsDetectionJobs.html) オペレーションを使用します。このリストには、使用された入力および出力の場所、各検出ジョブのステータスに関する情報が含まれます 例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend list-topics-detection-jobs \-- region
```

レスポンスには、以下に類似した JSON が返されます。

```
{
    "TopicsDetectionJobPropertiesList": [
        {
            "InputDataConfig": {
                "S3Uri": "s3://input bucket/input path",
                "InputFormat": "ONE_DOC_PER_LINE"
            },
            "NumberOfTopics": topics to return,
            "JobId": "job ID",
            "JobStatus": "COMPLETED",
            "JobName": "job name",
            "SubmitTime": timestamp,
            "OutputDataConfig": {
                "S3Uri": "s3://output bucket/output path"
            },
            "EndTime": timestamp
        },
        {
            "InputDataConfig": {
                "S3Uri": "s3://input bucket/input path",
                "InputFormat": "ONE_DOC_PER_LINE"
            },
            "NumberOfTopics": topics to return,
            "JobId": "job ID",
            "JobStatus": "RUNNING",
            "JobName": "job name",
            "SubmitTime": timestamp,
            "OutputDataConfig": {
                "S3Uri": "s3://output bucket/output path"
            }
        }
    ]
}
```

[DescribeTopicsDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeTopicsDetectionJob.html) オペレーションを使用すると、既存のジョブのステータスを取得できます。例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend describe-topics-detection-job --job-id job ID 
```

レスポンスには、次のような JSON が返されます。

```
{
    "TopicsDetectionJobProperties": {
        "InputDataConfig": {
            "S3Uri": "s3://input bucket/input path",
            "InputFormat": "ONE_DOC_PER_LINE"
        },
        "NumberOfTopics": topics to return,
        "JobId": "job ID",
        "JobStatus": "COMPLETED",
        "JobName": "job name",
        "SubmitTime": timestamp,
        "OutputDataConfig": {
            "S3Uri": "s3://output bucket/ouput path"
        },
        "EndTime": timestamp
    }
}
```

## SDK for Python または の使用 SDK for .NET
<a name="topic-java"></a>

トピックモデリングジョブの開始方法を示す SDK の例については、「[AWS SDK または CLI `StartTopicsDetectionJob`で を使用する](example_comprehend_StartTopicsDetectionJob_section.md)」を参照してください。