use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.
the class Discovery method updateCollection.
/**
* Update a collection.
*
* @param updateCollectionOptions the {@link UpdateCollectionOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link Collection}
*/
public ServiceCall<Collection> updateCollection(UpdateCollectionOptions updateCollectionOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(updateCollectionOptions, "updateCollectionOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", updateCollectionOptions.environmentId());
pathParamsMap.put("collection_id", updateCollectionOptions.collectionId());
RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "updateCollection");
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", updateCollectionOptions.name());
if (updateCollectionOptions.description() != null) {
contentJson.addProperty("description", updateCollectionOptions.description());
}
if (updateCollectionOptions.configurationId() != null) {
contentJson.addProperty("configuration_id", updateCollectionOptions.configurationId());
}
builder.bodyJson(contentJson);
ResponseConverter<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.
the class Discovery method listExpansions.
/**
* Get the expansion list.
*
* <p>Returns the current expansion list for the specified collection. If an expansion list is not
* specified, an object with empty expansion arrays is returned.
*
* @param listExpansionsOptions the {@link ListExpansionsOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link Expansions}
*/
public ServiceCall<Expansions> listExpansions(ListExpansionsOptions listExpansionsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(listExpansionsOptions, "listExpansionsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", listExpansionsOptions.environmentId());
pathParamsMap.put("collection_id", listExpansionsOptions.collectionId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/expansions", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "listExpansions");
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));
ResponseConverter<Expansions> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Expansions>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.
the class Discovery method getStopwordListStatus.
/**
* Get stopword list status.
*
* <p>Returns the current status of the stopword list for the specified collection.
*
* @param getStopwordListStatusOptions the {@link GetStopwordListStatusOptions} containing the
* options for the call
* @return a {@link ServiceCall} with a result of type {@link TokenDictStatusResponse}
*/
public ServiceCall<TokenDictStatusResponse> getStopwordListStatus(GetStopwordListStatusOptions getStopwordListStatusOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getStopwordListStatusOptions, "getStopwordListStatusOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", getStopwordListStatusOptions.environmentId());
pathParamsMap.put("collection_id", getStopwordListStatusOptions.collectionId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/word_lists/stopwords", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getStopwordListStatus");
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));
ResponseConverter<TokenDictStatusResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TokenDictStatusResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.
the class Discovery method query.
/**
* Query a collection.
*
* <p>By using this method, you can construct long queries. For details, see the [Discovery
* documentation](https://cloud.ibm.com/docs/discovery?topic=discovery-query-concepts#query-concepts).
*
* @param queryOptions the {@link QueryOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link QueryResponse}
*/
public ServiceCall<QueryResponse> query(QueryOptions queryOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(queryOptions, "queryOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", queryOptions.environmentId());
pathParamsMap.put("collection_id", queryOptions.collectionId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/query", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "query");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (queryOptions.xWatsonLoggingOptOut() != null) {
builder.header("X-Watson-Logging-Opt-Out", queryOptions.xWatsonLoggingOptOut());
}
builder.query("version", String.valueOf(this.version));
final JsonObject contentJson = new JsonObject();
if (queryOptions.filter() != null) {
contentJson.addProperty("filter", queryOptions.filter());
}
if (queryOptions.query() != null) {
contentJson.addProperty("query", queryOptions.query());
}
if (queryOptions.naturalLanguageQuery() != null) {
contentJson.addProperty("natural_language_query", queryOptions.naturalLanguageQuery());
}
if (queryOptions.passages() != null) {
contentJson.addProperty("passages", queryOptions.passages());
}
if (queryOptions.aggregation() != null) {
contentJson.addProperty("aggregation", queryOptions.aggregation());
}
if (queryOptions.count() != null) {
contentJson.addProperty("count", queryOptions.count());
}
if (queryOptions.xReturn() != null) {
contentJson.addProperty("return", queryOptions.xReturn());
}
if (queryOptions.offset() != null) {
contentJson.addProperty("offset", queryOptions.offset());
}
if (queryOptions.sort() != null) {
contentJson.addProperty("sort", queryOptions.sort());
}
if (queryOptions.highlight() != null) {
contentJson.addProperty("highlight", queryOptions.highlight());
}
if (queryOptions.passagesFields() != null) {
contentJson.addProperty("passages.fields", queryOptions.passagesFields());
}
if (queryOptions.passagesCount() != null) {
contentJson.addProperty("passages.count", queryOptions.passagesCount());
}
if (queryOptions.passagesCharacters() != null) {
contentJson.addProperty("passages.characters", queryOptions.passagesCharacters());
}
if (queryOptions.deduplicate() != null) {
contentJson.addProperty("deduplicate", queryOptions.deduplicate());
}
if (queryOptions.deduplicateField() != null) {
contentJson.addProperty("deduplicate.field", queryOptions.deduplicateField());
}
if (queryOptions.similar() != null) {
contentJson.addProperty("similar", queryOptions.similar());
}
if (queryOptions.similarDocumentIds() != null) {
contentJson.addProperty("similar.document_ids", queryOptions.similarDocumentIds());
}
if (queryOptions.similarFields() != null) {
contentJson.addProperty("similar.fields", queryOptions.similarFields());
}
if (queryOptions.bias() != null) {
contentJson.addProperty("bias", queryOptions.bias());
}
if (queryOptions.spellingSuggestions() != null) {
contentJson.addProperty("spelling_suggestions", queryOptions.spellingSuggestions());
}
builder.bodyJson(contentJson);
ResponseConverter<QueryResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<QueryResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.
the class Discovery method addTrainingData.
/**
* Add query to training data.
*
* <p>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 result of type {@link TrainingQuery}
*/
public ServiceCall<TrainingQuery> addTrainingData(AddTrainingDataOptions addTrainingDataOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(addTrainingDataOptions, "addTrainingDataOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", addTrainingDataOptions.environmentId());
pathParamsMap.put("collection_id", addTrainingDataOptions.collectionId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/training_data", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "addTrainingData");
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();
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", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(addTrainingDataOptions.examples()));
}
builder.bodyJson(contentJson);
ResponseConverter<TrainingQuery> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingQuery>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations