Drools: How to use forall in decision table to match anyof or all the items in the comma seperated string - drools

How to define Drool's conditional element forall in decision table? for ex. "fruit" and "vegetable" true if the input matches one of the comma separated string. "abc combo" true if the input string contains all of the comma separated string. I have achieved the same using a custom function, just want to know if the same can be achieved by forall?

To match either use the || in the forAll and to match all use &&
Example
eval(forall(&&){name == "$"})
eval(forall(||){name == "$"})

Related

Azure Data factory expression

i saw this expression in one of the Pipeine , in the filter activity condition. can anyone help me understad this expresson used( you can refrase inorder to make it understandable). looks difficult to understand.
#if(equals(pipeline().parameters.FileName,'default'),endswith(toUpper(item().name),'.PDF'),
and(startswith(item().name,replace(string(pipeline().parameters.Filemane),'*.txt','')),
endswith(toUpper(item().name),'.PGP')))
Thanks
I dont have blocker , but i cannot understand the Expression. Just wanted to get some clarity what is the purpose of that code , what are they trying to achieve in that particualar filter condition in the ADF
If you use the above expression in the filter activity. It will filter the values of the array based on the FileName parameter.
This is my sample array of file names:
['rakesh.pdf','correct1.pgp','wrong1.pgp','laddu.pdf','correct2.pgp','wrong2.pgp','virat.pdf','wrong3.pgp','correct3.txt']
For you the array will be an array of objects. that's why in the above expression it's there as item().name. For me it's only item().
Filter activity filters based on the condition. If the particular array item satisfies the condition(true/false) then it filters it.
#if(equals(pipeline().parameters.FileName,'default'),endswith(toUpper(item().name),'.PDF'), and(startswith(item().name,replace(string(pipeline().parameters.Filemane),'*.txt','')), endswith(toUpper(item().name),'.PGP')))
In the above expression, If the FileName parameter value is 'default', it filters the items which are ending with .PDF. if(condition,True case,else case) so in true case we are checking endswith() .PDF or not. If it is true, then filter condition is true and that particular array value will be filtered.
else case
and(startswith(item().name,replace(string(pipeline().parameters.Filemane),'*.txt','')), endswith(toUpper(item().name),'.PGP'))
If the parameter value is correct*.txt(other than default).
In this case it replaces the '*.txt' with empty strings('') and returns 'correct'. Then it checks(first condition) the whether the array value starts with 'correct' and endswith .PGP(second condition). If both conditions are true, then filter condition is true and array value is filtered.
This is a sample demo:
Array:
Filter with same condition:
for me it's only item() not item().name.
If I take the parameter value as 'default'.
Filter output array (all .PDF files):
If I take the parameter value as 'correct*.txt'.
Filter output array(.PGP files starts with 'correct'):
NOTE: If your parameter value is only like 'correct.txt' then use '.txt' in the expression.
Well I am not sure if there is a difference between the first code before 'Thanks' and the code after it.
But it seems that the code will return true or false.
I can reformulate to this in c# like format:
if(pipeline().parameters.FileName == 'default')
{
// if the name of item ends with .pdf then return true, else return false
return endswith(toUpper(item().name),'.PDF'),
}
else
{
// replace the *.txt with an empty string.
// I think it means if the file ends with .txt then replace it with an empty string
string replacedText = replace(pipeline().parameters.Filemane,'*.txt','')
// check if the itemName is ends with .txt (in this case this condition will fail)
boolean cond1 = startswith(item().name, replacedText)
// if the name of item ends with .PGP then cond2 = true
boolean cond2 = endswith(toUpper(item().name),'.PGP')
return cond1 && cond2
}

how do we iterate and store the results in a variable in kdb

