Search in sources :

Example 6 with TrainingQuery

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

the class DiscoveryServiceIT method createTestQuery.

private TrainingQuery createTestQuery(String collectionId, String naturalLanguageQuery) {
    AddTrainingDataOptions.Builder builder = new AddTrainingDataOptions.Builder(environmentId, collectionId);
    builder.naturalLanguageQuery(naturalLanguageQuery);
    TrainingQuery addResponse = discovery.addTrainingData(builder.build()).execute();
    return addResponse;
}
Also used : AddTrainingDataOptions(com.ibm.watson.developer_cloud.discovery.v1.model.AddTrainingDataOptions) TrainingQuery(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery)

Example 7 with TrainingQuery

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

the class Discovery method getTrainingData.

/**
 * Shows details for a specific training data query, including the query string and all examples.
 *
 * @param getTrainingDataOptions the {@link GetTrainingDataOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link TrainingQuery}
 */
public ServiceCall<TrainingQuery> getTrainingData(GetTrainingDataOptions getTrainingDataOptions) {
    Validator.notNull(getTrainingDataOptions, "getTrainingDataOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections", "training_data" };
    String[] pathParameters = { getTrainingDataOptions.environmentId(), getTrainingDataOptions.collectionId(), getTrainingDataOptions.queryId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TrainingQuery.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) TrainingQuery(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery)

Example 8 with TrainingQuery

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

the class DiscoveryServiceTest method getTrainingDataIsSuccessful.

/**
 * Gets the training data is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void getTrainingDataIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(getTrainingDataResp));
    GetTrainingDataOptions.Builder builder = new GetTrainingDataOptions.Builder(environmentId, collectionId, queryId);
    TrainingQuery response = discoveryService.getTrainingData(builder.build()).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(TRAINING3_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(getTrainingDataResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetTrainingDataOptions(com.ibm.watson.discovery.v1.model.GetTrainingDataOptions) TrainingQuery(com.ibm.watson.discovery.v1.model.TrainingQuery) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 9 with TrainingQuery

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

the class DiscoveryTest method testGetTrainingDataWOptions.

// Test the getTrainingData operation with a valid options model parameter
@Test
public void testGetTrainingDataWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"query_id\": \"queryId\", \"natural_language_query\": \"naturalLanguageQuery\", \"filter\": \"filter\", \"examples\": [{\"document_id\": \"documentId\", \"cross_reference\": \"crossReference\", \"relevance\": 9}]}";
    String getTrainingDataPath = "/v1/environments/testString/collections/testString/training_data/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetTrainingDataOptions model
    GetTrainingDataOptions getTrainingDataOptionsModel = new GetTrainingDataOptions.Builder().environmentId("testString").collectionId("testString").queryId("testString").build();
    // Invoke getTrainingData() with a valid options model and verify the result
    Response<TrainingQuery> response = discoveryService.getTrainingData(getTrainingDataOptionsModel).execute();
    assertNotNull(response);
    TrainingQuery responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getTrainingDataPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetTrainingDataOptions(com.ibm.watson.discovery.v1.model.GetTrainingDataOptions) TrainingQuery(com.ibm.watson.discovery.v1.model.TrainingQuery) Test(org.testng.annotations.Test)

Example 10 with TrainingQuery

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

the class DiscoveryServiceTest method addTrainingDataIsSuccessful.

/**
 * Adds the training data is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
// Training data tests
@Test
public void addTrainingDataIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(addTrainingQueryResp));
    AddTrainingDataOptions.Builder builder = new AddTrainingDataOptions.Builder(environmentId, collectionId);
    builder.naturalLanguageQuery("Example query");
    TrainingExample example = new TrainingExample.Builder().documentId(documentId).relevance(0).build();
    builder.addExamples(example);
    TrainingQuery response = discoveryService.addTrainingData(builder.build()).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(TRAINING1_PATH, request.getPath());
    assertEquals(POST, request.getMethod());
    assertEquals(addTrainingQueryResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) AddTrainingDataOptions(com.ibm.watson.discovery.v1.model.AddTrainingDataOptions) TrainingExample(com.ibm.watson.discovery.v1.model.TrainingExample) TrainingQuery(com.ibm.watson.discovery.v1.model.TrainingQuery) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Aggregations

TrainingQuery (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery)12 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)9 Test (org.junit.Test)9 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)7 TrainingExample (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample)6 TrainingQuery (com.ibm.watson.discovery.v1.model.TrainingQuery)6 TrainingQuery (com.ibm.watson.discovery.v2.model.TrainingQuery)6 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)5 AddTrainingDataOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddTrainingDataOptions)5 HashMap (java.util.HashMap)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 Test (org.testng.annotations.Test)5 JsonObject (com.google.gson.JsonObject)4 GetTrainingDataOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetTrainingDataOptions)4 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)2 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 AddTrainingDataOptions (com.ibm.watson.discovery.v1.model.AddTrainingDataOptions)2 GetTrainingDataOptions (com.ibm.watson.discovery.v1.model.GetTrainingDataOptions)2