2

Does anybody already figured out how to get dates that were inputed by the User in the 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. I want to create a verification that was this way on 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>

2 Answers2

2

The Conversation API does not have that feature yet. 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.

  • Hi David. I've figured out that I can validate regex using the input.text.matches function in the condition node. So I am using now input.text.matches("^\d{4}-\d{2}-\d{2}$") to validate if 2006-01-01 is in date format. – Jair Alves da Silva Junior Aug 08 '16 at 14:32
2

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

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. 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. This guy details how to do it using alchemyAPI

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