private void processRes(LuisResult res)
        {
            txtPredict.Text         = "";
            prevResult              = res;
            queryTextBlock.Text     = res.OriginalQuery;
            topIntentTextBlock.Text = res.TopScoringIntent.Name;
            List <string> entitiesNames = new List <string>();
            var           entities      = res.GetAllEntities();

            foreach (Entity entity in entities)
            {
                entitiesNames.Add(entity.Name);
            }
            entitiesListBox.ItemsSource = entitiesNames;
            if (res.DialogResponse != null)
            {
                if (res.DialogResponse.Status != "Finished")
                {
                    dialogTextBlock.Text = res.DialogResponse.Prompt;
                }
                else
                {
                    dialogTextBlock.Text = "Finished";
                }
            }
        }
Ejemplo n.º 2
0
        private void processRes(LuisResult res)
        {
            Console.WriteLine("OriginalQuery = " + res.OriginalQuery);
            Console.WriteLine("TopScoringIntent = " + res.TopScoringIntent.Name);

            Console.WriteLine("-------AllEntities-------");
            var entities = res.GetAllEntities();

            foreach (Entity entity in entities)
            {
                Console.WriteLine("entity.Name = " + entity.Name);
            }

            if (res.DialogResponse != null)
            {
                Console.WriteLine("-------DialogResponse-------");
                if (res.DialogResponse.Status != "Finished")
                {
                    Console.WriteLine(res.DialogResponse.Prompt);
                }
                else
                {
                    Console.WriteLine("Finished");
                }
            }
        }
Ejemplo n.º 3
0
        private async Task <IntentItem> CreateIntentItem(IntentItem item)
        {
            string appId           = Environment.GetEnvironmentVariable("LuisAppId");
            string subscriptionKey = Environment.GetEnvironmentVariable("LuisSubscriptionKey");
            bool   preview         = true;

            var client = new LuisClient(appId, subscriptionKey, preview);

            LuisResult res = await client.Predict(item.Utterance);

            var processingResult = new ProcessingResult();

            List <string> entitiesNames = new List <string>();
            var           entities      = res.GetAllEntities();

            foreach (Entity entity in entities)
            {
                processingResult.Entities.Add(entity.Name, entity.Value);
            }

            processingResult.Confidence  = res.TopScoringIntent.Score;
            processingResult.Intent      = res.TopScoringIntent.Name;
            processingResult.IsFromCache = false;

            item.Intent       = processingResult.Intent;
            item.JsonEntities = JsonConvert.SerializeObject(processingResult.Entities);

            return(item);
        }
