wongi-engine 0.1.4 → 0.2.0
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/.hgignore +6 -0
- data/.hgtags +2 -4
- data/.travis.yml +19 -6
- data/README.md +18 -442
- data/examples/ex02.rb +3 -2
- data/examples/graphviz.rb +1 -0
- data/lib/wongi-engine/alpha_memory.rb +11 -6
- data/lib/wongi-engine/beta/assignment_node.rb +0 -15
- data/lib/wongi-engine/beta/beta_memory.rb +7 -31
- data/lib/wongi-engine/beta/beta_node.rb +25 -95
- data/lib/wongi-engine/beta/join_node.rb +14 -46
- data/lib/wongi-engine/beta/ncc_node.rb +8 -34
- data/lib/wongi-engine/beta/ncc_partner.rb +3 -19
- data/lib/wongi-engine/beta/neg_node.rb +7 -16
- data/lib/wongi-engine/beta/optional_node.rb +23 -30
- data/lib/wongi-engine/beta/or_node.rb +0 -51
- data/lib/wongi-engine/beta/production_node.rb +1 -0
- data/lib/wongi-engine/compiler.rb +115 -0
- data/lib/wongi-engine/data_overlay.rb +140 -0
- data/lib/wongi-engine/dsl/action/base.rb +11 -0
- data/lib/wongi-engine/dsl/{actions → action}/error_generator.rb +3 -14
- data/lib/wongi-engine/dsl/action/simple_action.rb +60 -0
- data/lib/wongi-engine/dsl/action/simple_collector.rb +52 -0
- data/lib/wongi-engine/dsl/action/statement_generator.rb +45 -0
- data/lib/wongi-engine/dsl/action/trace_action.rb +49 -0
- data/lib/wongi-engine/dsl/any_rule.rb +4 -21
- data/lib/wongi-engine/dsl/assuming.rb +6 -12
- data/lib/wongi-engine/dsl/builder.rb +44 -0
- data/lib/wongi-engine/dsl/clause/assign.rb +15 -0
- data/lib/wongi-engine/dsl/clause/fact.rb +71 -0
- data/lib/wongi-engine/dsl/clause/gen.rb +17 -0
- data/lib/wongi-engine/dsl/clause/generic.rb +38 -0
- data/lib/wongi-engine/dsl/{dsl_extensions.rb → generated.rb} +5 -5
- data/lib/wongi-engine/dsl/ncc_subrule.rb +15 -0
- data/lib/wongi-engine/dsl/query.rb +10 -11
- data/lib/wongi-engine/dsl/rule.rb +84 -0
- data/lib/wongi-engine/dsl.rb +102 -97
- data/lib/wongi-engine/enumerators.rb +21 -0
- data/lib/wongi-engine/error.rb +13 -2
- data/lib/wongi-engine/filter/filter_test.rb +1 -13
- data/lib/wongi-engine/graph.rb +7 -7
- data/lib/wongi-engine/network.rb +108 -181
- data/lib/wongi-engine/ruleset.rb +6 -6
- data/lib/wongi-engine/template.rb +30 -84
- data/lib/wongi-engine/token.rb +3 -34
- data/lib/wongi-engine/version.rb +1 -1
- data/lib/wongi-engine/wme.rb +9 -60
- data/lib/wongi-engine.rb +3 -0
- data/spec/beta_node_spec.rb +2 -0
- data/spec/generation_spec.rb +1 -1
- data/spec/high_level_spec.rb +29 -11
- data/spec/overlay_spec.rb +22 -0
- data/spec/simple_action_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/wme_spec.rb +22 -22
- data/wongi-engine.gemspec +1 -1
- metadata +37 -17
- data/lib/wongi-engine/dsl/action.rb +0 -12
- data/lib/wongi-engine/dsl/actions/simple_action.rb +0 -62
- data/lib/wongi-engine/dsl/actions/simple_collector.rb +0 -51
- data/lib/wongi-engine/dsl/actions/statement_generator.rb +0 -67
- data/lib/wongi-engine/dsl/actions/trace_action.rb +0 -52
- data/lib/wongi-engine/dsl/dsl_builder.rb +0 -44
- data/lib/wongi-engine/dsl/extension_clause.rb +0 -36
- data/lib/wongi-engine/dsl/generation_clause.rb +0 -15
- data/lib/wongi-engine/dsl/generic_production_rule.rb +0 -82
- data/lib/wongi-engine/dsl/ncc_production_rule.rb +0 -21
- data/lib/wongi-engine/dsl/production_rule.rb +0 -4
- data/lib/wongi-engine/model_context.rb +0 -13
data/lib/wongi-engine/token.rb
CHANGED
|
@@ -7,6 +7,7 @@ module Wongi::Engine
|
|
|
7
7
|
attr_reader :children
|
|
8
8
|
attr_reader :wme
|
|
9
9
|
attr_reader :node
|
|
10
|
+
attr_reader :overlay
|
|
10
11
|
attr_accessor :owner, :parent
|
|
11
12
|
attr_reader :neg_join_results
|
|
12
13
|
attr_reader :opt_join_results
|
|
@@ -17,6 +18,7 @@ module Wongi::Engine
|
|
|
17
18
|
|
|
18
19
|
def initialize node, token, wme, assignments
|
|
19
20
|
@node, @parent, @wme, @assignments = node, token, wme, assignments
|
|
21
|
+
@overlay = wme ? wme.overlay.highest(token.overlay) : node.rete.default_overlay
|
|
20
22
|
@children = []
|
|
21
23
|
@deleted = false
|
|
22
24
|
@neg_join_results = []
|
|
@@ -24,7 +26,6 @@ module Wongi::Engine
|
|
|
24
26
|
@ncc_results = []
|
|
25
27
|
@generated_wmes = []
|
|
26
28
|
token.children << self if token
|
|
27
|
-
wme.tokens << self if wme
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
def ancestors
|
|
@@ -58,32 +59,16 @@ module Wongi::Engine
|
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
def to_s
|
|
61
|
-
str = "TOKEN [ parent=#{parent ? parent.object_id : 'nil'} "
|
|
62
|
+
str = "TOKEN [ #{object_id} parent=#{parent ? parent.object_id : 'nil'} "
|
|
62
63
|
all_assignments.each_pair { |key, value| str << "#{key} => #{value} " }
|
|
63
64
|
str << "]"
|
|
64
65
|
str
|
|
65
66
|
end
|
|
66
67
|
|
|
67
68
|
def destroy
|
|
68
|
-
# delete_children
|
|
69
|
-
# #@node.tokens.delete self unless @node.kind_of?( NccPartner )
|
|
70
|
-
# @wme.tokens.delete self if @wme
|
|
71
|
-
# @parent.children.delete self if @parent
|
|
72
|
-
|
|
73
|
-
# retract_generated
|
|
74
69
|
deleted!
|
|
75
|
-
# @node.delete_token self
|
|
76
70
|
end
|
|
77
71
|
|
|
78
|
-
# def delete_children
|
|
79
|
-
# children = @children
|
|
80
|
-
# @children = []
|
|
81
|
-
# children.each do |token|
|
|
82
|
-
# token.parent = nil
|
|
83
|
-
# token.destroy
|
|
84
|
-
# end
|
|
85
|
-
# end
|
|
86
|
-
|
|
87
72
|
# for neg feedback loop protection
|
|
88
73
|
def generated? wme
|
|
89
74
|
return true if generated_wmes.any? { |w| w == wme }
|
|
@@ -92,22 +77,6 @@ module Wongi::Engine
|
|
|
92
77
|
|
|
93
78
|
protected
|
|
94
79
|
|
|
95
|
-
# def retract_generated
|
|
96
|
-
# for_retraction = []
|
|
97
|
-
|
|
98
|
-
# @generated_wmes.dup.each do |wme|
|
|
99
|
-
# unless wme.manual? # => TODO: does this ever fail at all?
|
|
100
|
-
# wme.generating_tokens.delete self
|
|
101
|
-
# if wme.generating_tokens.empty?
|
|
102
|
-
# for_retraction << wme
|
|
103
|
-
# end
|
|
104
|
-
# end
|
|
105
|
-
# end
|
|
106
|
-
# @generated_wmes = []
|
|
107
|
-
# for_retraction.each { |wme| wme.rete.retract wme, true }
|
|
108
|
-
|
|
109
|
-
# end
|
|
110
|
-
|
|
111
80
|
def all_assignments
|
|
112
81
|
raise "Assignments is not a hash" unless @assignments.kind_of?( Hash )
|
|
113
82
|
if @parent
|
data/lib/wongi-engine/version.rb
CHANGED
data/lib/wongi-engine/wme.rb
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
module Wongi::Engine
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
WME = Struct.new( :subject, :predicate, :object ) do
|
|
4
4
|
|
|
5
5
|
include CoreExt
|
|
6
6
|
|
|
7
7
|
attr_reader :rete
|
|
8
8
|
|
|
9
|
-
attr_reader :
|
|
9
|
+
attr_reader :generating_tokens
|
|
10
10
|
attr_reader :neg_join_results, :opt_join_results
|
|
11
|
+
attr_accessor :overlay
|
|
11
12
|
attr_predicate :deleted
|
|
12
13
|
attr_predicate :manual
|
|
13
14
|
|
|
@@ -17,29 +18,27 @@ module Wongi::Engine
|
|
|
17
18
|
|
|
18
19
|
@deleted = false
|
|
19
20
|
@alphas = []
|
|
20
|
-
@tokens = []
|
|
21
21
|
@generating_tokens = []
|
|
22
22
|
@neg_join_results = []
|
|
23
23
|
@opt_join_results = []
|
|
24
24
|
|
|
25
25
|
@rete = r
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
else
|
|
30
|
-
super( s, p, o )
|
|
31
|
-
end
|
|
27
|
+
# TODO: reintroduce Network#import when bringing back RDF support
|
|
28
|
+
super( s, p, o )
|
|
32
29
|
|
|
33
30
|
end
|
|
34
31
|
|
|
35
32
|
def import_into r
|
|
36
33
|
self.class.new( subject, predicate, object, r ).tap do |wme|
|
|
34
|
+
wme.overlay = overlay
|
|
37
35
|
wme.manual = self.manual?
|
|
38
36
|
end
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
def dup
|
|
42
40
|
self.class.new( subject, predicate, object, rete ).tap do |wme|
|
|
41
|
+
wme.overlay = overlay
|
|
43
42
|
wme.manual = self.manual?
|
|
44
43
|
end
|
|
45
44
|
end
|
|
@@ -49,7 +48,7 @@ module Wongi::Engine
|
|
|
49
48
|
end
|
|
50
49
|
|
|
51
50
|
def =~ template
|
|
52
|
-
raise "Cannot match a WME against a #{template.class}" unless Template === template
|
|
51
|
+
raise Wongi::Engine::Error, "Cannot match a WME against a #{template.class}" unless Template === template
|
|
53
52
|
result = match_member( self.subject, template.subject ) & match_member( self.predicate, template.predicate ) & match_member( self.object, template.object )
|
|
54
53
|
if result.match?
|
|
55
54
|
result
|
|
@@ -60,19 +59,6 @@ module Wongi::Engine
|
|
|
60
59
|
!generating_tokens.empty?
|
|
61
60
|
end
|
|
62
61
|
|
|
63
|
-
# def destroy
|
|
64
|
-
# return if deleted?
|
|
65
|
-
# @deleted = true
|
|
66
|
-
# alphas.each { |alpha| alpha.remove self }.clear
|
|
67
|
-
# tokens = @tokens
|
|
68
|
-
# @tokens = []
|
|
69
|
-
# tokens.each &:destroy
|
|
70
|
-
|
|
71
|
-
# destroy_neg_join_results
|
|
72
|
-
# destroy_opt_join_results
|
|
73
|
-
|
|
74
|
-
# end
|
|
75
|
-
|
|
76
62
|
def inspect
|
|
77
63
|
"{#{subject.inspect} #{predicate.inspect} #{object.inspect}}"
|
|
78
64
|
end
|
|
@@ -82,48 +68,11 @@ module Wongi::Engine
|
|
|
82
68
|
end
|
|
83
69
|
|
|
84
70
|
def hash
|
|
85
|
-
@hash ||=
|
|
71
|
+
@hash ||= [subject.hash, predicate.hash, object.hash].hash
|
|
86
72
|
end
|
|
87
73
|
|
|
88
74
|
protected
|
|
89
75
|
|
|
90
|
-
def array_form
|
|
91
|
-
@array_form ||= [ subject, predicate, object ]
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# def destroy_neg_join_results
|
|
95
|
-
# neg_join_results.each do |njr|
|
|
96
|
-
|
|
97
|
-
# token = njr.owner
|
|
98
|
-
# results = token.neg_join_results
|
|
99
|
-
# results.delete njr
|
|
100
|
-
|
|
101
|
-
# if results.empty? #&& !rete.in_snapshot?
|
|
102
|
-
# token.node.children.each { |beta|
|
|
103
|
-
# beta.beta_activate token, nil, { }
|
|
104
|
-
# }
|
|
105
|
-
# end
|
|
106
|
-
|
|
107
|
-
# end.clear
|
|
108
|
-
# end
|
|
109
|
-
|
|
110
|
-
# def destroy_opt_join_results
|
|
111
|
-
# opt_join_results.each do |ojr|
|
|
112
|
-
|
|
113
|
-
# token = ojr.owner
|
|
114
|
-
# results = token.opt_join_results
|
|
115
|
-
# results.delete ojr
|
|
116
|
-
|
|
117
|
-
# if results.empty?
|
|
118
|
-
# token.delete_children
|
|
119
|
-
# token.node.children.each { |beta|
|
|
120
|
-
# beta.beta_activate token
|
|
121
|
-
# }
|
|
122
|
-
# end
|
|
123
|
-
|
|
124
|
-
# end.clear
|
|
125
|
-
# end
|
|
126
|
-
|
|
127
76
|
def match_member mine, theirs
|
|
128
77
|
result = WMEMatchData.new
|
|
129
78
|
if theirs == :_ || mine == theirs
|
data/lib/wongi-engine.rb
CHANGED
|
@@ -29,5 +29,8 @@ require 'wongi-engine/alpha_memory'
|
|
|
29
29
|
require 'wongi-engine/beta'
|
|
30
30
|
require 'wongi-engine/dsl'
|
|
31
31
|
require 'wongi-engine/ruleset'
|
|
32
|
+
require 'wongi-engine/compiler'
|
|
33
|
+
require 'wongi-engine/data_overlay'
|
|
34
|
+
require 'wongi-engine/enumerators'
|
|
32
35
|
require 'wongi-engine/network'
|
|
33
36
|
require 'wongi-engine/graph'
|
data/spec/beta_node_spec.rb
CHANGED
data/spec/generation_spec.rb
CHANGED
data/spec/high_level_spec.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
+
include Wongi::Engine::DSL
|
|
4
|
+
|
|
3
5
|
dsl {
|
|
4
6
|
|
|
5
7
|
section :make
|
|
6
8
|
clause :test_collector
|
|
7
|
-
action Wongi::Engine::SimpleCollector.collector
|
|
9
|
+
action Wongi::Engine::DSL::Action::SimpleCollector.collector
|
|
8
10
|
|
|
9
11
|
}
|
|
10
12
|
|
|
@@ -220,20 +222,36 @@ describe 'the engine' do
|
|
|
220
222
|
|
|
221
223
|
end
|
|
222
224
|
|
|
223
|
-
|
|
225
|
+
context 'queries' do
|
|
224
226
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
before :each do
|
|
228
|
+
rete << query("test-query") {
|
|
229
|
+
search_on :X
|
|
230
|
+
forall {
|
|
231
|
+
has :X, "is", :Y
|
|
232
|
+
}
|
|
229
233
|
}
|
|
230
|
-
|
|
234
|
+
end
|
|
231
235
|
|
|
232
|
-
|
|
236
|
+
it 'should run' do
|
|
237
|
+
rete << ["answer", "is", 42]
|
|
238
|
+
rete.execute "test-query", {X: "answer"}
|
|
239
|
+
expect(rete.results["test-query"].size).to eq(1)
|
|
240
|
+
expect(rete.results["test-query"].tokens.first[:Y]).to eq(42)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it 'should run several times' do
|
|
244
|
+
rete << ["answer", "is", 42]
|
|
245
|
+
rete << ['question', 'is', '6x9']
|
|
246
|
+
rete.execute "test-query", {X: "answer"}
|
|
247
|
+
rete.execute "test-query", {X: "question"}
|
|
248
|
+
expect(rete.results["test-query"].tokens.to_a.last[:Y]).to eq('6x9')
|
|
249
|
+
expect(rete.results["test-query"].size).to eq(1)
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
end
|
|
233
253
|
|
|
234
|
-
|
|
235
|
-
expect(rete.results["test-query"].size).to eq(1)
|
|
236
|
-
expect(rete.results["test-query"].tokens.first[:Y]).to eq(42)
|
|
254
|
+
it 'should correctly execute a query several times' do
|
|
237
255
|
|
|
238
256
|
end
|
|
239
257
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Wongi::Engine::DataOverlay do
|
|
4
|
+
include Wongi::Engine::DSL
|
|
5
|
+
|
|
6
|
+
let(:engine) { Wongi::Engine.create }
|
|
7
|
+
|
|
8
|
+
it 'should be disposable' do
|
|
9
|
+
production = engine << rule {
|
|
10
|
+
forall {
|
|
11
|
+
has 1, 2, :X
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
engine.with_overlay { |overlay|
|
|
15
|
+
overlay << [1,2,3]
|
|
16
|
+
expect(production).to have(1).token
|
|
17
|
+
}
|
|
18
|
+
expect(production).to have(0).tokens
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
data/spec/simple_action_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/wme_spec.rb
CHANGED
|
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Wongi::Engine::WME do
|
|
4
4
|
|
|
5
|
-
def capitalizing_rete
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
end
|
|
5
|
+
# def capitalizing_rete
|
|
6
|
+
# rete = double '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
|
+
# rete
|
|
11
|
+
# end
|
|
12
12
|
|
|
13
13
|
subject {
|
|
14
14
|
Wongi::Engine::WME.new "a", "b", "c"
|
|
@@ -22,17 +22,17 @@ describe Wongi::Engine::WME do
|
|
|
22
22
|
expect( subject.object ).to be == "c"
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
it 'should use the rete to import members' do
|
|
25
|
+
# it 'should use the rete to import members' do
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
# rete = capitalizing_rete
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
# wme = Wongi::Engine::WME.new "a", "b", "c", rete
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
# expect( wme.subject ).to be == "A"
|
|
32
|
+
# expect( wme.predicate ).to be == "B"
|
|
33
|
+
# expect( wme.object ).to be == "C"
|
|
34
34
|
|
|
35
|
-
end
|
|
35
|
+
# end
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
it {
|
|
@@ -45,17 +45,17 @@ describe Wongi::Engine::WME do
|
|
|
45
45
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
it 'should be able to import into rete' do
|
|
48
|
+
# it 'should be able to import into rete' do
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
# rete = capitalizing_rete
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
# imported = subject.import_into rete
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
# expect( imported.subject ).to be == "A"
|
|
55
|
+
# expect( imported.predicate ).to be == "B"
|
|
56
|
+
# expect( imported.object ).to be == "C"
|
|
57
57
|
|
|
58
|
-
end
|
|
58
|
+
# end
|
|
59
59
|
|
|
60
60
|
it 'should compare instances' do
|
|
61
61
|
|
|
@@ -69,7 +69,7 @@ describe Wongi::Engine::WME do
|
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
it 'should not match against non-templates' do
|
|
72
|
-
expect { subject =~ [1, 2, 3] }.to raise_error
|
|
72
|
+
expect { subject =~ [1, 2, 3] }.to raise_error( Wongi::Engine::Error )
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it 'should match against templates' do
|
data/wongi-engine.gemspec
CHANGED
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |gem|
|
|
|
33
33
|
gem.version = Wongi::Engine::VERSION
|
|
34
34
|
|
|
35
35
|
gem.add_development_dependency 'rake', '~> 10.0'
|
|
36
|
-
|
|
36
|
+
gem.add_development_dependency 'pry', '~> 0.10'
|
|
37
37
|
# gem.add_development_dependency 'pry-byebug', '~> 2.0'
|
|
38
38
|
gem.add_development_dependency 'rspec', '~> 3.1'
|
|
39
39
|
gem.add_development_dependency 'rspec-collection_matchers', '~> 1.1'
|
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
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Valeri Sokolov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-11-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -24,6 +24,20 @@ dependencies:
|
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '10.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: pry
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0.10'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0.10'
|
|
27
41
|
- !ruby/object:Gem::Dependency
|
|
28
42
|
name: rspec
|
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -60,6 +74,7 @@ extensions: []
|
|
|
60
74
|
extra_rdoc_files: []
|
|
61
75
|
files:
|
|
62
76
|
- ".gitignore"
|
|
77
|
+
- ".hgignore"
|
|
63
78
|
- ".hgtags"
|
|
64
79
|
- ".ruby-gemset"
|
|
65
80
|
- ".travis.yml"
|
|
@@ -87,24 +102,28 @@ files:
|
|
|
87
102
|
- lib/wongi-engine/beta/optional_node.rb
|
|
88
103
|
- lib/wongi-engine/beta/or_node.rb
|
|
89
104
|
- lib/wongi-engine/beta/production_node.rb
|
|
105
|
+
- lib/wongi-engine/compiler.rb
|
|
90
106
|
- lib/wongi-engine/core_ext.rb
|
|
107
|
+
- lib/wongi-engine/data_overlay.rb
|
|
91
108
|
- lib/wongi-engine/dsl.rb
|
|
92
|
-
- lib/wongi-engine/dsl/action.rb
|
|
93
|
-
- lib/wongi-engine/dsl/
|
|
94
|
-
- lib/wongi-engine/dsl/
|
|
95
|
-
- lib/wongi-engine/dsl/
|
|
96
|
-
- lib/wongi-engine/dsl/
|
|
97
|
-
- lib/wongi-engine/dsl/
|
|
109
|
+
- lib/wongi-engine/dsl/action/base.rb
|
|
110
|
+
- lib/wongi-engine/dsl/action/error_generator.rb
|
|
111
|
+
- lib/wongi-engine/dsl/action/simple_action.rb
|
|
112
|
+
- lib/wongi-engine/dsl/action/simple_collector.rb
|
|
113
|
+
- lib/wongi-engine/dsl/action/statement_generator.rb
|
|
114
|
+
- lib/wongi-engine/dsl/action/trace_action.rb
|
|
98
115
|
- lib/wongi-engine/dsl/any_rule.rb
|
|
99
116
|
- lib/wongi-engine/dsl/assuming.rb
|
|
100
|
-
- lib/wongi-engine/dsl/
|
|
101
|
-
- lib/wongi-engine/dsl/
|
|
102
|
-
- lib/wongi-engine/dsl/
|
|
103
|
-
- lib/wongi-engine/dsl/
|
|
104
|
-
- lib/wongi-engine/dsl/
|
|
105
|
-
- lib/wongi-engine/dsl/
|
|
106
|
-
- lib/wongi-engine/dsl/
|
|
117
|
+
- lib/wongi-engine/dsl/builder.rb
|
|
118
|
+
- lib/wongi-engine/dsl/clause/assign.rb
|
|
119
|
+
- lib/wongi-engine/dsl/clause/fact.rb
|
|
120
|
+
- lib/wongi-engine/dsl/clause/gen.rb
|
|
121
|
+
- lib/wongi-engine/dsl/clause/generic.rb
|
|
122
|
+
- lib/wongi-engine/dsl/generated.rb
|
|
123
|
+
- lib/wongi-engine/dsl/ncc_subrule.rb
|
|
107
124
|
- lib/wongi-engine/dsl/query.rb
|
|
125
|
+
- lib/wongi-engine/dsl/rule.rb
|
|
126
|
+
- lib/wongi-engine/enumerators.rb
|
|
108
127
|
- lib/wongi-engine/error.rb
|
|
109
128
|
- lib/wongi-engine/filter.rb
|
|
110
129
|
- lib/wongi-engine/filter/asserting_test.rb
|
|
@@ -114,7 +133,6 @@ files:
|
|
|
114
133
|
- lib/wongi-engine/filter/inequality_test.rb
|
|
115
134
|
- lib/wongi-engine/filter/less_than_test.rb
|
|
116
135
|
- lib/wongi-engine/graph.rb
|
|
117
|
-
- lib/wongi-engine/model_context.rb
|
|
118
136
|
- lib/wongi-engine/network.rb
|
|
119
137
|
- lib/wongi-engine/network/collectable.rb
|
|
120
138
|
- lib/wongi-engine/network/debug.rb
|
|
@@ -133,6 +151,7 @@ files:
|
|
|
133
151
|
- spec/generation_spec.rb
|
|
134
152
|
- spec/high_level_spec.rb
|
|
135
153
|
- spec/network_spec.rb
|
|
154
|
+
- spec/overlay_spec.rb
|
|
136
155
|
- spec/rule_specs/any_rule_spec.rb
|
|
137
156
|
- spec/rule_specs/assign_spec.rb
|
|
138
157
|
- spec/rule_specs/assuming_spec.rb
|
|
@@ -164,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
164
183
|
version: '0'
|
|
165
184
|
requirements: []
|
|
166
185
|
rubyforge_project:
|
|
167
|
-
rubygems_version: 2.4.
|
|
186
|
+
rubygems_version: 2.4.8
|
|
168
187
|
signing_key:
|
|
169
188
|
specification_version: 4
|
|
170
189
|
summary: A forward-chaining rule engine in pure Ruby.
|
|
@@ -178,6 +197,7 @@ test_files:
|
|
|
178
197
|
- spec/generation_spec.rb
|
|
179
198
|
- spec/high_level_spec.rb
|
|
180
199
|
- spec/network_spec.rb
|
|
200
|
+
- spec/overlay_spec.rb
|
|
181
201
|
- spec/rule_specs/any_rule_spec.rb
|
|
182
202
|
- spec/rule_specs/assign_spec.rb
|
|
183
203
|
- spec/rule_specs/assuming_spec.rb
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
module Wongi::Engine
|
|
2
|
-
|
|
3
|
-
class SimpleAction < Action
|
|
4
|
-
|
|
5
|
-
def initialize action = nil, *args, &block
|
|
6
|
-
@args = args
|
|
7
|
-
case action
|
|
8
|
-
when Class
|
|
9
|
-
@action = @deaction = @reaction = action.new *args, &block
|
|
10
|
-
when Hash
|
|
11
|
-
@action = instance_or_proc action[:activate]
|
|
12
|
-
@deaction = instance_or_proc action[:deactivate]
|
|
13
|
-
@reaction = instance_or_proc action[:reactivate]
|
|
14
|
-
end
|
|
15
|
-
@action ||= block
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def execute token
|
|
19
|
-
return unless @action
|
|
20
|
-
if @action.is_a?( Proc ) || @action.respond_to?( :to_proc )
|
|
21
|
-
rete.instance_exec token, &@action
|
|
22
|
-
elsif @action.respond_to? :call
|
|
23
|
-
@action.call token
|
|
24
|
-
elsif @action.respond_to? :execute
|
|
25
|
-
@action.execute token
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def deexecute token
|
|
30
|
-
return unless @deaction
|
|
31
|
-
if @deaction.is_a?( Proc ) || @deaction.respond_to?( :to_proc )
|
|
32
|
-
rete.instance_exec token, &@deaction
|
|
33
|
-
elsif @deaction.respond_to? :call
|
|
34
|
-
@deaction.call token
|
|
35
|
-
elsif @deaction.respond_to? :deexecute
|
|
36
|
-
@deaction.execute token
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def reexecute token, newtoken
|
|
41
|
-
return unless @reaction
|
|
42
|
-
if @reaction.is_a?( Proc ) || @reaction.respond_to?( :to_proc )
|
|
43
|
-
rete.instance_exec token, newtoken, &@reaction
|
|
44
|
-
elsif @reaction.respond_to? :call
|
|
45
|
-
@reaction.call token, newtoken
|
|
46
|
-
elsif @reaction.respond_to? :reexecute
|
|
47
|
-
@reaction.execute token, newtoken
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def instance_or_proc thing
|
|
52
|
-
case thing
|
|
53
|
-
when Class
|
|
54
|
-
thing.new
|
|
55
|
-
when Proc
|
|
56
|
-
thing
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
module Wongi::Engine
|
|
2
|
-
|
|
3
|
-
class SimpleCollector < Action
|
|
4
|
-
|
|
5
|
-
def self.collector
|
|
6
|
-
Class.new self
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def initialize variable, name = nil
|
|
10
|
-
@variable = variable
|
|
11
|
-
@name = name if name
|
|
12
|
-
#(class << self; self; end).instance_eval do
|
|
13
|
-
# define_method method do
|
|
14
|
-
# collect variable
|
|
15
|
-
# end
|
|
16
|
-
# alias_method method, :default_collect
|
|
17
|
-
# end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def default_collect
|
|
21
|
-
collect @variable
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def name= n
|
|
25
|
-
@name = n unless @name
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def rete= rete
|
|
29
|
-
rete.add_collector self, name
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def collect var
|
|
33
|
-
production.tokens.map { |token| token[var] }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
class GenericCollectClause
|
|
39
|
-
|
|
40
|
-
def initialize name, variable
|
|
41
|
-
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def import_into rete
|
|
45
|
-
collector = SimpleCollector.new @variable
|
|
46
|
-
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
end
|