public Analyzer(string xml) { ITextAnalyticsAPI client = Program.Client(); string xmlString = xml; Console.OutputEncoding = System.Text.Encoding.UTF8; Console.WriteLine("\n\n####TEXT ANALYSIS####"); KeyPhraseBatchResult analysis = client.KeyPhrases( new MultiLanguageBatchInput( new List <MultiLanguageInput>() { new MultiLanguageInput("en", "1", xmlString), })); foreach (var item in analysis.Documents) { Console.WriteLine("Document ID: {0}", item.Id); Console.WriteLine("\t Key phrases"); foreach (string keyphrase in item.KeyPhrases) { Console.WriteLine(keyphrase); phrases = item.KeyPhrases; } } Sentiment(phrases); Recommendations(phrases); }
public SentimentAnalysis() { client = new TextAnalyticsAPI(); client.AzureRegion = AzureRegions.Westeurope; client.SubscriptionKey = "98ce8da3795c4ea5b943468ec801eb2e"; //уникальний ключ сервіса }
private static void KeyPhrases(ITextAnalyticsAPI client) { // Getting key-phrases Console.WriteLine("\n\n===== KEY-PHRASE EXTRACTION ======"); var inputs2 = new List <MultiLanguageInput>() { new MultiLanguageInput("zh", "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!") }; KeyPhraseBatchResult result2 = client.KeyPhrases(new MultiLanguageBatchInput(inputs2)); // 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); } Console.WriteLine($"Text: {inputs2.FirstOrDefault(i => i.Id == document.Id).Text}"); Console.WriteLine(); } }
public CognitiveServiceHandler() { // initialize client _client = new TextAnalyticsAPI(); _client.AzureRegion = AzureRegions.Westcentralus; _client.SubscriptionKey = SUBSCRIPTION_KEY; }
public TextAnalyticsBL() { // Create a client. client = new TextAnalyticsAPI(); client.AzureRegion = AzureRegions.Westcentralus; client.SubscriptionKey = "6499bf6efdbe41a18c7ebbd41d870777"; }
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(); } }
public TextEmotionService() { client = new TextAnalyticsAPI { AzureRegion = AzureRegions.Westcentralus, SubscriptionKey = APIKEY }; }
public MicrosoftTextAnalytics(string key) { _AnalyticsClient = new TextAnalyticsAPI { AzureRegion = AzureRegions.Westus, SubscriptionKey = key }; }
public TextAnalytics() { _client = new TextAnalyticsAPI() { AzureRegion = AzureRegions.Westus, SubscriptionKey = "094adce6de9f4237875c0103f846c468" }; }
private static DetectedLanguage GetFirstDetectedLanguage(string description, ITextAnalyticsAPI client) { var result = client.DetectLanguage(new BatchInput(new List <Input> { new Input("1", description) })); return(result.Documents.First().DetectedLanguages.First()); }
public TextAnalyticsWrapper(string subscriptionKey, AzureRegions region) { if (string.IsNullOrWhiteSpace(subscriptionKey)) { throw new ArgumentNullException(nameof(subscriptionKey)); } _client = _client = new TextAnalyticsAPI(new ApiKeyServiceClientCredentials(subscriptionKey)); _client.AzureRegion = region; }
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; } ; }
public SentimentAnalysis() { var regionName = ConfigurationManager.AppSettings["TextAnalyticsApiRegion"]; var subscriptionKey = ConfigurationManager.AppSettings["TextAnalyticsApiKey"]; var validRegion = Enum.TryParse(regionName, out AzureRegions region); if (string.IsNullOrEmpty(subscriptionKey) || !validRegion) { throw new Exception("Unable to create Sentiment Analysis Client - check the region and subscription key"); } var client = new TextAnalyticsAPI { AzureRegion = region, SubscriptionKey = subscriptionKey }; _client = client; }
private static void DetectLanguage(ITextAnalyticsAPI client) { // Extracting language Console.WriteLine("===== LANGUAGE EXTRACTION ======"); var inputs1 = new List <Input>() { new Input("1", "This is a document written in English."), new Input("2", "C'est un fichier écrit en français."), new Input("3", "这是一个用中文写的文件") }; LanguageBatchResult result = client.DetectLanguage(new BatchInput(inputs1)); // Printing language results. foreach (var document in result.Documents) { Console.WriteLine($"Document ID: {document.Id} , Language: {document.DetectedLanguages[0].Name} , Text: {inputs1.FirstOrDefault(i => i.Id == document.Id).Text}"); } }
internal async Task <KeyPhraseBatchResult> GetKeyPhraseCall(List <Input> list, IList <LanguageBatchResultItem> documents, ITextAnalyticsAPI client) { string textid = ""; string textlang = ""; string textval = ""; List <MultiLanguageInput> keyphraselist = new List <MultiLanguageInput>(); for (int i = 0; i < documents.Count; i++) { textid = documents[i].Id; textlang = documents[i].DetectedLanguages[0].Iso6391Name; textval = list.Where(t => t.Id == i.ToString()).FirstOrDefault().Text; keyphraselist.Add(new MultiLanguageInput() { Id = textid, Text = textval, Language = textlang }); } return(await KeyPhraseCall(client, keyphraselist)); }
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}"); } }
public async Task <DetectedLanguage> Execute(ITextAnalyticsAPI client) { var id = Guid.NewGuid().ToString(); var input = new Input(id, text); var documents = new List <Input> { input }; var batchInput = new BatchInput(documents); var result = await client.DetectLanguageAsync(batchInput); // More than one language could be matched at the same max score... // this can cause some confusion var detectedLanguages = result.Documents.First() .DetectedLanguages; var detectedLanguage = detectedLanguages.Where(dl => dl.Score.HasValue && new[] { "en", "fr" }.Contains(dl.Iso6391Name)) .OrderByDescending(dl => dl.Score) .FirstOrDefault(); return(detectedLanguage); }
public TextAnalysisControl() { InitializeComponent(); client = new TextAnalyticsAPI(); client.AzureRegion = AzureRegions.Westeurope; }
internal async Task <LanguageBatchResult> DetectLangCall(ITextAnalyticsAPI client, List <Input> list) { return(await client.DetectLanguageAsync( new BatchInput(list))); }
public SentimentService(Secrets secrets) { this.secrets = secrets; this.client = new TextAnalyticsAPI(new ApiKeyServiceClientCredentials(secrets.AzureSentimentKey)); this.client.AzureRegion = AzureRegions.Westus2; }
public TextAnalysis() { client = new TextAnalyticsAPI(); client.AzureRegion = AzureRegions.Eastus2; client.SubscriptionKey = "xxxxxxxxxxxxxxxxxxxxxxxx"; }
/// <summary> /// Called when a final response is received; /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="SpeechResponseEventArgs"/> instance containing the event data.</param> private void OnMicShortPhraseResponseReceivedHandler(object sender, SpeechResponseEventArgs e) { Dispatcher.Invoke((Action)(() => { this.WriteLine("--- OnMicShortPhraseResponseReceivedHandler ---"); // we got the final result, so it we can end the mic reco. No need to do this // for dataReco, since we already called endAudio() on it as soon as we were done // sending all the data. this.micClient.EndMicAndRecognition(); this.WriteResponseResult(e); _startButton.IsEnabled = true; _radioGroup.IsEnabled = true; if (e.PhraseResponse == null || e.PhraseResponse.Results.Length <= 0) { return; } //call sentiment analysis if (this.textAnalyticsClient == null) { this.textAnalyticsClient = new TextAnalyticsAPI(); this.textAnalyticsClient.AzureRegion = AzureRegions.Southeastasia; this.textAnalyticsClient.SubscriptionKey = "<yourkey>"; Console.WriteLine("api init done"); } SentimentBatchResult result3 = this.textAnalyticsClient.Sentiment( new MultiLanguageBatchInput( new List <MultiLanguageInput>() { new MultiLanguageInput("en", "0", e.PhraseResponse.Results[0].DisplayText), })); // Printing sentiment results foreach (var document in result3.Documents) { //this.WriteLine("Document ID: {0} , Sentiment Score: {1:0.00}", document.Id, document.Score); //string.Format("{0:P2}", document.Score) String sentiment = ""; if (document.Score > 0 && document.Score < 0.1) { sentiment = "Dissatisfied"; this.WriteKnowledgeBaseLine("Please re-assure the customer that they are important. Check about exact customer requirements and offer to check with supervisor."); } else if (document.Score >= 0.1 && document.Score < 0.6) { sentiment = "Neutral"; } else if (document.Score >= 0.6 && document.Score < 0.8) { sentiment = "Positive"; } else if (document.Score >= 0.8 && document.Score < 1) { sentiment = "Delighted"; } Dispatcher.Invoke(() => { _SentimentText.Text = sentiment + " - " + string.Format("{0:P2}", document.Score); }); } })); }
internal async Task <KeyPhraseBatchResult> KeyPhraseCall(ITextAnalyticsAPI client, List <MultiLanguageInput> list) { return(await client.KeyPhrasesAsync( new MultiLanguageBatchInput(list))); }
public CognitiveServices() { _client = Initializeclient(); }
public TextAnalysisService(TextAnalyticsAPI textAnalyticsAPI, IList <MultiLanguageInput> multiLanguageInput, IList <AnalysisResult> analysisResults) { _textAnalyticsAPI = textAnalyticsAPI; _multiLanguageInput = multiLanguageInput; _analysisResults = analysisResults; }
internal async Task <SentimentBatchResult> SentimentCall(ITextAnalyticsAPI client, List <MultiLanguageInput> list) { return(await client.SentimentAsync( new MultiLanguageBatchInput(list))); }