在Watson对话框中使用实体类型进行配置文件变量

时间:2016-03-29 15:02:05

标签: ibm-watson watson-dialog

我注意到我们可以使用Watson EntityType从用户输入中提取time reference,例如:

<folder label="Invite Time">
                <output id="output_invite_time">
                    <prompt>
                        <item>What time is your meeting?</item>
                    </prompt>
                    <getUserInput>
                        <input>
                            <grammar>
                                <item>$ (DATE_TIME_RANGE)={var-invite_time}</item>
                            </grammar>
                            <action varName="var-invite_time" operator="SET_TO">{var-invite_time.value:FROM_TIME}</action>
                            <goto ref="output_invite_date"/>
                        </input>
                        <output>
                            <prompt>
                                <item>I'll need a valid time to continue.</item>
                            </prompt>
                            <goto ref="output_invite_time"/>
                        </output>
                    </getUserInput>
                </output>
            </folder>

我试图弄清楚如何使用其他(支持的?)EntityTypes,例如Generic,Location,Amount等。但结果有时会出乎意料。例如&#34;在科罗拉多州丹佛的好房子&#34; for Location实体结果为&#34; nice&#34 ;;或指定&#34;昨天&#34;日期导致日期不正确。

我的简化对话框文件如下:

&#13;
&#13;
<?xml version="1.0" encoding="UTF-8"?>
<dialog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="WatsonDialogDocument_1.0.xsd">
    <flow>
        <folder label="Main" id="Main">
            <output id="start">
                <prompt selectionType="RANDOM">
                    <item>DIALOG START - asking for user input</item>
                </prompt>
                <goto ref="processUserInput_start"/>
            </output>
            <getUserInput id="processUserInput_start">
                <search ref="library_supported-intents"/>
                <default>
                    <output>
                        <prompt selectionType="RANDOM">
                            <item>I am sorry, I did not understand your intents. Please choose intent1.</item>
                        </prompt>
                    </output>
                </default>
            </getUserInput>
        </folder>
        <folder label="Library" id="Library">
            <folder label="Main Input" id="library_supported-intents">
                <input>
                    <grammar>
                        <item>intent1</item>
                    </grammar>
                    <output>
                        <prompt selectionType="RANDOM">
                            <item>OK. Executing intent 1</item>
                        </prompt>
                        <goto ref="intent1-detail-generic"/>
                    </output>
                </input>
            </folder>
            <folder label="Intent 1 Input Generic" id="library_intent1-generic">
                <output id="intent1-detail-generic">
                    <prompt>
                        <item>Please specify generic</item>
                    </prompt>
                    <getUserInput>
                        <search ref="library_supported-intents"/>
                        <input>
                            <grammar>
                                <item>$ (ZIPCODE)={var-param_generic}</item>
                            </grammar>
                            <action varName="var-param_generic" operator="SET_TO">{var-param_generic.value:main}</action>
                            <goto ref="intent1-detail-location"/>
                        </input>
                        <output>
                            <prompt>
                                <item>I'll need a valid generic to continue.</item>
                            </prompt>
                            <goto ref="intent1-detail-generic"/>
                        </output>
                    </getUserInput>
                </output>
            </folder>
            <folder label="Intent 1 Input Location" id="library_intent1-location">
                <output id="intent1-detail-location">
                    <prompt>
                        <item>Please specify Location</item>
                    </prompt>
                    <getUserInput>
                        <search ref="library_supported-intents"/>
                        <input>
                            <grammar>
                                <item>$ (LOCATION)={var-param_location}</item>
                            </grammar>
                            <action varName="var-param_location" operator="SET_TO">{var-param_location.source}</action>
                            <goto ref="intent1-detail-amount"/>
                        </input>
                        <output>
                            <prompt>
                                <item>I'll need a valid location to continue.</item>
                            </prompt>
                            <goto ref="intent1-detail-location"/>
                        </output>
                    </getUserInput>
                </output>
            </folder>
            <folder label="Intent 1 Input Location" id="library_intent1-amount">
                <output id="intent1-detail-amount">
                    <prompt>
                        <item>Please specify Amount</item>
                    </prompt>
                    <getUserInput>
                        <search ref="library_supported-intents"/>
                        <input>
                            <grammar>
                                <item>$ (AMOUNT)={var-param_amount}</item>
                            </grammar>
                            <action varName="var-param_amount" operator="SET_TO">{var-param_amount.value:main}</action>
                            <goto ref="intent1-detail-time"/>
                        </input>
                        <output>
                            <prompt>
                                <item>I'll need a valid amount to continue.</item>
                            </prompt>
                            <goto ref="intent1-detail-amount"/>
                        </output>
                    </getUserInput>
                </output>
            </folder>
            <folder label="Intent 1 Input Time" id="library_intent1-time">
                <output id="intent1-detail-time">
                    <prompt>
                        <item>Please specify time</item>
                    </prompt>
                    <getUserInput>
                        <search ref="library_supported-intents"/>
                        <input>
                            <grammar>
                                <item>$ (DATE_TIME_RANGE)={var-param_time}</item>
                            </grammar>
                            <action varName="var-param_time" operator="SET_TO">{var-param_time.value:FROM_TIME}</action>
                            <goto ref="intent1-detail-date"/>
                        </input>
                        <output>
                            <prompt>
                                <item>I'll need a valid time to continue.</item>
                            </prompt>
                            <goto ref="intent1-detail-time"/>
                        </output>
                    </getUserInput>
                </output>
            </folder>
            <folder label="Intent 1 Input Date" id="library_intent1-date">
                <output id="intent1-detail-date">
                    <prompt>
                        <item>Please specify date</item>
                    </prompt>
                    <getUserInput>
                        <search ref="library_supported-intents"/>
                        <input>
                            <grammar>
                                <item>$ (DATE_TIME_RANGE)={var-param_date}</item>
                            </grammar>
                            <action varName="var-param_date" operator="SET_TO">{var-param_date.value:FROM_DATE}</action>
                            <output>
                                <prompt>
                                    <item>You've specified {var-param_time} on {var-param_date}.</item>
                                </prompt>
                            </output>
                            <goto ref="processUserInput_start"/>
                        </input>
                        <output>
                            <prompt>
                                <item>I'll need a valid date to continue.</item>
                            </prompt>
                            <goto ref="intent1-detail-date"/>
                        </output>
                    </getUserInput>
                </output>
            </folder>
        </folder>
        <folder label="Concepts" id="Concepts"></folder>
    </flow>
    <entities>
        <entity name="ZIPCODE" entityType="GENERIC">
            <value name="10024" value="10024"/>
            <value name="07928" value="07928"/>
            <value name="95118" value="95118"/>
            <value name="95120" value="95120"/>
            <value name="uszipcode" value="!^[0-9]{5}$"/>
            <entityRules></entityRules>
        </entity>
    </entities>
    <variables>
        <var_folder name="Home">
            <var name="IntentClass" type="TEXT"/>
            <var name="Class1" type="TEXT"/>
            <var name="Class1_Confidence" type="NUMBER" initValue="0" description="Confidence score for Class1 from NL classifier"/>
            <var name="var-param_date" type="TEXT" description="Date object"/>
            <var name="var-param_time" type="TEXT" description="Time object"/>
            <var name="var-param_generic" type="TEXT" description="Generic Object"/>
            <var name="var-param_location" type="TEXT" description="Location Object"/>
            <var name="var-param_amount" type="TEXT" description="Amount Object"/>
        </var_folder>
    </variables>
