Ejemplo n.º 1
0
        private static async Task KeyPhrases()
        {
            var service = ServiceFactory.Build();

            var phrases = await service.GetKeyPhrasesAsync("This is some awesome text that needs the key phrases extracted from.");

            Console.WriteLine(phrases.Success ? $"The key phrases are: {string.Join(",", phrases.Phrases)}" : phrases.Error);
        }
Ejemplo n.º 2
0
        private static async Task Sentiment()
        {
            var service = ServiceFactory.Build();

            var sentiment = await service.GetSentimentAsync("This is some awesome text that needs sentiment analysis;");

            Console.WriteLine(sentiment.Success ? $"The sentiment score is {sentiment.Score}" : sentiment.Error);
        }
        public async Task GetResultFromAzure()
        {
            var          expected = SentimentResult.Build(0.9742637M);
            const string Input    = "This is very positive text because I love this service";

            var sut    = ServiceFactory.Build();
            var result = await sut.GetSentimentAsync(Input);

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 4
0
        public async Task GetResultFromAzure()
        {
            var          expected = KeyPhraseResult.Build(new[] { "bunch of phrases", "wonderful hotel", "great service", "text" });
            const string Input    = "I need some text that can extract a bunch of phrases from. This was a wonderful hotel with great service but really overpriced.";

            var sut    = ServiceFactory.Build();
            var result = await sut.GetKeyPhrasesAsync(Input);

            Assert.AreEqual(expected, result, string.Join(",", result.Phrases));
        }
Ejemplo n.º 5
0
        private static async Task SentimentBatch()
        {
            var service = ServiceFactory.Build();

            var request = new Dictionary <string, string>
            {
                { "1", "This is very positive text because I love this service" },
                { "2", "Test is very bad because I hate this service" },
                { "3", "The service was OK, nothing special, I've had better" },
                { "4", "" }
            };

            var batchResult = await service.GetBatchSentimentAsync(request);

            foreach (var result in batchResult)
            {
                Console.WriteLine(result.Value.Success ? $"Id: {result.Key} = {result.Value.Score}" : $"Id: {result.Key} = Error: {result.Value.Error}");
            }
        }
Ejemplo n.º 6
0
        public async Task GetResultFromAzure()
        {
            var input = new Dictionary <string, string>
            {
                { "1", "This is very positive text because I love this service" },
                { "2", "Test is very bad because I hate this service" },
                { "3", "The service was OK, nothing special, I've had better" },
                { "4", "" }
            };

            var expected = new Dictionary <string, SentimentResult>
            {
                { "1", SentimentResult.Build(0.9742637M) },
                { "2", SentimentResult.Build(0.03089833M) },
                { "3", SentimentResult.Build(0.4267564M) },
                { "4", SentimentResult.Build("Record cannot be null/empty") }
            };

            var sut    = ServiceFactory.Build();
            var result = await sut.GetBatchSentimentAsync(input);

            CollectionAssert.AreEquivalent(expected, result.ToList());
        }