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



我注意到我们可以使用Watson EntityType从用户输入中提取时间参考,例如:

<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>

我正试图弄清楚如何使用其他(支持的?)EntityType,如Generic、Location、Amount等。但结果有时出乎意料。例如,Location实体的"nice house in Denver,Colorado"会导致"nice";或者指定"昨天"作为日期会导致日期不正确。

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

<?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>

我不确定我是否以正确的方式使用它,因为示例教程只提到了{ProfVar.value:main} or {ProfVar.value:name}。我在官方文档中找不到DATE_TIME_RANGEFROM_TIMEFROM_DATE

支持哪些实体类型,如何在Watson对话框中正确提取特定于实体的信息?

我正试图弄清楚如何使用其他(支持的?)EntityType,如Generic、Location、Amount等。但结果有时出乎意料。例如,Location实体的"nice house in Denver,Colorado"会导致"nice";或者指定"昨天"作为日期会导致日期不正确。

"尼斯"是法国的城市。所以它给出了正确的回应。

问题是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返回关键字/实体,然后使用它们。

相关内容

  • 没有找到相关文章

最新更新