executeRulesOnDataset: Run a set of rules on a dataset

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/Rdrools.R

Description

The executeRulesOnDataset function is an intuitive interface to execute rules on datasets, which is explicitly designed for data scientists. As input to this function rules are defined using the typical language of data science with verbs such as filter, group by and aggregate. Rules can be specified in a .csv file, loaded into the R session and passed to this function

Usage

1

Arguments

dataset

a data frame on which the defined set of rules should be applied

rules

a data frame in which rules are defined

Details

The vignette provides further details on the format of the rules file

Value

A list of input, intermediate output and output per rule

  1. input: a tibble containing the rules defined by the user

  2. intermediateOutput: is an empty tibble when there is no group by condition specified, and a tibble with the aggregated value for each group when it is

  3. output: a tibble with 3 columns:

    1. Group: represents group name when there is a group by condition specified and the row number in the case that there is no group by condition

    2. Indices: the row numbers corresponding to each group when there is a group by specified and row numbers of the data frame in the case that there is no group by condition

    3. IsTrue: flag indicating if the data point/ set of data points satisfies the rule or not. Returns TRUE if the point or group satisfies the rule and FALSE if not.

Author(s)

Dheekshitha PS < Dheekshitha.PS@mu-sigma.com>

Naren Srinivasan <Naren.Srinivasan@mu-sigma.com>

Mayukh Bose <Mayukh.Bose@mu-sigma.com>

See Also

runRulesDrl, Rdrools

Other Interface Functions to Drools: rulesSessionDrl, runRulesDrl

Examples

1
2
3
4
5
6
7
## Not run: 
  library(Rdrools)
  data("iris")
  data("irisRules")
  executeRulesOnDataset(iris, irisRules)
  
## End(Not run)

Example output

Loading required package: rJava
Loading required package: Rdroolsjars
List of 1
 $ :List of 20
  ..$ : chr "import java.util.HashMap"
  ..$ : chr "import java.lang.Double"
  ..$ : chr "global java.util.HashMap output"
  ..$ : chr ""
  ..$ : chr "  dialect \"mvel\""
  ..$ : chr "rule \"Rule1\""
  ..$ : chr "       salience 0"
  ..$ : chr "       when"
  ..$ : chr "        input: HashMap()"
  ..$ : chr "result: Double()\n                               from accumulate($condition:HashMap(),(Double.valueOf($conditio"| __truncated__
  ..$ : chr "then"
  ..$ : chr "output.put('SepalLength',input.get('SepalLength'));"
  ..$ : chr "output.put('SepalWidth',input.get('SepalWidth'));"
  ..$ : chr "output.put('PetalLength',input.get('PetalLength'));"
  ..$ : chr "output.put('PetalWidth',input.get('PetalWidth'));"
  ..$ : chr "output.put('Species',input.get('Species'));"
  ..$ : chr "output.put('rowNumber',input.get('rowNumber'));"
  ..$ : chr "output.put(\"Rule1\",result);"
  ..$ : chr "output.put('Rule1Value',result);"
  ..$ : chr "end"
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
List of 1
 $ :List of 20
  ..$ : chr "import java.util.HashMap"
  ..$ : chr "import java.lang.Double"
  ..$ : chr "global java.util.HashMap output"
  ..$ : chr ""
  ..$ : chr "  dialect \"mvel\""
  ..$ : chr "rule \"Rule2\""
  ..$ : chr "       salience 0"
  ..$ : chr "       when"
  ..$ : chr "        input: HashMap()"
  ..$ : chr "result: Double()\n                                 from accumulate($condition:HashMap(Species == input.get(\"Sp"| __truncated__
  ..$ : chr "then"
  ..$ : chr "output.put('SepalLength',input.get('SepalLength'));"
  ..$ : chr "output.put('SepalWidth',input.get('SepalWidth'));"
  ..$ : chr "output.put('PetalLength',input.get('PetalLength'));"
  ..$ : chr "output.put('PetalWidth',input.get('PetalWidth'));"
  ..$ : chr "output.put('Species',input.get('Species'));"
  ..$ : chr "output.put('rowNumber',input.get('rowNumber'));"
  ..$ : chr "output.put(\"Rule2\",result>=5.9);"
  ..$ : chr "output.put('Rule2Value',result);"
  ..$ : chr "end"
