Class: Wongi::Engine::NegNode
- Defined in:
- lib/wongi-engine/beta/neg_node.rb
Instance Attribute Summary collapse
-
#alpha ⇒ Object
readonly
Returns the value of attribute alpha.
-
#tests ⇒ Object
readonly
Returns the value of attribute tests.
Attributes inherited from BetaNode
#children, #context, #parent, #rete
Instance Method Summary collapse
- #alpha_activate(wme) ⇒ Object
- #alpha_deactivate(wme) ⇒ Object
- #beta_activate(token) ⇒ Object
- #beta_deactivate(token) ⇒ Object
-
#initialize(parent, tests, alpha, unsafe) ⇒ NegNode
constructor
A new instance of NegNode.
- #refresh_child(child) ⇒ Object
Methods inherited from BetaNode
#assignment_node, #beta_memory, #delete_token, #depth, #empty?, #filter_node, #join_node, #ncc_node, #neg_node, #network, #optional_node, #refresh, #size, #tokens
Methods included from CoreExt
Constructor Details
#initialize(parent, tests, alpha, unsafe) ⇒ NegNode
Returns a new instance of NegNode.
15 16 17 18 19 |
# File 'lib/wongi-engine/beta/neg_node.rb', line 15 def initialize parent, tests, alpha, unsafe super(parent) @tests, @alpha, @unsafe = tests, alpha, unsafe @tokens = [] end |
Instance Attribute Details
#alpha ⇒ Object (readonly)
Returns the value of attribute alpha.
13 14 15 |
# File 'lib/wongi-engine/beta/neg_node.rb', line 13 def alpha @alpha end |
#tests ⇒ Object (readonly)
Returns the value of attribute tests.
13 14 15 |
# File 'lib/wongi-engine/beta/neg_node.rb', line 13 def tests @tests end |
Instance Method Details
#alpha_activate(wme) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/wongi-engine/beta/neg_node.rb', line 21 def alpha_activate wme self.tokens.each do |token| if matches?( token, wme ) && ( @unsafe || ! token.generated?( wme ) )# feedback loop protection # order matters for proper invalidation make_join_result(token, wme) #token.delete_children #if token.neg_join_results.empty? # TODO why was this check here? it seems to break things children.each do |child| child.tokens.each do |t| if t.parent == token child.beta_deactivate t #token.destroy end end end end end end |
#alpha_deactivate(wme) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wongi-engine/beta/neg_node.rb', line 39 def alpha_deactivate wme wme.neg_join_results.dup.each do |njr| safe_tokens.each do |token| next unless token == njr.token njr.unlink if token.neg_join_results.empty? children.each do |child| child.beta_activate Token.new( child, token, nil, {} ) end end end end end |
#beta_activate(token) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/wongi-engine/beta/neg_node.rb', line 53 def beta_activate token return if @tokens.find { |et| et.duplicate? token } @tokens << token alpha.wmes.each do |wme| if matches?( token, wme ) make_join_result(token, wme) end end if token.neg_join_results.empty? children.each do |child| child.beta_activate Token.new( child, token, nil, {} ) end end end |
#beta_deactivate(token) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/wongi-engine/beta/neg_node.rb', line 68 def beta_deactivate token return nil unless tokens.find token @tokens.delete token token.deleted! if token.parent token.parent.children.delete token # should this go into Token#destroy? end token.neg_join_results.each &:unlink children.each do |child| child.tokens.each do |t| if t.parent == token child.beta_deactivate t #token.destroy end end end token end |
#refresh_child(child) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/wongi-engine/beta/neg_node.rb', line 87 def refresh_child child safe_tokens.each do |token| if token.neg_join_results.empty? child.beta_activate Token.new( child, token, nil, {} ) end end alpha.wmes.each do |wme| alpha_activate wme end end |