IBM Watson Assistant: Expressions on dialog node condition using array? - ibm-cloud

For IBM Watson Assistant and a dialog node condition I want to check if the context variable long_name_context_var has one of the values 1,2,3,4,5. The normal way would be
$long_name_context_var == 1 || $long_name_context_var == 2 ||
$long_name_context_var == 3 || $long_name_context_var == 4 ||
$long_name_context_var == 5
But it is visually too long. Thus, I want to shorten it.
I tried to use JSONArray.contains and Array literals as
[1,2,3,4,5].contains($long_name_context_var)
but failed.
Doesn't the node condition support array literals? Or would it give a syntax error?

The conditions on a dialog node in IBM Watson Assistant support SpEL-based expressions. This includes the contains function on JSON arrays.
Have you enabled debugging in the Try it to see the value of the context variable? I assume your node works with the "visually too long" expression. Is the type of the context variable a string or a number? Try using
["1","2","3","4","5"].contains($long_name_context_var)
What definitely works is to assign the array to a context variable (in my test testme in the context editor in Try it) and then use the following expression:
$testme.contains("3")
Else you could try the indexOf function.

Try with:
$long_name_context_var >= 1 || $long_name_context_var <= 5

Related

stuck in replacing negative values with zero in SPSS Modeler

I am trying to replace the -ve values with "0" and derive a new variable in SPSS Modeler . I am trying "Derive" node to accomplish the job using the function of "if INDV_ASS_INC_TAMT < 0 then INDV_ASS_INC_TAMT=0 else INDV_ASS_INC_TAMT=INDV_ASS_INC_TAMT endif" but getting the following error " The conditional expression contains incompatible return types: Boolean and Integer".
I am novice SPSS Modeler User and stuck for 2 days to figure it out . Your help would much appreciated .
Snap shot in link 1
[Error ][1]
Use "Filler node" to replace value in your Column based on condition.
https://www.ibm.com/support/producthub/icpdata/docs/content/SSQNUZ_current/wsd/nodes/filler.html

The || function isnt working when checking for user id

if (message.content.startsWith('!'))
{
if(message.author.id !== ('490510038469705747') || message.author.id !==('752606131569950800)') || message.author.id !==('422003274045063179') || message.author.id !==('395291950690861057'))
return message.channel.send('!You aint my master! ._.');
}
this code doesnt work, and it always just says You aint my master to anyone thats running the command
please help
i am using discord.js with visual studio code
You should be using && instead of ||. When you're using ||, the if statement will pass even if only one of the parameters resolves to true. If you use &&, the if statement will only pass if ALL of the parameters resolve to true.
Additionally it seems you've got a stray parenthese in one of your strings message.author.id !==('752606131569950800)').

How to know filename contains other string or not in firebase cloud storage?

I want to check that uploading image name contains "thumb_" or not .If filename contains "thumb_" then user do not allow to upload images.
something like that :
match/users/{id}/{image}{
if: request.resource.contentType.matches('image/.*') &&
request.resource.size < 1024 *1024 * 2 &&
image.size()<32 &&
!image.includes('thumb_')}
but it give error
Error running simulation — Error: simulator.rules line [13], column [27]. Function not found error: Name: [includes].
we can not use includes() function in security rule.So what should I use instead of includes() ?
According to the API documentation for security rules for Cloud Storage, there is no method called "includes" on string data. You can see there is a method called "matches" which lets you perform regular expression matching on strings. To see if the string in image contains the string "thumb_":
image.matches('thumb_')

Reuse of conditions (when) in Drool DSL statements

Is it possible to reuse a when/condition statement into another when/condition statement in a DSL file?
For example, I have two conditions:
[condition][]The client is invalid = Client( name == null || email == null )
[condition][]All the clients are invalid = forall( Client( name == null || email == null ) )
Note that the second condition just diff the first for the forall command, but the statement inside is equals. In these case, I want to reuse the first condition into the second.
Is it possible? How?
Thank you.
even the most recent version of drools will only let you substitute values into a template from pojo's or a corresponding map as per their documentation here.
This won't work for your use case though.
Since drool files are simply text files, there is nothing preventing you from considering a more powerful templating toolkit.
Possibilities include Apache Velocity, ANTLR or Scala!

How to reciprocate?

Actually I am coding a Matlab simulation where the AnchorID and SourceID will report to eachother. For example if I take an anchor 30 and source 50 it will collect all the agc values between these anchor and source and calculate rssi_dB and display them.Below mentioned is an example of anchor 30 and source id 50
Note: list of anchors ID's and source ID's are same. for e.g. 30 50 55 58 . These ID are both same for anchor and source.
function A30(BlinkSet)
for i=1:length(BlinkSet)
xAnchorID=30;
xSourceID=50;
a=BlinkSet{i}.AnchorID;
b=BlinkSet{i}.SourceID;
if xAnchorID==a && xSourceID==b
xagc=BlinkSet{i}.agc;
rssi_dB(i)=-(33+xagc*(89-33)/(29-1));
end
end
rssi_dB(rssi_dB==0)=[];
rssi_dBm=sum(rssi_dB(:))/length(rssi_dB);
disp([sprintf('The rssi value is %0.0f',rssi_dBm)]);
When I call the function in Matlab command window I get the rssi value of the above function.
Also my task is when I reciprocate the Anchor ID and source ID say Anchor as 50 and source as 30 like the function I have mentioned below I get an error which is mentioned after the function below.
function A50(BlinkSet)
for i=1:length(BlinkSet)
xAnchorID=50;
xSourceID=30;
a=BlinkSet{i}.AnchorID;
b=BlinkSet{i}.SourceID;
if xAnchorID==a && xSourceID==b
xagc=BlinkSet{i}.agc;
rssi_dB(i)=-(33+xagc*(89-33)/(29-1));
end
end
rssi_dB(rssi_dB==0)=[];
rssi_dBm=sum(rssi_dB(:))/length(rssi_dB);
disp([sprintf('The rssi value is %0.0f',rssi_dBm)]);
When I call this function I get an error as
??? Undefined function or variable "rssi_dB".
Error in ==> A50 at 14
rssi_dB(rssi_dB==0)=[];
Error in ==> main_reduced at 26
A50(BlinkSet);
In main function I have coded like this,
%A30(BlinkSet);
A50(BlinkSet);
Any help is highly appreciated.
In both of these functions, you only create the variable rssi_dB if execution enters the if statement within the loop (i.e., if xAnchorID==a && xSourceID==b is at some point true). Clearly, this code is never executed in your A50 function. Without knowing what is in BlinkSet it's a bit difficult to diagnose the exact problem, but this is the cause at least.
As a side note: it's not a good idea to create two separate functions to do this job when their code is almost identical. You should add an input argument to your function that allows it to do the job of both. In this particular case, all that changes is the value of xAnchorID and xSourceID, so you could just pass these in:
function srcToAnchorRssi(BlinkSet, xSourceID, xAnchorID)
% The rest of the function stays the same!
If you want to provide some defaults for these arguments, you can do, e.g.:
if nargin < 3 || isempty(xAnchorID), xAnchorID = 50; end
if nargin < 2 || isempty(xSourceID), xSourceID = 30; end
It's always a good idea to include an isempty in statements of this sort, so that your function supports syntax like myFunction(myArg1, [], myArg3). Also note that the order of the operands to || is crucial; if you did if isempty(theArgument) || nargin < theArgumentNumber and the user did not pass theArgument, then it would error in the isempty because theArgument would not exist as a local variable. We can get around this by swapping the operands' order because MATLAB is smart enough to know it doesn't have to evaluate the right operand if the left operand is true (note that this is also the case in many other programming languages).