class Wongi::Engine::BetaNode

Attributes

children[RW]
parent[R]

@return [Wongi::Engine::BetaNode]

rete[W]

Public Class Methods

new(parent = nil) click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 12
def initialize(parent = nil)
  @parent = parent
  @children = []
  parent.children << self if parent
end

Public Instance Methods

assignment_node(variable, body) click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 42
def assignment_node(variable, body)
  node = AssignmentNode.new self, variable, body
  node.refresh
  node
end
beta_deactivate_children(token: nil, wme: nil, children: self.children) click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 52
def beta_deactivate_children(token: nil, wme: nil, children: self.children)
  children.each do |child|
    child.tokens.select { (token.nil? || _1.child_of?(token)) && (wme.nil? || _1.wme == wme) }.each do |child_token|
      child.beta_deactivate(child_token)
    end
  end
end
depth() click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 22
def depth
  @depth ||= if parent.nil?
               0
             else
               parent.depth + 1
             end
end
empty?() click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 82
def empty?
  tokens.first.nil?
end
overlay() click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 78
def overlay
  rete.current_overlay
end
refresh() click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 48
def refresh
  parent.refresh_child self
end
rete() click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 30
def rete
  @rete ||= (parent.rete if parent)
end
root?() click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 18
def root?
  parent.nil?
end
size() click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 86
def size
  tokens.count
end
tokens() click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 74
def tokens
  overlay.node_tokens(self)
end

Private Instance Methods

dp(message) click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 92
def dp(message)
  puts "#{indent}#{message}" if debug?
end
indent() click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 96
def indent
  '  ' * depth
end
select_wmes(template) click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 60
        def select_wmes(template)
  # capture the enumerator
  rete.current_overlay.each(template).to_a
end
specialize(template, tests, token) click to toggle source
# File lib/wongi-engine/beta/beta_node.rb, line 65
        def specialize(template, tests, token)
  tests.each_with_object(template.dup) do |test, template|
    var = test.variable
    if token.has_var?(var)
      template.public_send("#{test.field}=", token[var])
    end
  end
end