Class: Wongi::Engine::RootNode

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

Instance Attribute Summary

Attributes inherited from BetaNode

#children, #parent, #rete

Instance Method Summary collapse

Methods inherited from BetaNode

#assignment_node, #beta_deactivate_children, #depth, #empty?, #initialize, #overlay, #refresh, #root?, #size, #tokens

Methods included from CoreExt

included

Constructor Details

This class inherits a constructor from Wongi::Engine::BetaNode

Instance Method Details

#beta_activate(token) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wongi-engine/beta/root_node.rb', line 16

def beta_activate(token)
  # existing = tokens.find { |et| et.duplicate? token }
  # return if existing # TODO: really?

  overlay.add_token(token)

  children.each do |child|
    child.beta_activate(Token.new(child, token, nil))
  end

  nil
end

#beta_deactivate(token) ⇒ Object



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

def beta_deactivate(token)
  return nil unless tokens.find token

  overlay.remove_token(token)

  children.each do |child|
    child.tokens.select { _1.child_of?(token) }.each { child.beta_deactivate(_1) }
  end

  nil
end

#refresh_child(child) ⇒ Object



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

def refresh_child(child)
  tokens.each do |token|
    child.beta_activate(Token.new(child, token, nil))
  end
end

#seed(assignments = {}) ⇒ Object



3
4
5
6
7
# File 'lib/wongi-engine/beta/root_node.rb', line 3

def seed(assignments = {})
  @seed = assignments
  t = Token.new(self, nil, nil, assignments)
  rete.default_overlay.add_token(t)
end

#subst(valuations) ⇒ Object



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

def subst(valuations)
  beta_deactivate(tokens.first)
  token = Token.new(self, nil, nil, @seed)
  valuations.each { |variable, value| token.subst variable, value }
  beta_activate(token)
end