

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

# 针对目标情绪的异步分析
<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)— 获取与指定的目标情绪检测作业关联的属性（包括状态）。
+  [StopTargetedSentimentDetectionJob](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"
}
```