I have a string say example "https://www.google.com" and a count of paging say 5
how do i iterate the URL to append p/page=incrementing numbers of paging and store the result in a variable as list?
"https://www.google.com/page=1"
"https://www.google.com/page=2"
"https://www.google.com/page=3"
"https://www.google.com/page=4"
"https://www.google.com/page=5"
So the end result will look like this having a variable query_var which will hold a list of string example below
query_var:("https://www.google.com/page=1";"https://www.google.com/page=2";"https://www.google.com/page=3";"https://www.google.com/page=4";"https://www.google.com/page=5");
count query_var \\5
You can use the join function , with the each-right adverb /:
query_var: "https://www.google.com/page=" ,/: string 1_til 6
Make it a function to support a varied count of pages:
f:{"https://www.google.com/page=" ,/: string 1_til x+1}
q)10=count f[10]
1b
Q1
You don’t even need a lambda to make this a function. It’s a sequence of unary functions, so you can compose them.
q)f: "https://www.google.com/page=",/: string ::
q)f 1+til 6
"https://www.google.com/page=1"
"https://www.google.com/page=2"
"https://www.google.com/page=3"
"https://www.google.com/page=4"
"https://www.google.com/page=5"
"https://www.google.com/page=6"
Q2
q)("https://www.google.com";;"info/history")
enlist["https://www.google.com";;"info/history"]
q)"/"sv'("https://www.google.com";;"info/history")#/: string `aapl`msft`nftx
"https://www.google.com/aapl/info/history"
"https://www.google.com/msft/info/history"
"https://www.google.com/nftx/info/history"
List notation is syntactic sugar for enlist. The list with a missing item is a projection of enlist and can be iterated.
Again, a sequence of unaries is all composable without a lambda:
q)g: "/"sv'("https://www.google.com";;"info/history")#/: string ::
q)g `aapl`msft`nftx
"https://www.google.com/aapl/info/history"
"https://www.google.com/msft/info/history"
"https://www.google.com/nftx/info/history"
If you can assume a unique character that doesn't appear elsewhere in your url (e.g. #) then ssr is a simple and easily-readable approach:
ssr["https://www.google.com/page=#";"#";]each string 1+til 5
ssr["https://www.google.com/#/info/history";"#";]each string`aapl`msft`nftx

Check if string contains any of the following

I'm trying to check if a string contains one of four sub strings in a simpler way than this:
if (imageUrl.contains('.jpg') ||
imageUrl.contains('.png') ||
imageUrl.contains('.tif') ||
imageUrl.contains('.gif')) {
}
Is there a way to do this? For example checking against a list?
You can use a regex pattern instead of a simple string:
imageUrl.contains(new RegExp("\.(jpg|png|tif|gif)"))
Might be somewhat simpler.
RegularExpression can solve your problem. RegEx are used to search patterns in strings.
RegEx example:
^The matches any string that starts with The
end$ matches a string that ends with end
^The end$ exact string match (starts and ends with The end)
abc* matches a string that has ab followed by zero or more c

How can we validate a string consist any single alphabets or not in scala?

My application takes in a string like this:
k0qVsfpz7_cG9n75OjZCCA
P700058213111115432196
1700058213111115432196
I need to validate in a Scala script that the string consists of any single alphabet or not.
Consider exists method over a given string, which maps each character onto a predicate provided. For instance, Char.isLetter proves true only if a given character is an alphabetical value (a letter). Hence
"P700058213111115432196".exists(_.isLetter)
Boolean = true
and
"700058213111115432196".exists(_.isLetter)
Boolean = false
Similarly with forall we can verify that each and every character in a string holds a predicate, for instance
"P700058213111115432196".forall(_.isDigit)
Boolean = false
and
"700058213111115432196".forall(_.isDigit)
Boolean = true
To remark that both exists and forall iterate over a collection. Here we iterate over a Scala string which is treated as a sequence of Char.

Autohotkey: Splitting a concatenated string into string and number

I am using an input box to request a string from the user that has the form "sometext5". I would like to separate this via regexp into a variable for the string component and a variable for the number. The number then shall be used in a loop.
The following just returns "0", even when I enter a string in the form "itemize5"
!n::
InputBox, UserEnv, Environment, Please enter an environment!, , 240, 120
If ErrorLevel
return
Else
FoundPos := RegExMatch(%UserEnv%, "\d+$")
MsgBox %FoundPos%
retur
n
FoundPos, as its name implies, contains the position of the leftmost occurrence of the needle. It does not contain anything you specifically want to match with your regex.
When passing variable contents to a function, don't enclose the variable names in percent signs (like %UserEnv%).
Your regex \d+$ will only match numbers at the end of the string, not the text before it.
A possible solution:
myText := "sometext55"
if( RegExMatch(myText, "(.*?)(\d+)$", splitted) ) {
msgbox, Text: %splitted1%`nNumber: %splitted2%
}
As described in the docs, splitted will be set to a pseudo-array (splitted1, splitted2 ...), with each element containing the matched subpattern of your regex (the stuff that is in between round brackets).