wongi-engine 0.0.10 → 0.0.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9121794caa930fa1efd4e9cd0e099bab35f73b2d
4
- data.tar.gz: e6c628f83a408993367941977f1b6452db903b76
3
+ metadata.gz: 4ae5e5e3f2683835f9cc181b8c5edcf06245a61e
4
+ data.tar.gz: c6fe8127c68c416904044459132476b06fef46f3
5
5
  SHA512:
6
- metadata.gz: e6a18165e16edfdb48b7d74d7e90f82ce58a571d351ed95ee2983cf07767c1bbb02b9873b376f8759af9fd06f79c7498b20a307a943653e50d750ba6594e22cc
7
- data.tar.gz: 22f63a10e4ab649182bbbd9311c3466fc4e7af3405c571f6f8c25997d415f1bd816ee3e381aaff1040894405e4ae66b175bbf19557801e3bc832f8c9680ce141
6
+ metadata.gz: 8fc1bc5e6e5e85ee8a4282e4a56be5f2bd2c59e3d1c0dc23e60a85b5b97fe3d552798778f4cae4211a01fea1a400e4a0bac629cb11b34a3c0c586a7f37b34e8d
7
+ data.tar.gz: 01ab14f7f0e0616b26afd687ba060938154f5408c87b1944ed9e888ebf646839a2536854d579219b9254d8c48946b548e98a52e77908058cdd94ad26229c3c62
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ wongi-engine
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/README.md CHANGED
@@ -448,6 +448,10 @@ The Rete implementation in this library largely follows the outline presented in
448
448
 
449
449
  ## Changelog
450
450
 
451
+ ### 0.0.11
452
+
453
+ * fixed cleanup of invalidated NCC branches
454
+
451
455
  ### 0.0.10
452
456
 
453
457
  * fixed interaction of filters and optional nodes
@@ -16,9 +16,11 @@ module Wongi
16
16
  def beta_activate token
17
17
  t = Token.new token, nil, {}
18
18
  t.node = self
19
- owner = ncc.tokens.find do |ncc_token|
20
- ncc_token.parent.node == divergent
21
- end
19
+ # owner = ncc.tokens.find do |ncc_token|
20
+ # ncc_token.parent.node == divergent
21
+ # end
22
+ divergent_token = t.ancestors.find { |a| a.node == divergent }
23
+ owner = ncc.tokens.find { |o| o.parent == divergent_token }
22
24
  if owner
23
25
  owner.ncc_results << t
24
26
  t.owner = owner
@@ -24,6 +24,14 @@ module Wongi::Engine
24
24
  wme.tokens << self if wme
25
25
  end
26
26
 
27
+ def ancestors
28
+ if parent
29
+ parent.ancestors.unshift parent
30
+ else
31
+ []
32
+ end
33
+ end
34
+
27
35
  def subst variable, value
28
36
  @cached_assignments = nil
29
37
  if @assignments.has_key? variable
@@ -1,5 +1,5 @@
1
1
  module Wongi
2
2
  module Engine
3
- VERSION = "0.0.10"
3
+ VERSION = "0.0.11"
4
4
  end
5
5
  end
@@ -60,5 +60,66 @@ describe "NCC rule" do
60
60
 
61
61
  end
62
62
 
63
+ it 'should clean up correctly' do
64
+
65
+ engine.rule :rule1 do
66
+ forall {
67
+ has :light_kitchen, :value, :on
68
+ }
69
+ make {
70
+ #trace values: true, generation: true
71
+ gen self.name, :light_bathroom, :on
72
+ gen self.name, :want_action_for, :light_bathroom
73
+ }
74
+ end
75
+
76
+ prod = engine.rule "action" do
77
+ forall {
78
+ has :Requestor, :want_action_for, :Actor
79
+ has :Requestor, :Actor, :Value
80
+ has :Requestor, :priority, :Priority
81
+ ncc {
82
+ has :OtherRequestor, :want_action_for, :Actor
83
+ diff :OtherRequestor, :Requestor
84
+ has :OtherRequestor, :priority, :OtherPriority
85
+ greater :OtherPriority, :Priority
86
+ }
87
+ }
88
+ make {
89
+ #trace values: true, generation: true
90
+ gen :Actor, :value, :Value
91
+ gen :Actor, :last_user, :Requestor
92
+ }
93
+ end
94
+
95
+ engine << [:user, :priority, 1]
96
+ engine << [:rule1, :priority, 2]
97
+ engine << [:poweruser, :priority, 3]
98
+ engine << [:god, :priority, 4]
99
+
100
+ puts "<- MANUAL"
101
+ engine << [:user, :want_action_for, :light_bathroom]
102
+ engine << [:user, :light_bathroom, :off]
103
+ expect( engine.select(:light_bathroom, :value, :_) ).to be == [ Wongi::Engine::WME.new(:light_bathroom, :value, :off) ]
104
+ expect( engine.select(:light_bathroom, :last_user, :_) ).to be == [ Wongi::Engine::WME.new(:light_bathroom, :last_user, :user) ]
105
+
106
+ puts "\n<- AUTOMATIC"
107
+ engine << [:light_kitchen, :value, :on]
108
+ expect( engine.select(:light_bathroom, :value, :_) ).to be == [ Wongi::Engine::WME.new(:light_bathroom, :value, :on) ]
109
+ expect( engine.select(:light_bathroom, :last_user, :_) ).to be == [ Wongi::Engine::WME.new(:light_bathroom, :last_user, :rule1) ]
110
+
111
+ puts "\n<- POWER USER"
112
+ engine << [:poweruser, :want_action_for, :light_bathroom]
113
+ engine << [:poweruser, :light_bathroom, :super_on]
114
+ expect( engine.select(:light_bathroom, :value, :_) ).to be == [ Wongi::Engine::WME.new(:light_bathroom, :value, :super_on) ]
115
+ expect( engine.select(:light_bathroom, :last_user, :_) ).to be == [ Wongi::Engine::WME.new(:light_bathroom, :last_user, :poweruser) ]
116
+
117
+ puts "\n<- GOD"
118
+ engine << [:god, :want_action_for, :light_bathroom]
119
+ engine << [:god, :light_bathroom, :let_there_be_light]
120
+ expect( engine.select(:light_bathroom, :value, :_) ).to be == [ Wongi::Engine::WME.new(:light_bathroom, :value, :let_there_be_light) ]
121
+ expect( engine.select(:light_bathroom, :last_user, :_) ).to be == [ Wongi::Engine::WME.new(:light_bathroom, :last_user, :god) ]
122
+
123
+ end
63
124
 
64
125
  end
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.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valeri Sokolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-15 00:00:00.000000000 Z
11
+ date: 2013-10-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A rule engine.
14
14
  email:
@@ -17,7 +17,9 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - ".gitignore"
20
+ - .gitignore
21
+ - .ruby-gemset
22
+ - .ruby-version
21
23
  - Gemfile
22
24
  - LICENSE
23
25
  - README.md
@@ -103,12 +105,12 @@ require_paths:
103
105
  - lib
104
106
  required_ruby_version: !ruby/object:Gem::Requirement
105
107
  requirements:
106
- - - ">="
108
+ - - '>='
107
109
  - !ruby/object:Gem::Version
108
110
  version: '0'
109
111
  required_rubygems_version: !ruby/object:Gem::Requirement
110
112
  requirements:
111
- - - ">="
113
+ - - '>='
112
114
  - !ruby/object:Gem::Version
113
115
  version: '0'
114
116
  requirements: []