代码之家  ›  专栏  ›  技术社区  ›  Jason Evans

formflow bot与枚举应答位置与应答文本混淆

  •  3
  • Jason Evans  · 技术社区  · 6 年前

    我有一个formflow对话框,它将以下问题定义为枚举

    public enum PreviousOwnerOptions
    {
        [Describe("Owned from new")]
        [Terms("0", "new", ".*[O|o]wned from new")]
        OwnedFromNew = 0,
    
        [Terms("1", "One")]
        One,
    
        [Terms("2", "Two")]
        Two,
    
        [Terms("3", "Three")]
        Three,
    
        [Terms("4", "Four")]
        Four,
    
        [Terms("5", "Five")]
        Five,
    
        [Terms("6", "Six")]
        Six,
    
        [Describe("More than six")]
        [Terms(".*More than six", "more")]
        MoreThanSix
    }
    

    下面是这个问题在用户看来是如何…

    enter image description here

    我的问题是,如果你输入数字“3”作为答案,那么答案就是…

    enter image description here

    看起来机器人不确定我的意思是位置3的答案,还是“三”。我以为 Terms 属性会处理这个澄清吗?

    我该怎么办?

    1 回复  |  直到 6 年前
        1
  •  11
  •   Zeryth    6 年前

    这是因为两件事的结合。

    首先,您尝试在看似不可为空的字段上使用0枚举值。在这种情况下,0值保留为空。从 formflow docs page 以下内容:

    任何数据类型都可以为空,您可以使用它来建模字段没有值。如果表单字段基于不可为空的枚举属性,则枚举中的值0表示空(即,表示该字段没有值),您应该从1开始枚举值。formflow忽略所有其他属性类型和方法。

    第二点是,由于在terms属性中使用的是1、2、3等数值,例如 [Terms("1", "One")] 默认情况下,formflow将尝试将这些值与正确的枚举对齐。所以我认为发生的是,它让你选择“3”,就像你在例子中使用的那样,因为3是你的术语之一 [Terms("3", "Three")] 它为你提供了选择。但是在0索引枚举值中,因为0是保留的,所以 [Terms("2", "Two")] Two, 是3。所以它不知道你的意思。

    因此,为了让这些术语起作用,应该如下所示:

        public enum PreviousOwnerOptions
        {
            [Terms("1", "One")]
            One=1,
    
            [Terms("2", "Two")]
            Two,
    
            [Terms("3", "Three")]
            Three,
    
            [Terms("4", "Four")]
            Four,
    
            [Terms("5", "Five")]
            Five,
    
            [Terms("6", "Six")]
            Six,
    
            [Describe("More than six")]
            [Terms(".*More than six", "more")]
            MoreThanSix,
    
            [Describe("Owned from new")]
            [Terms("new", ".*[O|o]wned from new")]
            OwnedFromNew
        }