wongi-engine 0.4.0.pre.alpha2 → 0.4.0.pre.alpha4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -3
- data/lib/wongi-engine/beta/aggregate_node.rb +44 -53
- data/lib/wongi-engine/beta/ncc_partner.rb +1 -1
- data/lib/wongi-engine/beta/neg_node.rb +2 -5
- data/lib/wongi-engine/compiler.rb +5 -8
- data/lib/wongi-engine/dsl/action/statement_generator.rb +34 -10
- data/lib/wongi-engine/dsl/clause/aggregate.rb +8 -10
- data/lib/wongi-engine/dsl/clause/fact.rb +1 -4
- data/lib/wongi-engine/dsl.rb +18 -8
- data/lib/wongi-engine/token.rb +4 -0
- data/lib/wongi-engine/version.rb +1 -1
- data/spec/action_class_spec.rb +1 -1
- data/spec/aggregate_spec.rb +180 -0
- data/spec/{rule_specs/any_rule_spec.rb → any_rule_spec.rb} +4 -4
- data/spec/{filter_specs/assert_test_spec.rb → assert_test_spec.rb} +5 -5
- data/spec/{rule_specs/assign_spec.rb → assign_spec.rb} +6 -6
- data/spec/{rule_specs/assuming_spec.rb → assuming_spec.rb} +3 -3
- data/spec/beta_node_spec.rb +1 -1
- data/spec/bug_specs/issue_4_spec.rb +4 -4
- data/spec/dataset_spec.rb +1 -1
- data/spec/generation_spec.rb +7 -7
- data/spec/{filter_specs/greater_than_equality_test_spec.rb → greater_than_equality_test_spec.rb} +1 -1
- data/spec/high_level_spec.rb +12 -12
- data/spec/{filter_specs/less_test_spec.rb → less_test_spec.rb} +1 -1
- data/spec/{filter_specs/less_than_equality_test_spec.rb → less_than_equality_test_spec.rb} +1 -1
- data/spec/{rule_specs/maybe_rule_spec.rb → maybe_rule_spec.rb} +7 -7
- data/spec/{rule_specs/ncc_spec.rb → ncc_spec.rb} +28 -5
- data/spec/{rule_specs/negative_rule_spec.rb → negative_rule_spec.rb} +3 -25
- data/spec/network_spec.rb +4 -3
- data/spec/overlay_spec.rb +3 -2
- data/spec/ruleset_spec.rb +6 -6
- data/spec/simple_action_spec.rb +1 -1
- data/spec/wme_spec.rb +4 -4
- metadata +14 -14
- data/spec/rule_specs/aggregate_spec.rb +0 -197
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wongi-engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.0.pre.
|
4
|
+
version: 0.4.0.pre.alpha4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valeri Sokolov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -152,25 +152,25 @@ files:
|
|
152
152
|
- lib/wongi-engine/wme.rb
|
153
153
|
- lib/wongi-engine/wme_match_data.rb
|
154
154
|
- spec/action_class_spec.rb
|
155
|
+
- spec/aggregate_spec.rb
|
155
156
|
- spec/alpha_index_spec.rb
|
157
|
+
- spec/any_rule_spec.rb
|
158
|
+
- spec/assert_test_spec.rb
|
159
|
+
- spec/assign_spec.rb
|
160
|
+
- spec/assuming_spec.rb
|
156
161
|
- spec/beta_node_spec.rb
|
157
162
|
- spec/bug_specs/issue_4_spec.rb
|
158
163
|
- spec/dataset_spec.rb
|
159
|
-
- spec/filter_specs/assert_test_spec.rb
|
160
|
-
- spec/filter_specs/greater_than_equality_test_spec.rb
|
161
|
-
- spec/filter_specs/less_test_spec.rb
|
162
|
-
- spec/filter_specs/less_than_equality_test_spec.rb
|
163
164
|
- spec/generation_spec.rb
|
165
|
+
- spec/greater_than_equality_test_spec.rb
|
164
166
|
- spec/high_level_spec.rb
|
167
|
+
- spec/less_test_spec.rb
|
168
|
+
- spec/less_than_equality_test_spec.rb
|
169
|
+
- spec/maybe_rule_spec.rb
|
170
|
+
- spec/ncc_spec.rb
|
171
|
+
- spec/negative_rule_spec.rb
|
165
172
|
- spec/network_spec.rb
|
166
173
|
- spec/overlay_spec.rb
|
167
|
-
- spec/rule_specs/aggregate_spec.rb
|
168
|
-
- spec/rule_specs/any_rule_spec.rb
|
169
|
-
- spec/rule_specs/assign_spec.rb
|
170
|
-
- spec/rule_specs/assuming_spec.rb
|
171
|
-
- spec/rule_specs/maybe_rule_spec.rb
|
172
|
-
- spec/rule_specs/ncc_spec.rb
|
173
|
-
- spec/rule_specs/negative_rule_spec.rb
|
174
174
|
- spec/ruleset_spec.rb
|
175
175
|
- spec/simple_action_spec.rb
|
176
176
|
- spec/spec_helper.rb
|
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
196
|
- !ruby/object:Gem::Version
|
197
197
|
version: 1.3.1
|
198
198
|
requirements: []
|
199
|
-
rubygems_version: 3.
|
199
|
+
rubygems_version: 3.3.7
|
200
200
|
signing_key:
|
201
201
|
specification_version: 4
|
202
202
|
summary: A forward-chaining rule engine in pure Ruby.
|
@@ -1,197 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'securerandom'
|
3
|
-
|
4
|
-
describe 'aggregate' do
|
5
|
-
include Wongi::Engine::DSL
|
6
|
-
|
7
|
-
let(:engine) { Wongi::Engine.create }
|
8
|
-
let(:rule_name) { SecureRandom.alphanumeric(16) }
|
9
|
-
let(:production) { engine.productions[rule_name] }
|
10
|
-
|
11
|
-
context 'generic clause' do
|
12
|
-
it 'should return a single token' do
|
13
|
-
engine << rule(rule_name) do
|
14
|
-
forall {
|
15
|
-
aggregate :_, :weight, :_, on: :object, function: :min, assign: :X
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
expect(production.size).to be == 0
|
20
|
-
|
21
|
-
engine << [:apple, :weight, 5]
|
22
|
-
expect(production.size).to be == 1
|
23
|
-
expect(production.tokens.first[:X]).to be == 5
|
24
|
-
|
25
|
-
engine << [:pea, :weight, 2]
|
26
|
-
expect(production.size).to be == 1
|
27
|
-
expect(production.tokens.first[:X]).to be == 2
|
28
|
-
|
29
|
-
engine << [:melon, :weight, 15]
|
30
|
-
expect(production.size).to be == 1
|
31
|
-
expect(production.tokens.first[:X]).to be == 2
|
32
|
-
|
33
|
-
engine.retract [:pea, :weight, 2]
|
34
|
-
expect(production.size).to be == 1
|
35
|
-
expect(production.tokens.first[:X]).to be == 5
|
36
|
-
|
37
|
-
engine.retract [:apple, :weight, 5]
|
38
|
-
expect(production.size).to be == 1
|
39
|
-
expect(production.tokens.first[:X]).to be == 15
|
40
|
-
|
41
|
-
engine.retract [:melon, :weight, 15]
|
42
|
-
expect(production.size).to be == 0
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'least' do
|
47
|
-
it 'works' do
|
48
|
-
engine << rule(rule_name) do
|
49
|
-
forall {
|
50
|
-
least :_, :weight, :_, on: :object, assign: :X
|
51
|
-
has :Fruit, :weight, :X
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
engine << [:apple, :weight, 5]
|
56
|
-
expect(production.size).to be == 1
|
57
|
-
expect(production.tokens.first[:X]).to be == 5
|
58
|
-
expect(production.tokens.first[:Fruit]).to be == :apple
|
59
|
-
|
60
|
-
engine << [:pea, :weight, 2]
|
61
|
-
expect(production.size).to be == 1
|
62
|
-
expect(production.tokens.first[:X]).to be == 2
|
63
|
-
expect(production.tokens.first[:Fruit]).to be == :pea
|
64
|
-
|
65
|
-
engine.retract [:pea, :weight, 2]
|
66
|
-
expect(production.size).to be == 1
|
67
|
-
expect(production.tokens.first[:X]).to be == 5
|
68
|
-
expect(production.tokens.first[:Fruit]).to be == :apple
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'min' do
|
73
|
-
it 'works' do
|
74
|
-
engine << rule(rule_name) do
|
75
|
-
forall {
|
76
|
-
min :_, :weight, :_, on: :object, assign: :X
|
77
|
-
has :Fruit, :weight, :X
|
78
|
-
}
|
79
|
-
end
|
80
|
-
|
81
|
-
engine << [:apple, :weight, 5]
|
82
|
-
expect(production.size).to be == 1
|
83
|
-
expect(production.tokens.first[:X]).to be == 5
|
84
|
-
expect(production.tokens.first[:Fruit]).to be == :apple
|
85
|
-
|
86
|
-
engine << [:pea, :weight, 2]
|
87
|
-
expect(production.size).to be == 1
|
88
|
-
expect(production.tokens.first[:X]).to be == 2
|
89
|
-
expect(production.tokens.first[:Fruit]).to be == :pea
|
90
|
-
|
91
|
-
engine.retract [:pea, :weight, 2]
|
92
|
-
expect(production.size).to be == 1
|
93
|
-
expect(production.tokens.first[:X]).to be == 5
|
94
|
-
expect(production.tokens.first[:Fruit]).to be == :apple
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'greatest' do
|
99
|
-
it 'works' do
|
100
|
-
engine << rule(rule_name) do
|
101
|
-
forall {
|
102
|
-
greatest :_, :weight, :_, on: :object, assign: :X
|
103
|
-
has :Fruit, :weight, :X
|
104
|
-
}
|
105
|
-
end
|
106
|
-
|
107
|
-
engine << [:pea, :weight, 2]
|
108
|
-
expect(production.size).to be == 1
|
109
|
-
expect(production.tokens.first[:X]).to be == 2
|
110
|
-
expect(production.tokens.first[:Fruit]).to be == :pea
|
111
|
-
|
112
|
-
engine << [:apple, :weight, 5]
|
113
|
-
expect(production.size).to be == 1
|
114
|
-
expect(production.tokens.first[:X]).to be == 5
|
115
|
-
expect(production.tokens.first[:Fruit]).to be == :apple
|
116
|
-
|
117
|
-
engine.retract [:apple, :weight, 5]
|
118
|
-
expect(production.size).to be == 1
|
119
|
-
expect(production.tokens.first[:X]).to be == 2
|
120
|
-
expect(production.tokens.first[:Fruit]).to be == :pea
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context 'max' do
|
125
|
-
it 'works' do
|
126
|
-
engine << rule(rule_name) do
|
127
|
-
forall {
|
128
|
-
max :_, :weight, :_, on: :object, assign: :X
|
129
|
-
has :Fruit, :weight, :X
|
130
|
-
}
|
131
|
-
end
|
132
|
-
|
133
|
-
engine << [:pea, :weight, 2]
|
134
|
-
expect(production.size).to be == 1
|
135
|
-
expect(production.tokens.first[:X]).to be == 2
|
136
|
-
expect(production.tokens.first[:Fruit]).to be == :pea
|
137
|
-
|
138
|
-
engine << [:apple, :weight, 5]
|
139
|
-
expect(production.size).to be == 1
|
140
|
-
expect(production.tokens.first[:X]).to be == 5
|
141
|
-
expect(production.tokens.first[:Fruit]).to be == :apple
|
142
|
-
|
143
|
-
engine.retract [:apple, :weight, 5]
|
144
|
-
expect(production.size).to be == 1
|
145
|
-
expect(production.tokens.first[:X]).to be == 2
|
146
|
-
expect(production.tokens.first[:Fruit]).to be == :pea
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context 'count' do
|
151
|
-
it 'works' do
|
152
|
-
engine << rule(rule_name) do
|
153
|
-
forall {
|
154
|
-
count :_, :weight, :_, assign: :Count
|
155
|
-
}
|
156
|
-
end
|
157
|
-
|
158
|
-
engine << [:pea, :weight, 1]
|
159
|
-
expect(production.size).to be == 1
|
160
|
-
expect(production.tokens.first[:Count]).to be == 1
|
161
|
-
|
162
|
-
engine << [:apple, :weight, 5]
|
163
|
-
expect(production.size).to be == 1
|
164
|
-
expect(production.tokens.first[:Count]).to be == 2
|
165
|
-
|
166
|
-
engine << [:watermelon, :weight, 15]
|
167
|
-
expect(production.size).to be == 1
|
168
|
-
expect(production.tokens.first[:Count]).to be == 3
|
169
|
-
|
170
|
-
engine.retract [:apple, :weight, 5]
|
171
|
-
expect(production.size).to be == 1
|
172
|
-
expect(production.tokens.first[:Count]).to be == 2
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'works with a post-filter' do
|
176
|
-
engine << rule(rule_name) do
|
177
|
-
forall {
|
178
|
-
count :_, :weight, :_, assign: :Count
|
179
|
-
gte :Count, 3 # pass if at least 3 matching facts exist
|
180
|
-
}
|
181
|
-
end
|
182
|
-
|
183
|
-
engine << [:pea, :weight, 1]
|
184
|
-
expect(production.size).to be == 0
|
185
|
-
|
186
|
-
engine << [:apple, :weight, 5]
|
187
|
-
expect(production.size).to be == 0
|
188
|
-
|
189
|
-
engine << [:watermelon, :weight, 15]
|
190
|
-
expect(production.size).to be == 1
|
191
|
-
expect(production.tokens.first[:Count]).to be == 3
|
192
|
-
|
193
|
-
engine.retract [:apple, :weight, 5]
|
194
|
-
expect(production.size).to be == 0
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|