/** * Classify. * * This method is here for backwards-compatibility with the other version of classify. * * @param classifierId the classifier ID * @param text the submitted phrase to classify * @return the classification of a phrase with a given classifier */ public ServiceCall<Classification> classify(String classifierId, String text) { ClassifyOptions classifyOptions = new ClassifyOptions.Builder() .classifierId(classifierId) .text(text) .build(); return classify(classifyOptions); }
/** * Classify. * * This method is here for backwards-compatibility with the other version of classify. * * @param classifierId the classifier ID * @param text the submitted phrase to classify * @return the classification of a phrase with a given classifier */ public ServiceCall<Classification> classify(String classifierId, String text) { ClassifyOptions classifyOptions = new ClassifyOptions.Builder() .classifierId(classifierId) .text(text) .build(); return classify(classifyOptions); }
/** * Test null classifier. */ @Test(expected = IllegalArgumentException.class) public void testNullClassifier() { ClassifyOptions classifyOptions = new ClassifyOptions.Builder() .text("test") .build(); service.classify(classifyOptions); }
/** * Test null text. */ @Test(expected = IllegalArgumentException.class) public void testNullText() { ClassifyOptions classifyOptions = new ClassifyOptions.Builder() .classifierId(classifierId) .build(); service.classify(classifyOptions); }
/** * 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); }
/** * 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) { // #324: Classifiers may be empty, because of other tests interfering. // 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()); }