Search in sources :

Example 1 with DetectionsResourceItems

use of com.google.api.services.translate.model.DetectionsResourceItems in project google-cloud-java by GoogleCloudPlatform.

the class HttpTranslateRpc method detect.

@Override
public List<List<DetectionsResourceItems>> detect(List<String> texts) {
    try {
        Map<String, ?> content = ImmutableMap.of("q", texts);
        HttpRequest httpRequest = translate.getRequestFactory().buildPostRequest(buildTargetUrl("detect"), new JsonHttpContent(translate.getJsonFactory(), content)).setParser(translate.getObjectParser());
        List<List<DetectionsResourceItems>> detections = httpRequest.execute().parseAs(DetectionsListResponse.class).getDetections();
        //    translate.detections().list(texts).setKey(options.getApiKey()).execute().getDetections();
        return detections != null ? detections : ImmutableList.<List<DetectionsResourceItems>>of();
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) DetectionsResourceItems(com.google.api.services.translate.model.DetectionsResourceItems) DetectionsListResponse(com.google.api.services.translate.model.DetectionsListResponse) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) JsonHttpContent(com.google.api.client.http.json.JsonHttpContent) IOException(java.io.IOException)

Aggregations

HttpRequest (com.google.api.client.http.HttpRequest)1 JsonHttpContent (com.google.api.client.http.json.JsonHttpContent)1 DetectionsListResponse (com.google.api.services.translate.model.DetectionsListResponse)1 DetectionsResourceItems (com.google.api.services.translate.model.DetectionsResourceItems)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 List (java.util.List)1