IBM Watson Conversation: How to capture and retrieve a list of values in a variable - ibm-cloud

I have a dialog where users can enter one or more country names.
How do I retrieve the values from the entity defined to store the responses.
Example :
Entity : Country
Question : Where did you travel to?
Answer : Africa, Thailand and
China.
How can I capture these 3 values in a list entity?

Henrik is right, just to add to that,
What he said will return them in an array, if you do
"countries": "<? entities['sys-location'] .toString() ?>"
you will get a comma separated list of the locations returned.

#sys-location entity in System Entities extracts location from the conversation. (Note: Ensure that you have switched on that entity as shown below)
You can now see that location has been extracted from conversation

You can use the system entity for locations, #sys-location. You need to turn that capability on for your workspace. See the wizard for entity creations.
In your dialog node where you want to capture the input in a list, you can assign those countries to a context variable. Switch to the JSON editor to edit variables. Then do something like:
"context": {
"countries": "<? entities['sys-location'] ?>"
},
See my collection of examples for context processing for something similar.

Its Quite Simple. Use
"countries": "#sys-location.values"
It will list all #sys-location values in array form.

Related

IBM Watson Assistant, how can I remove multiple items from an array?

I have a list unmentioned_colors = ["red", "green", "blue", "yellow"]
If I mention multiple colors, I want to update my unmentioned_colors array, removing the ones that I mentioned. So if I write "red green" I want to remove them from unmentioned_colors where it will become ["blue", "yellow"]
I tried
unmentioned_colors = "<? $unmentioned_colors.removeValue(#colors.values) ?>"
But it is not working.
How can I remove multiple #colors from my array?
Watson Assistant supports two methods to remove an item from a JSONArray, remove (using the index) and removeValue (using the value). Each method removes exactly one element. So you would need to loop / iterate over the elements to delete and then invoke the method. Could you process this in the app?
Another approach is to look into SpEL (the expression language) and work with collection selection / projection.
To remove all #colors items from $unmentioned_colors one should set a context variable $_bool_listchanged as shown here:
_bool_listchanged = "<? $unmentioned_colors.removeAll(#colors.values) ?>" .
This solution does not require a loop and works because underneath the hood Watson Assistant uses Java to manipulate items in the contact. So on this array we have the method removeAll which we can call from Java.

web2py: customizing form.vars to pass inputs id

I'm building a web app using web2py for attending employees.
this is the db in the model
db.define_table(
'employee',
Field('name'),
format = '%(name)s'
)
db.define_table(
'attendance',
Field('employee_id',db.employee),
Field('attend','boolean'),
Field('comments','text')
)
This is the controller:
employeeIDS=db(db.employee).select(db.employee.ALL)
table=[]
for eid in employeeIDS:
table.append([eid.name,INPUT(_type="checkbox",_name=eid.id,_id=eid.id),INPUT(_type="text",_name="comments",_id=eid.id)])
form=FORM( TABLE(TR("employee name","attended?","comments"),*[TR(*rows) for rows in table]),INPUT(_type="submit",_value="SUBMIT"))
if form.accepts(request,session):
response.flash="form accepted"
print(request.vars)
elif form.errors:
response.flash="form is invalid"
else:
response.flash="please fill the form"
return dict(form=form,vars=form.vars)
My question is this:
How can I access the id of the attend and comments fields in each row to associate these fields with the related employee. So, when I insert the form.vars to the attendance table, I guarantee that each employee recorded as attendance or absence and the related comments will inserted too.
Thanx
Instead of giving each comments input the same name, make the names unique, including the record ID as part of the name:
INPUT(_type="text", _name="comments_%s" % eid.id)
Then you will have form.vars.comments_1, form.vars.comments_2, etc.
As an aside, note that HTML id attributes should be unique, but you are using the value eid.id as the id attribute of both the checkbox input and the comments input.
I think a better choice is to use SQLFROM instead of FORM.
There you can customize the resulting form in the view right the layout you want to, even with HTML helper for tables, you have already used.
Please have a look at the signature of the SQLFORM - it offers a lot options as labels or showid (following the link just scroll down a little).
To exclude a field of being changed or even displayed in the SQLFORM use:
db.my_table.a_field.writable = False
db.my_table.a_field.readable = False
as described here - it's the same for SQLFORMS.

SAPUI5: How to create a control hierarchy?

I hope you can help me with this. After reading all the documentation several times, googling for days, etc I don't find the way to do what i'm going to explain in a clean way, and in think I'm missing something because it's a really basic scenario.
I'm working with oData models, in this case 2 named models, "Model1", "Model2". Now what I want is to show a "parent" ComboBox based on an oData path, and a table that changes its items depending on the selection, in other words.
Model1 { //JSON representation of the data.
Accounts:[
"account 1": {invoices: ["invoice1", "invoice2", "invoice3"]},
"account 2": {invoices:["invoice4", "invoice5"]}
]
}
Combo Box:
<... items={Model1>/Accounts} /> -- This works and shows Account 1, and Account2.
Table
<Table... items="{Model1>Invoices}">
..
<items>
....
</items>
</Table>
What I want is the table to change it's context to the account selected on the ComboBox. The point is that this works, but the first time it loads the view, as there is no account selected, it calls the wrong odata path MYSERVICE/Invoices, instead of doing nothing, as the Account is not set yet, and the path for the invoices, once selected the account, shoud be MYSERVICE/Account('Account1')/Invoices for example.
I know I can achieve this with code, but I'm sure there must be a clean way to do this.
Seriously, this is driving me crazy.
Thanks for your help.
Are you sure that
items="{Model1>Invoices}"
triggers odata call? Because this is a relative path (without leading slash), normally it should not do the call.
What you can do:
Handle ComboBox selectionChange event;
In this event handler, create a path that you will bound the table to. In your case the path could look like this: "/Account(Account1)" - "/{EntitySetName}({KEY})". You can make use of createKey method of ODataModel2;
Set the table's context using the path:
oTable.bindObject({
path: sPath,
model: "Model1",
parameters: {
$expand: "Invoices"
}
});
Once the context is set, the relative binding will start working automatically and table will get the "Invoices"
I assume that the Account and Invoices are linked via navigation property and one-to-many cardinality, that's why the $expand parameter will load the corresponding invoices.

redux-form Wizard form with linked fields

I am building a multi-step application form with React. Having first built it with pure internal state I am now in the process of refactoring to Redux using redux-form.
Having used the example here as a basis: http://redux-form.com/5.2.5/#/examples/wizard?_k=oftw7a we have come a good way.
However the problem appears when i have two forms which are supposed to have the same value. During one of the pages i have a name field, that is supposed to be duplicated on the name field of the next page. The opposite should happen if you go back from the last page. Any tips to how this could be achieved?
Using the wizard, you are basically working with the exact same form that's split into multiple pieces. Ultimately it's the same form, because redux-form tracks them by name. It is how the library identifies the pieces of the same form - using the name.
form: 'wizard',
Here you can see that the exact same instance of the form will be shared throughout the pieces. fields work in a similar manner. Each field is defined as part of a form.
As long as you use the same field constants inside the fields object that you pass into the reduxForm function and as long as the value for form is the same, so that they use the same underlying form object, it should work for you just fine.
On one page you should pass in
export default reduxForm({
form: 'wizard',
fields : {
'fieldIWantOnBothPartsOfTheForm',
'someOtherFieldThatShouldOnlyBeHere',
},
...
And then on the other page:
export default reduxForm({
form: 'wizard',
fields : {
'fieldIWantOnBothPartsOfTheForm',
'thirdFieldHere',
},
...
Also, make sure you keep destroyOnUnmount equal to false if you want to navigate back-and-forth.
Hope that helps.

Autocompleter for Mootools to set multiple form values

I need a Mootools based autocompleter that retrieves data by ajax, and will fill in multiple form input elements when an option is selected. I.E, a user searches for "foo", and one of the options might be "foobar", which has associated with it the variables objecttype AND objectid, both of which need to be set in the form when the user clicks on "foobar".
I've been looking at two autocompleters: Meio.Autocomplete and AutoCompleter as my best bet, but neither of them really seem to handle what I need them to handle.
I'm considering either rewriting/extending one of those, or possibly using the Meio version (which handles a single value) and storing my multiple variable in the form in one field, possibly as a json object that can be parsed client side with jsonParse and inserted into the form with an additional function after the selection is made.
Does anyone know of a simpler solution?
You could use the Meio.Autocomplete's onSelect event with an identifier, that JSON encodes all of the needed properties.
var data = [
{value: 'name1', identifier: {
id: 'id1',
type: 'type1'
}},
...
}
I made a quick example