智能对话机器人,需要对话时,需要判断条件,dialog ,节点的控制也是通过逻辑判断进入;
Condition表达式 只要符合 逻辑判断就是合法的输入
先介绍特殊的几个表达式
anything_else | 可以在对话框末尾使用此条件,当用户输入不匹配任何其他对话节点时进行处理。任何其他节点都是由这个 条件触发的 |
conversation_start | 像欢迎一样,这个条件在第一次对话回合中被评估为真。与欢迎不同,无论来自应用程序的初始请求是否包含用户输入,都是正确的。具有会话起始条件的节点可用于初始化上下文变量或在对话开始时执行其他任务 |
false | 此条件总是被评估为false。您可以在正在开发的分支开始时使用它,以防止它被使用,或者作为提供公共函数的节点的条件,并且仅用作跳转到动作的目标。 |
irrelevant | 当用户的输入文本watson认为不相干的内容时,这个条件会被识别为true;也就是没法识别进入任何一个预期节点 |
true | 总是识别为真 |
welcome | 只有当来自应用程序的初始请求不包含任何用户输入时,在第一个对话回合(当对话开始时),该条件才被计算为真。在随后的所有对话回合中,它被评估为假。此条件触发欢迎节点。通常,使用这种条件的节点来问候用户 |
condition 作文条件输入 ;可以在表达式中引用 entity,intent,context variables
格式: #应用意图。@ 应用实体 ,$引用上下文
1、单纯匹配 直接使用 意图和实体,上下文 #intent。@entity ,$context
#hello,@name $key ,not($key),$key=="yes"等 $variable_name:value
or $variable_name == 'value' 同一种比表达
2、 比表达式
a、上下文表达,其中表达
短表达式 完整表达式
$card_type context['card_type']
$(card-type) context['card-type']
$card_type:VISA context['card_type'] == 'VISA'
$card_type:(MASTER CARD) context['card_type'] == 'MASTER CARD'
实体表达
短表达式 完整表达式
@year entities['year']?.value
@year == 2016 entities['year']?.value == 2016
@year != 2016 entities['year']?.value != 2016
@city == 'Boston' entities['city']?.value == 'Boston'
@city:Boston entities['city']?.contains('Boston')
@city:(New York) entities['city']?.contains('New York')
注意:如果实体带有 括号的"()" 必须是完整表达式 如 @city == 'Dublin (Ohio)' instead of @city:(Dublin (Ohio))
意图表达
段表达 长表达
#help intent == 'help'
! #help intent != 'help'
NOT #help intent != 'help'
#help or #i_am_lost (intent == 'help' || intent == 'I_am_lost')
实体操作
访问实体
<? intents ?>
当识别到是时间实体,则响应结果里包含两个实体
[
{"entity":"sys-date","location":[6,9],"value":"2017-08-07",
"confidence":1,"metadata":{"calendar_type":"GREGORIAN",
"timezone":"America/New_York"}},
{"entity":"sys-time","location":[6,9],"value":"15:01:00",
"confidence":1,"metadata":{"calendar_type":"GREGORIAN",
"timezone":"America/New_York"}}
]
捕获组的模式实体,那么您可以检查某个组值匹配
@us_phone.groups[1] == '617'
匹配表达式 \b((958)|(555))-(\d{3})-(\d{4})\b
输入 958-234-3456 (@phone_number )
Group number | Regex engine value | Dialog value | Explanation |
groups[0] | 958-234-3456 | 958-234-3456 | The first group is always the full matching string |
groups[1] | ((958)l(555)) | 958 | String that matches the regex for the first defined group, which is ((958)l(555)). |
groups[2] | (958) | 958 | Match against the group that is included as the first operand in the OR expression ((958)l(555)) |
groups[3] | (555) | null | No match against the group that is included as the second operand in the OR expression ((958)l(555)) |
groups[4] | (\d{3}) | 234 | String that matches the regular expression that is defined for the group. |
groups[5] | (\d{4}) | 3456 | String that matches the regular expression that is defined for the group. |
匹配输入
当输入 I want to go from Toronto to Boston.
entities['city']?.contains('Boston') 返回 true
entities.city[0].value = 'Toronto' 返回 true
entities.city[1].value = 'Boston' 返回 true
condition | 表示服务对已识别实体的信任的十进制百分比。除非激活了实体的模糊匹配,否则实体的置信度为0或1。当启用模糊匹配时,默认置信水平阈值为0.3。无论是否启用模糊匹配,系统实体总是具有1的置信水平。 如果条件不高于指定的百分之一,则可以在条件下使用此属性使其返回false |
location | 基于零的字符偏移,指示检测到的实体值在输入文本中开始和结束的位置。 使用 .literal 来提取存储在location属性中的开始索引和结束索引值之间的文本跨度。 |
value | 输入中标识的实体值。 此属性返回在训练数据中定义的实体值,即使匹配是针对其关联的同义词之一进行的。您可以使用.values 来捕获可能出现在用户输入中的多个实体的出现。 |
实例
前置条件 实体中包含 JFK 与 Kennedy Airport 为同义词
输入 I want to go to Kennedy Aiport
则响应的条件 为 entities.airport[0].value == 'JFK' or @airport = "JFK" or @airport
响应表达式 So you want to go to <?entities.airport[0].literal?>... or So you want to go to @airport.literal
返回响应 So you want to go to Kennedy Airport...
启用模糊匹配 @实体.confidence
@airport && @airport.confidence > 0.
用户输入中捕获多个实体类型的出现 上下文"airports":"@airport.values"
表达式 You asked about these airports: <? $airports.join(', ') ?>
You asked about these airports: JFK, Logan, O'Hare.
意图操作
意图逻辑表达 intents[0] == 'Help' , intent == 'Help'
intent == 'help' 与 intents[0] == 'help' 是不同的 ,在意图没有识别到的情况下 intent == 'help' 不会报异常
intents[0] 会报空异常 ,如果要使用,可以先判断 intents.size() > 0 && intents[0] == 'help' && intents[0].confidence > 0.1
intents.size() > 0 && intents[0] == 'help' && intents[0].confidence > 0.1
其中confidenc为匹配的阈值,0-1之间
intents[0].intent.startsWith("User_")
,也已直接进行字符操作
输入的文本 操作 可以通过 input.text 表达式获得输入文本
栗子:
input.text.contains( 'Yes' )
input.text.matches( '[0-9]+' )
input.text.length() == 10
上下文操作;
上下文操作涉及较多表达式与栗子,转
https://blog.csdn.net/a1055186977/article/details/80338810