use of com.ibm.watson.personality_insights.v3.model.Content in project atlas-deer by atlasapi.
the class ContainerSetter method deserialize.
public void deserialize(org.atlasapi.content.Content content, org.atlasapi.content.v2.model.Content internal) {
Container container = (Container) content;
Map<Ref, PartialItemRef> itemRefs = internal.getItemRefs();
if (itemRefs != null) {
container.setItemRefs(itemRefs.entrySet().stream().map(entry -> itemRef.deserialize(entry.getKey(), entry.getValue())).collect(Collectors.toList()));
}
Map<Ref, ItemRefAndBroadcastRefs> internalUpcomingContent = internal.getUpcomingContent();
if (internalUpcomingContent != null) {
Map<org.atlasapi.content.ItemRef, Iterable<org.atlasapi.content.BroadcastRef>> upcomingContent = internalUpcomingContent.entrySet().stream().collect(MoreCollectors.toImmutableMap(entry -> {
Ref ref = entry.getKey();
ItemRefAndBroadcastRefs broadcasts = entry.getValue();
return itemRef.deserialize(ref, broadcasts.getItemRef());
}, entry -> entry.getValue().getBroadcastRefs().stream().map(broadcastRef::deserialize).collect(MoreCollectors.toImmutableList())));
container.setUpcomingContent(upcomingContent);
}
Map<Ref, ItemRefAndLocationSummaries> internalAvailableContent = internal.getAvailableContent();
if (internalAvailableContent != null) {
Map<org.atlasapi.content.ItemRef, Iterable<org.atlasapi.content.LocationSummary>> availableContent = internalAvailableContent.entrySet().stream().collect(MoreCollectors.toImmutableMap(entry -> {
Ref ref = entry.getKey();
ItemRefAndLocationSummaries locations = entry.getValue();
return itemRef.deserialize(ref, locations.getItemRef());
}, entry -> entry.getValue().getLocationSummaries().stream().map(locationSummary::deserialize).collect(MoreCollectors.toImmutableList())));
container.setAvailableContent(availableContent);
}
Map<Ref, ItemRefAndItemSummary> itemSummaries = internal.getItemSummaries();
if (itemSummaries != null) {
container.setItemSummaries(itemSummaries.entrySet().stream().map(entry -> {
Ref ref = entry.getKey();
ItemRefAndItemSummary summaryWithRef = entry.getValue();
ItemSummary summary = summaryWithRef.getSummary();
return itemSummary.deserialize(ref, summaryWithRef.getItemRef(), summary);
}).collect(MoreCollectors.toImmutableList()));
}
}
use of com.ibm.watson.personality_insights.v3.model.Content in project java-sdk by watson-developer-cloud.
the class PersonalityInsights method profile.
/**
* Get profile.
*
* <p>Generates a personality profile for the author of the input text. The service accepts a
* maximum of 20 MB of input content, but it requires much less text to produce an accurate
* profile. The service can analyze text in Arabic, English, Japanese, Korean, or Spanish. It can
* return its results in a variety of languages.
*
* <p>**See also:** * [Requesting a
* profile](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-input#input)
* * [Providing sufficient
* input](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-input#sufficient)
*
* <p>### Content types
*
* <p>You can provide input content as plain text (`text/plain`), HTML (`text/html`), or JSON
* (`application/json`) by specifying the **Content-Type** parameter. The default is `text/plain`.
* * Per the JSON specification, the default character encoding for JSON content is effectively
* always UTF-8. * Per the HTTP specification, the default encoding for plain text and HTML is
* ISO-8859-1 (effectively, the ASCII character set).
*
* <p>When specifying a content type of plain text or HTML, include the `charset` parameter to
* indicate the character encoding of the input text; for example, `Content-Type:
* text/plain;charset=utf-8`.
*
* <p>**See also:** [Specifying request and response
* formats](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-input#formats)
*
* <p>### Accept types
*
* <p>You must request a response as JSON (`application/json`) or comma-separated values
* (`text/csv`) by specifying the **Accept** parameter. CSV output includes a fixed number of
* columns. Set the **csv_headers** parameter to `true` to request optional column headers for CSV
* output.
*
* <p>**See also:** * [Understanding a JSON
* profile](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-output#output)
* * [Understanding a CSV
* profile](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-outputCSV#outputCSV).
*
* @param profileOptions the {@link ProfileOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Profile}
*/
public ServiceCall<Profile> profile(ProfileOptions profileOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(profileOptions, "profileOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v3/profile"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("personality_insights", "v3", "profile");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (profileOptions.contentType() != null) {
builder.header("Content-Type", profileOptions.contentType());
}
if (profileOptions.contentLanguage() != null) {
builder.header("Content-Language", profileOptions.contentLanguage());
}
if (profileOptions.acceptLanguage() != null) {
builder.header("Accept-Language", profileOptions.acceptLanguage());
}
builder.query("version", String.valueOf(this.version));
if (profileOptions.rawScores() != null) {
builder.query("raw_scores", String.valueOf(profileOptions.rawScores()));
}
if (profileOptions.csvHeaders() != null) {
builder.query("csv_headers", String.valueOf(profileOptions.csvHeaders()));
}
if (profileOptions.consumptionPreferences() != null) {
builder.query("consumption_preferences", String.valueOf(profileOptions.consumptionPreferences()));
}
builder.bodyContent(profileOptions.contentType(), profileOptions.content(), null, profileOptions.body());
ResponseConverter<Profile> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Profile>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.personality_insights.v3.model.Content 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);
}
use of com.ibm.watson.personality_insights.v3.model.Content in project java-sdk by watson-developer-cloud.
the class PersonalityInsightsIT method testReadme.
/**
* Test example in Readme.
*/
@Test
public void testReadme() {
// Demo content from Moby Dick by Hermann Melville (Chapter 1)
String text = "Call me Ishmael. Some years ago-never mind how long precisely-having " + "little or no money in my purse, and nothing particular to interest me on shore, " + "I thought I would sail about a little and see the watery part of the world. " + "It is a way I have of driving off the spleen and regulating the circulation. " + "Whenever I find myself growing grim about the mouth; whenever it is a damp, " + "drizzly November in my soul; whenever I find myself involuntarily pausing before " + "coffin warehouses, and bringing up the rear of every funeral I meet; and especially " + "whenever my hypos get such an upper hand of me, that it requires a strong moral " + "principle to prevent me from deliberately stepping into the street, and methodically " + "knocking people's hats off-then, I account it high time to get to sea as soon as I can. " + "This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself " + "upon his sword; I quietly take to the ship. There is nothing surprising in this. " + "If they but knew it, almost all men in their degree, some time or other, cherish " + "very nearly the same feelings towards the ocean with me. There now is your insular " + "city of the Manhattoes, belted round by wharves as Indian isles by coral reefs-commerce surrounds " + "it with her surf. Right and left, the streets take you waterward.";
ProfileOptions options = new ProfileOptions.Builder().text(text).build();
Profile profile = service.profile(options).execute().getResult();
Assert.assertNotNull(profile);
// System.out.println(profile);
}
use of com.ibm.watson.personality_insights.v3.model.Content 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);
}
Aggregations