Class: Wongi::Engine::JoinNode

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

Instance Attribute Summary collapse

Attributes inherited from BetaNode

#children, #parent, #rete

Instance Method Summary collapse

Methods inherited from BetaNode

#assignment_node, #delete_token, #depth, #refresh, #root?

Methods included from CoreExt

included

Constructor Details

#initialize(parent, tests, assignment) ⇒ JoinNode

Returns a new instance of JoinNode.



44
45
46
47
48
# File 'lib/wongi-engine/beta/join_node.rb', line 44

def initialize parent, tests, assignment
  super(parent)
  @tests = tests
  @assignment_pattern = assignment
end

Instance Attribute Details

#alphaObject

Returns the value of attribute alpha.



40
41
42
# File 'lib/wongi-engine/beta/join_node.rb', line 40

def alpha
  @alpha
end

#assignment_patternObject (readonly)

Returns the value of attribute assignment_pattern.



42
43
44
# File 'lib/wongi-engine/beta/join_node.rb', line 42

def assignment_pattern
  @assignment_pattern
end

#testsObject (readonly)

Returns the value of attribute tests.



41
42
43
# File 'lib/wongi-engine/beta/join_node.rb', line 41

def tests
  @tests
end

Instance Method Details

#alpha_activate(wme) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/wongi-engine/beta/join_node.rb', line 61

def alpha_activate wme
  assignments = collect_assignments( wme )
  parent.tokens.each do |token|
    if matches?( token, wme )
      children.each do |beta|
        beta.beta_activate Token.new( beta, token, wme, assignments )
      end
    end
  end
end

#alpha_deactivate(wme) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/wongi-engine/beta/join_node.rb', line 72

def alpha_deactivate wme
  children.each do |child|
    child.tokens.each do |token|
      if token.wme == wme
        child.beta_deactivate token
      end
    end
  end
end

#beta_activate(token) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/wongi-engine/beta/join_node.rb', line 82

def beta_activate token
  self.alpha.wmes.each do |wme|
    if matches?( token, wme )
      assignments = collect_assignments( wme )
      children.each do |beta|
        beta.beta_activate Token.new( beta, token, wme, assignments )
      end
    end
  end
end

#beta_deactivate(token) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/wongi-engine/beta/join_node.rb', line 93

def beta_deactivate token
  children.each do |child|
    child.tokens.each do |t|
      if t.parent == token
        child.beta_deactivate t
      end
    end
  end
end

#equivalent?(alpha, tests, assignment_pattern) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
# File 'lib/wongi-engine/beta/join_node.rb', line 50

def equivalent? alpha, tests, assignment_pattern
  return false unless self.alpha == alpha
  return false unless self.assignment_pattern == assignment_pattern
  return false unless (self.tests.empty? && tests.empty?) || self.tests.length == tests.length && self.tests.all? { |my_test|
    tests.any? { |new_test|
      my_test.equivalent? new_test
    }
  }
  true
end

#refresh_child(child) ⇒ Object



103
104
105
106
107
108
109
110
111
112
# File 'lib/wongi-engine/beta/join_node.rb', line 103

def refresh_child child
  alpha.wmes.each do |wme|
    assignments = collect_assignments( wme )
    parent.tokens.each do |token|
      if matches?( token, wme )
        child.beta_activate Token.new( child, token, wme, assignments )
      end
    end
  end
end