Search in sources :

Example 6 with ContentItem

use of com.ibm.watson.personality_insights.v3.model.ContentItem in project java-sdk by watson-developer-cloud.

the class PersonalityInsightsIT method getProfileWithASingleSpanishContentItem.

/**
 * Gets the profile from a single content item in Spanish.
 *
 * @throws Exception the exception
 */
@Test
public void getProfileWithASingleSpanishContentItem() throws Exception {
    File file = new File(RESOURCE + "es.txt");
    String englishText = getStringFromInputStream(new FileInputStream(file));
    ContentItem cItem = new ContentItem.Builder(englishText).language(ContentItem.Language.ES).build();
    Content content = new Content.Builder().contentItems(Collections.singletonList(cItem)).build();
    ProfileOptions options = new ProfileOptions.Builder().content(content).consumptionPreferences(true).rawScores(true).build();
    Profile profile = service.profile(options).execute().getResult();
    assertProfile(profile);
}
Also used : ProfileOptions(com.ibm.watson.personality_insights.v3.model.ProfileOptions) Content(com.ibm.watson.personality_insights.v3.model.Content) File(java.io.File) FileInputStream(java.io.FileInputStream) ContentItem(com.ibm.watson.personality_insights.v3.model.ContentItem) Profile(com.ibm.watson.personality_insights.v3.model.Profile) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 7 with ContentItem

use of com.ibm.watson.personality_insights.v3.model.ContentItem in project java-sdk by watson-developer-cloud.

the class PersonalityInsightsTest method testProfileAsCsvWOptions.

@Test
public void testProfileAsCsvWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "\"operationResponse\"";
    String profileAsCsvPath = "/v3/profile";
    server.enqueue(new MockResponse().setHeader("Content-type", "text/csv").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ContentItem model
    ContentItem contentItemModel = new ContentItem.Builder().content("testString").id("testString").created(Long.valueOf("26")).updated(Long.valueOf("26")).contenttype("text/plain").language("en").parentid("testString").reply(false).forward(false).build();
    // Construct an instance of the Content model
    Content contentModel = new Content.Builder().contentItems(new java.util.ArrayList<ContentItem>(java.util.Arrays.asList(contentItemModel))).build();
    // Construct an instance of the ProfileOptions model
    ProfileOptions profileOptionsModel = new ProfileOptions.Builder().content(contentModel).contentLanguage("en").acceptLanguage("en").rawScores(false).csvHeaders(false).consumptionPreferences(false).build();
    // Invoke operation with valid options model (positive test)
    Response<InputStream> response = personalityInsightsService.profileAsCsv(profileOptionsModel).execute();
    assertNotNull(response);
    InputStream responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("raw_scores")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("csv_headers")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("consumption_preferences")), Boolean.valueOf(false));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, profileAsCsvPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) InputStream(java.io.InputStream) ProfileOptions(com.ibm.watson.personality_insights.v3.model.ProfileOptions) Content(com.ibm.watson.personality_insights.v3.model.Content) ContentItem(com.ibm.watson.personality_insights.v3.model.ContentItem) Test(org.testng.annotations.Test)

Aggregations

Test (org.junit.Test)5 Content (com.ibm.watson.personality_insights.v3.model.Content)4 ContentItem (com.ibm.watson.personality_insights.v3.model.ContentItem)4 ProfileOptions (com.ibm.watson.personality_insights.v3.model.ProfileOptions)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 Content (com.ibm.watson.developer_cloud.personality_insights.v3.model.Content)3 ContentItem (com.ibm.watson.developer_cloud.personality_insights.v3.model.ContentItem)3 Profile (com.ibm.watson.personality_insights.v3.model.Profile)3 Date (java.util.Date)3 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 Profile (com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile)2 ProfileOptions (com.ibm.watson.developer_cloud.personality_insights.v3.model.ProfileOptions)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Test (org.testng.annotations.Test)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 ConsumptionPreferences (com.ibm.watson.developer_cloud.personality_insights.v3.model.ConsumptionPreferences)1 ConsumptionPreferences (com.ibm.watson.personality_insights.v3.model.ConsumptionPreferences)1