public async Task <ActionResult> TextAnalytics(string text) { text = string.IsNullOrWhiteSpace(text) ? "I had a wonderful experience! The rooms were wonderful and the staff were helpful." : text; var subscriptionKey = ConfigurationManager.AppSettings["TextApiKey"]; var requestService = new CognitiveServicesRequest(); var requestObject = requestService.CreateTextRequestObject(text); // Text Language API var urlLanguage = "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/languages"; var responseLanuage = await requestService.MakeRequest(urlLanguage, subscriptionKey, requestObject); // Text Topics API var urlTopics = "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/keyPhrases"; var responseTopics = await requestService.MakeRequest(urlTopics, subscriptionKey, requestObject); //Text Sentiment API var urlSentiment = "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment"; var responseSentiment = await requestService.MakeRequest(urlSentiment, subscriptionKey, requestObject); var viewModel = new TextAnalyticsViewModel { Text = text, JsonResponseLanuage = responseLanuage, JsonResponseTopics = responseTopics, JsonResponseSentiment = responseSentiment }; return(View(viewModel)); }
public async Task <ActionResult <TextAnalyticsViewModel> > TextAnalytics([FromForm] TextAnalyticsAnalyzeRequest request) { if (string.IsNullOrWhiteSpace(request.TextAnalyticsSubscriptionKey)) { throw new ArgumentException("Missing or invalid TextAnalyticsSubscriptionKey", nameof(request.TextAnalyticsSubscriptionKey)); } if (string.IsNullOrWhiteSpace(request.TextAnalyticsEndpoint)) { throw new ArgumentException("Missing or invalid TextAnalyticsEndpoint", nameof(request.TextAnalyticsEndpoint)); } if (string.IsNullOrWhiteSpace(request.Text)) { throw new ArgumentException("Missing or invalid Text", nameof(request.Text)); } Track("Language_TextAnalytics"); var textAnalyzer = new LanguageTextAnalyticsAnalyzer(request.TextAnalyticsSubscriptionKey, request.TextAnalyticsEndpoint); var analyzeResult = await textAnalyzer.Analyze(request.Text, request.LanguageHint); return(View(TextAnalyticsViewModel.Analyzed(request, analyzeResult))); }
public TextAnalyticsPage() { Title = "Text Analytics"; BindingContext = new TextAnalyticsViewModel(); var textEntry = new Editor { Text = "Hello world", FontSize = 16 }; textEntry.SetBinding(Editor.TextProperty, "Text"); var detectLanguageFromTextButton = new Button { Text = "Detect Language", TextColor = Color.White, BackgroundColor = Color.FromHex("#03A9F4"), FontSize = 24 }; detectLanguageFromTextButton.SetBinding(Button.CommandProperty, "DetectLanguageFromTextCommand"); var detectSentimentFromTextButton = new Button { Text = "Detect Sentiment", TextColor = Color.White, BackgroundColor = Color.Teal, FontSize = 24 }; detectSentimentFromTextButton.SetBinding(Button.CommandProperty, "DetectSentimentCommand"); var detectKeyPhrasesFromTextButton = new Button { Text = "Key Phrases", TextColor = Color.White, BackgroundColor = Color.Purple, FontSize = 24 }; detectKeyPhrasesFromTextButton.SetBinding(Button.CommandProperty, "DetectKeyPhrasesCommand"); var isBusyActivityIndicator = new ActivityIndicator(); isBusyActivityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy"); isBusyActivityIndicator.SetBinding(ActivityIndicator.IsEnabledProperty, "IsBusy"); isBusyActivityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy"); var errorMessageLabel = new Label { TextColor = Color.Red, FontSize = 20 }; errorMessageLabel.SetBinding(Label.TextProperty, "ErrorMessage"); var detectedLanguageLabel = new Label { TextColor = Color.FromHex("#03A9F4"), FontSize = 20 }; detectedLanguageLabel.SetBinding(Label.TextProperty, new Binding( "LanguageResult.Documents[0].DetectedLanguages[0].Name", BindingMode.Default, null, null, "Language: {0:F0}")); var detectedLanguageScoreLabel = new Label { TextColor = Color.FromHex("#03A9F4"), FontSize = 20 }; detectedLanguageScoreLabel.SetBinding(Label.TextProperty, new Binding( "LanguageResult.Documents[0].DetectedLanguages[0].Score", BindingMode.Default, null, null, "Score: {0:F0}")); var detectedSentimentLabel = new Label { TextColor = Color.Teal, FontSize = 20 }; detectedSentimentLabel.SetBinding(Label.TextProperty, new Binding( "SentimentResult.Documents[0].Score", BindingMode.Default, null, null, "Sentiment Score: {0:F0}")); var detectedKeyPhrasesLabel = new Label { TextColor = Color.Purple, FontSize = 20 }; detectedKeyPhrasesLabel.SetBinding(Label.TextProperty, new Binding( "KeyPhrasesResult.Documents[0].KeyPhrases", BindingMode.Default, new ListOfStringToOneStringConverter(), null, "KeyPhrases: {0:F0}")); var stackLayout = new StackLayout { Padding = new Thickness(10, 0), Children = { textEntry, detectLanguageFromTextButton, detectSentimentFromTextButton, detectKeyPhrasesFromTextButton, isBusyActivityIndicator, detectedLanguageLabel, detectedLanguageScoreLabel, detectedSentimentLabel, detectedKeyPhrasesLabel, errorMessageLabel } }; Content = new ScrollView { Content = stackLayout }; }
public IActionResult TextAnalytics() { return(View(TextAnalyticsViewModel.NotAnalyzed())); }