use of com.ibm.watson.natural_language_classifier.v1.model.Classification in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifierTest method testClassify.
/**
* Test classify.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void testClassify() throws InterruptedException {
final JsonObject contentJson = new JsonObject();
contentJson.addProperty(TEXT, classification.getText());
final String path = String.format(CLASSIFY_PATH, classifierId);
server.enqueue(jsonResponse(classification));
ClassifyOptions classifyOptions = new ClassifyOptions.Builder().classifierId(classifierId).text(classification.getText()).build();
final Classification result = service.classify(classifyOptions).execute();
final RecordedRequest request = server.takeRequest();
assertEquals(path, request.getPath());
assertEquals("POST", request.getMethod());
assertEquals(contentJson.toString(), request.getBody().readUtf8());
assertEquals(classification, result);
}
use of com.ibm.watson.natural_language_classifier.v1.model.Classification in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifierExample method main.
public static void main(String[] args) {
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
NaturalLanguageClassifier service = new NaturalLanguageClassifier(authenticator);
ClassifyOptions classifyOptions = new ClassifyOptions.Builder().classifierId("<classifierId>").text("Is it sunny?").build();
Classification classification = service.classify(classifyOptions).execute().getResult();
System.out.println(classification);
}
use of com.ibm.watson.natural_language_classifier.v1.model.Classification in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifier method classify.
/**
* Classify a phrase.
*
* <p>Returns label information for the input. The status must be `Available` before you can use
* the classifier to classify text.
*
* @param classifyOptions the {@link ClassifyOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Classification}
*/
public ServiceCall<Classification> classify(ClassifyOptions classifyOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(classifyOptions, "classifyOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("classifier_id", classifyOptions.classifierId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/classifiers/{classifier_id}/classify", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("natural_language_classifier", "v1", "classify");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("text", classifyOptions.text());
builder.bodyJson(contentJson);
ResponseConverter<Classification> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Classification>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations