private IEnumerator Examples() { Content content = new Content() { ContentItems = new List <ContentItem>() { new ContentItem() { Content = testString, Contenttype = ContentItem.ContenttypeValue.TEXT_PLAIN, Language = ContentItem.LanguageValue.EN } } }; Log.Debug("ExamplePersonalityInsights.Examples()", "Attempting to Profile..."); service.Profile(OnProfile, content: content); while (!profileTested) { yield return(null); } Log.Debug("ExamplePersonalityInsights.Examples()", "Attempting to ProfileAsCsv..."); service.ProfileAsCsv(OnProfileAsCsv, content: content, consumptionPreferences: true); while (!profileAsCsvTested) { yield return(null); } Log.Debug("ExamplePersonalityInsights.Examples()", "Personality insights examples complete."); }
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 void Profile_No_Content() { PersonalityInsightsService service = new PersonalityInsightsService("username", "password", "versionDate"); service.Profile(null, "contentType"); }
public void Profile() { TokenOptions tokenOptions = new TokenOptions() { IamApiKey = apikey, ServiceUrl = url }; PersonalityInsightsService service = new PersonalityInsightsService(tokenOptions, versionDate); 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 void Profle_Catch_Exception() { IClient client = CreateClient(); IRequest request = Substitute.For <IRequest>(); client.PostAsync(Arg.Any <string>()) .Returns(x => { throw new AggregateException(new ServiceResponseException(Substitute.For <IResponse>(), Substitute.For <HttpResponseMessage>(HttpStatusCode.BadRequest), string.Empty)); }); // Test Profile Content content = new Content() { ContentItems = new List <ContentItem>() { new ContentItem() { Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN, Language = ContentItem.LanguageEnum.EN, Content = contentString } } }; PersonalityInsightsService service = new PersonalityInsightsService(client); service.VersionDate = "versionDate"; service.Profile(content, "contentType", "application/json"); }
public void Profile() { IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}"); PersonalityInsightsService service = new PersonalityInsightsService("2017-10-13", authenticator); service.SetServiceUrl("{serviceUrl}"); using (FileStream fs = File.OpenRead("profile.json")) { using (MemoryStream ms = new MemoryStream()) { fs.CopyTo(ms); var result = service.Profile( content: ms, contentType: "application/json", rawScores: true, consumptionPreferences: true ); Console.WriteLine(result.Response); } } }
public static void Main(string[] args) { var environmentVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES"); var fileContent = File.ReadAllText(environmentVariable); var vcapServices = JObject.Parse(fileContent); var _username = vcapServices["personality_insights"][0]["credentials"]["username"]; var _password = vcapServices["personality_insights"][0]["credentials"]["password"]; PersonalityInsightsService _personalityInsights = new PersonalityInsightsService(_username.ToString(), _password.ToString(), "2016-10-20"); string content = "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 ContentListContainer contentListContainer = new ContentListContainer() { ContentItems = new List <ContentItem>() { new ContentItem() { Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN, Language = ContentItem.LanguageEnum.EN, Content = content } } }; var result = _personalityInsights.Profile("text/plain", "application/json", contentListContainer, rawScores: true, consumptionPreferences: true, csvHeaders: true); Console.WriteLine(string.Format("Profile result: {0}", result)); Console.ReadKey(); }
public void Profile_Success() { 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."; Content content = new Content() { ContentItems = new List<ContentItem>() { new ContentItem() { Contenttype = ContentItem.ContenttypeEnumValue.TEXT_PLAIN, Language = ContentItem.LanguageEnumValue.EN, Content = contentToProfile } } }; service.WithHeader("X-Watson-Test", "1"); var result = service.Profile( content: content, contentType: "text/plain", contentLanguage: "en", acceptLanguage: "en", rawScores: true, consumptionPreferences: true, csvHeaders: true ); Assert.IsNotNull(result.Result); Assert.IsNotNull(result.Result.Personality); }
public IEnumerator TestProfile() { Log.Debug("PersonalityInsightsServiceV3IntegrationTests", "Attempting to Profile..."); Profile profileResponse = null; byte[] bytes = Encoding.ASCII.GetBytes(contentToProfile); MemoryStream content = new MemoryStream(bytes); service.Profile( callback: (DetailedResponse <Profile> response, IBMError error) => { Log.Debug("PersonalityInsightsServiceV3IntegrationTests", "Profile result: {0}", response.Response); profileResponse = response.Result; Assert.IsNotNull(profileResponse); Assert.IsNotNull(profileResponse.Personality); Assert.IsNull(error); }, content: content, contentLanguage: "en", acceptLanguage: "en", rawScores: true, csvHeaders: true, consumptionPreferences: true, contentType: "text/plain" ); while (profileResponse == null) { yield return(null); } }
public void Profile_Success() { IClient client = Substitute.For <IClient>(); IRequest request = Substitute.For <IRequest>(); client.PostAsync(Arg.Any <string>()) .Returns(request); PersonalityInsightsService service = new PersonalityInsightsService(client); var versionDate = "versionDate"; service.Version = versionDate; var content = new MemoryStream(); var contentType = "contentType"; var contentLanguage = "contentLanguage"; var acceptLanguage = "acceptLanguage"; var rawScores = false; var csvHeaders = false; var consumptionPreferences = false; var result = service.Profile(content: content, contentType: contentType, contentLanguage: contentLanguage, acceptLanguage: acceptLanguage, rawScores: rawScores, csvHeaders: csvHeaders, consumptionPreferences: consumptionPreferences); JObject bodyObject = new JObject(); var json = JsonConvert.SerializeObject(bodyObject); request.Received().WithArgument("version", versionDate); //TODO: fix unit test //request.Received().WithBodyContent(Arg.Is<StringContent>(x => x.ReadAsStringAsync().Result.Equals(json))); }
private Profile Profile(Content content, string contentType, string contentLanguage = null, string acceptLanguage = null, bool?rawScores = null, bool?csvHeaders = null, bool?consumptionPreferences = null) { Console.WriteLine("\nAttempting to Profile()"); var result = _service.Profile(content: content, contentType: contentType, contentLanguage: contentLanguage, acceptLanguage: acceptLanguage, rawScores: rawScores, csvHeaders: csvHeaders, consumptionPreferences: consumptionPreferences); if (result != null) { Console.WriteLine("Profile() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented)); } else { Console.WriteLine("Failed to Profile()"); } return(result); }
public ActionResult Sonuc([FromBody] WatsonPI.Gelen value) { try { if (value.Body != null && value.Body.Length > 0) { var credential = GoogleCredential.FromFile("C:\\Shelff-4e74dc12eb0d.json"); TranslationClient client = TranslationClient.Create(credential); var response = client.TranslateText(value.Body, "en"); string contentToProfile = response.TranslatedText; PersonalityInsightsService _personalityInsights = new PersonalityInsightsService("6480d872-d50e-46bc-84e9-c24da9ea920b", "wWUDvxn3NdGw", "2017-10-13"); Content content = new Content() { ContentItems = new List <ContentItem>() { new ContentItem() { Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN, Language = ContentItem.LanguageEnum.EN, Content = contentToProfile } } }; var result = _personalityInsights.Profile(content, "text/plain", acceptLanguage: "application/json", rawScores: true, consumptionPreferences: true, csvHeaders: true); WatsonPI.Sonuclar sonuc = new WatsonPI.Sonuclar { Personality = result.Personality, Needs = result.Needs, Values = result.Values }; return(Json(sonuc)); } else { return(BadRequest()); } } catch (Exception ex) { return(BadRequest(ex)); } }
public void Profile_No_Accept() { PersonalityInsightsService service = new PersonalityInsightsService("username", "password", "versionDate"); // Test Profile ContentListContainer contentListContainer = new ContentListContainer() { ContentItems = new List <ContentItem>() { new ContentItem() { Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN, Language = ContentItem.LanguageEnum.EN, Content = content } } }; service.Profile("test", null, contentListContainer); }
private IEnumerator Examples() { byte[] bytes = Encoding.ASCII.GetBytes(testString); MemoryStream content = new MemoryStream(bytes); Log.Debug("ExamplePersonalityInsights.Examples()", "Attempting to Profile..."); service.Profile(OnProfile, content: content); while (!profileTested) { yield return(null); } Log.Debug("ExamplePersonalityInsights.Examples()", "Attempting to ProfileAsCsv..."); service.ProfileAsCsv(OnProfileAsCsv, content: content, consumptionPreferences: true); while (!profileAsCsvTested) { yield return(null); } Log.Debug("ExamplePersonalityInsights.Examples()", "Personality insights examples complete."); }
public IEnumerator TestProfile() { Log.Debug("PersonalityInsightsServiceV3IntegrationTests", "Attempting to Profile..."); Profile profileResponse = null; Content content = new Content() { ContentItems = new List <ContentItem>() { new ContentItem() { Contenttype = ContentItem.ContenttypeValue.TEXT_PLAIN, Language = ContentItem.LanguageValue.EN, Content = contentToProfile } } }; service.Profile( callback: (DetailedResponse <Profile> response, IBMError error) => { Log.Debug("PersonalityInsightsServiceV3IntegrationTests", "Profile result: {0}", response.Response); profileResponse = response.Result; Assert.IsNotNull(profileResponse); Assert.IsNotNull(profileResponse.Personality); Assert.IsNull(error); }, content: content, contentLanguage: "en", acceptLanguage: "en", rawScores: true, csvHeaders: true, consumptionPreferences: true, contentType: "text/plain" ); while (profileResponse == null) { yield return(null); } }
public void Profile_No_Content_Type() { PersonalityInsightsService service = new PersonalityInsightsService("username", "password", "versionDate"); // Test Profile Content content = new Content() { ContentItems = new List <ContentItem>() { new ContentItem() { Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN, Language = ContentItem.LanguageEnum.EN, Content = contentString } } }; service.Profile(content, null); }
public void AnalyzePersonality(Options option, string content) { // TODO Build from var personalityContents = new Content() { ContentItems = new List <ContentItem> { new ContentItem() { Content = content } } }; var result = PersonalityService.Profile( content: personalityContents, contentType: "application/json", rawScores: true, consumptionPreferences: true ); if (option.Verbose) { Console.WriteLine(result.Response); } result.Result.ConsumptionPreferences?.SelectMany(cp => cp.ConsumptionPreferences).ToList() .ForEach(cp => Console.WriteLine($"CP:{cp.Name}: {cp.Score.ToPcnt()}")); result.Result.Behavior?.ForEach(b => Console.WriteLine($"B:{b.Name}:{b.Percentage.ToPcnt()}") ); result.Result.Personality.ForEach(p => Console.WriteLine($"P:{p.Name}:{p.Percentile.ToPcnt()} Significant:{p.Significant}") ); Console.WriteLine($"Analyzed Words: {result.Result.WordCount}"); }
public void Profile() { IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}"); PersonalityInsightsService service = new PersonalityInsightsService("2017-10-13", authenticator); service.SetServiceUrl("{serviceUrl}"); Content content = null; content = JsonConvert.DeserializeObject <Content>(File.ReadAllText("profile.json")); var result = service.Profile( content: content, contentType: "application/json", rawScores: true, consumptionPreferences: true ); Console.WriteLine(result.Response); }
public void Profile_Success() { PersonalityInsightsService _personalityInsights = new PersonalityInsightsService(_username.ToString(), _password.ToString(), "2016-10-20"); string content = "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."; ContentListContainer contentListContainer = new ContentListContainer() { ContentItems = new List <ContentItem>() { new ContentItem() { Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN, Language = ContentItem.LanguageEnum.EN, Content = content } } }; var result = _personalityInsights.Profile("text/plain", "application/json", contentListContainer, rawScores: true, consumptionPreferences: true, csvHeaders: true); Assert.IsNotNull(result); }
public DetailedResponse <Profile> GetInsights(string text) { string apiKey = _appConfiguration["WatsonAPIs:PersonalityInsights:Key"]; string version = _appConfiguration["WatsonAPIs:PersonalityInsights:Version"]; string instanceURL = _appConfiguration["WatsonAPIs:PersonalityInsights:InstanceURL"]; //Check settings are OK if (String.IsNullOrEmpty(apiKey) || String.IsNullOrEmpty(version) || String.IsNullOrEmpty(instanceURL)) { throw new Exception("Invalid PersonalityInsights API configuration. Please check appsettings.json."); } IamAuthenticator authenticator = new IamAuthenticator(apikey: apiKey); PersonalityInsightsService personalityInsights = new PersonalityInsightsService(version, authenticator); personalityInsights.SetServiceUrl(instanceURL); personalityInsights.DisableSslVerification(true); Content content = new Content(); List <ContentItem> lst = new List <ContentItem>(); lst.Add(new ContentItem() { Content = text, Contenttype = "text/plain", Language = "en" }); content.ContentItems = lst; return(personalityInsights.Profile( content: content, contentType: "text/plain", rawScores: true, consumptionPreferences: false )); }
private JsonResult AnalyseData(string data) { if (data.Length < 100) { throw new ArgumentException($"The number of words {data.Length} is less than the minimum number of words required for analysis: 100"); } ContentListContainer contentListContainer = new ContentListContainer { ContentItems = new List <ContentItem>() { new ContentItem() { Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN, Language = ContentItem.LanguageEnum.EN, Content = data } } }; var result = _personalityInsights.Profile("text/plain", "application/json", contentListContainer, rawScores: true, consumptionPreferences: true, csvHeaders: true); return(Json(result)); }
public WatsonService() { string apikey = "{apikey}"; string url = "{serviceUrl}"; string versionDate = "{versionDate}"; void Main(string[] args) { WatsonService example = new WatsonService(); example.Profile(); example.ProfileAsCsv(); Console.WriteLine("Examples complete. Press any key to close the application."); Console.ReadKey(); } #region Profile void Profile() { IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}"); PersonalityInsightsService service = new PersonalityInsightsService("2017-10-13", authenticator); service.SetServiceUrl("{serviceUrl}"); Content content = null; content = JsonConvert.DeserializeObject <Content>(File.ReadAllText("profile.json")); var result = service.Profile( content: content, contentType: "application/json", rawScores: true, consumptionPreferences: true ); Console.WriteLine(result.Response); } void ProfileAsCsv() { IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}"); PersonalityInsightsService service = new PersonalityInsightsService("2017-10-13", authenticator); service.SetServiceUrl("{serviceUrl}"); Content content = null; content = JsonConvert.DeserializeObject <Content>(File.ReadAllText("profile.json")); var result = service.ProfileAsCsv( content: content, contentType: "application/json", consumptionPreferences: true, rawScores: true, csvHeaders: true ); using (FileStream fs = File.Create("output.csv")) { result.Result.WriteTo(fs); fs.Close(); result.Result.Close(); } } #endregion }
public void Profile_Success() { IClient client = this.CreateClient(); IRequest request = Substitute.For <IRequest>(); client.PostAsync(Arg.Any <string>()) .Returns(request); #region Response Profile response = new Profile() { ProcessedLanguage = Profile.ProcessedLanguageEnum.EN, WordCount = 10, WordCountMessage = "wordCountMessage", Personality = new List <Trait>() { new Trait() { TraitId = "traitID", Name = "name", Category = Trait.CategoryEnum.NEEDS, Percentile = 50.0, RawScore = 25.0, Children = new List <Trait>() { new Trait() { TraitId = "traitID", Name = "name", Category = Trait.CategoryEnum.NEEDS, Percentile = 50.0, RawScore = 25.0 } } } }, Values = new List <Trait>() { new Trait() { TraitId = "traitID", Name = "name", Category = Trait.CategoryEnum.PERSONALITY, Percentile = 50.0, RawScore = 25.0, Children = new List <Trait>() { new Trait() { TraitId = "traitID", Name = "name", Category = Trait.CategoryEnum.PERSONALITY, Percentile = 50.0, RawScore = 25.0 } } } }, Needs = new List <Trait>() { new Trait() { TraitId = "traitID", Name = "name", Category = Trait.CategoryEnum.NEEDS, Percentile = 50.0, RawScore = 25.0, Children = new List <Trait>() { new Trait() { TraitId = "traitID", Name = "name", Category = Trait.CategoryEnum.NEEDS, Percentile = 50.0, RawScore = 25.0 } } } }, Behavior = new List <Behavior>() { new Behavior() { TraitId = "traitID", Name = "name", Category = "category", Percentage = 50.0 } }, ConsumptionPreferences = new List <ConsumptionPreferencesCategory>() { new ConsumptionPreferencesCategory() { ConsumptionPreferenceCategoryId = "consumptionPreferenceCategoryId", Name = "name", ConsumptionPreferences = new List <ConsumptionPreferences>() { new ConsumptionPreferences() { ConsumptionPreferenceId = "consumptionPreferenceId", Name = "name", Score = 50.0 } } } }, Warnings = new List <Warning>() { new Warning() { WarningId = Warning.WarningIdEnum.WORD_COUNT_MESSAGE, Message = "message" } } }; #endregion // Test Profile Content content = new Content() { ContentItems = new List <ContentItem>() { new ContentItem() { Contenttype = ContentItem.ContenttypeEnum.TEXT_PLAIN, Language = ContentItem.LanguageEnum.EN, Content = contentString } } }; request.WithArgument(Arg.Any <string>(), Arg.Any <string>()) .Returns(request); request.WithHeader(Arg.Any <string>(), Arg.Any <string>()) .Returns(request); request.WithHeader(Arg.Any <string>(), Arg.Any <string>()) .Returns(request); request.WithHeader(Arg.Any <string>(), Arg.Any <string>()) .Returns(request); request.WithHeader(Arg.Any <string>(), Arg.Any <string>()) .Returns(request); request.WithArgument(Arg.Any <string>(), Arg.Any <bool>()) .Returns(request); request.WithArgument(Arg.Any <string>(), Arg.Any <bool>()) .Returns(request); request.WithArgument(Arg.Any <string>(), Arg.Any <bool>()) .Returns(request); request.WithBody(Arg.Any <Content>()) .Returns(request); request.As <Profile>() .Returns(Task.FromResult(response)); PersonalityInsightsService service = new PersonalityInsightsService(client); service.VersionDate = "versionDate"; var result = service.Profile(content, "contentType"); Assert.IsNotNull(result); client.Received().PostAsync(Arg.Any <string>()); Assert.IsTrue(result.Behavior.Count > 0); Assert.IsTrue(result.ConsumptionPreferences.Count > 0); Assert.IsTrue(result.Needs.Count > 0); Assert.IsTrue(result.Personality.Count > 0); Assert.IsTrue(result.ProcessedLanguage == Profile.ProcessedLanguageEnum.EN); Assert.IsTrue(result.WordCount == 10); Assert.IsTrue(result.Values.Count > 0); Assert.IsTrue(result.Warnings.Count > 0); Assert.IsTrue(result.WordCountMessage == "wordCountMessage"); }
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.Endpoint = _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(); }