與微軟的Luis + bot框架一起玩,我的「這會讓一個好的類型提供者」感覺開始刺痛。不幸的是,類型提供者不能輸出歧視聯盟。我希望做一些像下面,但它是不可能的:爲Microsoft的Luis編寫F#Type Provider有什麼好方法?
type Luis = LuisProvider<@"LuisId",@"LuisPasskey">
let IntentMatcher Intent =
match intent with
| Luis.Intents.Greeting -> GreetingHandler()
| Luis.Intents.SetAlarm title startDate startTime -> AlarmHandler title startDate startTime
| _ -> CouldNotUnderstand()
的路易斯意圖及其參數都可以通過API使他們極大的候選人typeProviderization
僅供參考這裏是一個從一個例子C#機器人處理器(我想這可能是更清潔,更型F#安全):
public const string Entity_Alarm_Title = "builtin.alarm.title";
public const string Entity_Alarm_Start_Time = "builtin.alarm.start_time";
public const string Entity_Alarm_Start_Date = "builtin.alarm.start_date";
public const string DefaultAlarmWhat = "default";
[LuisIntent("builtin.intent.alarm.set_alarm")]
public async Task SetAlarm(IDialogContext context, LuisResult result)
{
EntityRecommendation title;
if (!result.TryFindEntity(Entity_Alarm_Title, out title))
{
title = new EntityRecommendation(type: Entity_Alarm_Title) { Entity = DefaultAlarmWhat };
}
EntityRecommendation date;
if (!result.TryFindEntity(Entity_Alarm_Start_Date, out date))
{
date = new EntityRecommendation(type: Entity_Alarm_Start_Date) { Entity = string.Empty };
}
EntityRecommendation time;
if (!result.TryFindEntity(Entity_Alarm_Start_Time, out time))
{
time = new EntityRecommendation(type: Entity_Alarm_Start_Time) { Entity = string.Empty };
}
var parser = new Chronic.Parser();
var span = parser.Parse(date.Entity + " " + time.Entity);
if (span != null)
{
var when = span.Start ?? span.End;
var alarm = new Alarm() { What = title.Entity, When = when.Value };
this.alarmByWhat[alarm.What] = alarm;
string reply = $"alarm {alarm} created";
await context.PostAsync(reply);
}
else
{
await context.PostAsync("could not find time for alarm");
}
context.Wait(MessageReceived);
}
但無論如何,問題是:有沒有人有更多經驗的建築類型供應商對我哪有什麼好主意構建一個可讀的dsl,即ac完全可行的構建?
托馬斯你是明星!後者的兩個看起來很完美:) –