Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Serializable]
- public class BasicLuisDialog : LuisDialog<object>
- {
- public BasicLuisDialog() : base(new LuisService(new LuisModelAttribute(
- ConfigurationManager.AppSettings["LuisAppId"],
- ConfigurationManager.AppSettings["LuisAPIKey"],
- domain: ConfigurationManager.AppSettings["LuisAPIHostName"])))
- {
- }
- //Constants
- // Intents
- public const string IntentContractualPower = "SearchContractualPower";
- public const string IntentNone = "None";
- // Entities
- public const string EntityEAN = "EAN";
- public const string EntityBeginDate = "BeginDate";
- // Entities found in result
- public string BotEntityRecognition(LuisResult result)
- {
- StringBuilder entityResults = new StringBuilder();
- if (result.Entities.Count > 0)
- {
- foreach (EntityRecommendation item in result.Entities)
- {
- entityResults.Append(item.Type + "=" + item.Entity + ",");
- }
- // remove last comma
- entityResults.Remove(entityResults.Length - 1, 1);
- }
- return entityResults.ToString();
- }
- [LuisIntent("SearchContractualPower")]
- public async Task ContractualPowerIntent(IDialogContext context, LuisResult result)
- {
- await ContractualPower(context, result);
- }
- private Task ContractualPower(IDialogContext context, LuisResult result)
- {
- throw new NotImplementedException();
- }
- private void ContractualPower(object sender, EventArgs e)
- {
- try
- {
- SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
- builder.DataSource = "X";
- builder.UserID = "X";
- builder.Password = "X";
- builder.InitialCatalog = "ChatBot_EDWErrors";
- using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
- {
- connection.Open();
- StringBuilder sb = new StringBuilder();
- sb.Append("SELECT ErrorDescription FROM [err].[ErrorFactContractualPower]");
- sb.Append(" WHERE EAN = ");
- sb.Append(EntityEAN);
- sb.Append(" AND BeginDate = ");
- sb.Append(EntityEAN);
- String sql = sb.ToString();
- using (SqlCommand command = new SqlCommand(sql, connection))
- {
- using (SqlDataReader reader = command.ExecuteReader())
- {
- while (reader.Read())
- {
- Console.WriteLine("{0}", reader.GetString(0));
- }
- }
- }
- }
- }
- catch (SqlException exception)
- {
- Console.WriteLine(exception.ToString());
- }
- Console.ReadLine();
- }
- [LuisIntent("None")]
- public async Task NoneIntent(IDialogContext context, LuisResult result)
- {
- await this.ShowLuisResult(context, result);
- }
- private async Task ShowLuisResult(IDialogContext context, LuisResult result)
- {
- // get recognized entities
- string entities = this.BotEntityRecognition(result);
- // round number
- string roundedScore = result.Intents[0].Score != null ? (Math.Round(result.Intents[0].Score.Value, 2).ToString()) : "0";
- await context.PostAsync($"**Query**: {result.Query}, **Intent**: {result.Intents[0].Intent}, **Score**: {roundedScore}. **Entities**: {entities}");
- context.Wait(MessageReceived);
- }
- }
Add Comment
Please, Sign In to add comment