public 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();
            }
        }
        public void ProfileAsCsv()
        {
            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.ProfileAsCsv(
                        content: ms,
                        contentType: "application/json",
                        consumptionPreferences: true,
                        rawScores: true,
                        csvHeaders: true
                        );

                    using (FileStream fsOutput = File.Create("output.csv"))
                    {
                        result.Result.WriteTo(fsOutput);
                        fsOutput.Close();
                        result.Result.Close();
                    }
                }
            }
        }
        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);
                }
            }
        }
Example #4
0
        private IEnumerator CreateService()
        {
            IamAuthenticator authenticator = new IamAuthenticator(apikey: "{iamApikey}");

            //  Wait for tokendata
            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            service = new PersonalityInsightsService("2019-02-18", authenticator);
            service.SetServiceUrl("{serviceUrl}");

            Runnable.Run(Examples());
        }
        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);
        }
Example #6
0
        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
                       ));
        }
        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
        }