private static void SentimentConsoleInput(ITextAnalyticsAPI client)
        {
            // Extracting sentiment
            Console.WriteLine("\n\n===== SENTIMENT ANALYSIS CONSOLE INPUT ======");

            var canBreak = false;

            for (; ;)
            {
                Console.WriteLine("Please type your comment and press 'Enter', 'Q' or 'q' to exit.");
                var input = Console.ReadLine();
                canBreak = input.Equals("q", StringComparison.OrdinalIgnoreCase);

                if (canBreak)
                {
                    Console.WriteLine("Exit.");
                    break;
                }

                SentimentBatchResult result = client.Sentiment(new MultiLanguageBatchInput(new List <MultiLanguageInput> {
                    new MultiLanguageInput()
                    {
                        Id   = DateTimeOffset.UtcNow.ToFileTime().ToString(),
                        Text = input
                    }
                }));

                foreach (var document in result.Documents)
                {
                    Console.WriteLine($"Document ID: {document.Id} , Sentiment Score: {document.Score:0.00} , Text: {input}");
                }

                Console.WriteLine();
            }
        }
        private void AnalizeFeelings()
        {
            string text = m_InputText.Text;

            m_FeelingsText.Text = "Phrase: " + text + '\n';

            client.AzureRegion     = AzureRegions.Westcentralus;
            client.SubscriptionKey = m_SentimentKey;

            SentimentBatchResult m_SentimentList = client.Sentiment(
                new MultiLanguageBatchInput(
                    new List <MultiLanguageInput>()
            {
                // The text is always in english
                new MultiLanguageInput("en", "0", text)
            }));

            foreach (var document in m_SentimentList.Documents)
            {
                m_FeelingsText.Text += "Sentiment Score: " + document.Score + '\n';
                double score = (double)document.Score;
                if (score < 0.2)
                {
                    m_FeelingsText.Text += "Sentiment: Bad";
                }
                else if (score < 0.8)
                {
                    m_FeelingsText.Text += "Sentiment: Neutral";
                }
                else
                {
                    m_FeelingsText.Text += "Sentiment: Good";
                }
            }
        }
示例#3
0
        private void ReturnSentiment(string userInput, string lang)
        {
            SentimentBatchResult sentiment = client.Sentiment(new MultiLanguageBatchInput(new List <MultiLanguageInput>()
            {
                new MultiLanguageInput(lang, "0", userInput)
            }));

            foreach (var document in sentiment.Documents)
            {
                Console.WriteLine("Sentiment score of inserted text is {0}\n", Math.Round(document.Score.Value, 2));
            }
        }
        public EvaluatedSentiment SentimentEvaluation(string word)
        {
            // Translate the sentence to detect what lgnauge it is

            TranslatedItem sentence = DetectLanguage(word);

            SentimentBatchResult result = _client.Sentiment(
                new MultiLanguageBatchInput(
                    new List <MultiLanguageInput>()
            {
                new MultiLanguageInput(sentence.ISOName, "0", sentence.OrignalWord),
            }));

            EvaluatedSentiment sentiment = new EvaluatedSentiment {
                Sentence = word, Score = (double)result.Documents[0].Score * 100
            };

            return(sentiment);
        }
示例#5
0
        public IList <SentimentBatchResultItem> getSentimentalClass(List <string> reviews)
        {
            List <MultiLanguageInput> rews = new List <MultiLanguageInput>();
            int i = 0;

            foreach (var rew in reviews)
            {
                rews.Add(new MultiLanguageInput("ru", i.ToString(), rew));
                i++;
            }
            SentimentBatchResult result = null;

            try
            {
                result = client.Sentiment(
                    new MultiLanguageBatchInput(rews

                                                /*new List<MultiLanguageInput>()
                                                 * {
                                                 *
                                                 *  //вставити замість цього коменти з бд
                                                 *  new MultiLanguageInput("ru", "0", "Это очень хороший телефон!"),
                                                 *  new MultiLanguageInput("ru", "1", "доволен покупкой"),
                                                 *  new MultiLanguageInput("ru", "2", "Не покупайте этот ужасный телефон"),
                                                 *  new MultiLanguageInput("ru", "3", "Хорошее решение за свои деньги"),
                                                 *  new MultiLanguageInput("ru", "4", "Не советую это к покупке"),
                                                 *  new MultiLanguageInput("ru", "5", "Купил телефон три месяца назад. Обновился к андройд 7.1.2. В игры не играю, поэтому батареи хватает на день. Хорошие качество самого телефона, материал метал. Стекло горила глаз 3, хожу без пленки. Царапин нет. Жду обновлений на Андройд 8. Установил гугл камеру, качество снимков увеличилось! Рекомендую аппарат .Переваги: Отличный телефон! Чистый андройд. Качественная сборка. Презентабельный на вид.Недоліки: Нет."),
                                                 * }*/
                                                ));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            StreamWriter sw = new StreamWriter(new FileStream("sentiment_test.txt", FileMode.Create, FileAccess.Write), Encoding.GetEncoding(1251));

            foreach (var doc in result.Documents)
            {
                sw.WriteLine("Document ID: {0} , Sentiment Score: {1:0.00}", doc.Id, doc.Score);
            }
            sw.Close();
            return(result.Documents);
        }
示例#6
0
        public List <double?> AnalyzeEmotion(List <string> texts)
        {
            List <double?>            sentimentScores = new List <double?>();
            List <MultiLanguageInput> inputList       = new List <MultiLanguageInput>();

            for (int i = 0; i < texts.Count; i++)
            {
                inputList.Add(new MultiLanguageInput("pt", i.ToString(), texts[i]));
            }

            SentimentBatchResult result = client.Sentiment(new MultiLanguageBatchInput(inputList));

            // Storing the sentiment results
            foreach (var document in result.Documents)
            {
                sentimentScores.Add(document.Score);
            }

            return(sentimentScores);
        }
示例#7
0
        public Sentiment(IList <string> phraseList)
        {
            Console.WriteLine("\n\n####SENTIMENT SCORE####");
            ITextAnalyticsAPI    client         = Client();
            double?              sentiment      = new double?();
            SentimentBatchResult sentimentScore = client.Sentiment(
                new MultiLanguageBatchInput(
                    new List <MultiLanguageInput>()
            {
                new MultiLanguageInput("en", "1"),
            }));

            foreach (var item in sentimentScore.Documents)
            {
                Console.WriteLine("Document ID: {0}", "Sentiment Score: {1:0.00}", item.Id);
                Console.WriteLine(item.Score);
                sentiment = item.Score;
            }
            ;
        }
        private static void Sentiment(ITextAnalyticsAPI client)
        {
            // Extracting sentiment
            Console.WriteLine("\n\n===== SENTIMENT ANALYSIS ======");

            var inputs3 = 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("fr", "2", "lol, eh qu'on a pas fini de passer à la caisse!"),
                new MultiLanguageInput("es", "3", "No tengo dinero ni nada que dar..."),
                new MultiLanguageInput("it", "4", "L'hotel veneziano era meraviglioso. È un bellissimo pezzo di architettura."),
            };

            SentimentBatchResult result3 = client.Sentiment(new MultiLanguageBatchInput(inputs3));

            // Printing sentiment results
            foreach (var document in result3.Documents)
            {
                Console.WriteLine($"Document ID: {document.Id} , Sentiment Score: {document.Score:0.00} , Text: {inputs3.FirstOrDefault(i => i.Id == document.Id).Text}");
            }
        }
