简体   繁体   中英

How to extract current date in watson conversation

I need to create a condition, in Watson Conversation dialog model, like this:

if "today's date" < 04-15-2017 do something. else do something else.

I prefer not asking the user for current date and save it.

I tried many ways but they don't work, I also tried to output the date (doesn't work):

{
  "context": {
    "currdate": "@sys-date:today"
  },
  "output": {
    "text": {
      "values": [
        "here it is $currdate"
      ],
      "selection_policy": "sequential"
    }
  }
} 

I'm not sure about that, but with all tests I've tried, if user dont type today or something, Watson dont recognize, but, I believe with code we can do something. Probably someone work with IBM Watson will answer you correctly.

But, in my basic knowledge:

Try use now() in condition and save the date inside context variable.

The return is:

yyyy-MM-dd HH:mm:ss

Use your code to get the context variable and get just the date... after you can make conditions...

JSON Example:

{
  "context": {
    "dateHour": "<? now() ?>"
  },
  "output": {
    "text": {
      "values": [
        "Now is $dateHour."
      ],
      "selection_policy": "sequential"
    }
  }
}

I'm study all documentation about System entities within Watson and I dont see anything about extract the data if user dont request, but, how I say, probably someone work at IBM will answer, I'm just trying help you with my basic knowledge.

Check the Documentation about this entitie @sys-date now() here .

She's right, you'll need application code to grab the current date and time and pass it through as context. So far, all our system entities and efforts are around understanding what the user says, so if they don't say today, we won't know that its important. Theoretically I think you could just have your application pass through 'today' at the end of the user's sentence or something and that would run it through the processing pipeline and give you today's date, but might be a weird user experience.

If you use now() then you can reformat it to get it to work.

I store the date I want to compare it against in $date, in your case "date": "04-15-2017" , then use the following:

To see if the date is in the future use: now().reformatDateTime('dd-MM-yyyy').before($date)

If the past: now().reformatDateTime('dd-MM-yyyy').after($date)

You can read up on reformatDateTime here . It uses standard JAVA date string formatting rules which you can find here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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