List of 1
 $ :List of 20
  ..$ : chr "import java.util.HashMap"
  ..$ : chr "import java.lang.Double"
  ..$ : chr "global java.util.HashMap output"
  ..$ : chr ""
  ..$ : chr "  dialect \"mvel\""
  ..$ : chr "rule \"Rule3\""
  ..$ : chr "       salience 0"
  ..$ : chr "       when"
  ..$ : chr "        input: HashMap()"
  ..$ : chr "result: Double()\n                               from accumulate($condition:HashMap(),average(Double.valueOf($c"| __truncated__
  ..$ : chr "then"
  ..$ : chr "output.put('SepalLength',input.get('SepalLength'));"
  ..$ : chr "output.put('SepalWidth',input.get('SepalWidth'));"
  ..$ : chr "output.put('PetalLength',input.get('PetalLength'));"
  ..$ : chr "output.put('PetalWidth',input.get('PetalWidth'));"
  ..$ : chr "output.put('Species',input.get('Species'));"
  ..$ : chr "output.put('rowNumber',input.get('rowNumber'));"
  ..$ : chr "output.put(\"Rule3\",result<5);"
  ..$ : chr "output.put('Rule3Value',result);"
  ..$ : chr "end"
List of 1
 $ :List of 20
  ..$ : chr "import java.util.HashMap"
  ..$ : chr "import java.lang.Double"
  ..$ : chr "global java.util.HashMap output"
  ..$ : chr ""
  ..$ : chr "  dialect \"mvel\""
  ..$ : chr "rule \"Rule4\""
  ..$ : chr "       salience 0"
  ..$ : chr "       when"
  ..$ : chr "        input: HashMap()"
  ..$ : chr "result: Double()\n                               from accumulate($condition:HashMap(),average(Double.valueOf($c"| __truncated__
  ..$ : chr "then"
  ..$ : chr "output.put('SepalLength',input.get('SepalLength'));"
  ..$ : chr "output.put('SepalWidth',input.get('SepalWidth'));"
  ..$ : chr "output.put('PetalLength',input.get('PetalLength'));"
  ..$ : chr "output.put('PetalWidth',input.get('PetalWidth'));"
  ..$ : chr "output.put('Species',input.get('Species'));"
  ..$ : chr "output.put('rowNumber',input.get('rowNumber'));"
  ..$ : chr "output.put(\"Rule4\",result>=5);"
  ..$ : chr "output.put('Rule4Value',result);"
  ..$ : chr "end"
List of 1
 $ :List of 20
  ..$ : chr "import java.util.HashMap"
  ..$ : chr "import java.lang.Double"
  ..$ : chr "global java.util.HashMap output"
  ..$ : chr ""
  ..$ : chr "  dialect \"mvel\""
  ..$ : chr "rule \"Rule5\""
  ..$ : chr "       salience 0"
  ..$ : chr "       when"
  ..$ : chr "        input: HashMap()"
  ..$ : chr "result: Double()\n                                 from accumulate($condition:HashMap(Species == input.get(\"Sp"| __truncated__
  ..$ : chr "then"
  ..$ : chr "output.put('SepalLength',input.get('SepalLength'));"
  ..$ : chr "output.put('SepalWidth',input.get('SepalWidth'));"
  ..$ : chr "output.put('PetalLength',input.get('PetalLength'));"
  ..$ : chr "output.put('PetalWidth',input.get('PetalWidth'));"
  ..$ : chr "output.put('Species',input.get('Species'));"
  ..$ : chr "output.put('rowNumber',input.get('rowNumber'));"
  ..$ : chr "output.put(\"Rule5\",result<5);"
  ..$ : chr "output.put('Rule5Value',result);"
  ..$ : chr "end"
List of 1
 $ :List of 20
  ..$ : chr "import java.util.HashMap"
  ..$ : chr "import java.lang.Double"
  ..$ : chr "global java.util.HashMap output"
  ..$ : chr ""
  ..$ : chr "  dialect \"mvel\""
  ..$ : chr "rule \"Rule6\""
  ..$ : chr "       salience 0"
  ..$ : chr "       when"
  ..$ : chr "        input: HashMap()"
  ..$ : chr "result: Double()\n                               from accumulate($condition:HashMap(),compare(Double.valueOf($c"| __truncated__
  ..$ : chr "then"
  ..$ : chr "output.put('SepalLength',input.get('SepalLength'));"
  ..$ : chr "output.put('SepalWidth',input.get('SepalWidth'));"
  ..$ : chr "output.put('PetalLength',input.get('PetalLength'));"
  ..$ : chr "output.put('PetalWidth',input.get('PetalWidth'));"
  ..$ : chr "output.put('Species',input.get('Species'));"
  ..$ : chr "output.put('rowNumber',input.get('rowNumber'));"
  ..$ : chr "output.put(\"Rule6\",result>=SepalWidth);"
  ..$ : chr "output.put('Rule6Value',result);"
  ..$ : chr "end"
List of 1
 $ :List of 20
  ..$ : chr "import java.util.HashMap"
  ..$ : chr "import java.lang.Double"
  ..$ : chr "global java.util.HashMap output"
  ..$ : chr ""
  ..$ : chr "  dialect \"mvel\""
  ..$ : chr "rule \"Rule7\""
  ..$ : chr "       salience 0"
  ..$ : chr "       when"
  ..$ : chr "        input: HashMap()"
  ..$ : chr "result: Double()\n                               from accumulate($condition:HashMap(),compare(Double.valueOf($c"| __truncated__
  ..$ : chr "then"
  ..$ : chr "output.put('SepalLength',input.get('SepalLength'));"
  ..$ : chr "output.put('SepalWidth',input.get('SepalWidth'));"
  ..$ : chr "output.put('PetalLength',input.get('PetalLength'));"
  ..$ : chr "output.put('PetalWidth',input.get('PetalWidth'));"
  ..$ : chr "output.put('Species',input.get('Species'));"
  ..$ : chr "output.put('rowNumber',input.get('rowNumber'));"
  ..$ : chr "output.put(\"Rule7\",result>=SepalWidth);"
  ..$ : chr "output.put('Rule7Value',result);"
  ..$ : chr "end"
[[1]]
[[1]]$input
# A tibble: 1 x 7
  Filters             GroupBy Column Function Operation Argument ruleNum
  <chr>               <chr>   <chr>  <chr>    <chr>     <chr>      <int>
1 Species == 'setosa' ""      ""     ""       ""        ""             1

[[1]]$intermediateOutput
list()

[[1]]$output
    Group Indices IsTrue
