I've tried using the daysBetween (start, end) function in my bot. For some reason it's not working. The support documentation for IBM Watson Assistant said it supported the java.util.Date.
Maybe I'm not using it right. Could you guys give me an example how to use the daysBetween (start, end) function within the java.util.Date in the JSON dialog editor?
As per the documentation, "You can use standard methods of the java.util.Date class"
https://cloud.ibm.com/docs/services/assistant?topic=assistant-dialog-methods#dialog-methods-dates-java-util-date
daysBetween is not a standard method of java.util.Date
https://docs.oracle.com/javase/7/docs/api/java/util/Date.html
You can achieve this by written a Cloud Function and calling it from Watson Assistant.
Related
Is there a possibility to set the start and stop date of an simulation run using a function or parameter?
Thanks for helping!
There is. These functions can be accessed via the Engine object. You can find the documentation of the class here. The functions you are looking for are:
setStartDate(java.util.Date date)
setStartTime(double tstart)
setStopDate(java.util.Date date)
setStopTime(double tstop)
Either in the Experiment or in the Main of your model, you can use (as an example) this code:
getEngine().setStartTime(100);
Of course, once the model is already started, only setting of stop time/date will have an effect.
I am gathering some context variables with slots, and they work just fine.
So I decided to do in another node of the conversation, check if one of these context variables is a specific number:
I was thinking on enabling multi-responses and check if, for example $dni:1 (it is an integer, pattern of 1 integer only), or if it is 2 or 3:
But this is not working. I was trying to solve it for some days with different approaches but I really cannot find a way through it.
My guess is that a context variable has a value, and you can print it to use it like responding with the user's name and stuff like that (which indeed is useful!), but comparing values is not possible.
Any insights on this I can receive?
Watson Assistant uses a short-hand syntax but also supports the more complex expressions. What you could do is to edit the condition in the JSON editor. There, for the condition, use a function like matches() on the value of the context variable.
Note that it is not recommended to check for context variables in the slot conditions. You can use multi-responses. An alternative way is to put the check into the response itself. There, you can use predicates to generate the answer.
<? context.dni==1 ? 'Very well' : 'Your number is not 1' ?>
You can nest the evaluation to have three different answers. Another way is to build an array of responses and use dni as key.
Instead of matching to specific integers, you could consider using the Numbers system entity. Watson Assistant supports several languages. As a benefit, users could answer "the first one", "the 2nd option", etc., and the bot still would understand and your logic could still route to the correct answer.
I have a DateTextField component in my application and I want the input of date using a predefined pattern. The pattern that I need is "yyyy-MM-dd". I created the DateTextField using the following code.
DateTextField dtf_ExpiryDate = DateTextField.forDatePattern("ExpDate", "yyyy-MM-dd");
dtf_ExpiryDate.add(new DatePicker());
It helps to prevent date input in most of other formats. But it accepts input in dd-MM-yyyy format and converts it into some weird format. For example, 12-06-2013 is automatically converted to 0012-06-20.
Is there a way to throw an error when the date is given in dd-MM-yyyy ?
Javadocs of DateTextField says that the conversion is done internally using the Joda time parser. Is there a way to add more constraints ?
I really don't want the data to be captured as String and add a StringValidator to check if it confirms to the pattern using Regex.
Thank you
As far as I know, the answer is NO. DateTextField uses DatePattern or DateStyles internally and it is not possible to enforce stricter rules. If you don't want to use Javascript (custom) or JQuery, you have to use a REGEX to validate the input.
Have a look at here. Use the StrictPatternDateConverter class shown below to enforce a strict validation for the input.
Yep! StringRegExp is a good solution. But another solution could be the use of jqWicket. It provides a MaskedInputBehavior. Take a look at: http://code.google.com/p/jqwicket/wiki/MaskedInputExample
I'm trying to create a simple FireBreath plugin. I need to pass a date from JavaScript to my plugin and to get date from my plugin and use it in JavaScript.
I have an idea about getting date in FB plugin from JS. I can use a FB::JSObjectPtr parameter and get it's attributes with GetAttribute.
The main question is how to pass a date back to JS? The only way I can find in my head is to create class DateJSAPI derived from FB::JSAPIAuto an implement all methods so JS can use instance of my class as JS Date.
I don't like such a weird way.
Can anyone advise me some good way of returning date to JS?
I spent several hours once trying to find a way to create Date objects in a NPAPI plugin (specifically in FireBreath) and it seems the only way to do so is to create a javascript function that returns a date object. Given that you'd have to pass a string or timestamp into said function it seems silly to do this.
If I were you I'd just send it as a timestamp (number) so you can convert it to a Date object once it gets to javascript.
If I'm using this:
DateTime.Now.Date.ToString("yyyy-MM-dd")
FXCop complains that I'm violating CA1305 and says that I should provider an IFormatProvider. Do I need to? I'm asking for the date in a specific format anyway (which is the format I'm expected to put it into the XML as).
Would providing a format provider make any difference? Might it actually produce the wrong results in this case?
Why don't you want to specify the format provider?
If it is just laziness then I can recommend defining two snippets. ic for CultureInfo.InvariantCulture and cc for CultureInfo.CurrentCulture.
Never assume anything about how conversion to string works with the default culture. Not everyone in the world uses the gregorian calendar. Some day you customer might hire a contractor with a computer with another calendar as default and then you are not generating correct XML. Explain then to your customer that you didn't want to follow the FxCop recommendation.
Best thing would be if .Net included a Xml Culture. Then you could just do
DateTime.Today.ToString("d", CultureInfo.Xml)
For some reason Microsoft choose to create a separate class instead XmlConvert. The class has been there since .Net 1.0.
XmlConvert.ToString(DateTime.Today, "yyyy-MM-dd")
will always create a correct Xml date.
Not sure if it is bug or intended behaviour but XmlConvert.ToString(DateTime.Today, "d") will not create a valid Xml date.
so after a bit more research it seems that in my instance it doesn't make any difference, but in the general case months might be displayed in a specific locale.
More details here:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx