Exemplo n.º 1
0
        internal static async Task <string> Sentiment(this string text, string apiKey)
        {
            if (string.IsNullOrEmpty(text))
            {
                return("0.0");
            }

            // Create a client
            var client = new TextAnalyticsAPI(new ServiceCredentials.ApiKeyServiceClientCredentials(apiKey));

            // Extract the language
            var result = await client.DetectLanguageAsync(new BatchInput(new List <Input>()
            {
                new Input("1", text)
            }));

            var language = result.Documents?[0].DetectedLanguages?[0].Name;

            // Get the sentiment
            var sentimentResult = await client.SentimentAsync(
                new MultiLanguageBatchInput(
                    new List <MultiLanguageInput>()
            {
                new MultiLanguageInput(language, "0", text),
            }));

            return(sentimentResult.Documents?[0].Score?.ToString("#.#"));
        }
        public async Task OnTurn(ITurnContext context, MiddlewareSet.NextDelegate next)
        {
            if (context.Activity.Type is ActivityTypes.Message)
            {
                if (string.IsNullOrEmpty(context.Activity.Text))
                {
                    context.Services.Add <string>("0.0");
                }

                // Create a client
                var client = new TextAnalyticsAPI(new ApiKeyServiceClientCredentials(ApiKey));

                client.AzureRegion = AzureRegions.Westeurope;

                // Extract the language
                var result = await client.DetectLanguageAsync(new BatchInput(new List <Input>()
                {
                    new Input("1", context.Activity.Text)
                }));

                var language = result.Documents?[0].DetectedLanguages?[0].Name;

                // Get the sentiment
                var sentimentResult = await client.SentimentAsync(
                    new MultiLanguageBatchInput(
                        new List <MultiLanguageInput>()
                {
                    new MultiLanguageInput("en", "0", context.Activity.Text),
                }));

                context.Services.Add <string>(sentimentResult.Documents?[0].Score?.ToString("#.#"));
            }

            await next();
        }
Exemplo n.º 3
0
        public async Task <TextAnalyticsResult> AnalyzeTextAsync(string text)
        {
            try
            {
                // COGNITIVE SERVICE : client API REST
                ITextAnalyticsAPI client = new TextAnalyticsAPI(new ApiKeyServiceClientCredentials())
                {
                    AzureRegion = AzureRegions.Australiaeast
                };

                var result = new TextAnalyticsResult();

                // COGNITIVE SERVICE : Détection de la langue
                var resultLanguage = await client.DetectLanguageAsync(new BatchInput(
                                                                          new List <Input>()
                {
                    new Input("0", text)
                }));

                var l = resultLanguage.Documents[0].DetectedLanguages[0];
                result.Language    = l.Name;
                result.LanguageIso = l.Iso6391Name;

                // COGNITIVE SERVICE : Détection des phrases clés
                var resultKeyPhrases = client.KeyPhrasesAsync(new MultiLanguageBatchInput(
                                                                  new List <MultiLanguageInput>()
                {
                    new MultiLanguageInput(result.LanguageIso, "0", text)
                }));

                result.KeyPhrases = resultKeyPhrases.Result.Documents[0].KeyPhrases.ToArray();

                // COGNITIVE SERVICE : Détection du score de sentiment
                var resultSentiment = client.SentimentAsync(new MultiLanguageBatchInput(
                                                                new List <MultiLanguageInput>()
                {
                    new MultiLanguageInput(result.LanguageIso, "0", text)
                }));

                result.ScoreSentiment = resultSentiment.Result.Documents[0].Score;

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Text analyze : {ex.Message}");
                return(null);
            }
        }