1       1       1   true
2       2       2   true
3       3       3   true
4       4       4   true
5       5       5   true
6       6       6   true
7       7       7   true
8       8       8   true
9       9       9   true
10     10      10   true
11     11      11   true
12     12      12   true
13     13      13   true
14     14      14   true
15     15      15   true
16     16      16   true
17     17      17   true
18     18      18   true
19     19      19   true
20     20      20   true
21     21      21   true
22     22      22   true
23     23      23   true
24     24      24   true
25     25      25   true
26     26      26   true
27     27      27   true
28     28      28   true
29     29      29   true
30     30      30   true
31     31      31   true
32     32      32   true
33     33      33   true
34     34      34   true
35     35      35   true
36     36      36   true
37     37      37   true
38     38      38   true
39     39      39   true
40     40      40   true
41     41      41   true
42     42      42   true
43     43      43   true
44     44      44   true
45     45      45   true
46     46      46   true
47     47      47   true
48     48      48   true
49     49      49   true
50     50      50   true
51     51      51  false
52     52      52  false
53     53      53  false
54     54      54  false
55     55      55  false
56     56      56  false
57     57      57  false
58     58      58  false
59     59      59  false
60     60      60  false
61     61      61  false
62     62      62  false
63     63      63  false
64     64      64  false
65     65      65  false
66     66      66  false
67     67      67  false
68     68      68  false
69     69      69  false
70     70      70  false
71     71      71  false
72     72      72  false
73     73      73  false
74     74      74  false
75     75      75  false
76     76      76  false
77     77      77  false
78     78      78  false
79     79      79  false
80     80      80  false
81     81      81  false
82     82      82  false
83     83      83  false
84     84      84  false
85     85      85  false
86     86      86  false
87     87      87  false
88     88      88  false
89     89      89  false
90     90      90  false
91     91      91  false
92     92      92  false
93     93      93  false
94     94      94  false
95     95      95  false
96     96      96  false
97     97      97  false
98     98      98  false
99     99      99  false
100   100     100  false
101   101     101  false
102   102     102  false
103   103     103  false
104   104     104  false
105   105     105  false
106   106     106  false
107   107     107  false
108   108     108  false
109   109     109  false
110   110     110  false
111   111     111  false
112   112     112  false
113   113     113  false
114   114     114  false
115   115     115  false
116   116     116  false
117   117     117  false
118   118     118  false
119   119     119  false
120   120     120  false
121   121     121  false
122   122     122  false
123   123     123  false
124   124     124  false
125   125     125  false
126   126     126  false
127   127     127  false
128   128     128  false
129   129     129  false
130   130     130  false
131   131     131  false
132   132     132  false
133   133     133  false
134   134     134  false
135   135     135  false
136   136     136  false
137   137     137  false
138   138     138  false
139   139     139  false
140   140     140  false
141   141     141  false
142   142     142  false
143   143     143  false
144   144     144  false
145   145     145  false
146   146     146  false
147   147     147  false
148   148     148  false
149   149     149  false
150   150     150  false


[[2]]
[[2]]$input
# A tibble: 1 x 7
  Filters GroupBy Column      Function Operation Argument ruleNum
  <chr>   <chr>   <chr>       <chr>    <chr>     <chr>      <int>
1 ""      Species SepalLength average  >=        5.9            2

[[2]]$intermediateOutput
# A tibble: 3 x 3
  Species    Rule2 Rule2Value
  <fct>      <fct>      <dbl>
1 setosa     false       5.01
2 versicolor true        5.94
3 virginica  true        6.59

[[2]]$output
# A tibble: 3 x 3
  Group     Indices                                                       IsTrue
  <chr>     <chr>                                                         <fct> 
1 setosa    1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,~ false 
2 versicol~ 51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,~ true  
3 virginica 101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,~ true  


[[3]]
[[3]]$input
# A tibble: 1 x 7
  Filters GroupBy Column      Function Operation Argument ruleNum
  <chr>   <chr>   <chr>       <chr>    <chr>     <chr>      <int>
1 ""      ""      SepalLength average  <         5              3

[[3]]$intermediateOutput
list()

[[3]]$output
# A tibble: 1 x 3
  Group Indices                                                           IsTrue
  <dbl> <chr>                                                             <fct> 
1     1 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,2~ false 


[[4]]
[[4]]$input
# A tibble: 1 x 7
  Filters        GroupBy Column      Function Operation Argument ruleNum
  <chr>          <chr>   <chr>       <chr>    <chr>     <chr>      <int>
1 SepalWidth > 3 ""      SepalLength average  >=        5              4

[[4]]$intermediateOutput
list()

[[4]]$output
# A tibble: 1 x 3
  Group Indices                                                           IsTrue
  <dbl> <chr>                                                             <fct> 
