代码之家  ›  专栏  ›  技术社区  ›  Kunal Mukherjee

LUIS buitin datetime。v2实体无法分析值的daterange类型

  •  1
  • Kunal Mukherjee  · 技术社区  · 7 年前

    我使用了预构建的datetime。v2实体来处理LUIS中所有与datetime相关的内容。

    我有这样一句话: March to June 2017

    在实体中,LUIS的预期输出应为:

    "resolution": {
            "values": [
              {
                "timex": "XXXX-03",
                "type": "daterange",
                "start": "2017-03-01",
                "end": "2017-06-01"
              }
            ]
          }
    

    但当我询问路易斯时,我得到的是:

    {
      "query": "march to june 2017",
      "topScoringIntent": {
        "intent": "TestIntent",
        "score": 1.0
      },
      "intents": [
        {
          "intent": "TestIntent",
          "score": 1.0
        },
        {
          "intent": "None",
          "score": 0.05487651
        }
      ],
      "entities": [
        {
          "entity": "march",
          "type": "builtin.datetimeV2.daterange",
          "startIndex": 0,
          "endIndex": 4,
          "resolution": {
            "values": [
              {
                "timex": "XXXX-03",
                "type": "daterange",
                "start": "2017-03-01",
                "end": "2017-04-01"
              },
              {
                "timex": "XXXX-03",
                "type": "daterange",
                "start": "2018-03-01",
                "end": "2018-04-01"
              }
            ]
          }
        },
        {
          "entity": "june 2017",
          "type": "builtin.datetimeV2.daterange",
          "startIndex": 9,
          "endIndex": 17,
          "resolution": {
            "values": [
              {
                "timex": "2017-06",
                "type": "daterange",
                "start": "2017-06-01",
                "end": "2017-07-01"
              }
            ]
          }
        }
      ]
    }
    

    我编写了以下C#代码,用于查询LUIS intent中的日期范围

            [LuisIntent("TestIntent")]
            public async Task TestIntentHandler(IDialogContext context, LuisResult result)
            {
                EntityRecommendation dateTimeEntity, dateRangeEntity;
                if(result.TryFindEntity("builtin.datetimeV2.date", out dateTimeEntity))
                {
                   var s = dateTimeEntity.Resolution.Values.Select(x => x).OfType<List<object>>().SelectMany(i => i).ToList();
                }
                if(result.TryFindEntity("builtin.datetimeV2.daterange", out dateRangeEntity))
                {
                    var s = dateRangeEntity.Resolution.Values.Select(x => x).OfType<List<object>>().SelectMany(i => i).FirstOrDefault();
                    var type = s.GetType();
                }
            }
    

    有谁能告诉我如何使用预先构建的日期时间来查询LUIS中的上述月份范围吗。v2实体类型。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Fei Han    7 年前

    我可以从我的角度重复这个问题,但在我看来,3月(3月1日至3月31日)是日期范围,6月(6月1日至6月30日)是日期范围,这很容易被认为是两个日期范围(就像路易斯那样)。在里面 this article ,它为我们提供了一个日期范围示例 ,如果可能,请指定开始月份和结束月份的日期,例如 2017年3月1日至6月1日 .

    enter image description here

    此外,我查了 TryFindEntity ,我发现它分配了 无效的 第一个默认值 实体收件人 EntityRecommendation entity dateRangeEntity 将是第一个实体,即使LUIS返回两个实体( 前进 2017年6月 ). 如果要在查询时提取两个实体 march to june 2017 ,请操作 LuisResult result 直接,不打电话 尝试一致性 方法

    的源代码 尝试一致性 :

    // Microsoft.Bot.Builder.Luis.Extensions
    public static bool TryFindEntity(this LuisResult result, string type, out EntityRecommendation entity)
    {
        IList<EntityRecommendation> expr_14 = result.Entities;
        entity = ((expr_14 != null) ? expr_14.FirstOrDefault((EntityRecommendation e) => e.Type == type) : null);
        return entity != null;
    }