Search in sources :

Example 11 with TrainingQuery

use of com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method deleteTrainingDataExampleIsSuccessful.

@Test
public void deleteTrainingDataExampleIsSuccessful() {
    TrainingQuery newQuery = createTestQuery(collectionId, "Query" + UUID.randomUUID().toString());
    String queryId = newQuery.getQueryId();
    String documentId = "document_id";
    String crossReference = "cross_reference";
    int relevance = 50;
    CreateTrainingExampleOptions.Builder exampleBuilder = new CreateTrainingExampleOptions.Builder(environmentId, collectionId, queryId);
    exampleBuilder.documentId(documentId);
    exampleBuilder.crossReference(crossReference);
    exampleBuilder.relevance(relevance);
    TrainingExample createdExample = discovery.createTrainingExample(exampleBuilder.build()).execute();
    String exampleId = createdExample.getDocumentId();
    GetTrainingDataOptions.Builder queryBuilder = new GetTrainingDataOptions.Builder(environmentId, collectionId, queryId);
    TrainingQuery queryWithAddedExample = discovery.getTrainingData(queryBuilder.build()).execute();
    int startingCount = queryWithAddedExample.getExamples().size();
    DeleteTrainingExampleOptions.Builder deleteBuilder = new DeleteTrainingExampleOptions.Builder(environmentId, collectionId, queryId, exampleId);
    discovery.deleteTrainingExample(deleteBuilder.build()).execute();
    GetTrainingDataOptions.Builder newQueryBuilder = new GetTrainingDataOptions.Builder(environmentId, collectionId, queryId);
    TrainingQuery queryWithDeletedExample = discovery.getTrainingData(newQueryBuilder.build()).execute();
    assertTrue(startingCount > queryWithDeletedExample.getExamples().size());
}
Also used : CreateTrainingExampleOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateTrainingExampleOptions) GetTrainingDataOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetTrainingDataOptions) TrainingExample(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample) DeleteTrainingExampleOptions(com.ibm.watson.developer_cloud.discovery.v1.model.DeleteTrainingExampleOptions) TrainingQuery(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 12 with TrainingQuery

use of com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery 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));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) TrainingQuery(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery)

Aggregations

TrainingQuery (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery)12 Test (org.junit.Test)9 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)7 TrainingExample (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample)6 AddTrainingDataOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddTrainingDataOptions)5 GetTrainingDataOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetTrainingDataOptions)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 CreateTrainingExampleOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateTrainingExampleOptions)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 JsonObject (com.google.gson.JsonObject)1 DeleteTrainingDataOptions (com.ibm.watson.developer_cloud.discovery.v1.model.DeleteTrainingDataOptions)1 DeleteTrainingExampleOptions (com.ibm.watson.developer_cloud.discovery.v1.model.DeleteTrainingExampleOptions)1 GetTrainingExampleOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetTrainingExampleOptions)1 ListTrainingDataOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListTrainingDataOptions)1 TrainingDataSet (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingDataSet)1 UpdateTrainingExampleOptions (com.ibm.watson.developer_cloud.discovery.v1.model.UpdateTrainingExampleOptions)1