简体   繁体   English

如何从Watson对话API中的用户输入获取日期?

[英]How to get dates from user input in Watson's conversation API?

Does anybody already figured out how to get dates that were inputed by the User in the Watson's Conversation API? 是否有人已经知道如何获取用户在Watson's Conversation API中输入的日期? In the Dialog API, we could use the standard entities, like DATE_TIME_RANGE and FROM_DATE, but I wont find any way that doesn't end adding a new custom entity by myself. 在Dialog API中,我们可以使用标准实体,例如DATE_TIME_RANGE和FROM_DATE,但是我找不到任何可以自己添加新的自定义实体的方法。 I want to create a verification that was this way on Dialog API: 我想创建一个通过Dialog API进行的验证:

<input>
<grammar>
    <item>$ (IATA)={var-from} * (IATA)={var-to} * (DATE_TIME_RANGE)={var-date1} * (DATE_TIME_RANGE)={var-date2}</item>
    <item>$ (IATA)={var-from} * (IATA)={var-to} * (DATE_TIME_RANGE)={var-date1} * (DATE_TIME_RANGE)={var-date2} *</item>
    <item>(IATA)={var-from} * (IATA)={var-to} * (DATE_TIME_RANGE)={var-date1} * (DATE_TIME_RANGE)={var-date2} *</item>
    <item>(IATA)={var-from} * (IATA)={var-to} * (DATE_TIME_RANGE)={var-date1} * (DATE_TIME_RANGE)={var-date2}</item>
</grammar>  
<output id="itinerario">
    <action varName="var-from" operator="SET_TO">{var-from.value:main}</action>
    <action varName="var-to" operator="SET_TO">{var-to.value:main}</action>
    <action varName="var-date1" operator="SET_TO">{var-date1.value:FROM_DATE}</action>
    <action varName="var-date2" operator="SET_TO">{var-date2.value:FROM_DATE}</action>
    <prompt>
        <item>{var-from} {var-to} {var-date1} {var-date2}</item>
    </prompt>
</outputt>

The Conversation API does not have that feature yet. 对话API尚不具有该功能。 In the short term, one work around might be to extract dates in the client application using a regex, and passing them to the API as a context variable. 在短期内,一种解决方法可能是使用正则表达式在客户端应用程序中提取日期,并将其作为上下文变量传递给API。

You can use a condition to access a special node with 您可以使用条件来访问特殊节点

input.text.matches( '[0-9]+' )

(add any regex you want inside) http://www.ibm.com/watson/developercloud/doc/conversation/expression-language.html (在其中添加任何所需的正则表达式) http://www.ibm.com/watson/developercloud/doc/conversation/expression-language.html

To extract the value in the node you want to extract the value. 要在要提取值的节点中提取值。 Inside the context variable add something like 在上下文变量中添加类似

"context": {
    "number_extract": "<? input.text.extract('[\\d]+',0) ?>"
}

(you can put any regex you want inside the extract) (您可以将任何所需的正则表达式放入摘录中)

That is the best you can do currently with watson conversation. 这是您目前通过Watson对话所能做的最好的事情。 So you have to make your own regex to parse the date. 因此,您必须制作自己的正则表达式来解析日期。

I personally use another solution which is to make a custom parser that comes before watson. 我个人使用了另一个解决方案,那就是在Watson之前制作一个自定义解析器。 This guy details how to do it using alchemyAPI 这个家伙详细说明了如何使用alchemyAPI进行操作

https://kozhayasite.wordpress.com/2016/08/27/watson-conversation-with-alchemy-entity-extraction/ https://kozhayasite.wordpress.com/2016/08/27/watson-conversation-with-alchemy-entity-extraction/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM