use of com.ibm.watson.developer_cloud.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.
the class Discovery method createCollection.
/**
* Create a collection.
*
* @param createCollectionOptions the {@link CreateCollectionOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Collection}
*/
public ServiceCall<Collection> createCollection(CreateCollectionOptions createCollectionOptions) {
Validator.notNull(createCollectionOptions, "createCollectionOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections" };
String[] pathParameters = { createCollectionOptions.environmentId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("name", createCollectionOptions.name());
if (createCollectionOptions.description() != null) {
contentJson.addProperty("description", createCollectionOptions.description());
}
if (createCollectionOptions.configurationId() != null) {
contentJson.addProperty("configuration_id", createCollectionOptions.configurationId());
}
if (createCollectionOptions.language() != null) {
contentJson.addProperty("language", createCollectionOptions.language());
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Collection.class));
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.
the class Discovery method addDocument.
/**
* Add a document.
*
* Add a document to a collection with optional metadata. * The `version` query parameter is still required. * Returns
* immediately after the system has accepted the document for processing. * The user must provide document content,
* metadata, or both. If the request is missing both document content and metadata, it is rejected. * The user can set
* the `Content-Type` parameter on the `file` part to indicate the media type of the document. If the `Content-Type`
* parameter is missing or is one of the generic media types (for example, `application/octet-stream`), then the
* service attempts to automatically detect the document's media type. * The following field names are reserved and
* will be filtered out if present after normalization: `id`, `score`, `highlight`, and any field with the prefix of:
* `_`, `+`, or `-` * Fields with empty name values after normalization are filtered out before indexing. * Fields
* containing the following characters after normalization are filtered out before indexing: `#` and `,`.
*
* @param addDocumentOptions the {@link AddDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link DocumentAccepted}
*/
public ServiceCall<DocumentAccepted> addDocument(AddDocumentOptions addDocumentOptions) {
Validator.notNull(addDocumentOptions, "addDocumentOptions cannot be null");
Validator.isTrue((addDocumentOptions.file() != null) || (addDocumentOptions.metadata() != null), "At least one of file or metadata must be supplied.");
String[] pathSegments = { "v1/environments", "collections", "documents" };
String[] pathParameters = { addDocumentOptions.environmentId(), addDocumentOptions.collectionId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
if (addDocumentOptions.file() != null) {
RequestBody fileBody = RequestUtils.inputStreamBody(addDocumentOptions.file(), addDocumentOptions.fileContentType());
multipartBuilder.addFormDataPart("file", addDocumentOptions.filename(), fileBody);
}
if (addDocumentOptions.metadata() != null) {
multipartBuilder.addFormDataPart("metadata", addDocumentOptions.metadata());
}
builder.body(multipartBuilder.build());
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DocumentAccepted.class));
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.
the class Discovery method createExpansions.
/**
* Set the expansion list.
*
* Create or replace the Expansion list for this collection. The maximum number of expanded terms per collection is
* `500`. The current expansion list is replaced with the uploaded content.
*
* @param createExpansionsOptions the {@link CreateExpansionsOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Expansions}
*/
public ServiceCall<Expansions> createExpansions(CreateExpansionsOptions createExpansionsOptions) {
Validator.notNull(createExpansionsOptions, "createExpansionsOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections", "expansions" };
String[] pathParameters = { createExpansionsOptions.environmentId(), createExpansionsOptions.collectionId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
if (createExpansionsOptions.expansions() != null) {
contentJson.add("expansions", GsonSingleton.getGson().toJsonTree(createExpansionsOptions.expansions()));
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Expansions.class));
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.
the class Discovery method addTrainingData.
/**
* Adds a query to the training data for this collection. The query can contain a filter and natural language query.
*
* @param addTrainingDataOptions the {@link AddTrainingDataOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link TrainingQuery}
*/
public ServiceCall<TrainingQuery> addTrainingData(AddTrainingDataOptions addTrainingDataOptions) {
Validator.notNull(addTrainingDataOptions, "addTrainingDataOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections", "training_data" };
String[] pathParameters = { addTrainingDataOptions.environmentId(), addTrainingDataOptions.collectionId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
if (addTrainingDataOptions.naturalLanguageQuery() != null) {
contentJson.addProperty("natural_language_query", addTrainingDataOptions.naturalLanguageQuery());
}
if (addTrainingDataOptions.filter() != null) {
contentJson.addProperty("filter", addTrainingDataOptions.filter());
}
if (addTrainingDataOptions.examples() != null) {
contentJson.add("examples", GsonSingleton.getGson().toJsonTree(addTrainingDataOptions.examples()));
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TrainingQuery.class));
}
Aggregations