public void Profile() { IamConfig config = new IamConfig( apikey: apikey ); PersonalityInsightsService service = new PersonalityInsightsService(versionDate, config); service.SetEndpoint(url); Content content = new Content() { ContentItems = new List <ContentItem>() { new ContentItem() { Contenttype = ContentItem.ContenttypeEnumValue.TEXT_PLAIN, Language = ContentItem.LanguageEnumValue.EN, Content = contentToProfile } } }; var result = service.Profile( content: content, contentType: "text/plain", contentLanguage: "en", acceptLanguage: "en", rawScores: true, consumptionPreferences: true, csvHeaders: true ); Console.WriteLine(result.Response); }
public static void Main(string[] args) { #region Get Credentials string credentials = string.Empty; string _endpoint = string.Empty; string _username = string.Empty; string _password = string.Empty; if (string.IsNullOrEmpty(credentials)) { var parentDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.Parent.FullName; string credentialsFilepath = parentDirectory + Path.DirectorySeparatorChar + "sdk-credentials" + Path.DirectorySeparatorChar + "credentials.json"; if (File.Exists(credentialsFilepath)) { try { credentials = File.ReadAllText(credentialsFilepath); credentials = Utility.AddTopLevelObjectToJson(credentials, "VCAP_SERVICES"); } catch (Exception e) { throw new Exception(string.Format("Failed to load credentials: {0}", e.Message)); } VcapCredentials vcapCredentials = JsonConvert.DeserializeObject <VcapCredentials>(credentials); var vcapServices = JObject.Parse(credentials); Credential credential = vcapCredentials.GetCredentialByname("personality-insights-sdk")[0].Credentials; _endpoint = credential.Url; _username = credential.Username; _password = credential.Password; } else { Console.WriteLine("Credentials file does not exist. Please define credentials."); _username = ""; _password = ""; _endpoint = ""; } } #endregion PersonalityInsightsService _service = new PersonalityInsightsService(_username, _password, "2016-10-20"); _service.SetEndpoint(_endpoint); string contentToProfile = "The IBM Watson™ Personality Insights service provides a Representational State Transfer (REST) Application Programming Interface (API) that enables applications to derive insights from social media, enterprise data, or other digital communications. The service uses linguistic analytics to infer individuals' intrinsic personality characteristics, including Big Five, Needs, and Values, from digital communications such as email, text messages, tweets, and forum posts. The service can automatically infer, from potentially noisy social media, portraits of individuals that reflect their personality characteristics. The service can report consumption preferences based on the results of its analysis, and for JSON content that is timestamped, it can report temporal behavior."; // Test Profile Content content = new Content() { ContentItems = new List <ContentItem>() { new ContentItem() { Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN, Language = ContentItem.LanguageEnum.EN, Content = contentToProfile } } }; var result = _service.Profile(content, "text/plain", acceptLanguage: "application/json", rawScores: true, consumptionPreferences: true, csvHeaders: true); Console.WriteLine("Profile() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented)); Console.ReadKey(); }