如何在Android中使用Amazon Comprehend API

时间:2018-06-09 07:09:03

标签: android amazon-web-services text analytics

我在gradle中添加了这个依赖

implementation 'com.amazonaws:aws-android-sdk-comprehend:2.6.+'

但找不到任何方法/类来使用它。

我想将其用于Text Analytics

我想使用这两个类

com.amazonaws.services.comprehend.model.DetectEntitiesRequest
com.amazonaws.services.comprehend.model.DetectEntitiesResult

2 个答案:

答案 0 :(得分:1)

在build.gradle文件中添加以下依赖项。

dependencies {
    implementation 'com.amazonaws:aws-android-sdk-comprehend:2.6.22'
}

您需要使用AmazonComprehendClient类来调用Comprehend API。

按如下方式创建AmazonComprehendClient

AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretAccessKey);

AmazonComprehendClient comprehendClient = new AmazonComprehendClient(credentials);

调用detecEntities

DetectEntitiesRequest detectEntitiesRequest = new DetectEntitiesRequest()
            .withText(ENGLISH_TEXT)
            .withLanguageCode("en");
DetectEntitiesResult detectEntitiesResult = comprehendClient.detectEntities(detectEntitiesRequest);

答案 1 :(得分:0)

存在一些问题
dependencies {
    implementation 'com.amazonaws:aws-android-sdk-comprehend:2.6.+'
}

改为使用

dependencies {
    implementation 'com.amazonaws:aws-android-sdk-comprehend:2.6.22'
}

然后您将能够找到AmazonComprehendClient和其他理解类。