Class: Wongi::Engine::BetaMemory

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

Direct Known Subclasses

OrNode, ProductionNode

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) ⇒ BetaMemory

Returns a new instance of BetaMemory.



6
7
8
9
# File 'lib/wongi-engine/beta/beta_memory.rb', line 6

def initialize parent
  super
  @tokens = []
end

Instance Attribute Details

#last_tokenObject (readonly)

Returns the value of attribute last_token.



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

def last_token
  @last_token
end

#tokensObject (readonly)

Returns the value of attribute tokens.



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

def tokens
  @tokens
end

Instance Method Details

#left_activate(token, wme, assignments) ⇒ Object



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

def left_activate token, wme, assignments
  # puts "MEMORY #{@id} left-activated with #{wme}"
  t = Token.new( token, wme, assignments)
  t.node = self
  @last_token = t
  @tokens << t
  self.children.each do |child|
    if child.kind_of? BetaMemory
      child.left_activate t, nil, {}
    else
      child.left_activate t
    end
  end
end

#seed(assignments = {}) ⇒ Object



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

def seed assignments = {}
  t = Token.new( nil, nil, assignments )
  t.node = self
  @tokens << t
end

#subst(valuations) ⇒ Object



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

def subst valuations
  token = @tokens.first
  token.delete true
  valuations.each { |variable, value| token.subst variable, value }
  self.children.each do |child|
    child.left_activate token
  end
end