This repository was archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathFlightBooking.cs
More file actions
120 lines (108 loc) · 3.45 KB
/
Copy pathFlightBooking.cs
File metadata and controls
120 lines (108 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// <auto-generated>
// Code generated by luis:generate:cs
// Tool github: https://github.com/microsoft/botframwork-cli
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.AI.Luis;
namespace Luis
{
public partial class FlightBooking: IRecognizerConvert
{
[JsonProperty("text")]
public string Text;
[JsonProperty("alteredText")]
public string AlteredText;
public enum Intent {
BookFlight,
Cancel,
GetWeather,
None
};
[JsonProperty("intents")]
public Dictionary<Intent, IntentScore> Intents;
public class _Entities
{
// Built-in entities
public DateTimeSpec[] datetime;
// Lists
public string[][] Airport;
// Composites
public class _InstanceFrom
{
public InstanceData[] Airport;
}
public class FromClass
{
public string[][] Airport;
[JsonProperty("$instance")]
public _InstanceFrom _instance;
}
public FromClass[] From;
public class _InstanceTo
{
public InstanceData[] Airport;
}
public class ToClass
{
public string[][] Airport;
[JsonProperty("$instance")]
public _InstanceTo _instance;
}
public ToClass[] To;
// Instance
public class _Instance
{
public InstanceData[] Airport;
public InstanceData[] From;
public InstanceData[] To;
public InstanceData[] datetime;
}
[JsonProperty("$instance")]
public _Instance _instance;
}
[JsonProperty("entities")]
public _Entities Entities;
[JsonExtensionData(ReadData = true, WriteData = true)]
public IDictionary<string, object> Properties {get; set; }
public void Convert(dynamic result)
{
var app = JsonConvert.DeserializeObject<FlightBooking>(
JsonConvert.SerializeObject(
result,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Error = OnError }
)
);
Text = app.Text;
AlteredText = app.AlteredText;
Intents = app.Intents;
Entities = app.Entities;
Properties = app.Properties;
}
private static void OnError(object sender, ErrorEventArgs args)
{
// If needed, put your custom error logic here
Console.WriteLine(args.ErrorContext.Error.Message);
args.ErrorContext.Handled = true;
}
public (Intent intent, double score) TopIntent()
{
Intent maxIntent = Intent.None;
var max = 0.0;
foreach (var entry in Intents)
{
if (entry.Value.Score > max)
{
maxIntent = entry.Key;
max = entry.Value.Score.Value;
}
}
return (maxIntent, max);
}
}
}