Drools compare two objects in decision table - drools

I have the following code in DRL file
rule "MyExample"
when
$eentity : ExampleEntity()
$sentity : SecondEntity( secondField == $eentity.getMainField())
then
System.out.println(true);
end
This is works but I need to convert it to spreadsheet table. I tried so much variants but no one works. How can I write this rule in decision table?

Use a single condition column:
CONDITION
ExampleEntity($mf: mainField) SecondEntity
secondField == $mf /*param*/
Combine Ex with Sec on equal field values
x
The /*param*/ and the x is a hack to get the condition being generated for the row.

Related

scala increment nested for comprehension

I am working on detecting PI/SI information within given dataset(spark). I have set of rules (in csv format) as below
Rule_No,Target,Pattern,Fuzzy_Match,EPDR,Category,Active
1,Name,name,true,PI - Name,General/ID,true
1,Name,identity,true,PI - Name,General/ID,true
1,Content,Smith,true,PI - Name,General/ID,true
1,Content,Jones,true,PI - Name,General/ID,true
1,Content,Williams,true,PI - Name,General/ID,true
5,Name,Gender,true,PI - Gender,General/ID,true
5,Content,M,false,PI - Gender,General/ID,true
5,Content,F,false,PI - Gender,General/ID,true
5,Content,Male,false,PI - Gender,General/ID,true
5,Content,Female,false,PI - Gender,General/ID,true
What I am trying to do is iterate over dataset columns and apply each of these rules to check whether particular column has PII or not.
So say if I have column called name and given rule says scan the content of this column with pattern say Smith. If I found the match I will know this column is PI column and then move to next column and apply each and every rule until I find a match.
I am using nested for comprehension to iterate over list of columns and list of rules. What I want is when I find a match I want to move to the next column instead of applying remaining rules.
I have written code like this
for {
c <- ds.columns.toList
rule <- rules if rule.active && checkPII(ds, c, rule.target, rule.pattern, rule.fuzzyMatch)
} yield {
<return PII information>
}
but this will apply every rule to same column even if it gets match. How can I move to next column instead of keep applying remaining rules?
for turns into a map call which always checks every elements. You need to use collectFirst, which stops at the first match.
ds.columns.toList.flatMap { c =>
rules.collectFirst {
case rule if rule.active && checkPII(ds, c, rule.target, rule.pattern, rule.fuzzyMatch) =>
<return PII information>
}
}
Using flatMap means that it will discard failed matches and just return a list of matching values.

How to extract columns of data from .txt files MATLAB

I have some data in a .txt file. that are separated by commas.
for example:
1.4,2,3,4,5
2,3,4.2,5,6
24,5,2,33.4,62
what if you want the average of columns, like first column (1.4,2 and 24)? or second column(2,3 and 5)?
I think putting the column in an array and using the built in mean function would work, but so far, I am only able to extract rows, not columns
instead of making another thread, I thought i'd edit this one. I am working on getting the average of each column of the well known iris data set.
I cut a small portion of the data:
5.1,3.5,1.4,0.2,Iris-setosa
4.9,3.0,1.4,0.2,Iris-setosa
4.7,3.2,1.3,0.2,Iris-setosa
4.6,3.1,1.5,0.2,Iris-setosa
5.0,3.6,1.4,0.2,Iris-setosa
5.4,3.9,1.7,0.4,Iris-setosa
4.6,3.4,1.4,0.3,Iris-setosa
delimiterln= ',';
data = importdata('iris.txt', delimiterln);
meanCol1 = mean(data(:,1))
meanCol2 = mean(data(:,2))
meanCol3 = mean(data(:,3))
meanCol4 = mean(data(:,4))
Undefined function 'sum' for input arguments of type 'cell'.
Error in mean (line 115)
y = sum(x, dim, flag)/size(x,dim);
Error in irisData(line 6)
meanCol1 = mean(data(:,1))
it looks like there is an error with handling data type...any thoughts on this? I tried getting rid of the last column, which are strings. and it seems to work without error. So i am thinking that it's because of the strings.
Use comma separated file reading function:
M = csvread(filename);
Now you have the matrix M:
col1Mean=mean(M(:,1));

Best way to select from several LUTs? (Modelica)

In our model of a physical system, we modify one flux value by a factor from a look-up table. The LUT itself is selected from a catalog of LUTs based on an integer index. We're currently loading the table data into CombiTable2D components. What is the correct way to select/define the correct LUT? If we have them all as named tables in one input data file, is there a way to pick an LUT based on it's tableName (the CombiTable parameter)? I've been playing with For loops in either equation or algorithm formats, but haven't found a syntax that works yet.
Thanks in advance for the thoughts...
I think it only works with one table per file so you can have an array of tables, something like:
parameter Integer N = 3;
parameter String selectTable = "tab2";
Modelica.Blocks.Tables.CombiTable2D tableArray[N](
each tableOnFile = true,
fileName = {"file1", "file2", "file3"},
tableName={"tab1", "tab2", "tab3"});
// use the tableArray
for i in 1:N loop
// note that N and selectTable need to be known at compile
// time so that the if and the for loop can be expanded
if (tableArray[i].tableName == selectTable)
then
connect(tableArray[i].u1, u1);
connect(tableArray[i].u2, u2);
connect(tableArray[i].y, y);
endif;
end for;

Print the name of a variable on upon a plot/figure

Is it possible to refer back to/access the names of variables (say nx1 arrays) that make up a matrix? I wish to access them to insert there names into a plot or figure (as a text) that I have created. Here is an example:
A = [supdamp, clgvlv,redamp,extfanstat,htgvlv,occupied,supfanspd]
%lots of code here but not changing A, just using A(:,:)'s
%drawn figure
text(1,1,'supdamp')
...
text(1,n,'supfanspd')
I have failed in an attempt create a string named a with their names in so that I could loop through a(i,1), then use something like text(1,n,'a(i,1)')
Depending on your problem, it might make sense to use structures with dynamical field names.
Especially if your data in the array have some meaning other than just entries of a matrix in linear algebra sense.
# name your variables so that your grandma could understand what they store
A.('supdamp') = supdamp
A.('clgvlv') = clgvlv
...
fieldsOfA = fieldnames(a)
for n = 1 : numel(fieldsOfA )
text(1, n, fieldsOfA{n})
end

How to select rows from character array that match char string and save them in a new array?

I have a char array A which basically contains a list of files names (each row one file)
(char, 526x26)
val =
0815_5275_UBA_A_1971.txt
0815_5275_UBA_A_1972.txt
0823_6275_UBA_A_1971.txt
0823_6275_UBA_A_1972.txt
0823_6275_UBA_A_1973.txt
...
I also have a variable
B = '0815_5275'
I'd like to select all rows (filenames) that start with B and save them in a new array C.
This should be simple, but somehow I can't make it work.
I've got this:
C = A(A(:,1:9) == B);
but I get the error message:
Error using ==
Matrix dimensions must agree.
I do not know in advance how many rows will match, so I can not pre-define an empty array.
thanks, any help is appreciated!
Try ismember(A(:, 1:numel(B)), B, 'rows') rather to get a logical vector that indexes only the rows you want
and now
A(C,:) to extract the rows
The reason you're getting a dimension mismatch error is because your A(:,1:9) has many rows but B only has one and Matlab does not automatically broadcast like Octave or Python. You could do it using either repmat or bsxfun but in this case ismember is the correct function to choose.