Class: Wongi::Engine::AlphaMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/wongi-engine/alpha_memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, rete = nil) ⇒ AlphaMemory

Returns a new instance of AlphaMemory.



7
8
9
10
11
12
13
# File 'lib/wongi-engine/alpha_memory.rb', line 7

def initialize template, rete = nil
  @template = template
  @rete = rete
  @betas = []
  @wmes = []
  @frozen = false
end

Instance Attribute Details

#betasObject (readonly)

Returns the value of attribute betas.



5
6
7
# File 'lib/wongi-engine/alpha_memory.rb', line 5

def betas
  @betas
end

#reteObject (readonly)

Returns the value of attribute rete.



5
6
7
# File 'lib/wongi-engine/alpha_memory.rb', line 5

def rete
  @rete
end

#templateObject (readonly)

Returns the value of attribute template.



5
6
7
# File 'lib/wongi-engine/alpha_memory.rb', line 5

def template
  @template
end

Instance Method Details

#activate(wme) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/wongi-engine/alpha_memory.rb', line 15

def activate wme
  wme.overlay.add_wme(wme, self)
  # TODO: it used to activate before adding to the list. mandated by the original thesis. investigate. it appears to create duplicate tokens - needs a remedy in collecting nodes
  betas.each do |beta|
    beta.alpha_activate wme
  end
end

#deactivate(wme) ⇒ Object



23
24
25
26
27
28
# File 'lib/wongi-engine/alpha_memory.rb', line 23

def deactivate wme
  wme.overlay.remove_wme(wme, self)
  betas.each do |beta|
    beta.alpha_deactivate wme
  end
end

#inspectObject



36
37
38
# File 'lib/wongi-engine/alpha_memory.rb', line 36

def inspect
  "<Alpha #{__id__} template=#{template}>"
end

#sizeObject



44
45
46
# File 'lib/wongi-engine/alpha_memory.rb', line 44

def size
  wmes.count
end

#snapshot!(alpha) ⇒ Object



30
31
32
33
34
# File 'lib/wongi-engine/alpha_memory.rb', line 30

def snapshot! alpha
  alpha.wmes.map( &:dup ).each do |wme|
    activate wme
  end
end

#to_sObject



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

def to_s
  inspect
end

#wmesObject



48
49
50
51
52
53
54
55
56
# File 'lib/wongi-engine/alpha_memory.rb', line 48

def wmes
  Enumerator.new do |y|
    rete.overlays.each do |overlay|
      overlay.raw_wmes(self).dup.each do |wme|
        y << wme
      end
    end
  end
end