【问题标题】:How to add Bing Spellcheck to LuisRecognizerMiddleware?如何将 Bing 拼写检查添加到 LuisRecognizer 中间件?
【发布时间】:2018-05-13 07:45:12
【问题描述】:

好的,这就是我的 LUIS 应用在我的机器人中的配置方式。
在 LUIS 网站上,我可以添加 Bing Spell Check 以纠正常见的拼写错误,并更好地匹配 intententity

只需将 BING API 密钥添加到 LUIS 查询字符串。但是我在LuisRecognizerMiddleware 的哪里配置呢?

我什至不确定这是否是正确的地方。但我想它确实将 URI 放在了一起。

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.AddBot<MyBot>(options =>
    {
        options.CredentialProvider = new ConfigurationCredentialProvider(_configuration);

        options.Middleware.Add(new CatchExceptionMiddleware<Exception>(async (context, exception) =>
        {
            await context.TraceActivity("MyBotException", exception);
            await context.SendActivity("Sorry, it looks like something went wrong!");
        }));

        IStorage dataStore = new MemoryStorage();

        options.Middleware.Add(new ConversationState<MyBotConversationState>(dataStore));

        // Add LUIS recognizer as middleware
        // see https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-v4-luis?view=azure-bot-service-4.0&tabs=cs
        (string modelId, string subscriptionKey, Uri url) = GetLuisConfiguration(_configuration);
        LuisModel luisModel = new LuisModel(modelId, subscriptionKey, url);
        options.Middleware.Add(new LuisRecognizerMiddleware(luisModel));
    });
}

private static (string modelId, string subscriptionKey, Uri url) GetLuisConfiguration(IConfiguration configuration)
{
    string modelId = configuration.GetSection("Luis-ModelId")?.Value;
    string subscriptionKey = configuration.GetSection("Luis-SubscriptionId")?.Value;
    string url = configuration.GetSection("Luis-Url")?.Value;
    Uri baseUri = new Uri(url);

    return (modelId, subscriptionKey, baseUri);
}

到目前为止我得到的只是......

GET https://westeurope.api.cognitive.microsoft.com/luis/v2.0/apps/?subscription-key=&q=test234&log=True HTTP/1.1

我所期望的是其中的一些内容(从 LUIS 门户网站复制)

GET https://westeurope.api.cognitive.microsoft.com/luis/v2.0/apps/?subscription-key=&spellCheck=true&bing-spell-check-subscription-key=&verbose=true&timezoneOffset=0&q=test234

【问题讨论】:

    标签: c# botframework azure-language-understanding bing-api


    【解决方案1】:

    我刚刚快速浏览了源代码,并认为 ILuisOptions 是我正在寻找的。对此没有具体的实施。我猜这是“自己动手”...

    public class MyLuisOptions : ILuisOptions
    {
        public bool? Log { get; set; }
        public bool? SpellCheck { get; set; }
        public bool? Staging { get; set; }
        public double? TimezoneOffset { get; set; }
        public bool? Verbose { get; set; }
        public string BingSpellCheckSubscriptionKey { get; set; }
    }
    

    ...当然,您必须将其传递给 LuisRecognizerMiddleware。

    options.Middleware.Add(new LuisRecognizerMiddleware(luisModel, new LuisRecognizerOptions { Verbose = true }, new MyLuisOptions { SpellCheck = true, BingSpellCheckSubscriptionKey = "test123" }));
    

    【讨论】:

    • 您是否让这个工作除了您的初始代码(显示在您的问题中)或代替您在原始问题中的努力?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-04
    • 2010-12-28
    • 1970-01-01
    • 2011-05-23
    • 2011-08-08
    • 2013-04-21
    相关资源
    最近更新 更多