use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Discovery method query.
/**
* Query documents.
*
* See the [Discovery service documentation](https://console.bluemix.net/docs/services/discovery/using.html) for more
* details.
*
* @param queryOptions the {@link QueryOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link QueryResponse}
*/
public ServiceCall<QueryResponse> query(QueryOptions queryOptions) {
Validator.notNull(queryOptions, "queryOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections", "query" };
String[] pathParameters = { queryOptions.environmentId(), queryOptions.collectionId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
if (queryOptions.filter() != null) {
builder.query("filter", queryOptions.filter());
}
if (queryOptions.query() != null) {
builder.query("query", queryOptions.query());
}
if (queryOptions.naturalLanguageQuery() != null) {
builder.query("natural_language_query", queryOptions.naturalLanguageQuery());
}
if (queryOptions.passages() != null) {
builder.query("passages", String.valueOf(queryOptions.passages()));
}
if (queryOptions.aggregation() != null) {
builder.query("aggregation", queryOptions.aggregation());
}
if (queryOptions.count() != null) {
builder.query("count", String.valueOf(queryOptions.count()));
}
if (queryOptions.returnFields() != null) {
builder.query("return", RequestUtils.join(queryOptions.returnFields(), ","));
}
if (queryOptions.offset() != null) {
builder.query("offset", String.valueOf(queryOptions.offset()));
}
if (queryOptions.sort() != null) {
builder.query("sort", RequestUtils.join(queryOptions.sort(), ","));
}
if (queryOptions.highlight() != null) {
builder.query("highlight", String.valueOf(queryOptions.highlight()));
}
if (queryOptions.passagesFields() != null) {
builder.query("passages.fields", RequestUtils.join(queryOptions.passagesFields(), ","));
}
if (queryOptions.passagesCount() != null) {
builder.query("passages.count", String.valueOf(queryOptions.passagesCount()));
}
if (queryOptions.passagesCharacters() != null) {
builder.query("passages.characters", String.valueOf(queryOptions.passagesCharacters()));
}
if (queryOptions.deduplicate() != null) {
builder.query("deduplicate", String.valueOf(queryOptions.deduplicate()));
}
if (queryOptions.deduplicateField() != null) {
builder.query("deduplicate.field", queryOptions.deduplicateField());
}
if (queryOptions.similar() != null) {
builder.query("similar", String.valueOf(queryOptions.similar()));
}
if (queryOptions.similarDocumentIds() != null) {
builder.query("similar.document_ids", RequestUtils.join(queryOptions.similarDocumentIds(), ","));
}
if (queryOptions.similarFields() != null) {
builder.query("similar.fields", RequestUtils.join(queryOptions.similarFields(), ","));
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(QueryResponse.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Discovery method getCollection.
/**
* Get collection details.
*
* @param getCollectionOptions the {@link GetCollectionOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Collection}
*/
public ServiceCall<Collection> getCollection(GetCollectionOptions getCollectionOptions) {
Validator.notNull(getCollectionOptions, "getCollectionOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections" };
String[] pathParameters = { getCollectionOptions.environmentId(), getCollectionOptions.collectionId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Collection.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Discovery method deleteCollection.
/**
* Delete a collection.
*
* @param deleteCollectionOptions the {@link DeleteCollectionOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of Void
*/
public ServiceCall<Void> deleteCollection(DeleteCollectionOptions deleteCollectionOptions) {
Validator.notNull(deleteCollectionOptions, "deleteCollectionOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections" };
String[] pathParameters = { deleteCollectionOptions.environmentId(), deleteCollectionOptions.collectionId() };
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Discovery method getConfiguration.
/**
* Get configuration details.
*
* @param getConfigurationOptions the {@link GetConfigurationOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Configuration}
*/
public ServiceCall<Configuration> getConfiguration(GetConfigurationOptions getConfigurationOptions) {
Validator.notNull(getConfigurationOptions, "getConfigurationOptions cannot be null");
String[] pathSegments = { "v1/environments", "configurations" };
String[] pathParameters = { getConfigurationOptions.environmentId(), getConfigurationOptions.configurationId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Configuration.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Discovery method queryEntities.
/**
* Knowledge Graph entity query.
*
* See the [Knowledge Graph documentation](https://console.bluemix.net/docs/services/discovery/building-kg.html) for
* more details.
*
* @param queryEntitiesOptions the {@link QueryEntitiesOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link QueryEntitiesResponse}
*/
public ServiceCall<QueryEntitiesResponse> queryEntities(QueryEntitiesOptions queryEntitiesOptions) {
Validator.notNull(queryEntitiesOptions, "queryEntitiesOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections", "query_entities" };
String[] pathParameters = { queryEntitiesOptions.environmentId(), queryEntitiesOptions.collectionId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
if (queryEntitiesOptions.feature() != null) {
contentJson.addProperty("feature", queryEntitiesOptions.feature());
}
if (queryEntitiesOptions.entity() != null) {
contentJson.add("entity", GsonSingleton.getGson().toJsonTree(queryEntitiesOptions.entity()));
}
if (queryEntitiesOptions.context() != null) {
contentJson.add("context", GsonSingleton.getGson().toJsonTree(queryEntitiesOptions.context()));
}
if (queryEntitiesOptions.count() != null) {
contentJson.addProperty("count", queryEntitiesOptions.count());
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(QueryEntitiesResponse.class));
}
Aggregations