Exemplo n.º 4
0
        public static async Task <SentimentResult> AnalyzeWords(string words)
        {
            SentimentResult sentimentResult = new SentimentResult();

            try
            {
                var sentimentInput = new MultiLanguageInput(text: words, id: "1");

                // First find out the input language
                var detectLanguageInput = new Input(id: "1", text: words);
                var languageResult      = await client.DetectLanguageAsync(new BatchInput(new List <Input> {
                    detectLanguageInput
                }), numberOfLanguagesToDetect : 1);

                if (languageResult.Errors.Count > 0)
                {
                    return(null);
                }

                sentimentResult.DetectedLanguage = languageResult.Documents.FirstOrDefault().DetectedLanguages.FirstOrDefault().Iso6391Name;

                // Setup for the sentiment
                sentimentInput.Language = sentimentResult.DetectedLanguage;
                var mlbi = new MultiLanguageBatchInput(new List <MultiLanguageInput>()
                {
                    sentimentInput
                });

                // Find the sentiment!
                var sentimentResultCall = await client.SentimentAsync(mlbi);

                if (sentimentResultCall.Errors.Count > 0)
                {
                    return(null);
                }

                sentimentResult.SentimentAnalysis = sentimentResultCall.Documents.FirstOrDefault().Score ?? 0;

                sentimentResult.ScoreResult();

                return(sentimentResult);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            return(sentimentResult);
        }
Exemplo n.º 5
0
        public async Task <IList <DetectedLanguage> > AnalyzeTextAsync(string text)
        {
            ITextAnalyticsAPI client = new TextAnalyticsAPI(_apiKeyServiceClientCredentialsFactory.GetServiceClientCredentials());

            client.AzureRegion = AzureRegions.Eastus;

            var result = await client.DetectLanguageAsync(new BatchInput
            {
                Documents = new List <Input>
                {
                    new Input(id: Guid.NewGuid().ToString(), text: text) // Id is nullable, but it's required!
                }
            });

            return(result.Documents.First().DetectedLanguages);
        }
Exemplo n.º 6
0
        public static async Task <double> GetTextSentiment(string input)
        {
            var client = new TextAnalyticsAPI
            {
                AzureRegion     = AzureRegions.Westus,
                SubscriptionKey = ConfigurationManager.AppSettings["TextAnalyticsKey"]
            };

            var language = await client.DetectLanguageAsync(new BatchInput(
                                                                new[] { new Input(id: "0", text: input) }
                                                                ));

            var langCode = language.Documents[0].DetectedLanguages[0].Iso6391Name;

            var sentiment = await client.SentimentAsync(new MultiLanguageBatchInput(
                                                            new[] { new MultiLanguageInput(id: "0", language: langCode, text: input) }
                                                            ));

            return(sentiment.Documents[0].Score.GetValueOrDefault());
        }
Exemplo n.º 7
0
        private static async Task <List <MultiLanguageInput> > GetPurposeDescriptionsAsMultiLanguageInput(TextAnalyticsAPI client, IReadOnlyCollection <Stiftung> stiftungen)
        {
            List <MultiLanguageInput> purposeDescriptions = new List <MultiLanguageInput>();

            foreach (var stiftung in stiftungen.Where(s => !string.IsNullOrWhiteSpace(s.zweck)))
            {
                // extract language
                var languageResult = await client.DetectLanguageAsync(new BatchInput(
                                                                          new List <Input>()
                {
                    new Input("1", stiftung.zweck)
                }));

                await Task.Delay(2000);

                purposeDescriptions.Add(new MultiLanguageInput(languageResult.Documents[0].DetectedLanguages[0].Iso6391Name, stiftung.id.ToString(), stiftung.zweck));
            }

            return(purposeDescriptions);
        }
Exemplo n.º 8
0
        public static async Task <string> obtainLanguage(string key, AzureRegions region, string text)
        {
            TextAnalyticsAPI client = new TextAnalyticsAPI(new ApiKeyServiceClientCredentials());

            client.AzureRegion = region;

            BatchInput input = new BatchInput(new List <Input>()
            {
                new Input("1", text)
            });
            var result = await client.DetectLanguageAsync(input);

            var languages = result.Documents.FirstOrDefault()?.DetectedLanguages;

            if (languages.Count > 0)
            {
                return("Language: " + string.Join(", ", languages.Select(x => x.Name)));
            }
            else
            {
                return("Unable to detect language!");
            }
        }
Exemplo n.º 9
0
        public async Task <TextAnalysisResult> AnalyzeTextAsync(string text)
        {
            // See: https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/quickstarts/csharp

            var analysisResult = new TextAnalysisResult();

            if (string.IsNullOrEmpty(text))
            {
                Console.WriteLine("\t\t\tContentAnalyzer.AnalyzeTextAsync(): no text to analyze");
                return(analysisResult);
            }

            string textToAnalyze = text;

            if (text.Length > 5000)
            {
                Console.WriteLine("\t\t\tContentAnalyzer.AnalyzeTextAsync(): text longer than supported length. Trimming it...");
                textToAnalyze = text.Substring(0, 5000);
            }

            Console.WriteLine("\t\t\tContentAnalyzer.AnalyzeTextAsync(): initializing TextAnalyticsAPI");

            ITextAnalyticsAPI m_TextAnalyticsClient = new TextAnalyticsAPI
            {
                AzureRegion     = AzureRegions.Westeurope,
                SubscriptionKey = m_TextAnalyticsAPISubscriptionKey
            };

            Console.WriteLine("\t\t\tContentAnalyzer.AnalyzeTextAsync(): detecting content language");

            var batchLanguageResult = await m_TextAnalyticsClient.DetectLanguageAsync(new BatchInput(new List <Input>()
            {
                new Input("1", textToAnalyze)
            })).ConfigureAwait(false);

            if (batchLanguageResult.Errors.Count > 0)
            {
                Console.WriteLine("\t\t\tContentAnalyzer.AnalyzeTextAsync(): error while detecting language");
                foreach (var errors in batchLanguageResult.Errors)
                {
                    Console.WriteLine($"\t{errors.Message}");
                }
                return(analysisResult);
            }

            analysisResult.DetectedLanguage      = batchLanguageResult.Documents[0].DetectedLanguages[0].Name;
            analysisResult.DetectedLanguageScore = batchLanguageResult.Documents[0].DetectedLanguages[0].Score.GetValueOrDefault();

            Console.WriteLine($"\t\t\tContentAnalyzer.AnalyzeTextAsync(): detected language is '{analysisResult.DetectedLanguage}' ({(analysisResult.DetectedLanguageScore * 100):0.00}%)");

            Console.WriteLine("\t\t\tContentAnalyzer.AnalyzeTextAsync(): performing key-phrase extraction");

            var multiLanguageInput = new MultiLanguageBatchInput(new List <MultiLanguageInput>()
            {
                new MultiLanguageInput(batchLanguageResult.Documents[0].DetectedLanguages[0].Iso6391Name, "1", textToAnalyze)
            });
            var batchKeyphraseResult = await m_TextAnalyticsClient.KeyPhrasesAsync(multiLanguageInput).ConfigureAwait(false);

            if (batchKeyphraseResult.Errors.Count > 0)
            {
                Console.WriteLine("\t\t\tContentAnalyzer.AnalyzeTextAsync(): error while extracting key-phrases");
                foreach (var errors in batchKeyphraseResult.Errors)
                {
                    Console.WriteLine($"\t\t\t\t{errors.Message}");
                }
                return(analysisResult);
            }

            Console.WriteLine($"\t\t\tContentAnalyzer.AnalyzeTextAsync(): retrieved {batchKeyphraseResult.Documents[0].KeyPhrases.Count} key-phrases:");
            foreach (var keyphrase in batchKeyphraseResult.Documents[0].KeyPhrases)
            {
                analysisResult.KeyPhrases.Add(keyphrase);
                Console.WriteLine($"\t\t\t\t{keyphrase}");
            }

            Console.WriteLine("\t\t\tContentAnalyzer.AnalyzeTextAsync(): performing sentiment analysis");

            var batchSentimentResult = await m_TextAnalyticsClient.SentimentAsync(multiLanguageInput).ConfigureAwait(false);

            if (batchSentimentResult.Errors.Count > 0)
            {
                Console.WriteLine("\t\t\tContentAnalyzer.AnalyzeTextAsync(): error while detecting sentiment");
                foreach (var errors in batchSentimentResult.Errors)
                {
                    Console.WriteLine($"\t\t\t\t{errors.Message}");
                }
                return(analysisResult);
            }

            analysisResult.SentimentScore = batchSentimentResult.Documents[0].Score.GetValueOrDefault();
            analysisResult.Sentiment      = GetSentiment(analysisResult.SentimentScore);

            Console.WriteLine($"\t\t\tContentAnalyzer.AnalyzeTextAsync(): sentiment is '{analysisResult.Sentiment}' ({(analysisResult.SentimentScore * 100):0.00}%)");

            // Extend analysis by estimating reading time for content
            analysisResult.WordCount            = TextTokenizer.GetWordCount(text);
            analysisResult.ReadingTimeInMinutes = ReadingTimeEstimator.GetEstimatedReadingTime(analysisResult.WordCount, analysisResult.DetectedLanguage);

            return(analysisResult);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            //Configure Twitter OAuth
            var oauthToken          = ConfigurationManager.AppSettings["oauth_token"];
            var oauthTokenSecret    = ConfigurationManager.AppSettings["oauth_token_secret"];
            var oauthCustomerKey    = ConfigurationManager.AppSettings["oauth_consumer_key"];
            var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"];
            var keywords            = ConfigurationManager.AppSettings["twitter_keywords"];

            // https://github.com/linvi/tweetinvi/wiki/Streams
            Auth.SetUserCredentials(oauthCustomerKey, oauthConsumerSecret, oauthToken, oauthTokenSecret);

            // Create a stream for the requested keyword
            var stream = Stream.CreateFilteredStream();
            var tracks = keywords.Split(',');

            foreach (var keyword in tracks)
            {
                stream.AddTrack(keyword);
            }

            // Create client for CA
            ITextAnalyticsAPI client = new TextAnalyticsAPI(new ApiKeyServiceClientCredentials())
            {
                AzureRegion = AzureRegions.Westeurope
            };

            stream.MatchingTweetReceived += (sender, targs) =>
            {
                var tweet = targs.Tweet;
                Console.WriteLine("New Tweet: {0}", tweet.Text);

                var tweetRow = new TweetWithAnalysis()
                {
                    TweetAuthor              = tweet.CreatedBy.Name,
                    TweetAuthorCreatedAt     = tweet.CreatedBy.CreatedAt,
                    TweetAuthorFollowerCount = tweet.CreatedBy.FollowersCount,
                    TweetAuthorLocation      = tweet.CreatedBy.Location ?? "Unknown",
                    TweetCreatedAt           = tweet.CreatedAt,
                    TweetFavoriteCount       = tweet.FavoriteCount,
                    TweetGeoCountryCode      = (tweet.Place == null) ? "" : tweet.Place.CountryCode,
                    TweetGeoFullName         = (tweet.Place == null) ? "Unknown" : tweet.Place.FullName,
                    TweetRetweetCount        = tweet.RetweetCount,
                    TweetText          = tweet.Text,
                    TweetUrl           = tweet.Url,
                    TweetNamedEntities = ""
                };

                List <string> entityHashtags = new List <string>();
                foreach (var entity in tweet.Entities.Hashtags)
                {
                    entityHashtags.Add(entity.Text);
                }
                tweetRow.TweetHashtags = string.Join(", ", entityHashtags);

                List <string> mediaUrls = new List <string>();
                foreach (var media in tweet.Media)
                {
                    mediaUrls.Add(media.MediaURL);
                }
                tweetRow.TweetMediaUrls = string.Join(", ", mediaUrls);

                // Get Language
                var result = client.DetectLanguageAsync(new BatchInput(new List <Input> {
                    new Input(tweet.Id.ToString(), tweet.Text)
                })).Result;
                foreach (var document in result.Documents)
                {
                    Console.WriteLine("Document ID: {0} , Language: {1}", document.Id, document.DetectedLanguages[0].Name);
                    tweetRow.TweetLanguageCode = document.DetectedLanguages[0].Iso6391Name;

                    // Get Phrases
                    var inputTweet = new List <MultiLanguageInput>()
                    {
                        new MultiLanguageInput(document.DetectedLanguages[0].Iso6391Name, document.Id, tweet.Text)
                    };
                    KeyPhraseBatchResult result2 = client.KeyPhrasesAsync(new MultiLanguageBatchInput(inputTweet)).Result;

                    foreach (var document2 in result2.Documents)
                    {
                        string keyPhrases = string.Join(", ", document2.KeyPhrases);
                        Console.WriteLine("Key phrases: {0}", keyPhrases);
                        tweetRow.TweetKeyPhrases = keyPhrases;
                    }

                    // Get Sentiment
                    SentimentBatchResult result3 = client.SentimentAsync(new MultiLanguageBatchInput(inputTweet)).Result;
                    foreach (var document3 in result3.Documents)
                    {
                        Console.WriteLine("Sentiment Score: {0:0.00}", document3.Score);
                        tweetRow.TweetSentiment = document3.Score;
                    }

                    // Get Named Entities
                    var result4 = client.EntitiesAsync(new MultiLanguageBatchInput(inputTweet)).Result;
                    foreach (var document4 in result4.Documents)
                    {
                        List <string> entityNames = new List <string>();
                        foreach (var entity in document4.Entities)
                        {
                            entityNames.Add(entity.Name);
                        }

                        string entities = string.Join(", ", entityNames);
                        Console.WriteLine("Entities: {0}", entities);
                        tweetRow.TweetNamedEntities = entities;
                        Console.WriteLine("Entities found: {0}", entities);
                    }
                }

                Console.WriteLine(tweetRow.ToJson());

                string conn = "Data Source=localhost;Initial Catalog=WorldCup;Integrated Security=True";
                using (SqlConnection connection = new SqlConnection(conn))
                {
                    string sqlCommand = "INSERT into TweetInfo (TweetCreatedAt, TweetText, TweetAuthor, " +
                                        "TweetAuthorLocation, TweetAuthorFollowerCount, TweetAuthorCreatedAt," +
                                        "TweetGeoFullName, TweetGeoCountryCode, TweetRetweetCount, " +
                                        "TweetFavoriteCount, TweetHashtags, TweetUrl, TweetMediaUrls, " +
                                        "TweetLanguageCode, TweetSentiment, TweetKeyPhrases, TweetNamedEntities)" +
                                        " VALUES (@TweetCreatedAt, @TweetText, @TweetAuthor, " +
                                        "@TweetAuthorLocation, @TweetAuthorFollowerCount, @TweetAuthorCreatedAt," +
                                        "@TweetGeoFullName, @TweetGeoCountryCode, @TweetRetweetCount, " +
                                        "@TweetFavoriteCount, @TweetHashtags, @TweetUrl, @TweetMediaUrls, " +
                                        "@TweetLanguageCode, @TweetSentiment, @TweetKeyPhrases, @TweetNamedEntities)";

                    using (SqlCommand command = new SqlCommand(sqlCommand))
                    {
                        command.Connection = connection;
                        command.Parameters.AddWithValue("@TweetCreatedAt", tweetRow.TweetCreatedAt);
                        command.Parameters.AddWithValue("@TweetText", tweetRow.TweetText);
                        command.Parameters.AddWithValue("@TweetAuthor", tweetRow.TweetAuthor);
                        command.Parameters.AddWithValue("@TweetAuthorLocation", tweetRow.TweetAuthorLocation);
                        command.Parameters.AddWithValue("@TweetAuthorFollowerCount", tweetRow.TweetAuthorFollowerCount);
                        command.Parameters.AddWithValue("@TweetAuthorCreatedAt", tweetRow.TweetAuthorCreatedAt);
                        command.Parameters.AddWithValue("@TweetGeoFullName", tweetRow.TweetGeoFullName);
                        command.Parameters.AddWithValue("@TweetGeoCountryCode", tweetRow.TweetGeoCountryCode);
                        command.Parameters.AddWithValue("@TweetRetweetCount", tweetRow.TweetRetweetCount);
                        command.Parameters.AddWithValue("@TweetFavoriteCount", tweetRow.TweetFavoriteCount);
                        command.Parameters.AddWithValue("@TweetHashtags", tweetRow.TweetHashtags);
                        command.Parameters.AddWithValue("@TweetUrl", tweetRow.TweetUrl);
                        command.Parameters.AddWithValue("@TweetMediaUrls", tweetRow.TweetMediaUrls);
                        command.Parameters.AddWithValue("@TweetLanguageCode", tweetRow.TweetLanguageCode);
                        command.Parameters.AddWithValue("@TweetSentiment", tweetRow.TweetSentiment);
                        command.Parameters.AddWithValue("@TweetKeyPhrases", tweetRow.TweetKeyPhrases);
                        command.Parameters.AddWithValue("@TweetNamedEntities", tweetRow.TweetNamedEntities);

                        connection.Open();
                        int recordsAffected = command.ExecuteNonQuery();
                    }
                };
            };

            // Start the stream but only if all tracks are found
            stream.StartStreamMatchingAllConditions();
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            // Create a client.
            //ITextAnalyticsClient client = new TextAnalyticsClient(new ApiKeyServiceClientCredentials())
            //{
            //    Endpoint = "https://eastus.api.cognitive.microsoft.com"
            //};
            TextAnalyticsAPI client = new TextAnalyticsAPI(new ApiKeyServiceClientCredentials())
            {
                AzureRegion = AzureRegions.Eastus2 // example
            };

            Console.OutputEncoding = System.Text.Encoding.UTF8;

            // Extracting language
            Console.WriteLine("===== LANGUAGE EXTRACTION ======");

            var result = client.DetectLanguageAsync(new BatchInput(
                                                        new List <Input>()
            {
                new Input("1", "This is a document written in English."),
                new Input("2", "Este es un document escrito en Español."),
                new Input("3", "这是一个用中文写的文件")
            })).Result;

            // Printing language results.
            foreach (var document in result.Documents)
            {
                Console.WriteLine("Document ID: {0} , Language: {1}", document.Id, document.DetectedLanguages[0].Name);
            }

            // Getting key-phrases
            Console.WriteLine("\n\n===== KEY-PHRASE EXTRACTION ======");

            KeyPhraseBatchResult result2 = client.KeyPhrasesAsync(new MultiLanguageBatchInput(
                                                                      new List <MultiLanguageInput>()
            {
                new MultiLanguageInput("ja", "1", "猫は幸せ"),
                new MultiLanguageInput("de", "2", "Fahrt nach Stuttgart und dann zum Hotel zu Fu."),
                new MultiLanguageInput("en", "3", "My cat is stiff as a rock."),
                new MultiLanguageInput("es", "4", "A mi me encanta el fútbol!")
            })).Result;

            // Printing keyphrases
            foreach (var document in result2.Documents)
            {
                Console.WriteLine("Document ID: {0} ", document.Id);

                Console.WriteLine("\t Key phrases:");

                foreach (string keyphrase in document.KeyPhrases)
                {
                    Console.WriteLine("\t\t" + keyphrase);
                }
            }

            // Extracting sentiment
            Console.WriteLine("\n\n===== SENTIMENT ANALYSIS ======");

            SentimentBatchResult result3 = client.SentimentAsync(
                new MultiLanguageBatchInput(
                    new List <MultiLanguageInput>()
            {
                new MultiLanguageInput("en", "0", "I had the best day of my life."),
                new MultiLanguageInput("en", "1", "This was a waste of my time. The speaker put me to sleep."),
                new MultiLanguageInput("es", "2", "No tengo dinero ni nada que dar..."),
                new MultiLanguageInput("it", "3", "L'hotel veneziano era meraviglioso. È un bellissimo pezzo di architettura."),
            })).Result;


            // Printing sentiment results
            foreach (var document in result3.Documents)
            {
                Console.WriteLine("Document ID: {0} , Sentiment Score: {1:0.00}", document.Id, document.Score);
            }

            Console.ReadLine();
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            //Configure Twitter OAuth
            var oauthToken          = ConfigurationManager.AppSettings["oauth_token"];
            var oauthTokenSecret    = ConfigurationManager.AppSettings["oauth_token_secret"];
            var oauthCustomerKey    = ConfigurationManager.AppSettings["oauth_consumer_key"];
            var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"];
            var keywords            = ConfigurationManager.AppSettings["twitter_keywords"];

            // https://github.com/linvi/tweetinvi/wiki/Streams
            Auth.SetUserCredentials(oauthCustomerKey, oauthConsumerSecret, oauthToken, oauthTokenSecret);

            var stream = Stream.CreateFilteredStream();

            stream.AddTrack("beer");
            stream.AddTweetLanguageFilter(LanguageFilter.English);

            // Create client for CA
            ITextAnalyticsAPI client = new TextAnalyticsAPI(new ApiKeyServiceClientCredentials())
            {
                AzureRegion = AzureRegions.Westeurope
            };

            stream.MatchingTweetReceived += (sender, targs) =>
            {
                var tweet = targs.Tweet;
                Console.WriteLine("New {0} Beer Tweet: {1}", tweet.Language, tweet.Text);

                // Get Language
                var result = client.DetectLanguageAsync(new BatchInput(new List <Input> {
                    new Input(tweet.Id.ToString(), tweet.Text)
                })).Result;
                foreach (var document in result.Documents)
                {
                    Console.WriteLine("Document ID: {0} , Language: {1}", document.Id, document.DetectedLanguages[0].Name);

                    // Get Phrases
                    var inputTweet = new List <MultiLanguageInput>()
                    {
                        new MultiLanguageInput(document.DetectedLanguages[0].Iso6391Name, document.Id, tweet.Text)
                    };
                    KeyPhraseBatchResult result2 = client.KeyPhrasesAsync(new MultiLanguageBatchInput(inputTweet)).Result;

                    foreach (var document2 in result2.Documents)
                    {
                        Console.WriteLine("Document ID: {0} ", document2.Id);
                        Console.WriteLine("\t Key phrases:");
                        foreach (string keyphrase in document2.KeyPhrases)
                        {
                            Console.WriteLine("\t\t" + keyphrase);
                        }
                    }

                    // Get Sentiment
                    SentimentBatchResult result3 = client.SentimentAsync(new MultiLanguageBatchInput(inputTweet)).Result;
                    foreach (var document3 in result3.Documents)
                    {
                        Console.WriteLine("Document ID: {0} , Sentiment Score: {1:0.00}", document3.Id, document3.Score);
                    }

                    // Get Named Entities
                    var result4 = client.EntitiesAsync(new MultiLanguageBatchInput(inputTweet)).Result;
                    foreach (var document4 in result4.Documents)
                    {
                        Console.WriteLine("Entities found:");
                        foreach (var entity in document4.Entities)
                        {
                            Console.WriteLine("Entity Name: {0}", entity.Name);
                        }
                    }
                }
            };

            stream.StartStreamMatchingAllConditions();
        }