use of com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classification in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifierIT method dClassify.
/**
* Test classify. Use the pre created classifier to avoid waiting for availability
*/
@Test
public void dClassify() {
Classification classification = null;
try {
ClassifyOptions classifyOptions = new ClassifyOptions.Builder().classifierId(preCreatedClassifierId).text("is it hot outside?").build();
classification = service.classify(classifyOptions).execute();
} catch (NotFoundException e) {
// The build should not fail here, because this is out of our control.
throw new AssumptionViolatedException(e.getMessage(), e);
}
assertNotNull(classification);
assertEquals("temperature", classification.getTopClass());
}
use of com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classification in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifier method classify.
/**
* Classify a phrase.
*
* 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 response type of {@link Classification}
*/
public ServiceCall<Classification> classify(ClassifyOptions classifyOptions) {
Validator.notNull(classifyOptions, "classifyOptions cannot be null");
String[] pathSegments = { "v1/classifiers", "classify" };
String[] pathParameters = { classifyOptions.classifierId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("text", classifyOptions.text());
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classification.class));
}
use of com.ibm.watson.developer_cloud.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) {
NaturalLanguageClassifier service = new NaturalLanguageClassifier();
service.setUsernameAndPassword("<username>", "<password>");
ClassifyOptions classifyOptions = new ClassifyOptions.Builder().classifierId("<classifierId>").text("Is it sunny?").build();
Classification classification = service.classify(classifyOptions).execute();
System.out.println(classification);
}
use of com.ibm.watson.developer_cloud.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);
}
Aggregations