示例#9
0
文件: Tracker.cs 项目: aelena/trackme
        private void ParseSentenceForSentiment(string message)
        {
            // call API for analysis
            SentimentBatchResult result = client.Sentiment(
                new MultiLanguageBatchInput(
                    new List <MultiLanguageInput>()
            {
                new MultiLanguageInput("en", "0", message)
            }));


            Task.Factory.StartNew
                (() => dispUI.BeginInvoke
                    (new Action
                        (() => this.lblParsedSentence.Text = message), null));

            var _score = result.Documents.First().Score;

            this.UpdateUI(() => this.lblScore.Text = _score.Value.ToString("0.00"));

            ProcessResult(message, result, _score);
        }
        public String InterpreteFeedback(string language, string text)
        {
            SentimentBatchResult result = _client.Sentiment(
                new MultiLanguageBatchInput(
                    new List <MultiLanguageInput>()
            {
                new MultiLanguageInput(language, "1", text)
            }
                    ));
            var score = result.Documents.First().Score;

            if (score > 0.7d)
            {
                return($" Score = {score}. Thank you for your feedback. We are glad you enjoyed the experience");
            }
            else if (score < 0.3)
            {
                return($" Score = {score}. We are sorry you did not find the HR Bot useful. Feel free to look at our complete FAQ: www.ourfaq.com or call the HR department at (800)-111-1111");
            }
            else
            {
                return($" Score = {score}. Thank you for your feeback");
            }
        }
        public TextAnalyticsModel TextAnalysis(string value)
        {
            TextAnalyticsModel objTextAnalyticsModel = new TextAnalyticsModel();

            // Extracting language
            //"===== LANGUAGE EXTRACTION ======");

            LanguageBatchResult result = client.DetectLanguage(
                new BatchInput(
                    new List <Input>()
            {
                new Input("1", value)
            })
                );

            StringBuilder strbld   = new StringBuilder();
            string        Language = string.Empty;

            var    allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
            string TwoLetterISOLanguageName = string.Empty;



            // Printing language results.
            foreach (var document in result.Documents)
            {
                //strbld.Append(" Language: " + document.DetectedLanguages[0].Name);
                Language = document.DetectedLanguages[0].Name;
                objTextAnalyticsModel.Language = document.DetectedLanguages[0].Name;
                TwoLetterISOLanguageName       = allCultures.FirstOrDefault(c => c.DisplayName == Language).Name;
            }

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

            KeyPhraseBatchResult result2 = client.KeyPhrases(
                new MultiLanguageBatchInput(
                    new List <MultiLanguageInput>()
            {
                new MultiLanguageInput(TwoLetterISOLanguageName, "1", value)
            }));


            // Printing keyphrases
            foreach (var document in result2.Documents)
            {
                // strbld.Append(" Key Phrases: ");
                foreach (string keyphrase in document.KeyPhrases)
                {
                    strbld.Append(keyphrase + ", ");
                    //Console.WriteLine("\t\t" + keyphrase);
                    objTextAnalyticsModel.KeyPhrases = strbld.ToString();
                }
            }

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

            SentimentBatchResult result3 = client.Sentiment(
                new MultiLanguageBatchInput(
                    new List <MultiLanguageInput>()
            {
                new MultiLanguageInput(TwoLetterISOLanguageName, "0", value)
            }));


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



            return(objTextAnalyticsModel);
        }
示例#12
0
 public SentimentBatchResult GetSentiment(List <MultiLanguageInput> data)
 {
     return(_client.Sentiment(new MultiLanguageBatchInput(data)));
 }