use of com.ibm.watson.discovery.v2.Discovery in project java-sdk by watson-developer-cloud.
the class Discovery method createTrainingQuery.
/**
* Create training query.
*
* <p>Add a query to the training data for this project. The query can contain a filter and
* natural language query.
*
* @param createTrainingQueryOptions the {@link CreateTrainingQueryOptions} containing the options
* for the call
* @return a {@link ServiceCall} with a result of type {@link TrainingQuery}
*/
public ServiceCall<TrainingQuery> createTrainingQuery(CreateTrainingQueryOptions createTrainingQueryOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createTrainingQueryOptions, "createTrainingQueryOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("project_id", createTrainingQueryOptions.projectId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/training_data/queries", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "createTrainingQuery");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("natural_language_query", createTrainingQueryOptions.naturalLanguageQuery());
contentJson.add("examples", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createTrainingQueryOptions.examples()));
if (createTrainingQueryOptions.filter() != null) {
contentJson.addProperty("filter", createTrainingQueryOptions.filter());
}
builder.bodyJson(contentJson);
ResponseConverter<TrainingQuery> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingQuery>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v2.Discovery in project java-sdk by watson-developer-cloud.
the class Discovery method deleteDocument.
/**
* Delete a document.
*
* <p>If the given document ID is invalid, or if the document is not found, then the a success
* response is returned (HTTP status code `200`) with the status set to 'deleted'.
*
* <p>**Note:** This operation only works on collections created to accept direct file uploads. It
* cannot be used to modify a collection that connects to an external source such as Microsoft
* SharePoint.
*
* <p>**Note:** Segments of an uploaded document cannot be deleted individually. Delete all
* segments by deleting using the `parent_document_id` of a segment result.
*
* @param deleteDocumentOptions the {@link DeleteDocumentOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link DeleteDocumentResponse}
*/
public ServiceCall<DeleteDocumentResponse> deleteDocument(DeleteDocumentOptions deleteDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteDocumentOptions, "deleteDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("project_id", deleteDocumentOptions.projectId());
pathParamsMap.put("collection_id", deleteDocumentOptions.collectionId());
pathParamsMap.put("document_id", deleteDocumentOptions.documentId());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/collections/{collection_id}/documents/{document_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "deleteDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (deleteDocumentOptions.xWatsonDiscoveryForce() != null) {
builder.header("X-Watson-Discovery-Force", deleteDocumentOptions.xWatsonDiscoveryForce());
}
builder.query("version", String.valueOf(this.version));
ResponseConverter<DeleteDocumentResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DeleteDocumentResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v2.Discovery in project java-sdk by watson-developer-cloud.
the class Discovery method createCollection.
/**
* Create a collection.
*
* <p>Create a new collection in the specified project.
*
* @param createCollectionOptions the {@link CreateCollectionOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link CollectionDetails}
*/
public ServiceCall<CollectionDetails> createCollection(CreateCollectionOptions createCollectionOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createCollectionOptions, "createCollectionOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("project_id", createCollectionOptions.projectId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/collections", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "createCollection");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("name", createCollectionOptions.name());
if (createCollectionOptions.description() != null) {
contentJson.addProperty("description", createCollectionOptions.description());
}
if (createCollectionOptions.language() != null) {
contentJson.addProperty("language", createCollectionOptions.language());
}
if (createCollectionOptions.enrichments() != null) {
contentJson.add("enrichments", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createCollectionOptions.enrichments()));
}
builder.bodyJson(contentJson);
ResponseConverter<CollectionDetails> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CollectionDetails>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v2.Discovery in project java-sdk by watson-developer-cloud.
the class Discovery method analyzeDocument.
/**
* Analyze a Document.
*
* <p>Process a document and return it for realtime use. Supports JSON files only.
*
* <p>The document is processed according to the collection's configuration settings but is not
* stored in the collection.
*
* <p>**Note:** This method is supported on installed instances of Discovery only.
*
* @param analyzeDocumentOptions the {@link AnalyzeDocumentOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link AnalyzedDocument}
*/
public ServiceCall<AnalyzedDocument> analyzeDocument(AnalyzeDocumentOptions analyzeDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(analyzeDocumentOptions, "analyzeDocumentOptions cannot be null");
com.ibm.cloud.sdk.core.util.Validator.isTrue((analyzeDocumentOptions.file() != null) || (analyzeDocumentOptions.metadata() != null), "At least one of file or metadata must be supplied.");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("project_id", analyzeDocumentOptions.projectId());
pathParamsMap.put("collection_id", analyzeDocumentOptions.collectionId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/collections/{collection_id}/analyze", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "analyzeDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
if (analyzeDocumentOptions.file() != null) {
okhttp3.RequestBody fileBody = RequestUtils.inputStreamBody(analyzeDocumentOptions.file(), analyzeDocumentOptions.fileContentType());
multipartBuilder.addFormDataPart("file", analyzeDocumentOptions.filename(), fileBody);
}
if (analyzeDocumentOptions.metadata() != null) {
multipartBuilder.addFormDataPart("metadata", analyzeDocumentOptions.metadata());
}
builder.body(multipartBuilder.build());
ResponseConverter<AnalyzedDocument> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AnalyzedDocument>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v2.Discovery in project java-sdk by watson-developer-cloud.
the class Discovery method updateDocument.
/**
* Update a document.
*
* <p>Replace an existing document or add a document with a specified **document_id**. Starts
* ingesting a document with optional metadata.
*
* <p>If the document is uploaded to a collection that shares its data with another collection,
* the **X-Watson-Discovery-Force** header must be set to `true`.
*
* <p>**Note:** When uploading a new document with this method it automatically replaces any
* document stored with the same **document_id** if it exists.
*
* <p>**Note:** This operation only works on collections created to accept direct file uploads. It
* cannot be used to modify a collection that connects to an external source such as Microsoft
* SharePoint.
*
* <p>**Note:** If an uploaded document is segmented, all segments are overwritten, even if the
* updated version of the document has fewer segments.
*
* @param updateDocumentOptions the {@link UpdateDocumentOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link DocumentAccepted}
*/
public ServiceCall<DocumentAccepted> updateDocument(UpdateDocumentOptions updateDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(updateDocumentOptions, "updateDocumentOptions cannot be null");
com.ibm.cloud.sdk.core.util.Validator.isTrue((updateDocumentOptions.file() != null) || (updateDocumentOptions.metadata() != null), "At least one of file or metadata must be supplied.");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("project_id", updateDocumentOptions.projectId());
pathParamsMap.put("collection_id", updateDocumentOptions.collectionId());
pathParamsMap.put("document_id", updateDocumentOptions.documentId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/collections/{collection_id}/documents/{document_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "updateDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (updateDocumentOptions.xWatsonDiscoveryForce() != null) {
builder.header("X-Watson-Discovery-Force", updateDocumentOptions.xWatsonDiscoveryForce());
}
builder.query("version", String.valueOf(this.version));
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
if (updateDocumentOptions.file() != null) {
okhttp3.RequestBody fileBody = RequestUtils.inputStreamBody(updateDocumentOptions.file(), updateDocumentOptions.fileContentType());
multipartBuilder.addFormDataPart("file", updateDocumentOptions.filename(), fileBody);
}
if (updateDocumentOptions.metadata() != null) {
multipartBuilder.addFormDataPart("metadata", updateDocumentOptions.metadata());
}
builder.body(multipartBuilder.build());
ResponseConverter<DocumentAccepted> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentAccepted>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations