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

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.

Related

Can you use nested Repeating Content Controls with the Populate a Microsoft Word template action?

Basically what I am trying to accomplish is to have a table which has a section for each Division and within that section have subsections for each Company within that Division. This is as close as I have gotten (with DivisionTable and CompanyTable both being repeating content controls):
After populating the template from a workflow the Divisions are working fine (its repeating three times w/ the correct info) but in the Company Table it just shows [obj] where it should be the Company Name. It also looks like there may be two new unnamed tags placed here after its generated but I'm not sure.
In the Populate a Word Template action inside the DivsionTable tag I am putting an array:
This is what the first object in the array looks like:
{
"CompanyTable": [
{
"CompanyName": "Company Name Goes Here"
}
],
"DivisionDesc": "Finishes",
"DivisionNo": "09"
}
Is what I am trying to do even possible? I looked at some other posts but I never saw a clear answer.
If it is possible then what exactly am I doing wrong? If it is not possible do you have any suggestions on how to accomplish this another way?

SwiftUI combine search text

I have backend API /search?q=New Je which is return list of JSON cities
"city": "New Jersey"
"city": "New Jenny Lind"
"city": "New Jerusalem"
...
I have a class
final class LocationStore: ObservableObject{
#Published var List : [LocationModel] = []
func search(q: String) {
call backend search API and assign to List
}
}
and I have search TextField in my view.
How to call search api and assign to my list when user type in search TextField. Need to show dropdown after type 3 character in TextField
Loose structure of how you tackle something like this:
Set up a text field that you can observe the output from in some fashion.
If you want to use Combine, create a pipeline that sends the value of that field on every change, and then trigger some output when it matches your spec (>3 characters)
when the combine pipeline triggers, use the value provided, or just the nature of the trigger, to do whatever action you have in mind.
There's sample code that does nearly exactly this available online within Using Combine in the pattern named Declarative UI updates from user input. It covers a bit more. The github project that hosts Using Combine has a SwiftUI variation of this as well in the project if you'd prefer to see it with SwiftUI.

What is the best way to wire global data in multiple places using hyperHTML?

I'm working on an application that reuses a lot of constants. I know that I can use wire IDs to use the same data in multiple places, but I'm not sure if I'm supposed to create a new globally unique ID every time I want to use that data.
This is a simplified example of what I'm working with:
const colors = [
{value: 'red', label: 'Red'},
{value: 'blue', label: 'Blue'}
]
class MyElement extends HTMLElement {
constructor() {
super()
this.html = hyperHTML.bind(this)
}
connectedCallback() {
this.html`
Hi, ${this.getAttribute('name')}! What is your favorite color?<br/>
<select>
${colors.map(option => hyperHTML.wire(option)`<option value=${option.value}>${option.label}</option>`)}
</select>
`
}
get name() {
return this.getAttribute('name')
}
}
customElements.define('my-element',MyElement);
hyperHTML.bind(document.body)`
<my-element name="Alice"></my-element>
<my-element name="Bob"></my-element>`
I know that unless I specify a wire ID, the options will only appear in one place. I could use :${this.name} as the wire ID, but I have to figure out what to do if there are two people with the same name, and if I want to have one form for "What is your favorite color?" and another for "What color is your shirt?", I have to make another unique ID for that.
Is there a way to somehow scope wire IDs or do I have to make globally unique ones?
There is a subtle issue in your logic, you'd like to map an array of items to themselves, instead of contextualizing their value.
Example: you are wiring the option object, out of usage, situation, context, instead of wiring the Custom Element instance to some data it's using to render itself.
As you can see in this CodePen example, you can simply wire the Custom Element context, and make the option information unique, in terms of scoped id, simply pointing at its value, through its owner:
hyperHTML.wire(this, `:option:${option.value}`)
At this point you'll have a single option element per each node so that you can easily select anything you want instead of moving the same option node globally all over the place.
Actually, the global ID is an anti-pattern as it is, I believe, in every other keyed framework such React or Vue so ... just use the instance, as your wire context/reference, and create a unique id for it with ease.
I hope this solved your issue.

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

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.

enterprise architect api: Add element to a collection

I have few short questions regarding Enterprise architect.
My question is regarding the automation interface. When following the instructions provided on this page: http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/colle... in order to add a new element to the collection ( and the .eap file) it does not add the element. I can get data from the elements, modify and even delete them, but adding a new element does not work?
Instructions provided:
Call AddNew to add a new item.
Modify the item as required.
Call Update on the item to save it to the database.
Call Refresh on the collection to include it in the current set.
my java example:
elements is a collection of all the elements in the model...
org.sparx.Element elementEa = elements.AddNew("Requirement", "non-functional");
elementEa.Update();
elements.Refresh();
With the api is it possible to change the id or guid of an element since there are no methods specified in org.sparx for that?
One last thing... Is it possible to create a custom element in EA, for example a requirement which will not have the standard properties like difficulty, priority etc.. , but will have others? (normal properties, not tagged values)
The arguments to AddNew() are Name and Type, so to create a Requirement element you should specify "SomeRequirementName" and "Requirement".
You can't change the ID or GUID through the API, and your models would crash and burn if you did (connectors would be left dangling, elements would vanish from diagrams, etc, etc).
With an MDG Technology you can create very detailed stereotyped elements if you like, with their own visual representations (shape scripts) etc, but if you're after creating an element type with its own properties dialog the answer is no; there is no hook for a custom dialog in the API.
Collection<Package> packageCollection = myPackage.GetPackages();
Package consolidatedCfsSpecPackage = packageCollection.AddNew("somePackageName", "");
if (!consolidatedCfsSpecPackage.Update()) {
System.err.println("Not Updated: somePackageName");
}
packageCollection.Refresh();
This works for me. I suggest you to check return value of elementEa.Update() method you called. If it returns false, you can get the reason by calling elementEa.GetLastError().