</dialog>
&#13;
&#13;
&#13;

我不确定我是否以the sample tutorial仅提及{ProfVar.value:main} or {ProfVar.value:name}的正确方式使用它。我在官方文档中找不到FROM_TIME FROM_DATEDATE_TIME_RANGE

支持哪些实体类型,如何在Watson Dialog中正确提取实体特定信息?

1 个答案:

答案 0 :(得分:0)

  

我试图弄清楚如何使用其他(支持的?)EntityTypes,如Generic,Location,Amount等。但结果有时会出乎意料。例如&#34;在科罗拉多州丹佛的好房子&#34; for Location实体结果为&#34; nice&#34 ;;或指定&#34;昨天&#34;日期导致日期不正确。

&#34;尼斯&#34;是法国的城市。所以它给出了正确的答案。

问题是Dialogs实体提取是非常基本的。来自您的样本:

$ (LOCATION)={var-param_location}

这将找到第一个实体并停止寻找。为了证明这种限制,假设您希望在用户响应中获得三个可能的位置。

$ (LOCATION)={var-param_location}
$ (LOCATION)={var-param_location} (LOCATION)={var-param_location2}
$ (LOCATION)={var-param_location} * (LOCATION)={var-param_location2}
$ (LOCATION)={var-param_location} (LOCATION)={var-param_location2} (LOCATION)={var-param_location3}
$ (LOCATION)={var-param_location} * (LOCATION)={var-param_location2} (LOCATION)={var-param_location3}
$ (LOCATION)={var-param_location} * (LOCATION)={var-param_location2 * (LOCATION)={var-param_location3}
$ (LOCATION)={var-param_location} (LOCATION)={var-param_location2 * (LOCATION)={var-param_location3}

正如你所看到的,它将开始变得凌乱。它实际上仅适用于您期望返回一个实体或显式数量的实体的位置。

如果您想获得更准确的实体/关键字提取,请先将其发送到AlchemyAPI之类的内容。让API返回关键字/实体,然后使用它们。