1     1 1,3,4,5,6,7,8,10,11,12,15,16,17,18,19,20,21,22,23,24,25,27,28,29~ true  


[[5]]
[[5]]$input
# A tibble: 1 x 7
  Filters          GroupBy Column      Function Operation Argument ruleNum
  <chr>            <chr>   <chr>       <chr>    <chr>     <chr>      <int>
1 PetalWidth > 0.4 Species PetalLength average  <         5              5

[[5]]$intermediateOutput
# A tibble: 3 x 3
  Species    Rule5 Rule5Value
  <fct>      <fct>      <dbl>
1 setosa     true        1.65
2 versicolor true        4.26
3 virginica  false       5.55

[[5]]$output
# A tibble: 3 x 3
  Group     Indices                                                       IsTrue
  <chr>     <chr>                                                         <fct> 
1 setosa    24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,~ true  
2 versicol~ 51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,~ true  
3 virginica 101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,~ false 


[[6]]
[[6]]$input
# A tibble: 1 x 7
  Filters GroupBy Column      Function Operation Argument   ruleNum
  <chr>   <chr>   <chr>       <chr>    <chr>     <chr>        <int>
1 ""      ""      PetalLength compare  >=        SepalWidth       6

[[6]]$intermediateOutput
list()

[[6]]$output
    Group Indices IsTrue
1      51      51   true
2      52      52   true
3      53      53   true
4      54      54   true
5      55      55   true
6      56      56   true
7      57      57   true
8      58      58   true
9      59      59   true
10     60      60   true
11     61      61   true
12     62      62   true
13     63      63   true
14     64      64   true
15     65      65   true
16     66      66   true
17     67      67   true
18     68      68   true
19     69      69   true
20     70      70   true
21     71      71   true
22     72      72   true
23     73      73   true
24     74      74   true
25     75      75   true
26     76      76   true
27     77      77   true
28     78      78   true
29     79      79   true
30     80      80   true
31     81      81   true
32     82      82   true
33     83      83   true
34     84      84   true
35     85      85   true
36     86      86   true
37     87      87   true
38     88      88   true
39     89      89   true
40     90      90   true
41     91      91   true
42     92      92   true
43     93      93   true
44     94      94   true
45     95      95   true
46     96      96   true
47     97      97   true
48     98      98   true
49     99      99   true
50    100     100   true
51    101     101   true
52    102     102   true
53    103     103   true
54    104     104   true
55    105     105   true
56    106     106   true
57    107     107   true
58    108     108   true
59    109     109   true
60    110     110   true
61    111     111   true
62    112     112   true
63    113     113   true
64    114     114   true
65    115     115   true
66    116     116   true
67    117     117   true
68    118     118   true
69    119     119   true
70    120     120   true
71    121     121   true
72    122     122   true
73    123     123   true
74    124     124   true
75    125     125   true
76    126     126   true
77    127     127   true
78    128     128   true
79    129     129   true
80    130     130   true
81    131     131   true
82    132     132   true
83    133     133   true
84    134     134   true
85    135     135   true
86    136     136   true
87    137     137   true
88    138     138   true
89    139     139   true
90    140     140   true
91    141     141   true
92    142     142   true
93    143     143   true
94    144     144   true
95    145     145   true
96    146     146   true
97    147     147   true
98    148     148   true
99    149     149   true
100   150     150   true
101     1       1  false
102     2       2  false
103     3       3  false
104     4       4  false
105     5       5  false
106     6       6  false
107     7       7  false
108     8       8  false
109     9       9  false
110    10      10  false
111    11      11  false
112    12      12  false
113    13      13  false
114    14      14  false
115    15      15  false
116    16      16  false
117    17      17  false
118    18      18  false
119    19      19  false
120    20      20  false
121    21      21  false
122    22      22  false
123    23      23  false
124    24      24  false
125    25      25  false
126    26      26  false
127    27      27  false
128    28      28  false
129    29      29  false
130    30      30  false
131    31      31  false
132    32      32  false
133    33      33  false
134    34      34  false
135    35      35  false
136    36      36  false
137    37      37  false
138    38      38  false
139    39      39  false
140    40      40  false
141    41      41  false
142    42      42  false
143    43      43  false
144    44      44  false
145    45      45  false
146    46      46  false
147    47      47  false
148    48      48  false
149    49      49  false
150    50      50  false


