Drools Rule Engine: Is it possible to have a params be a list and you run the condition for each value in the list in a Decision table? - drools

I am trying to create a rules engine via a decision table. I want to run a rule on each value in a given list.
For example, I have the following condition column:
Decision Table Column Picture
I am trying to follow the following snippet from section 6.1.4.3 from
docs
where it states:
A text according to the pattern forall(delimiter){snippet} is expanded by repeating the snippet once for each of the values of the comma-separated list of values in each of the cells below, inserting the value in place of the symbol $ and by joining these expansions by the given delimiter. Note that the forall construct may be surrounded by other text.
However when I try the above snippet condition, I get the following error:
java.lang.RuntimeException: Error while creating KieBase[Message [id=1, kieBase=rules, level=ERROR, path=rules_for_jpmc.xls, line=7, column=0
text=[ERR 102] Line 7:123 mismatched input 'param' in rule "Green Scenario 1.2"], Message [id=2, kieBase=rules, level=ERROR, path=rules_for_jpmc.xls, line=0, column=0
text=Parser returned a null Package]]
I just want to run productCurrent == $param on both pizza and calzone, and if one is met, the condition is true, without having to use $1, $2, etc. Is there a pattern on how to run a condition on a paramater list?

Related

How to remove the first 2 rows using zipwithindex using spark scala

I have two headers in the file. have to remove them. i tried with zipwithindex. it will assign the index from zero onwards. But its showing error while performing filter condition on it.
val data=spark.sparkContext.textFile(filename)
val s=data.zipWithIndex().filter(row=>row[0]>1) --> throwing error here
Any help here please.
Sample data:
===============
sno,empno,name --> need to remove
c1,c2,c3 ==> need to remove
1,123,ramakrishna
2,234,deepthi
Error: identifier expected but integer literal found
value row of type (String,Long) does not take type parameters.
not found: type <error>
If you have to remove rows, you can use row_num and remove rows easily by filter row_num>2.

I am getting an error in prolog in vs code please check

This is the code:
dog(rottweiler).
cat(sphynx). dog(poodle).
dog(bulldog). cat(bengal).
dog(dobermann).
cat(himalayan). cat(singapura).
ND THE ERROR IS:-
Warning: Clauses of dog/1 are not together in the source-file
Warning: Earlier definition at c:/users/dell/desktop/prolog/dog:1
Warning: Current predicate: cat/1
Warning: Use :- discontiguous dog/1. to suppress this message
Warning: c:/users/dell/desktop/prolog/dog:4:
Warning: Clauses of cat/1 are not together in the source-file
Warning: Earlier definition at c:/users/dell/desktop/prolog/dog:2
Warning: Current predicate: dog/1
Warning: Use :- discontiguous cat/1. to suppress this message.
TRUE
In Prolog, an n-ary predicate p, for n≥0, is defined by a procedure, which consists of one or more clauses whose conclusions are terms of the form p(a1, ..., an), where each a_i is an argument. Clauses belonging to the same procedure are expected to be declared in sequence, contiguously.
When the clauses of two or more distinct procedures appear interleaved in the source code, the compiler produces the warning messages you get. To suppress such messages, you can use a directive of the form :- discontiguous predicate/arity.
For example:
:- discontiguous dog/1.
:- discontiguous cat/1.
dog(rottweiler).
cat(sphynx).
dog(poodle).
dog(bulldog).
cat(bengal).
dog(dobermann).
cat(himalayan).
cat(singapura).
Note, however, that the best option is to follow the Prolog convention and modify your code as follows:
% clauses of the first procedure
dog(rottweiler).
dog(poodle).
dog(bulldog).
dog(dobermann).
% clauses of the second procedure
cat(sphynx).
cat(bengal).
cat(himalayan).
cat(singapura).

Postgres LIKE %% syntax errors

I have been trying to do a LIKE comparison in postgres but repeatedly receive an error telling me that the column "%#firstname%" doesn't exist.
I should clarify, this query is executed in a function, "#firstname" is the parameter passed into the function.
The relevant section of the query is below:
WHERE u."firstname" LIKE "%#firstname%"
I do not want an exact comparison which is why I am trying to add the %% to the query. It works just fine without them for exact queries. Whenever, I add the % then it assumes that they are part of the variable name and subsequently can't find it.
I have also tried the following:
'%"#firstname"%' which results in an empty array being returned even though it should have matched
"%'#firstname'%" which results in error: column "%'#filter'%" does not exist
%"#firstname"% which results in error: column "%'#filter'%" does not exist
If "#firstname" is a parameter you need something like:
WHERE u.firstname LIKE concat('%', "#firstname", '%');

ERROR: invalid input syntax for type numeric: "N/A" ... nice but which column?

I am running a function in PostgreSQL which contains several functions which purpose is to load data from foreign tables into mine. While running I get this error:
[SELECT - 0 row(s), 762.353 secs] [Error Code: 0, SQL State: 22P02] ERROR: invalid input syntax for type numeric: "N/A"
Where: PL/pgSQL function import_data_3(integer,timestamp with time zone,timestamp with time zone,integer) line 16 at SQL statement
SQL statement "SELECT import_data_3(import, beg, end_t, is_l)"
PL/pgSQL function data_import_all(timestamp with time zone,timestamp with time zone,integer,integer) line 31 at PERFORM
I know what that means and also its reason I am trying to convert 'N/A' string to number and there for this error, problem is this lousy error does not specify the column where the error occurred.
Is there a way to get more precise error message which would tell me the exact column where the error happened?
It's not in the column but in one of the parameters that are passed to import_data_3.
You called the query SELECT import_data_3(import, beg, end_t, is_l).
The specification of this function is import_data_3(integer,timestamp with time zone,timestamp with time zone,integer)
Since you got the error
invalid input syntax for type numeric: "N/A"
this most likely means that either first parameter "import" or the last one "is_l" contain the value "N/A". Try to debug the calling code of the function data_import_all and see how those two parameter values are generated.

search a name in dataset error :Undefined function 'eq' for input arguments of type 'cell'

I load a file which has some columns with data.The first line contains ,CITY,YEAR2000 .
The first column has name of cities.The other columns contain number data.
I am trying to search for a specific city using:
data(data.CITY=='Athens',3:end)
where
data = dataset('File','cities.txt','Delimiter',',')
but I receive an error
Undefined function 'eq' for input arguments of type 'cell'.
--------UPDATE-----------------------------
Ok, use :
data(find(strncmp(data.CITY,'Athens',length('Athens'))),3:end)
Have you tried with using strncmp tangled with find?
I would use it this way
find(strncmp(data.CITY,'ATHENS',length('ATHENS')))
EDIT
Other opportunities to exploit would encompass strfind
strfind(data.CITY,'ATHENS')
EDIT 2
You could also try with
data(ismember(data.CITY,'ATHENS'),3:end)
This should lead you to the results you expect (at least I guess so).
EDIT 3
Given your last request I would go for this solution:
inp = input('Name of the CITY: ','s')
Name of the City: ATHENS
data(find(strncmp(data.CITY,inp,length(inp))),3:end)