Ejemplo n.º 4
0
        private async Task GetQuoteInformation(IDialogContext context, LuisResult luisResult)
        {
            Microsoft.Cognitive.LUIS.Entity ativo = luisResult.GetAllEntities().FirstOrDefault(e => e.Name == "Ativo");

            if (ativo != null)
            {
                await GetQuote_PrintQuoteValueAsync(context, ativo.Value);
            }
            else
            {
                PromptDialog.Text(context, GetQuote_AfterUserInputAsync, "Qual o ativo ou empresa você deseja consultar?");
            }
        }
        public static void FillStateActivity(LuisResult result, object context)
        {
            List <Entity> entitis = result.GetAllEntities();

            if (entitis != null && entitis.Count > 0)
            {
                foreach (Entity entity in entitis)
                {
                    if (entity.Name.Equals(Constant.StateEntity, StringComparison.CurrentCultureIgnoreCase))
                    {
                        Aggregator.GetEvent <FillStateEvent>().Publish(entity.Value);
                    }
                }
            }
        }
        public static void FillCityActivity(LuisResult result, object context)
        {
            List <Entity> entitis = result.GetAllEntities();

            if (entitis != null && entitis.Count > 0)
            {
                foreach (Entity entity in entitis)
                {
                    if (entity.Name.Contains(Constant.GeographyEntity))
                    {
                        Aggregator.GetEvent <FillCityEvent>().Publish(entity.Value);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private ProcessingResult processRes(LuisResult res)
        {
            var processingResult = new ProcessingResult();

            List <string> entitiesNames = new List <string>();
            var           entities      = res.GetAllEntities();

            foreach (Entity entity in entities)
            {
                processingResult.Entities.Add(entity.Name, entity.Value);
            }

            processingResult.Confidence  = res.TopScoringIntent.Score;
            processingResult.Intent      = res.TopScoringIntent.Name;
            processingResult.IsFromCache = false;

            return(processingResult);
        }
Ejemplo n.º 8
0
        private static void GetQuoteInformation(LuisResult luisResult)
        {
            Entity quoteEntity = luisResult.GetAllEntities().FirstOrDefault(e => e.Name == "Ativo");

            string entityValue = string.Empty;

            if (quoteEntity != null)
            {
                entityValue = quoteEntity.Value;
            }
            else
            {
                Console.WriteLine("Qual o ativo ou empresa você deseja consultar?");
                entityValue = Console.ReadLine();
            }

            QuoteResult quoteResult = FakeQuote.GetPrice(entityValue);

            Console.WriteLine($"O preço do ativo {quoteResult.Name} é {quoteResult.Value:C2}.");
        }
        private void processRes(LuisResult res)
        {
            string entityValue = "";

            if (res.TopScoringIntent.Score < 0.7 || res.TopScoringIntent.Name == "None")
            {
                if (loopTestCheckbox.IsChecked == false)
                {
                    return;
                }
            }
            prevResult = res;

            //((MainWindow)Application.Current.MainWindow)._scenariosControl.LogLuis(res.OriginalQuery);
            ((MainWindow)Application.Current.MainWindow)._scenariosControl.LogLuis("\"" + res.OriginalQuery + "\": LUIS Intent: " + res.TopScoringIntent.Name + ", confidence: " + (res.TopScoringIntent.Score * 100).ToString().Substring(0, 4) + "%");
            List <string> entitiesNames = new List <string>();
            var           entities      = res.GetAllEntities();

            foreach (Entity entity in entities)
            {
                entitiesNames.Add(entity.Name);
                ((MainWindow)Application.Current.MainWindow)._scenariosControl.LogLuis(", " + entity.Name + ": " + entity.Value);
                entityValue = entity.Value;
            }
            ((MainWindow)Application.Current.MainWindow)._scenariosControl.LogLuis("\n");
            switch (res.TopScoringIntent.Name)
            {
            case "New Quote":
                if (entityValue.ToLower().Contains("car"))
                {
                    OpenUri("https://www.suncorp.com.au/insurance/car.html");
                }
                else if (entityValue.ToLower().Contains("house"))
                {
                    OpenUri("https://www.suncorp.com.au/insurance/home/home-and-contents.html");
                }
                else if (entityValue.ToLower().Contains("insurance"))
                {
                    OpenUri("https://www.suncorp.com.au/insurance/");
                }
                else
                {
                    OpenUri("https://www.suncorp.com.au/insurance/");
                }
                break;

            case "New Complaint":
                OpenUri("https://www.suncorp.com.au/insurance/contact-us.html#write");
                break;

            case "New Incident":
                OpenUri("https://www.suncorp.com.au/insurance/claims.html#car-insurance");
                break;

            case "Update Contact Details":
                OpenUri("https://insurance.suncorp.com.au/usermgmt/public/suncorp/login.jsp?contextType=external&username=string&contextValue=%2Foam&password=sercure_string&challenge_url=https%3A%2F%2Finsurance.suncorp.com.au%2Fusermgmt%2Fpublic%2Fsuncorp%2Flogin.jsp&request_id=-414593964383372649&authn_try_count=0&locale=en_US&resource_url=http%253A%252F%252Finsurance.suncorp.com.au%252Fpss");
                break;

            default:
                break;
            }
        }
Ejemplo n.º 10
0
        public RobotBehavior(LuisResult luisResult, List <SynAppsIntentModel> synappsIntents, Dictionary <long, List <PredictionIntentModel> > _predictions = null, Dictionary <string, List <PredictionEntityModel> > _predictionEntities = null)
        {
            this.IntentName     = None;
            this.Score          = 0.0;
            this.FreeAction     = ErrorAction;
            this.LinkedEntities = None;
            this.LuisEntities   = new List <string>();
            this.IsContinues    = false;
            if (luisResult != null && luisResult.TopScoringIntent != null)
            {
                this.ExampleText = luisResult.OriginalQuery;
                this.IntentName  = luisResult.TopScoringIntent.Name;
                this.Score       = luisResult.TopScoringIntent.Score;
                var entities     = luisResult.GetAllEntities();
                var entityValues = entities.Select(entity => ToNarrow(Regex.Replace(Regex.Replace(entity.Value, " ", "", RegexOptions.Singleline), " ", "", RegexOptions.Singleline)));
                this.LuisEntities = entityValues.ToList();
                var targetsWithEntities = synappsIntents.Where(intent =>
                                                               intent.Name == this.IntentName &&
                                                               entityValues.Any(Regex.Replace(ToNarrow(intent.Entity.ToLower()), " ", "", RegexOptions.Singleline).Split(',').Contains)
                                                               ).ToList();
                targetsWithEntities = targetsWithEntities.OrderByDescending(intent =>
                                                                            entityValues.Count(intent.Entity.Split(',').Contains)
                                                                            ).ThenBy(intent =>
                                                                                     intent.Entity.Split(',').Count()
                                                                                     ).ToList();

                var resultWithEntities = getLinkedAction(targetsWithEntities, entities);
                if (resultWithEntities.Status == Status.Success)
                {
                    this.FreeAction     = resultWithEntities.FreeAction;
                    this.LinkedEntities = resultWithEntities.LinkedEntities;
                }
                else
                {
                    var targets = synappsIntents.Where(intent =>
                                                       intent.Name == this.IntentName &&
                                                       intent.Entity == ""
                                                       ).ToList();
                    var result = getLinkedAction(targets, entities);
                    if (result.Status == Status.Success)
                    {
                        this.FreeAction     = result.FreeAction;
                        this.LinkedEntities = result.LinkedEntities;
                    }
                    else
                    {
                        var preview = new PreviewLabeledExampleDto();
                        preview.IntentLabel = this.IntentName;
                        var entityLabels = new List <PredictionEntityDto>();
                        foreach (var e in entities)
                        {
                            var entityLabel = new PredictionEntityDto();
                            entityLabel.EntityName  = e.Name;
                            entityLabel.EntityValue = e.Value;

                            entityLabels.Add(entityLabel);
                        }
                        preview.EntityLabels = entityLabels;

                        this.FreeAction     = Predictions(preview, _predictions, _predictionEntities, targetsWithEntities) ?? this.FreeAction;
                        this.LinkedEntities = result.LinkedEntities;
                    }
                }

                string talk = "";
                this.IsContinues = (bool)(this.FreeAction["IsContinuance"] ?? false);
                if (this.IsContinues)
                {
                    talk = (this.FreeAction["Talk1"] ?? "").ToString();
                }
                else
                {
                    talk = (this.FreeAction["Talk"] ?? "").ToString();
                }
                if (talk != "")
                {
                    talk = Regex.Replace(talk, "\\\\rspd=.+?\\\\", "", RegexOptions.Singleline);
                    talk = Regex.Replace(talk, "\\\\vct=.+?\\\\", "", RegexOptions.Singleline);
                    this.NaturalTalkText = talk.Trim();
                }
            }
        }
Ejemplo n.º 11
0
        public async Task <bool> WikipediaLookup(LuisResult result, object context, object speak)
        {
            string s;
            var    speech = (App.SpeechFunc)speak;

            //get the entities from the result
            List <Microsoft.Cognitive.LUIS.Entity> entities = result.GetAllEntities();

            if (entities.Count > 0)
            {
                s = "I'll lookup " + entities[0].Value;
            }
            else
            {
                s = "looking it up";
            }

            speech(s);

            string query = result.OriginalQuery;

            // See if we can work out the look up topic from the query parameters
            query = query.Replace("lookup", "");
            query = query.Replace("look up", "");
            query = query.TrimStart(' ');
            System.Diagnostics.Debug.WriteLine(query);

            HttpClient client = new HttpClient();

            //query = UppercaseWords(query);

            string urie = WebUtility.UrlEncode(query);


            //string uri = "https://en.wikipedia.org/w/api.php?action=query&titles=" + urie + "&prop=revisions&rvprop=content&format=json";
            string uri = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=" + urie;

            HttpResponseMessage ressp = await client.GetAsync(new Uri(uri, UriKind.Absolute));

            string res = await ressp.Content.ReadAsStringAsync();

            int start = 0;
            int end   = 0;

            start = res.IndexOf("missing");
            if (start > 0)
            {
                speech("Topic not found");
                return(false);
            }

            start = res.IndexOf("extract");
            if (start > 0)
            {
                end = res.IndexOf("}}}}");
            }
            else
            {
                speech("Topic not found");
                return(false);
            }

            start = start + 10;
            string basic = res.Substring(start);// 10 = extract":"

            basic = basic.Replace("'", "");
            basic = basic.Replace("[", "");
            basic = basic.Replace("]", "");
            basic = basic.Replace("\n", "");
            basic = basic.Replace(".", " ");
            basic = basic.Replace("}", "");
            basic = basic.Replace("\\", "");
            speech(basic);

            return(true);
        }
Ejemplo n.º 12
0
        public static async System.Threading.Tasks.Task RunAsync([TimerTrigger("* */1 * * * *")] TimerInfo myTimer,
                                                                 TraceWriter log)
        {
            IList <IntentItem> items = null;

            try
            {
                // Retrieve all non processed items
                items = await intentTable.Where(i => i.IsProcessed == false).ToListAsync();
            }
            catch (Exception ex)
            {
                log.Error($"Error while Retrieving all IntentItems : {ex}");
                throw ex;
            }

            log.Info($"Total items to process = {items.Count}");

            foreach (var item in items)
            {
                var intentId = item.Id;

                log.Info($"C# Processing Intent ID : {intentId}");

                // Erro handling
                if (item == null)
                {
                    log.Info($"No itent item retrieved (null) - {intentId}");
                    return;
                }

                // Ensure item require procesing otherwise skip it
                if (item.IsProcessed == true)
                {
                    log.Info($" ItemItemd with if {intentId} has already been processed {item.IsProcessed} - will be skipped");
                    return;
                }

                // Calling Luis
                var  appId           = Environment.GetEnvironmentVariable("LuisAppId");
                var  subscriptionKey = Environment.GetEnvironmentVariable("LuisSubscriptionKey");
                bool isPreview       = true;

                var        client = new LuisClient(appId, subscriptionKey, isPreview);
                LuisResult res    = await client.Predict(item.Utterance);

                log.Info($"Luis result : {res.DialogResponse}");
                var processingResult = new ProcessingResult();

                List <string> entitiesNames = new List <string>();
                var           entities      = res.GetAllEntities();
                foreach (Entity entity in entities)
                {
                    processingResult.Entities.Add(entity.Name, entity.Value);
                }

                processingResult.Confidence  = res.TopScoringIntent.Score;
                processingResult.Intent      = res.TopScoringIntent.Name;
                processingResult.IsFromCache = false;

                item.Intent       = processingResult.Intent;
                item.JsonEntities = JsonConvert.SerializeObject(processingResult.Entities);
                item.IsProcessed  = true;

                await intentTable.UpdateAsync(item);
            }
        }
        public static void OpenIncidentActivity(LuisResult result, object context)
        {
            List <Entity> entitis = result.GetAllEntities();

            Aggregator.GetEvent <UIOperationEvent>().Publish(new KeyValuePair <string, List <Entity> >(Constant.IncidentScreenUrl, entitis));
        }