stevie
Posts: 21
Joined: Sun Feb 25, 2018 5:59 pm

Re: Using SQL Server connection in Oscova dialog

Sat Mar 17, 2018 1:35 pm

Finally below is working for me. Is it the right way of usage? Does it make any performance issue for large database?


CSharp Code


  public static void LaunchOscovaBot()
        {
            var websiteUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
            var oscovaBot = new OscovaBot();
            string constr = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;

            oscovaBot.Dialogs.Add(new MyTestDialog());
            oscovaBot.CreateRecognizer("start", new Regex(@"(?<!/)(/(?:start))(?(?<=\w)\b)", RegexOptions.IgnoreCase));


//BELOW IS MY THREE DB COLUMNS
           var NameParser = oscovaBot.CreateRecognizer("Name");
            var DeptParser = oscovaBot.CreateRecognizer("Dept");
            var TitleParser = oscovaBot.CreateRecognizer("Title");
            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand("SELECT Name,Dept,Title FROM [Employees].[dbo].[tbl_Employees]", con))
                {
                    con.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            NameParser.Entries.Add(reader["Name"].ToString());
                            DeptParser.Entries.Add(reader["Dept"].ToString());
                            TitleParser.Entries.Add(reader["Title"].ToString());

                        }

                        reader.Close();

                    }
                }
            }



 oscovaBot.Trainer.StartTraining();

            _oscovaBotChannel = new WidgetChannel<OscovaBot>(oscovaBot)
            {
                ServiceUrl = websiteUrl + "/BotService.aspx",
                ResourceUrl = websiteUrl + "/BotResource",
            };


}

}



CSharp Code



         [Expression("Find emp @Name in @Dept who is @Title")]
        public void FindEmployee(Context context, Result result)
        {
           
           var empname = result.Entities.OfType("Name");
          var dept = result.Entities.OfType("Dept");
           var title = result.Entities.OfType("Title");
         //.................

         }


User avatar
Sreejith
Help & Support
Posts: 20
Joined: Sat Apr 06, 2013 6:16 pm

Re: Using SQL Server connection in Oscova dialog

Mon Mar 19, 2018 2:57 am

loading thousands of entries to recognizers is ok...but if you want to save memory then u can parse entry one by one from database...you must first check which method is faster for u...line 78 here shows how to parse entity entry manually.
If your experiment needs statistics, you ought to have done a better experiment - Ernest Rutherford

stevie
Posts: 21
Joined: Sun Feb 25, 2018 5:59 pm

Re: Using SQL Server connection in Oscova dialog

Tue Mar 20, 2018 10:04 am

So just for clarification, If i have 10 fields from database , do i need to create 10 recognizer like below?

CSharp Code


//NAME
 private void CreateNameParser()
        {
            Bot.CreateRecognizer("Name", request =>
            {
            }
         }

//DEPARTMENT
 private void CreateDeptParser()
        {
            Bot.CreateRecognizer("Department", request =>
            {
            }
         }

//PHONE
 private void CreatePhoneParser()
        {
            Bot.CreateRecognizer("Phone", request =>
            {
            }
         }

.................


User avatar
Sreejith
Help & Support
Posts: 20
Joined: Sat Apr 06, 2013 6:16 pm

Re: Using SQL Server connection in Oscova dialog

Tue Mar 20, 2018 12:44 pm

yes stevie...you must create recognizers for known fields for better recognition...if the field has 100s of values then you can just store them in entry recognizers....if it has 1000s of values then you can create recognizers just like in your code.
If your experiment needs statistics, you ought to have done a better experiment - Ernest Rutherford

stevie
Posts: 21
Joined: Sun Feb 25, 2018 5:59 pm

Re: Using SQL Server connection in Oscova dialog

Tue Mar 20, 2018 3:00 pm

Thanks Sreejith for your support.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest