internal void TranscribeAndExtractTagsForAGivenFile() { HelperFunctions.PromptForConfirmationAndExecute( "Press Y to Continue with single file contigous transciption or any key to skip...", () => { string inputPath = HelperFunctions.GetSampleDataFullPath(customSettings.SampleDataFolders.VoiceMemosFolder); string inputFile = Path.Combine(inputPath, customSettings.SampleIndividualFiles.SampleVoiceMemoFile); // transcribing speech - a single file case scenario IndividualFileTranscribe.TranscribeSpeechFileAsync( customSettings.SpeechConfigSettings.Key, customSettings.SpeechConfigSettings.Region, inputFile, HelperFunctions.GetSampleDataFullPath(customSettings.SampleDataFolders.TranscribedFileFolder)).Wait(); }); HelperFunctions.PromptForConfirmationAndExecute( "Press Y to Continue to extract tags from a single file or any key to skip...", () => { string outPath = HelperFunctions.GetSampleDataFullPath(customSettings.SampleDataFolders.TranscribedFileFolder); string outFile = Path.Combine(outPath, customSettings.SampleIndividualFiles.SampleVoiceMemoFile) + ".txt"; TextAnalyticsClient textClient = TextAnalytics.GetClient( customSettings.TextAnalyticsSettings.Key, customSettings.TextAnalyticsSettings.Endpoint); var tags = TextAnalytics.GetTags(textClient, outFile).ConfigureAwait(false).GetAwaiter().GetResult(); Console.WriteLine(string.Join(", ", tags)); }); }
private static async Task SurveyReceivedAsync(IDialogContext context, IAwaitable <object> result) { var activity = await result as Activity; var text = activity?.Text; var textAnalisysService = new TextAnalytics(); var score = await textAnalisysService.MakeRequest(text); if (score < 50) { var message = context.MakeMessage(); message.AttachmentLayout = AttachmentLayoutTypes.Carousel; var card = new ThumbnailCard { Title = "Sorry for not help you, but you can enter in contact through our other channels", Subtitle = "Click on the buttons below to talk to our agents through phone or chat", Buttons = new List <CardAction> { new CardAction("call", $"Call", null, $"tel:1149029052"), new CardAction(ActionTypes.OpenUrl, $"Chat", null, "http://www.gndi.com.br/web/guest/atendimento-em-saude") } }; message.Attachments.Add(card.ToAttachment()); await context.PostAsync(message); } else { await context.PostAsync("Thanks for your answer, I'll be here if you need anything else"); } InsightUtils.TrackEvent(MenuOptions.Survey); context.Done <object>(null); }
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result) { var activity = await result as Activity; var message = context.MakeMessage(); message.Text = activity.Text; await context.PostAsync("about to call text analytics"); TextAnalytics textAnalytics = new TextAnalytics(); string response = await textAnalytics.Start(activity.Text); await context.PostAsync(response); await context.PostAsync("about to call qna"); QnAMaker qna = new QnAMaker(); response = await qna.TryQuery(activity.Text); await context.PostAsync(response); if (response.Contains("Fall Back Response")) { await context.PostAsync("about to call luis"); await context.Forward(new LUIS(), AfterLuis, activity, System.Threading.CancellationToken.None); context.Done(true); } }
public async Task <IActionResult> Post([FromBody] string value) { var ta = new TextAnalytics(); var prop = await ta.MakeRequestAsync(value); return(new OkObjectResult(lib.getEmojiForSentiment(prop))); }
// This method is to get the feedback from the user and generated the Score base on the Text Analytics API private async Task feedback(IDialogContext context, IAwaitable <string> result) { var score = await TextAnalytics.TextAnalysis(await result); await context.PostAsync($"You rate us as {double.Parse(score)*100}%. \r\n {await TextAnalytics.Sentiment(score)}"); context.Wait(MessageReceived); }
public IHttpActionResult Post([FromBody] Activity activity) { if (string.IsNullOrEmpty(activity.Text)) { return(NotFound()); } string reply = ""; if (activity.Type == ActivityTypes.Message) { // calculate something for us to return int length = (activity.Text ?? string.Empty).Length; var keyPhrases = TextAnalytics.GetKeyPhrases(activity.Text, activity.Id); //MessageDB.MessagesList.Add(message); var keys = _keyWords_manager.FindKeyWords(activity.Text, _question_manager.CurrentTopic); if (keys.Count == 0) { var topic = _keyWords_manager.RecognizeTopic(activity.Text); if (topic != Topic.None) { reply = _question_manager.GetQuestion(topic); } } _question_manager.AllowToNextQuestion = keys.Count > 0; if (String.IsNullOrEmpty(reply)) { if (_question_manager.CurrentTopic == Topic.Experience) { if (_question_manager.CurrentTopic == Topic.Experience) { string txt = ""; foreach (var key in keyPhrases.Result.documents) { txt += key + ", "; } txt += " seems cool!"; } } reply = _question_manager.GetQuestion(); } // connector.Conversations.ReplyToActivityAsync(reply); } else { HandleSystemMessage(activity); } //var response = Request.CreateResponse(HttpStatusCode.OK); //response.Content = //return response; return(Ok(reply)); }
static void Main(string[] args) { //1 - using LUIS //var task1 = LUISMakerShowClient.ParseUserInput("What can you tell me about an arduino?"); //task1.Wait(); //2 - Tuple, calling text analytics var task2 = TextAnalytics.ProcessLanguage(); task2.Wait(); Console.WriteLine(task2.Result.keyPhrases); //3 - Face API with SDK (this is .net core so copied classes manually into my project) BlurFaces.Process(); //4 - TopicDetection.MakeRequest(); }
public async Task <ActionResult> Text([FromBody] InputModel inputModel) { if (inputModel.Document.HasContent()) { // Get settings from cache var settingHelper = new SettingHelper(_memoryCache); var keys = $"{SettingKeys.TextAnalyticsEndpoint},{SettingKeys.TextAnalyticsSecret}"; Dictionary <string, string> settings = settingHelper.GetCachedSettingValuesByKeys(keys); // Text analytics var textAnalytics = new TextAnalytics(settings[SettingKeys.TextAnalyticsEndpoint], settings[SettingKeys.TextAnalyticsSecret]); var response = await textAnalytics.ProcessText(inputModel.Document); return(Ok(response)); } // If it reaches here document has no content return HTTP 400 Bad Request return(BadRequest(new { Message = "Document cannot be empty" })); }
/// <summary> /// Get Ask Question Results from Bing Web Search Result /// </summary> public static async Task <string[]> GetTopics(string question, string[] currentTopics) { // Run keyphrases extraction TextAnalyticsResult <TextAnalyticsKeyPhrasesResult> textAnalyticsResult = await TextAnalytics.AnalyzeKeyPhrasesAsync(question); string[] topics = currentTopics; if (textAnalyticsResult.Results?.Count() > 0 == true) { topics = textAnalyticsResult.Results.Select(r => r.KeyPhrases).FirstOrDefault(); } if (topics?.Count() > 0) { topics = topics.Select(t => t.ToLower()).ToArray(); } return(topics); }
public TextAnalyticsTest() { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); SQLHelperConfig.ConnectionConfig = configuration.GetConnectionString("ContentderAIConnection"); var provider = new ServiceCollection() .AddMemoryCache() .BuildServiceProvider(); var memoryCache = provider.GetService <IMemoryCache>(); var settingHelper = new SettingHelper(memoryCache); settingHelper.CacheAllSettings(); var keys = $"{SettingKeys.TextAnalyticsEndpoint},{SettingKeys.TextAnalyticsSecret}"; Dictionary <string, string> settings = settingHelper.GetCachedSettingValuesByKeys(keys); _textAnalytics = new TextAnalytics(settings[SettingKeys.TextAnalyticsEndpoint], settings[SettingKeys.TextAnalyticsSecret]); }
public async Task <ActionResult <IList> > PostKeyPhraseAsync([FromBody] DocsWithTime json) { Docs jsonDoc = JsonSerializer.Deserialize <Docs>(JsonSerializer.Serialize(json)); //string result = await CallTextAnalyticsAPI(jsonDoc); string result = await TextAnalticsAPI.CallTextAnalyticsAPI(json : jsonDoc, RequestType : "keyphrases", azure_key : _configuration["azure_key"]); TextAnalytics textanalyticsresponse = JsonSerializer.Deserialize <TextAnalytics>(result); var p = textanalyticsresponse.documents; //.GroupBy(i => i.keyPhrases); var allphrases = p.SelectMany(s => s.keyPhrases).ToList(); var allPhrasesCount = allphrases.GroupBy(x => x) .Where(g => g.Count() > 1) .Select(y => new { word = y.Key, count = y.Count() }) .ToList(); return(allPhrasesCount.ToList()); }
internal async Task ReadImageOcrTextAndTranslate(string toLanguage = "en-US") { string inputImageFilePath = Path.Combine( HelperFunctions.GetSampleDataFullPath(customSettings.SampleDataFolders.PhotosToAnalyzeFolder), customSettings.SampleIndividualFiles.PhotoFileToProcess ); string fileNamePrefix = Path.GetFileName(inputImageFilePath); string outFolder = HelperFunctions.GetSampleDataFullPath(customSettings.SampleDataFolders.AnalyzedImagesFolder); string outBaseFilePath = Path.Combine(outFolder, fileNamePrefix); // ensure destination Path exists Directory.CreateDirectory(outFolder); // OCR - text extraction // Get vision client Console.WriteLine($"Extracting Text using Vision OCR from {inputImageFilePath}..."); ComputerVisionClient visionClient = ComputerVision.Authenticate( customSettings.ComputerVisionSettings.Endpoint, customSettings.ComputerVisionSettings.Key); string ocrFilePath = outBaseFilePath + "-ReadOcrResults.txt"; var ocrResult = await ComputerVision.RecognizeTextFromImageLocal(visionClient, inputImageFilePath, false); var ocrLineTexts = ComputerVisionHelper.GetOcrResultLineTexts(ocrResult); await File.WriteAllLinesAsync(ocrFilePath, ocrLineTexts); Console.WriteLine($"Generated OCR output file {ocrFilePath}."); Console.WriteLine(); // Detect Languages using Text Analytics Api TextAnalyticsClient textClient = TextAnalytics.GetClient( customSettings.TextAnalyticsSettings.Key, customSettings.TextAnalyticsSettings.Endpoint ); Console.WriteLine("Detect the language from generated OCR text using TextAnalytics..."); IEnumerable <string> sourceLanguages = await TextAnalytics.DetectLanguageBatchAsync(textClient, ocrLineTexts); //Console.WriteLine($"Detected languages Count: {sourceLanguages.Count()}"); //Console.WriteLine($"Detected Languages: {string.Join(", ", sourceLanguages)}"); Console.WriteLine(); // Now translate the extracted text (OCR) to output language (here default is English) Console.WriteLine($"Now translate the generated OCR file to English {toLanguage}..."); string ocrText = await File.ReadAllTextAsync(ocrFilePath); string translatedText = await JournalHelper.Translator.Translate.TranslateTextRequestAsync( customSettings.TranslatorConfigSettings.Key, customSettings.TranslatorConfigSettings.Endpoint, toLanguage, ocrText ); string outTranslatedFilePath = outBaseFilePath + "-translated-" + toLanguage + ".json"; if (!translatedText.StartsWith("[")) { Console.WriteLine($"Storing the generated translation output to file: {outTranslatedFilePath}... "); var json = JObject.Parse(translatedText); Helper.WriteToJsonFile <JObject>(outTranslatedFilePath, json); if (json.ContainsKey("error")) { Console.WriteLine($"\t\t\tTRANSLATOR ERROR: {json["error"]["code"]}"); Console.WriteLine($"\t\t\tMESSAGE: {json["error"]["message"]}"); return; } } string txtFile = outTranslatedFilePath + ".txt"; Console.WriteLine($"Generating txt file with translated texts - {txtFile}"); IEnumerable <string> texts = JournalHelper.Translator.Translate.GetTranslatedTexts(translatedText); await File.WriteAllLinesAsync(txtFile, texts); Console.WriteLine(); }
public async Task <IActionResult> GetCommentsAnalyse([FromRoute] Guid eventId) { var model = new List <CommentAnalyticsDTO>(); var comments = await _commentRepo.Comments(eventId); if (!comments.IsNullOrEmpty()) { var inputs = new List <Input>(); foreach (var comment in comments) { inputs.Add(new Input() { Id = comment.Id.ToString(), Text = comment.Content }); model.Add(new CommentAnalyticsDTO() { CommentId = comment.Id, Content = comment.Content, CreatedAt = comment.CreatedAt }); } TextAnalytics _textAnalytics = new TextAnalytics(); var multiLanguageInputs = new List <MultiLanguageInput>(); var languageResult = _textAnalytics.DetectLanguage(inputs); if (languageResult != null) { for (int i = 0; i < languageResult.Documents.Count; i++) { foreach (var item in model) { if (item.CommentId.ToString() == languageResult.Documents[i].Id) { item.Language = languageResult.Documents[i].DetectedLanguages[0].Name; item.LanguageCode = languageResult.Documents[i].DetectedLanguages[0].Iso6391Name; } } multiLanguageInputs.Add(new MultiLanguageInput() { Id = model[i].CommentId.ToString(), Language = model[i].LanguageCode, Text = model[i].Content }); } var keyPhrases = _textAnalytics.GetKeyPhrases(multiLanguageInputs); if (keyPhrases != null) { for (int i = 0; i < keyPhrases.Documents.Count; i++) { foreach (var item in model) { if (item.CommentId.ToString() == keyPhrases.Documents[i].Id) { item.KeyPhrases = keyPhrases.Documents[i].KeyPhrases.ToList(); } } } } var sentimentResult = _textAnalytics.GetSentiment(multiLanguageInputs); if (sentimentResult != null) { for (int i = 0; i < sentimentResult.Documents.Count; i++) { foreach (var item in model) { if (item.CommentId.ToString() == sentimentResult.Documents[i].Id) { item.Sentiment = sentimentResult.Documents[i].Score.ToString(); } } } } } } return(Ok(model)); }