Search in sources :

Example 11 with TrainingExample

use of com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample 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 TrainingExample

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

the class Discovery method createTrainingExample.

/**
 * Adds a new example to this training data query.
 *
 * @param createTrainingExampleOptions the {@link CreateTrainingExampleOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link TrainingExample}
 */
public ServiceCall<TrainingExample> createTrainingExample(CreateTrainingExampleOptions createTrainingExampleOptions) {
    Validator.notNull(createTrainingExampleOptions, "createTrainingExampleOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections", "training_data", "examples" };
    String[] pathParameters = { createTrainingExampleOptions.environmentId(), createTrainingExampleOptions.collectionId(), createTrainingExampleOptions.queryId() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (createTrainingExampleOptions.documentId() != null) {
        contentJson.addProperty("document_id", createTrainingExampleOptions.documentId());
    }
    if (createTrainingExampleOptions.crossReference() != null) {
        contentJson.addProperty("cross_reference", createTrainingExampleOptions.crossReference());
    }
    if (createTrainingExampleOptions.relevance() != null) {
        contentJson.addProperty("relevance", createTrainingExampleOptions.relevance());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TrainingExample.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) TrainingExample(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample) JsonObject(com.google.gson.JsonObject)

Aggregations

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