/** * Instantiates a new `NaturalLanguageClassifier`. * */ public NaturalLanguageClassifier() { super(SERVICE_NAME); if ((getEndPoint() == null) || getEndPoint().isEmpty()) { setEndPoint(URL); } }
/** * Instantiates a new `NaturalLanguageClassifier`. * */ public NaturalLanguageClassifier() { super(SERVICE_NAME); if ((getEndPoint() == null) || getEndPoint().isEmpty()) { setEndPoint(URL); } }
/** * 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)); }
/** * Classify multiple phrases. * * Returns label information for multiple phrases. The status must be `Available` before you can use the classifier to * classify text. * * Note that classifying Japanese texts is a beta feature. * * @param classifyCollectionOptions the {@link ClassifyCollectionOptions} containing the options for the call * @return a {@link ServiceCall} with a response type of {@link ClassificationCollection} */ public ServiceCall<ClassificationCollection> classifyCollection(ClassifyCollectionOptions classifyCollectionOptions) { Validator.notNull(classifyCollectionOptions, "classifyCollectionOptions cannot be null"); String[] pathSegments = { "v1/classifiers", "classify_collection" }; String[] pathParameters = { classifyCollectionOptions.classifierId() }; RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters)); final JsonObject contentJson = new JsonObject(); contentJson.add("collection", GsonSingleton.getGson().toJsonTree(classifyCollectionOptions.collection())); builder.bodyJson(contentJson); return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ClassificationCollection.class)); }
/** * 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)); }
/** * Classify multiple phrases. * * Returns label information for multiple phrases. The status must be `Available` before you can use the classifier to * classify text. * * Note that classifying Japanese texts is a beta feature. * * @param classifyCollectionOptions the {@link ClassifyCollectionOptions} containing the options for the call * @return a {@link ServiceCall} with a response type of {@link ClassificationCollection} */ public ServiceCall<ClassificationCollection> classifyCollection(ClassifyCollectionOptions classifyCollectionOptions) { Validator.notNull(classifyCollectionOptions, "classifyCollectionOptions cannot be null"); String[] pathSegments = { "v1/classifiers", "classify_collection" }; String[] pathParameters = { classifyCollectionOptions.classifierId() }; RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters)); builder.header("X-IBMCloud-SDK-Analytics", "service_name=natural_language_classifier;service_version=v1;operation_id=classifyCollection"); final JsonObject contentJson = new JsonObject(); contentJson.add("collection", GsonSingleton.getGson().toJsonTree(classifyCollectionOptions.collection())); builder.bodyJson(contentJson); return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ClassificationCollection.class)); }
/** * 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)); }
/** * 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()); }
/** * Get information about a classifier. * * Returns status and other information about a classifier. * * @param getClassifierOptions the {@link GetClassifierOptions} containing the options for the call * @return a {@link ServiceCall} with a response type of {@link Classifier} */ public ServiceCall<Classifier> getClassifier(GetClassifierOptions getClassifierOptions) { Validator.notNull(getClassifierOptions, "getClassifierOptions cannot be null"); String[] pathSegments = { "v1/classifiers" }; String[] pathParameters = { getClassifierOptions.classifierId() }; RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters)); return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifier.class)); }
/** * 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)); builder.header("X-IBMCloud-SDK-Analytics", "service_name=natural_language_classifier;service_version=v1;operation_id=classify"); final JsonObject contentJson = new JsonObject(); contentJson.addProperty("text", classifyOptions.text()); builder.bodyJson(contentJson); return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classification.class)); }
/** * 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)); builder.header("X-IBMCloud-SDK-Analytics", "service_name=natural_language_classifier;service_version=v1;operation_id=deleteClassifier"); return createServiceCall(builder.build(), ResponseConverterUtils.getVoid()); }
/** * Get information about a classifier. * * Returns status and other information about a classifier. * * @param getClassifierOptions the {@link GetClassifierOptions} containing the options for the call * @return a {@link ServiceCall} with a response type of {@link Classifier} */ public ServiceCall<Classifier> getClassifier(GetClassifierOptions getClassifierOptions) { Validator.notNull(getClassifierOptions, "getClassifierOptions cannot be null"); String[] pathSegments = { "v1/classifiers" }; String[] pathParameters = { getClassifierOptions.classifierId() }; RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters)); builder.header("X-IBMCloud-SDK-Analytics", "service_name=natural_language_classifier;service_version=v1;operation_id=getClassifier"); return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifier.class)); }
/** * Create classifier. * * Sends data to create and train a classifier and returns information about the new classifier. * * @param createClassifierOptions the {@link CreateClassifierOptions} containing the options for the call * @return a {@link ServiceCall} with a response type of {@link Classifier} */ public ServiceCall<Classifier> createClassifier(CreateClassifierOptions createClassifierOptions) { Validator.notNull(createClassifierOptions, "createClassifierOptions cannot be null"); String[] pathSegments = { "v1/classifiers" }; RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); MultipartBody.Builder multipartBuilder = new MultipartBody.Builder(); multipartBuilder.setType(MultipartBody.FORM); RequestBody trainingMetadataBody = RequestUtils.inputStreamBody(createClassifierOptions.metadata(), "application/json"); multipartBuilder.addFormDataPart("training_metadata", createClassifierOptions.metadataFilename(), trainingMetadataBody); RequestBody trainingDataBody = RequestUtils.inputStreamBody(createClassifierOptions.trainingData(), "text/csv"); multipartBuilder.addFormDataPart("training_data", createClassifierOptions.trainingDataFilename(), trainingDataBody); builder.body(multipartBuilder.build()); return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifier.class)); }
/** * Create classifier. * * Sends data to create and train a classifier and returns information about the new classifier. * * @param createClassifierOptions the {@link CreateClassifierOptions} containing the options for the call * @return a {@link ServiceCall} with a response type of {@link Classifier} */ public ServiceCall<Classifier> createClassifier(CreateClassifierOptions createClassifierOptions) { Validator.notNull(createClassifierOptions, "createClassifierOptions cannot be null"); String[] pathSegments = { "v1/classifiers" }; RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); builder.header("X-IBMCloud-SDK-Analytics", "service_name=natural_language_classifier;service_version=v1;operation_id=createClassifier"); MultipartBody.Builder multipartBuilder = new MultipartBody.Builder(); multipartBuilder.setType(MultipartBody.FORM); RequestBody trainingMetadataBody = RequestUtils.inputStreamBody(createClassifierOptions.metadata(), "application/json"); multipartBuilder.addFormDataPart("training_metadata", createClassifierOptions.metadataFilename(), trainingMetadataBody); RequestBody trainingDataBody = RequestUtils.inputStreamBody(createClassifierOptions.trainingData(), "text/csv"); multipartBuilder.addFormDataPart("training_data", createClassifierOptions.trainingDataFilename(), trainingDataBody); builder.body(multipartBuilder.build()); return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifier.class)); }