/** * List classifiers. * * Returns an empty array if no classifiers are available. * * @return a {@link ServiceCall} with a response type of {@link ClassifierList} */ public ServiceCall<ClassifierList> listClassifiers() { return listClassifiers(null); }
/** * Instantiates a new `NaturalLanguageClassifier`. * */ public NaturalLanguageClassifier() { super(SERVICE_NAME); if ((getEndPoint() == null) || getEndPoint().isEmpty()) { setEndPoint(URL); } }
/** * Instantiates a new `NaturalLanguageClassifier` with username and password. * * @param username the username * @param password the password */ public NaturalLanguageClassifier(String username, String password) { this(); setUsernameAndPassword(username, password); }
/** * List classifiers. * * Returns an empty array if no classifiers are available. * * @param listClassifiersOptions the {@link ListClassifiersOptions} containing the options for the call * @return a {@link ServiceCall} with a response type of {@link ClassifierList} */ public ServiceCall<ClassifierList> listClassifiers(ListClassifiersOptions listClassifiersOptions) { String[] pathSegments = { "v1/classifiers" }; RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); if (listClassifiersOptions != null) { } return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ClassifierList.class)); }
@Override @Before public void setUp() throws Exception { super.setUp(); String username = getProperty("natural_language_classifier.username"); String password = getProperty("natural_language_classifier.password"); Assume.assumeFalse("config.properties doesn't have valid credentials.", (username == null) || username.equals(PLACEHOLDER)); service = new NaturalLanguageClassifier(); service.setDefaultHeaders(getDefaultHeaders()); service.setUsernameAndPassword(username, password); service.setEndPoint(getProperty("natural_language_classifier.url")); preCreatedClassifierId = getProperty("natural_language_classifier.classifier_id"); }
@Override @Before public void setUp() throws Exception { super.setUp(); service = new NaturalLanguageClassifier(); service.setUsernameAndPassword("", ""); service.setEndPoint(getMockWebServerUrl()); classifierId = "foo"; classifiers = loadFixture(RESOURCE + "classifiers.json", ClassifierList.class); classifier = loadFixture(RESOURCE + "classifier.json", Classifier.class); classification = loadFixture(RESOURCE + "classification.json", Classification.class); classificationCollection = loadFixture(RESOURCE + "classification_collection.json", ClassificationCollection.class); }
/** * 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); }
/** * Delete classifier. * * This method is here for backwards-compatibility with the old version of deleteClassifier. * * @param classifierId the classifier ID * @return the service call */ public ServiceCall<Void> deleteClassifier(String classifierId) { DeleteClassifierOptions deleteClassifierOptions = new DeleteClassifierOptions.Builder() .classifierId(classifierId) .build(); return deleteClassifier(deleteClassifierOptions); }
/** * Create classifier. * * This method is here for backwards-compatibility with the old version of createClassifier. * * @param name the classifier name * @param language IETF primary language for the classifier. for example: 'en' * @param trainingData the set of questions and their "keys" used to adapt a system to a domain (the ground truth) * @return the classifier * @throws FileNotFoundException if the file could not be found */ public ServiceCall<Classifier> createClassifier(String name, String language, File trainingData) throws FileNotFoundException { Map<String, String> metadataMap = new HashMap<>(); metadataMap.put("name", name); metadataMap.put("language", language); String metadataString = GsonSingleton.getGson().toJson(metadataMap); CreateClassifierOptions createClassifierOptions = new CreateClassifierOptions.Builder() .metadata(new ByteArrayInputStream(metadataString.getBytes())) .trainingData(trainingData) .build(); return createClassifier(createClassifierOptions); }
/** * Get information about a classifier. * * This method is here for backwards-compatibility with the old version of getClassifier. * * @param classifierId the classifier ID * @return the classifier */ public ServiceCall<Classifier> getClassifier(String classifierId) { GetClassifierOptions getClassifierOptions = new GetClassifierOptions.Builder() .classifierId(classifierId) .build(); return getClassifier(getClassifierOptions); }
/** * Instantiates a new `NaturalLanguageClassifier` with IAM. Note that if the access token is specified in the * iamOptions, you accept responsibility for managing the access token yourself. You must set a new access token * before this * one expires or after receiving a 401 error from the service. Failing to do so will result in authentication errors * after this token expires. * * @param iamOptions the options for authenticating through IAM */ public NaturalLanguageClassifier(IamOptions iamOptions) { this(); setIamCredentials(iamOptions); }
/** * Delete classifier. * * @param deleteClassifierOptions the {@link DeleteClassifierOptions} containing the options for the call * @return a {@link ServiceCall} with a response type of Void */ public ServiceCall<Void> deleteClassifier(DeleteClassifierOptions deleteClassifierOptions) { Validator.notNull(deleteClassifierOptions, "deleteClassifierOptions cannot be null"); String[] pathSegments = { "v1/classifiers" }; String[] pathParameters = { deleteClassifierOptions.classifierId() }; RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters)); return createServiceCall(builder.build(), ResponseConverterUtils.getVoid()); }
/** * 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); }
/** * Delete classifier. * * This method is here for backwards-compatibility with the old version of deleteClassifier. * * @param classifierId the classifier ID * @return the service call */ public ServiceCall<Void> deleteClassifier(String classifierId) { DeleteClassifierOptions deleteClassifierOptions = new DeleteClassifierOptions.Builder() .classifierId(classifierId) .build(); return deleteClassifier(deleteClassifierOptions); }
/** * Create classifier. * * This method is here for backwards-compatibility with the old version of createClassifier. * * @param name the classifier name * @param language IETF primary language for the classifier. for example: 'en' * @param trainingData the set of questions and their "keys" used to adapt a system to a domain (the ground truth) * @return the classifier * @throws FileNotFoundException if the file could not be found */ public ServiceCall<Classifier> createClassifier(String name, String language, File trainingData) throws FileNotFoundException { Map<String, String> metadataMap = new HashMap<>(); metadataMap.put("name", name); metadataMap.put("language", language); String metadataString = GsonSingleton.getGson().toJson(metadataMap); CreateClassifierOptions createClassifierOptions = new CreateClassifierOptions.Builder() .metadata(new ByteArrayInputStream(metadataString.getBytes())) .trainingData(trainingData) .build(); return createClassifier(createClassifierOptions); }
/** * Get information about a classifier. * * This method is here for backwards-compatibility with the old version of getClassifier. * * @param classifierId the classifier ID * @return the classifier */ public ServiceCall<Classifier> getClassifier(String classifierId) { GetClassifierOptions getClassifierOptions = new GetClassifierOptions.Builder() .classifierId(classifierId) .build(); return getClassifier(getClassifierOptions); }
/** * Instantiates a new `NaturalLanguageClassifier` with IAM. Note that if the access token is specified in the * iamOptions, you accept responsibility for managing the access token yourself. You must set a new access token * before this * one expires or after receiving a 401 error from the service. Failing to do so will result in authentication errors * after this token expires. * * @param iamOptions the options for authenticating through IAM */ public NaturalLanguageClassifier(IamOptions iamOptions) { this(); setIamCredentials(iamOptions); }
/** * List classifiers. * * Returns an empty array if no classifiers are available. * * @param listClassifiersOptions the {@link ListClassifiersOptions} containing the options for the call * @return a {@link ServiceCall} with a response type of {@link ClassifierList} */ public ServiceCall<ClassifierList> listClassifiers(ListClassifiersOptions listClassifiersOptions) { String[] pathSegments = { "v1/classifiers" }; RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); builder.header("X-IBMCloud-SDK-Analytics", "service_name=natural_language_classifier;service_version=v1;operation_id=listClassifiers"); if (listClassifiersOptions != null) { } return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ClassifierList.class)); }
/** * List classifiers. * * This method is here for backwards-compatibility with the old version of getClassifiers, which has been renamed * to listClassifiers. * * @return the classifier list */ public ServiceCall<ClassifierList> getClassifiers() { return listClassifiers(); } }
/** * Test null text. */ @Test(expected = IllegalArgumentException.class) public void testNullText() { ClassifyOptions classifyOptions = new ClassifyOptions.Builder() .classifierId(classifierId) .build(); service.classify(classifyOptions); }