[[7]]
[[7]]$input
# A tibble: 1 x 7
  Filters               GroupBy Column      Function Operation Argument  ruleNum
  <chr>                 <chr>   <chr>       <chr>    <chr>     <chr>       <int>
1 Species == 'versicol~ ""      PetalLength compare  >=        SepalWid~       7

[[7]]$intermediateOutput
list()

[[7]]$output
    Group Indices IsTrue
1      51      51   true
2      52      52   true
3      53      53   true
4      54      54   true
5      55      55   true
6      56      56   true
7      57      57   true
8      58      58   true
9      59      59   true
10     60      60   true
11     61      61   true
12     62      62   true
13     63      63   true
14     64      64   true
15     65      65   true
16     66      66   true
17     67      67   true
18     68      68   true
19     69      69   true
20     70      70   true
21     71      71   true
22     72      72   true
23     73      73   true
24     74      74   true
25     75      75   true
26     76      76   true
27     77      77   true
28     78      78   true
29     79      79   true
30     80      80   true
31     81      81   true
32     82      82   true
33     83      83   true
34     84      84   true
35     85      85   true
36     86      86   true
37     87      87   true
38     88      88   true
39     89      89   true
40     90      90   true
41     91      91   true
42     92      92   true
43     93      93   true
44     94      94   true
45     95      95   true
46     96      96   true
47     97      97   true
48     98      98   true
49     99      99   true
50    100     100   true
51      1       1  false
52      2       2  false
53      3       3  false
54      4       4  false
55      5       5  false
56      6       6  false
57      7       7  false
58      8       8  false
59      9       9  false
60     10      10  false
61     11      11  false
62     12      12  false
63     13      13  false
64     14      14  false
65     15      15  false
66     16      16  false
67     17      17  false
68     18      18  false
69     19      19  false
70     20      20  false
71     21      21  false
72     22      22  false
73     23      23  false
74     24      24  false
75     25      25  false
76     26      26  false
77     27      27  false
78     28      28  false
79     29      29  false
80     30      30  false
81     31      31  false
82     32      32  false
83     33      33  false
84     34      34  false
85     35      35  false
86     36      36  false
87     37      37  false
88     38      38  false
89     39      39  false
90     40      40  false
91     41      41  false
92     42      42  false
93     43      43  false
94     44      44  false
95     45      45  false
96     46      46  false
97     47      47  false
98     48      48  false
99     49      49  false
100    50      50  false
101   101     101  false
102   102     102  false
103   103     103  false
104   104     104  false
105   105     105  false
106   106     106  false
107   107     107  false
108   108     108  false
109   109     109  false
110   110     110  false
111   111     111  false
112   112     112  false
113   113     113  false
114   114     114  false
115   115     115  false
116   116     116  false
117   117     117  false
118   118     118  false
119   119     119  false
120   120     120  false
121   121     121  false
122   122     122  false
123   123     123  false
124   124     124  false
125   125     125  false
126   126     126  false
127   127     127  false
128   128     128  false
129   129     129  false
130   130     130  false
131   131     131  false
132   132     132  false
133   133     133  false
134   134     134  false
135   135     135  false
136   136     136  false
137   137     137  false
138   138     138  false
139   139     139  false
140   140     140  false
141   141     141  false
142   142     142  false
143   143     143  false
144   144     144  false
145   145     145  false
146   146     146  false
147   147     147  false
148   148     148  false
149   149     149  false
150   150     150  false

Rdrools documentation built on May 2, 2019, 8:23 a.m.