wongi-engine 0.0.14 → 0.0.16
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/.travis.yml +8 -0
- data/README.md +3 -11
- data/lib/wongi-engine/beta/beta_memory.rb +3 -4
- data/lib/wongi-engine/beta/beta_node.rb +5 -0
- data/lib/wongi-engine/beta/neg_node.rb +92 -94
- data/lib/wongi-engine/beta/production_node.rb +1 -2
- data/lib/wongi-engine/dsl/actions/statement_generator.rb +55 -55
- data/lib/wongi-engine/network.rb +442 -443
- data/lib/wongi-engine/token.rb +138 -133
- data/lib/wongi-engine/version.rb +1 -1
- data/lib/wongi-engine/wme.rb +138 -140
- data/spec/bug_specs/issue_4_spec.rb +9 -9
- data/spec/dataset_spec.rb +3 -3
- data/spec/filter_specs/assert_test_spec.rb +6 -6
- data/spec/filter_specs/less_test_spec.rb +1 -1
- data/spec/high_level_spec.rb +34 -34
- data/spec/rule_specs/any_rule_spec.rb +4 -4
- data/spec/rule_specs/assign_spec.rb +3 -4
- data/spec/rule_specs/maybe_rule_spec.rb +12 -12
- data/spec/rule_specs/ncc_spec.rb +6 -6
- data/spec/rule_specs/negative_rule_spec.rb +70 -70
- data/spec/ruleset_spec.rb +8 -8
- data/spec/simple_action_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/wme_spec.rb +21 -21
- data/wongi-engine.gemspec +6 -2
- metadata +53 -9
data/spec/high_level_spec.rb
CHANGED
@@ -34,11 +34,11 @@ describe 'the engine' do
|
|
34
34
|
|
35
35
|
rete << Wongi::Engine::WME.new( "friend", "symmetric", true )
|
36
36
|
rete << Wongi::Engine::WME.new( "Alice", "friend", "Bob" )
|
37
|
-
|
38
|
-
rete.
|
39
|
-
rete.facts.select( &:manual? ).
|
37
|
+
|
38
|
+
expect(rete.facts.to_a.length).to eq(3)
|
39
|
+
expect(rete.facts.select( &:manual? ).length).to eq(2)
|
40
40
|
generated = rete.facts.find( &:generated? )
|
41
|
-
generated.
|
41
|
+
expect( generated ).to be == Wongi::Engine::WME.new( "Bob", "friend", "Alice" )
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should generate wmes with an added rule' do
|
@@ -46,7 +46,7 @@ describe 'the engine' do
|
|
46
46
|
rete << Wongi::Engine::WME.new( "friend", "symmetric", true )
|
47
47
|
rete << Wongi::Engine::WME.new( "Alice", "friend", "Bob" )
|
48
48
|
|
49
|
-
rete.
|
49
|
+
expect(rete.facts.to_a.length).to eq(2)
|
50
50
|
|
51
51
|
rete << rule('symmetric') {
|
52
52
|
forall {
|
@@ -58,8 +58,8 @@ describe 'the engine' do
|
|
58
58
|
}
|
59
59
|
}
|
60
60
|
|
61
|
-
rete.
|
62
|
-
rete.facts.select( &:manual? ).
|
61
|
+
expect(rete.facts.to_a.length).to eq(3)
|
62
|
+
expect(rete.facts.select( &:manual? ).size).to eq(2)
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'should not get confused by recursive activations' do
|
@@ -78,9 +78,9 @@ describe 'the engine' do
|
|
78
78
|
rete << [:p, "reflexive", true]
|
79
79
|
rete << [:x, :p, :y]
|
80
80
|
|
81
|
-
expect(
|
82
|
-
expect(
|
83
|
-
expect(
|
81
|
+
expect(rete.wmes.to_a.length).to eq(4)
|
82
|
+
expect(rete.select(:x, :p, :x).length).to eq(1)
|
83
|
+
expect(rete.select(:y, :p, :y).length).to eq(1)
|
84
84
|
|
85
85
|
end
|
86
86
|
|
@@ -99,7 +99,7 @@ describe 'the engine' do
|
|
99
99
|
}
|
100
100
|
|
101
101
|
rete << [ 42, "same", 42 ]
|
102
|
-
node.
|
102
|
+
expect(node.size).to eq(1)
|
103
103
|
|
104
104
|
end
|
105
105
|
|
@@ -131,10 +131,10 @@ describe 'the engine' do
|
|
131
131
|
rete << ["Bob", :age, 43]
|
132
132
|
|
133
133
|
items = rete.select "Alice", :younger, "Bob"
|
134
|
-
items.
|
134
|
+
expect(items.size).to eq(1)
|
135
135
|
|
136
136
|
items = rete.select "Bob", :older, "Alice"
|
137
|
-
items.
|
137
|
+
expect(items.size).to eq(1)
|
138
138
|
|
139
139
|
end
|
140
140
|
|
@@ -153,8 +153,8 @@ describe 'the engine' do
|
|
153
153
|
rete << [ "question", "is", -1 ]
|
154
154
|
|
155
155
|
collection = rete.collection(:test_collector)
|
156
|
-
collection.
|
157
|
-
collection.first.
|
156
|
+
expect(collection.size).to eq(1)
|
157
|
+
expect(collection.first).to eq("answer")
|
158
158
|
|
159
159
|
end
|
160
160
|
|
@@ -173,14 +173,14 @@ describe 'the engine' do
|
|
173
173
|
rete << [ "question", "is", -1 ]
|
174
174
|
|
175
175
|
collection = rete.collection(:things_that_are_42)
|
176
|
-
collection.
|
177
|
-
collection.first.
|
176
|
+
expect(collection.size).to eq(1)
|
177
|
+
expect(collection.first).to eq("answer")
|
178
178
|
|
179
179
|
end
|
180
180
|
|
181
181
|
it 'should accept several rules' do
|
182
182
|
|
183
|
-
|
183
|
+
expect {
|
184
184
|
|
185
185
|
rete << rule('generic-collector') {
|
186
186
|
forall {
|
@@ -200,7 +200,7 @@ describe 'the engine' do
|
|
200
200
|
}
|
201
201
|
}
|
202
202
|
|
203
|
-
|
203
|
+
}.not_to raise_error
|
204
204
|
|
205
205
|
end
|
206
206
|
|
@@ -212,11 +212,11 @@ describe 'the engine' do
|
|
212
212
|
}
|
213
213
|
})
|
214
214
|
|
215
|
-
production.
|
215
|
+
expect(production.size).to eq(1)
|
216
216
|
|
217
217
|
rete << [ "answer", "is", 42 ]
|
218
218
|
|
219
|
-
production.
|
219
|
+
expect(production.size).to eq(0)
|
220
220
|
|
221
221
|
end
|
222
222
|
|
@@ -232,8 +232,8 @@ describe 'the engine' do
|
|
232
232
|
rete << ["answer", "is", 42]
|
233
233
|
|
234
234
|
rete.execute "test-query", {X: "answer"}
|
235
|
-
rete.results["test-query"].
|
236
|
-
rete.results["test-query"].tokens.first[:Y].
|
235
|
+
expect(rete.results["test-query"].size).to eq(1)
|
236
|
+
expect(rete.results["test-query"].tokens.first[:Y]).to eq(42)
|
237
237
|
|
238
238
|
end
|
239
239
|
|
@@ -247,11 +247,11 @@ describe 'the engine' do
|
|
247
247
|
}
|
248
248
|
}
|
249
249
|
|
250
|
-
production.
|
250
|
+
expect(production.size).to eq(0)
|
251
251
|
|
252
252
|
rete << [1, 2, 3]
|
253
253
|
|
254
|
-
production.
|
254
|
+
expect(production.size).to eq(0)
|
255
255
|
|
256
256
|
end
|
257
257
|
|
@@ -266,7 +266,7 @@ describe 'the engine' do
|
|
266
266
|
rete << [1, 2, 3]
|
267
267
|
rete.snapshot!
|
268
268
|
|
269
|
-
production.
|
269
|
+
expect(production.size).to eq(1)
|
270
270
|
|
271
271
|
end
|
272
272
|
|
@@ -280,10 +280,10 @@ describe 'the engine' do
|
|
280
280
|
}
|
281
281
|
make { action { count += 1} }
|
282
282
|
end
|
283
|
-
production.
|
283
|
+
expect(production.size).to eq(0)
|
284
284
|
rete.snapshot!
|
285
285
|
rete << [1, 2, 3]
|
286
|
-
production.
|
286
|
+
expect(production.size).to eq(1)
|
287
287
|
#puts count
|
288
288
|
end
|
289
289
|
|
@@ -296,9 +296,9 @@ describe 'the engine' do
|
|
296
296
|
make { action { count += 1} }
|
297
297
|
end
|
298
298
|
rete << [1, 2, 3]
|
299
|
-
production.
|
299
|
+
expect(production.size).to eq(1)
|
300
300
|
rete.snapshot!
|
301
|
-
production.
|
301
|
+
expect(production.size).to eq(0)
|
302
302
|
#puts count
|
303
303
|
end
|
304
304
|
|
@@ -315,9 +315,9 @@ describe 'the engine' do
|
|
315
315
|
make { action { count += 1} }
|
316
316
|
end
|
317
317
|
rete << [1, 2, 3]
|
318
|
-
production.
|
318
|
+
expect(production.size).to eq(0)
|
319
319
|
rete.snapshot!
|
320
|
-
production.
|
320
|
+
expect(production.size).to eq(1)
|
321
321
|
#puts count
|
322
322
|
end
|
323
323
|
|
@@ -329,10 +329,10 @@ describe 'the engine' do
|
|
329
329
|
}
|
330
330
|
make { action { count += 1} }
|
331
331
|
end
|
332
|
-
production.
|
332
|
+
expect(production.size).to eq(0)
|
333
333
|
rete.snapshot!
|
334
334
|
rete << [1, 2, 3]
|
335
|
-
production.
|
335
|
+
expect(production.size).to eq(0)
|
336
336
|
#puts count
|
337
337
|
end
|
338
338
|
|
@@ -30,7 +30,7 @@ describe "ANY rule" do
|
|
30
30
|
engine << [1, 2, 3]
|
31
31
|
engine << [3, 4, 5]
|
32
32
|
|
33
|
-
production.
|
33
|
+
expect(production.size).to eq(1)
|
34
34
|
|
35
35
|
end
|
36
36
|
|
@@ -64,9 +64,9 @@ describe "ANY rule" do
|
|
64
64
|
engine << [1, 2, "three"]
|
65
65
|
engine << ["three", "four", "five"]
|
66
66
|
|
67
|
-
production.
|
68
|
-
engine.collection(:threes).
|
69
|
-
engine.collection(:threes).
|
67
|
+
expect(production.size).to eq(2)
|
68
|
+
expect( engine.collection(:threes) ).to include(3)
|
69
|
+
expect( engine.collection(:threes) ).to include("three")
|
70
70
|
|
71
71
|
end
|
72
72
|
|
@@ -27,9 +27,8 @@ describe "ASSIGN rule" do
|
|
27
27
|
end
|
28
28
|
}
|
29
29
|
}
|
30
|
-
|
31
|
-
production.
|
32
|
-
production.tokens.first[:X].should == 42
|
30
|
+
expect(production.size).to eq(1)
|
31
|
+
expect(production.tokens.first[:X]).to eq(42)
|
33
32
|
|
34
33
|
end
|
35
34
|
|
@@ -45,7 +44,7 @@ describe "ASSIGN rule" do
|
|
45
44
|
}
|
46
45
|
|
47
46
|
engine << [1, 2, 5]
|
48
|
-
production.tokens.first[:Y].
|
47
|
+
expect(production.tokens.first[:Y]).to eq(10)
|
49
48
|
|
50
49
|
end
|
51
50
|
|
@@ -19,15 +19,15 @@ describe "MAYBE rule" do
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
production = engine.productions['test']
|
23
23
|
|
24
24
|
engine << [1, 2, 3]
|
25
25
|
engine << [3, 4, 5]
|
26
26
|
|
27
|
-
|
27
|
+
expect(production.size).to eq(1)
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
expect(production.tokens.first[:X]).to eq(3)
|
30
|
+
expect(production.tokens.first[:Y]).to eq(5)
|
31
31
|
|
32
32
|
end
|
33
33
|
|
@@ -40,14 +40,14 @@ describe "MAYBE rule" do
|
|
40
40
|
}
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
production = engine.productions['test']
|
44
44
|
|
45
45
|
engine << [1, 2, 3]
|
46
46
|
|
47
|
-
|
47
|
+
expect(production.size).to eq(1)
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
expect(production.tokens.first[:X]).to eq(3)
|
50
|
+
expect(production.tokens.first[:Y]).to be_nil
|
51
51
|
|
52
52
|
end
|
53
53
|
|
@@ -62,12 +62,12 @@ describe "MAYBE rule" do
|
|
62
62
|
}
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
production = engine.productions['test']
|
66
66
|
|
67
|
-
|
67
|
+
expect(production.size).to eq(1)
|
68
68
|
|
69
|
-
|
70
|
-
|
69
|
+
expect(production.tokens.first[:X]).to eq(3)
|
70
|
+
expect(production.tokens.first[:Y]).to be_nil
|
71
71
|
|
72
72
|
end
|
73
73
|
|
data/spec/rule_specs/ncc_spec.rb
CHANGED
@@ -29,15 +29,15 @@ describe "NCC rule" do
|
|
29
29
|
|
30
30
|
engine << ["base", "is", 1]
|
31
31
|
|
32
|
-
production.
|
32
|
+
expect(production.size).to eq(1)
|
33
33
|
|
34
34
|
engine << [1, 2, 3]
|
35
35
|
|
36
|
-
production.
|
36
|
+
expect(production.size).to eq(1)
|
37
37
|
|
38
38
|
engine << [3, 4, 5]
|
39
39
|
|
40
|
-
production.
|
40
|
+
expect(production.size).to eq(0)
|
41
41
|
|
42
42
|
end
|
43
43
|
|
@@ -50,13 +50,13 @@ describe "NCC rule" do
|
|
50
50
|
engine << [1, 2, 3]
|
51
51
|
engine << [3, 4, 5]
|
52
52
|
|
53
|
-
production.
|
53
|
+
expect(production.size).to eq(0)
|
54
54
|
|
55
55
|
engine.retract [3, 4, 5]
|
56
|
-
production.
|
56
|
+
expect( production ).to have(1).token
|
57
57
|
|
58
58
|
engine.retract ["base", "is", 1]
|
59
|
-
production.
|
59
|
+
expect(production.size).to eq(0)
|
60
60
|
|
61
61
|
end
|
62
62
|
|
@@ -1,70 +1,70 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "negative rule" do
|
4
|
-
|
5
|
-
before :each do
|
6
|
-
@engine = Wongi::Engine.create
|
7
|
-
end
|
8
|
-
|
9
|
-
def engine
|
10
|
-
@engine
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should not introduce variables" do
|
14
|
-
|
15
|
-
proc = lambda {
|
16
|
-
|
17
|
-
engine << rule('one-option') {
|
18
|
-
forall {
|
19
|
-
neg :Foo, :bar, :_
|
20
|
-
}
|
21
|
-
make {
|
22
|
-
action { |tokens|
|
23
|
-
raise "This should never get executed #{tokens}"
|
24
|
-
}
|
25
|
-
}
|
26
|
-
}
|
27
|
-
|
28
|
-
}
|
29
|
-
|
30
|
-
proc.
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
# it "should not create infinite feedback loops by default" do
|
35
|
-
|
36
|
-
# engine << rule('feedback') {
|
37
|
-
# forall {
|
38
|
-
# neg :a, :b, :_
|
39
|
-
# }
|
40
|
-
# make {
|
41
|
-
# gen :a, :b, :c
|
42
|
-
# }
|
43
|
-
# }
|
44
|
-
|
45
|
-
# engine.should have(1).facts
|
46
|
-
|
47
|
-
# end
|
48
|
-
|
49
|
-
it "should create infinite feedback loops with unsafe option" do
|
50
|
-
|
51
|
-
counter = 0
|
52
|
-
exception = Class.new( StandardError )
|
53
|
-
|
54
|
-
proc = lambda {
|
55
|
-
engine << rule('feedback') {
|
56
|
-
forall {
|
57
|
-
neg :a, :b, :_, unsafe: true
|
58
|
-
}
|
59
|
-
make {
|
60
|
-
action { counter += 1 ; if counter > 5 then raise exception.new end }
|
61
|
-
gen :a, :b, :c
|
62
|
-
}
|
63
|
-
}
|
64
|
-
}
|
65
|
-
|
66
|
-
proc.
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "negative rule" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@engine = Wongi::Engine.create
|
7
|
+
end
|
8
|
+
|
9
|
+
def engine
|
10
|
+
@engine
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not introduce variables" do
|
14
|
+
|
15
|
+
proc = lambda {
|
16
|
+
|
17
|
+
engine << rule('one-option') {
|
18
|
+
forall {
|
19
|
+
neg :Foo, :bar, :_
|
20
|
+
}
|
21
|
+
make {
|
22
|
+
action { |tokens|
|
23
|
+
raise "This should never get executed #{tokens}"
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
}
|
29
|
+
|
30
|
+
expect( &proc ).to raise_error( Wongi::Engine::DefinitionError )
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
# it "should not create infinite feedback loops by default" do
|
35
|
+
|
36
|
+
# engine << rule('feedback') {
|
37
|
+
# forall {
|
38
|
+
# neg :a, :b, :_
|
39
|
+
# }
|
40
|
+
# make {
|
41
|
+
# gen :a, :b, :c
|
42
|
+
# }
|
43
|
+
# }
|
44
|
+
|
45
|
+
# engine.should have(1).facts
|
46
|
+
|
47
|
+
# end
|
48
|
+
|
49
|
+
it "should create infinite feedback loops with unsafe option" do
|
50
|
+
|
51
|
+
counter = 0
|
52
|
+
exception = Class.new( StandardError )
|
53
|
+
|
54
|
+
proc = lambda {
|
55
|
+
engine << rule('feedback') {
|
56
|
+
forall {
|
57
|
+
neg :a, :b, :_, unsafe: true
|
58
|
+
}
|
59
|
+
make {
|
60
|
+
action { counter += 1 ; if counter > 5 then raise exception.new end }
|
61
|
+
gen :a, :b, :c
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
expect( &proc ).to raise_error( exception )
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
data/spec/ruleset_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe Wongi::Engine::Ruleset do
|
|
9
9
|
context 'initially' do
|
10
10
|
|
11
11
|
it 'should have no rules' do
|
12
|
-
Wongi::Engine::Ruleset.rulesets.
|
12
|
+
expect( Wongi::Engine::Ruleset.rulesets ).to be_empty
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
@@ -18,19 +18,19 @@ describe Wongi::Engine::Ruleset do
|
|
18
18
|
|
19
19
|
it 'should not register itself when not given a name' do
|
20
20
|
ruleset = Wongi::Engine::Ruleset.new
|
21
|
-
ruleset.name.
|
22
|
-
Wongi::Engine::Ruleset.rulesets.
|
21
|
+
expect( ruleset.name ).to be_nil
|
22
|
+
expect( Wongi::Engine::Ruleset.rulesets ).to be_empty
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should have a name' do
|
26
26
|
ruleset = Wongi::Engine::Ruleset.new 'testing-ruleset'
|
27
|
-
ruleset.name.
|
27
|
+
expect( ruleset.name ).to be == 'testing-ruleset'
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should register itself when given a name' do
|
31
31
|
ruleset = Wongi::Engine::Ruleset.new 'testing-ruleset'
|
32
|
-
Wongi::Engine::Ruleset.rulesets.
|
33
|
-
Wongi::Engine::Ruleset[ruleset.name].
|
32
|
+
expect( Wongi::Engine::Ruleset.rulesets ).not_to be_empty
|
33
|
+
expect( Wongi::Engine::Ruleset[ruleset.name] ).to be == ruleset
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
@@ -38,7 +38,7 @@ describe Wongi::Engine::Ruleset do
|
|
38
38
|
it 'should be able to clear registered rulesets' do
|
39
39
|
ruleset = Wongi::Engine::Ruleset.new 'testing-ruleset'
|
40
40
|
Wongi::Engine::Ruleset.reset
|
41
|
-
Wongi::Engine::Ruleset.rulesets.
|
41
|
+
expect( Wongi::Engine::Ruleset.rulesets ).to be_empty
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should install creating rules into a rete' do
|
@@ -47,7 +47,7 @@ describe Wongi::Engine::Ruleset do
|
|
47
47
|
ruleset = Wongi::Engine::Ruleset.new
|
48
48
|
rule = ruleset.rule( 'test-rule' ) { }
|
49
49
|
|
50
|
-
rete.
|
50
|
+
expect( rete ).to receive(:<<).with(rule).once
|
51
51
|
ruleset.install rete
|
52
52
|
end
|
53
53
|
|
data/spec/simple_action_spec.rb
CHANGED
@@ -25,15 +25,15 @@ describe Wongi::Engine::SimpleAction do
|
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
|
-
count.
|
28
|
+
expect(count).to eq(0)
|
29
29
|
|
30
30
|
rete << [1, 2, 3]
|
31
31
|
|
32
|
-
count.
|
32
|
+
expect(count).to eq(1)
|
33
33
|
|
34
34
|
rete << [1, 2, 4]
|
35
35
|
|
36
|
-
count.
|
36
|
+
expect(count).to eq(2)
|
37
37
|
|
38
38
|
end
|
39
39
|
|
data/spec/spec_helper.rb
CHANGED
data/spec/wme_spec.rb
CHANGED
@@ -4,9 +4,9 @@ describe Wongi::Engine::WME do
|
|
4
4
|
|
5
5
|
def capitalizing_rete
|
6
6
|
rete = double 'rete'
|
7
|
-
rete.
|
8
|
-
rete.
|
9
|
-
rete.
|
7
|
+
expect( rete ).to receive(:import).with("b").and_return("B")
|
8
|
+
expect( rete ).to receive(:import).with("a").and_return("A")
|
9
|
+
expect( rete ).to receive(:import).with("c").and_return("C")
|
10
10
|
rete
|
11
11
|
end
|
12
12
|
|
@@ -17,9 +17,9 @@ describe Wongi::Engine::WME do
|
|
17
17
|
context 'a new WME' do
|
18
18
|
|
19
19
|
it 'should initialize and expose members' do
|
20
|
-
subject.subject.
|
21
|
-
subject.predicate.
|
22
|
-
subject.object.
|
20
|
+
expect( subject.subject ).to be == "a"
|
21
|
+
expect( subject.predicate ).to be == "b"
|
22
|
+
expect( subject.object ).to be == "c"
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should use the rete to import members' do
|
@@ -28,19 +28,19 @@ describe Wongi::Engine::WME do
|
|
28
28
|
|
29
29
|
wme = Wongi::Engine::WME.new "a", "b", "c", rete
|
30
30
|
|
31
|
-
wme.subject.
|
32
|
-
wme.predicate.
|
33
|
-
wme.object.
|
31
|
+
expect( wme.subject ).to be == "A"
|
32
|
+
expect( wme.predicate ).to be == "B"
|
33
|
+
expect( wme.object ).to be == "C"
|
34
34
|
|
35
35
|
end
|
36
36
|
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
it {
|
39
|
+
should be_manual
|
40
40
|
}
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
it {
|
43
|
+
should_not be_generated
|
44
44
|
}
|
45
45
|
|
46
46
|
end
|
@@ -51,9 +51,9 @@ describe Wongi::Engine::WME do
|
|
51
51
|
|
52
52
|
imported = subject.import_into rete
|
53
53
|
|
54
|
-
imported.subject.
|
55
|
-
imported.predicate.
|
56
|
-
imported.object.
|
54
|
+
expect( imported.subject ).to be == "A"
|
55
|
+
expect( imported.predicate ).to be == "B"
|
56
|
+
expect( imported.object ).to be == "C"
|
57
57
|
|
58
58
|
end
|
59
59
|
|
@@ -63,21 +63,21 @@ describe Wongi::Engine::WME do
|
|
63
63
|
wme2 = Wongi::Engine::WME.new "a", "b", "c"
|
64
64
|
wme3 = Wongi::Engine::WME.new "a", "b", "d"
|
65
65
|
|
66
|
-
wme1.
|
67
|
-
wme1.
|
66
|
+
expect( wme1 ).to be == wme2
|
67
|
+
expect( wme1 ).not_to be == wme3
|
68
68
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'should not match against non-templates' do
|
72
|
-
|
72
|
+
expect { subject =~ [1, 2, 3] }.to raise_error
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'should match against templates' do
|
76
76
|
t1 = Wongi::Engine::Template.new "a", :_, :_
|
77
77
|
t2 = Wongi::Engine::Template.new "b", :_, :_
|
78
78
|
|
79
|
-
subject.
|
80
|
-
subject.
|
79
|
+
expect( subject ).to be =~ t1
|
80
|
+
expect( subject ).not_to be =~ t2
|
81
81
|
end
|
82
82
|
|
83
83
|
end
|
data/wongi-engine.gemspec
CHANGED
@@ -5,8 +5,9 @@ Gem::Specification.new do |gem|
|
|
5
5
|
gem.authors = ["Valeri Sokolov"]
|
6
6
|
gem.email = ["ulfurinn@ulfurinn.net"]
|
7
7
|
gem.description = %q{A rule engine.}
|
8
|
-
gem.summary = %q{A rule engine.}
|
8
|
+
gem.summary = %q{A forward-chaining rule engine in pure Ruby.}
|
9
9
|
gem.homepage = "https://github.com/ulfurinn/wongi-engine"
|
10
|
+
gem.licenses = %w(MIT)
|
10
11
|
|
11
12
|
gem.files = `git ls-files`.split($\)
|
12
13
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -15,5 +16,8 @@ Gem::Specification.new do |gem|
|
|
15
16
|
gem.require_paths = ["lib"]
|
16
17
|
gem.version = Wongi::Engine::VERSION
|
17
18
|
|
18
|
-
gem.add_development_dependency '
|
19
|
+
gem.add_development_dependency 'rake', '~> 10'
|
20
|
+
gem.add_development_dependency 'pry', '~> 0.10'
|
21
|
+
gem.add_development_dependency 'rspec', '~> 3.1', '< 3.2'
|
22
|
+
gem.add_development_dependency 'rspec-collection_matchers', '~> 1.1'
|
19
23
|
end
|