public IndexModel(TextAnalysisService textAnalysisService, ReviewsService reviewsService, ILogger <IndexModel> logger, IConfiguration config) { _reviewsService = reviewsService; _textAnalysisService = textAnalysisService; _logger = logger; _config = config; ReviewsUrl = _config["Reviews:Url"]; }
public TwitterPayload(Tweet tweet) { this.Id = tweet.Id; this.Text = tweet.Text; this.Name = tweet.User != null ? tweet.User.Name : null; this.CreatedAt = ParseTwitterDateTime(tweet.CreatedAt); this.TimeZone = tweet.User != null ? (tweet.User.TimeZone != null ? tweet.User.TimeZone : "(unknown)") : "(unknown)"; this.Language = TextAnalysisService.AnalyzeLanguage(this.Id.ToString(), this.Text); this.LanguageName = String.Format("{0}({1})", this.Language.Name, this.Language.Iso639Name); this.LanguageConfidence = this.Language.Score * 100; this.RawJson = tweet.RawJson; this.SentimentScore = TextAnalysisService.AnalyzeSentiment(this.Id.ToString(), this.Text, this.Language.Iso639Name); this.KeyPhrases = TextAnalysisService.AnalyzeKeyPhrases(this.Id.ToString(), this.Text, this.Language.Iso639Name); }
private void UpdateUI(String message) { Device.BeginInvokeOnMainThread(async() => { //AI_LIS.IsRunning = false; listening = false; ListenBtn.Text = "listen"; ListenBtn.BackgroundColor = Color.FromHex("#2E74D1"); var textBox = new PancakeView { BackgroundColor = Color.WhiteSmoke, CornerRadius = 10, HasShadow = true }; var sentiment = await TextAnalysisService.GetSentiment(message); textBox.BackgroundColor = SetSpeechColour((double)sentiment); textBox.Content = new Label { Text = message, Margin = 7 }; speech.Children.Add(textBox); }); }
private async void OnRecognitionButtonClicked(object sender, EventArgs e) { //ActivityIndicator activityIndicator = new ActivityIndicator { IsRunning = false }; //AI_LIS.IsRunning = true; listening = true; ListenBtn.Text = "listening"; ListenBtn.BackgroundColor = Color.Green; //Check if the app has microphone permissions bool micAccessGranted = await DependencyService.Get <IMicrophoneService>().GetPermissionsAsync(); if (!micAccessGranted) { UpdateUI("Please give access to microphone"); } else { Console.WriteLine("mic access granted"); } try { // Creates an instance of a speech config with specified subscription key and service region. // Replace with your own subscription key and service region (e.g., "westus"). var config = SpeechConfig.FromSubscription("fa287654e33b43e8a92abe5e40beef4f", "westus2"); // Creates a speech recognizer using microphone as audio input. using (var recognizer = new SpeechRecognizer(config)) { // Starts speech recognition, and returns after a single utterance is recognized. The end of a // single utterance is determined by listening for silence at the end or until a maximum of 15 // seconds of audio is processed. The task returns the recognition text as result. // Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single // shot recognition like command or query. // For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead. var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false); // Checks result. StringBuilder sb = new StringBuilder(); if (result.Reason == ResultReason.RecognizedSpeech) { sb.AppendLine($"{result.Text}"); phrases.Add(result.Text); Console.WriteLine("This is what I heard: " + result.Text); foreach (var phrase in phrases) { Console.WriteLine(phrase); } } else if (result.Reason == ResultReason.NoMatch) { sb.AppendLine($"NOMATCH: Speech could not be recognized."); } else if (result.Reason == ResultReason.Canceled) { var cancellation = CancellationDetails.FromResult(result); sb.AppendLine($"CANCELED: Reason={cancellation.Reason}"); if (cancellation.Reason == CancellationReason.Error) { sb.AppendLine($"CANCELED: ErrorCode={cancellation.ErrorCode}"); sb.AppendLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}"); sb.AppendLine($"CANCELED: Did you update the subscription info?"); } } if (sb.ToString().Contains(currentUser.Name)) { //var tone = await SentimentAnalysis.GetSentiment("Tony is a great man"); //Console.WriteLine("SENTIMENT ANALYSIS -> "+tone); UpdateUI(sb.ToString()); } else { UpdateUI("No one is talking about you"); } } } catch (Exception ex) { UpdateUI("Exception: " + ex.ToString()); } Console.WriteLine("SENTIMENT SCORE -> " + await TextAnalysisService.GetSentiment("I f*****g hate you")); }
public async Task ProcessText(IDialogContext context, string query) { switch (query) { case "olá": case "ola": case "ajuda": case "oi": case "socorro": case "cancelar": case "começar": case "comecar": case "recomeçar": case "recomecar": await Wellcome(context); context.Wait(ReadText); return; } var medidores = new Medidores(); var textAnalysis = new TextAnalysisService(); double sentiment = await textAnalysis.Sentiment(language : "pt", text : query); var medidor = medidores.CalculaMedidor(sentiment); var image = @"https://botmood.azurewebsites.net/images/" + medidor.Image; await context.PostAsync("O grau de emoção é um valor entre 0 e 1, sendo que 0 significa totalmente negativo e 1 totalmente positivo."); await context.PostAsync("Naturalmente meu grau de precisão é menor quanto menor for a frase. A brincadeira fica mais legal " + "se você escrever uma opinião, tal qual faria em um site de opiniões como o TripAdvisor."); var img = new List <string>() { image }; var card1 = CardUtilities.CreateHeroCard("", "Grau de emoção", sentiment.ToString("0.00"), img, null); var reply1 = context.MakeMessage(); reply1.Attachments = CardUtilities.CreateCards(); reply1.Attachments.Add(card1.ToAttachment()); await context.PostAsync(reply1); var keyPhrases = await textAnalysis.KeyPhrases(language : "pt", text : query); if ((keyPhrases != null) && (keyPhrases.Count > 0)) { var key = ""; foreach (var s in keyPhrases) { if (!string.IsNullOrEmpty(s)) { if (key.Length > 0) { key = key + ", "; } key = key + s; } } var card2 = CardUtilities.CreateHeroCard("", "Palavras chave", key, null, null); var reply2 = context.MakeMessage(); reply2.Attachments = CardUtilities.CreateCards(); reply2.Attachments.Add(card2.ToAttachment()); await context.PostAsync(reply2); } //var detectLanguage = await textAnalysis.DetectLanguage(result.Query); context.Wait(ReadText); }