Class: Wongi::Engine::NegNode

Inherits:
BetaNode
  • Object
show all
Defined in:
lib/wongi-engine/beta/neg_node.rb

Instance Attribute Summary collapse

Attributes inherited from BetaNode

#children, #parent, #rete

Instance Method Summary collapse

Methods inherited from BetaNode

#beta_memory, #depth, #filter_node, #join_node, #ncc_node, #neg_node, #network, #optional_node, #update_above

Methods included from CoreExt

included

Constructor Details

#initialize(parent, tests, alpha) ⇒ NegNode

Returns a new instance of NegNode.



10
11
12
13
14
# File 'lib/wongi-engine/beta/neg_node.rb', line 10

def initialize parent, tests, alpha
  super(parent)
  @tests, @alpha = tests, alpha
  @tokens = []
end

Instance Attribute Details

#alphaObject (readonly)

Returns the value of attribute alpha.



8
9
10
# File 'lib/wongi-engine/beta/neg_node.rb', line 8

def alpha
  @alpha
end

#testsObject (readonly)

Returns the value of attribute tests.



8
9
10
# File 'lib/wongi-engine/beta/neg_node.rb', line 8

def tests
  @tests
end

#tokensObject (readonly)

Returns the value of attribute tokens.



8
9
10
# File 'lib/wongi-engine/beta/neg_node.rb', line 8

def tokens
  @tokens
end

Instance Method Details

#left_activate(token, newwme, assignments) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/wongi-engine/beta/neg_node.rb', line 25

def left_activate token, newwme, assignments
  t = Token.new token, newwme, assignments
  t.node = self
  self.tokens << t
  @alpha.wmes.each do |wme|
    if matches?( t, wme )
      make_join_result(t, wme)
    end
  end
  if t.neg_join_results.empty?
    self.children.each do |child|
      child.left_activate t, nil, {}
    end
  end
end

#right_activate(wme) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/wongi-engine/beta/neg_node.rb', line 16

def right_activate wme
  self.tokens.each do |token|
    if matches?( token, wme )
      token.delete_children if token.neg_join_results.empty?
      make_join_result(token, wme)
    end
  end
end