public void ProfileAsCsv_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.ProfileAsCsv(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)));
        }
        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();
            }
        }
Пример #3
0
        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 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 ProfileAsCsv_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.ProfileAsCsv(
                content: content,
                contentLanguage: "en",
                acceptLanguage: "en",
                rawScores: true,
                csvHeaders: true,
                consumptionPreferences: true,
                contentType: "text/plain"
                );

            StreamReader reader = new StreamReader(result.Result);
            var text = reader.ReadToEnd();

            Assert.IsFalse(text.StartsWith("{"));
        }
Пример #6
0
        private Profile ProfileAsCsv(Content content, string contentType, string contentLanguage = null, string acceptLanguage = null, bool?rawScores = null, bool?csvHeaders = null, bool?consumptionPreferences = null, Dictionary <string, object> customData = null)
        {
            Console.WriteLine("\nAttempting to ProfileAsCsv()");
            var result = _service.ProfileAsCsv(content: content, contentType: contentType, contentLanguage: contentLanguage, acceptLanguage: acceptLanguage, rawScores: rawScores, csvHeaders: csvHeaders, consumptionPreferences: consumptionPreferences, customData: customData);

            if (result != null)
            {
                Console.WriteLine("ProfileAsCsv() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
            }
            else
            {
                Console.WriteLine("Failed to ProfileAsCsv()");
            }

            return(result);
        }
        private System.IO.MemoryStream ProfileAsCsv(Content content, string contentType, string contentLanguage = null, string acceptLanguage = null, bool?rawScores = null, bool?csvHeaders = null, bool?consumptionPreferences = null, Dictionary <string, object> customData = null)
        {
            Console.WriteLine("\nAttempting to ProfileAsCsv()");
            var result = service.ProfileAsCsv(content: content, contentType: contentType, contentLanguage: contentLanguage, acceptLanguage: acceptLanguage, rawScores: rawScores, csvHeaders: csvHeaders, consumptionPreferences: consumptionPreferences, customData: customData);

            if (result != null)
            {
                Console.WriteLine("ProfileAsCsv() succeeded!");
            }
            else
            {
                Console.WriteLine("Failed to ProfileAsCsv()");
            }

            return(result);
        }
Пример #8
0
        public IEnumerator TestProfileAsCsv()
        {
            Log.Debug("PersonalityInsightsServiceV3IntegrationTests", "Attempting to ProfileAsCsv...");
            System.IO.MemoryStream profileAsCsvResponse = null;
            Content content = new Content()
            {
                ContentItems = new List <ContentItem>()
                {
                    new ContentItem()
                    {
                        Contenttype = ContentItem.ContenttypeValue.TEXT_PLAIN,
                        Language    = ContentItem.LanguageValue.EN,
                        Content     = contentToProfile
                    }
                }
            };

            service.ProfileAsCsv(
                callback: (DetailedResponse <System.IO.MemoryStream> response, IBMError error) =>
            {
                profileAsCsvResponse = response.Result;
                Assert.IsNotNull(profileAsCsvResponse);
                Assert.IsNull(error);

                //  Save file
                using (FileStream fs = File.Create(Application.dataPath + "/personality-profile.csv"))
                {
                    profileAsCsvResponse.WriteTo(fs);
                    fs.Close();
                    profileAsCsvResponse.Close();
                }
            },
                content: content,
                contentLanguage: "en",
                acceptLanguage: "en",
                rawScores: true,
                csvHeaders: true,
                consumptionPreferences: true,
                contentType: "text/plain"
                );

            while (profileAsCsvResponse == null)
            {
                yield return(null);
            }
        }
Пример #9
0
        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.");
        }
Пример #10
0
        public void ProfileAsCsv()
        {
            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.ProfileAsCsv(
                content: content,
                contentLanguage: "en",
                acceptLanguage: "en",
                rawScores: true,
                csvHeaders: true,
                consumptionPreferences: true,
                contentType: "text/plain"
                );

            StreamReader reader = new StreamReader(result.Result);
            var          text   = reader.ReadToEnd();

            Console.WriteLine(text);
        }
Пример #11
0
        public void ProfileAsCsv()
        {
            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.ProfileAsCsv(
                content: content,
                contentLanguage: "en",
                acceptLanguage: "en",
                rawScores: true,
                csvHeaders: true,
                consumptionPreferences: true,
                contentType: "text/plain"
                );

            StreamReader reader = new StreamReader(result.Result);
            var          text   = reader.ReadToEnd();

            Console.WriteLine(text);
        }
        public IEnumerator TestProfileAsCsv()
        {
            Log.Debug("PersonalityInsightsServiceV3IntegrationTests", "Attempting to ProfileAsCsv...");
            System.IO.MemoryStream profileAsCsvResponse = null;
            byte[]       bytes   = Encoding.ASCII.GetBytes(contentToProfile);
            MemoryStream content = new MemoryStream(bytes);

            service.ProfileAsCsv(
                callback: (DetailedResponse <System.IO.MemoryStream> response, IBMError error) =>
            {
                profileAsCsvResponse = response.Result;
                Assert.IsNotNull(profileAsCsvResponse);
                Assert.IsNull(error);

                //  Save file
                using (FileStream fs = File.Create(Application.dataPath + "/personality-profile.csv"))
                {
                    profileAsCsvResponse.WriteTo(fs);
                    fs.Close();
                    profileAsCsvResponse.Close();
                }
            },
                content: content,
                contentLanguage: "en",
                acceptLanguage: "en",
                rawScores: true,
                csvHeaders: true,
                consumptionPreferences: true,
                contentType: "text/plain"
                );

            while (profileAsCsvResponse == null)
            {
                yield return(null);
            }
        }
Пример #13
0
        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
        }