Class: KBS::AlphaMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/kbs/alpha_memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern = {}) ⇒ AlphaMemory

Returns a new instance of AlphaMemory.



8
9
10
11
12
13
# File 'lib/kbs/alpha_memory.rb', line 8

def initialize(pattern = {})
  @items = []
  @successors = []
  @pattern = pattern
  @linked = true
end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



5
6
7
# File 'lib/kbs/alpha_memory.rb', line 5

def items
  @items
end

#linkedObject (readonly)

Returns the value of attribute linked.



6
7
8
# File 'lib/kbs/alpha_memory.rb', line 6

def linked
  @linked
end

#patternObject

Returns the value of attribute pattern.



5
6
7
# File 'lib/kbs/alpha_memory.rb', line 5

def pattern
  @pattern
end

#successorsObject

Returns the value of attribute successors.



5
6
7
# File 'lib/kbs/alpha_memory.rb', line 5

def successors
  @successors
end

Instance Method Details

#activate(fact) ⇒ Object



25
26
27
28
29
# File 'lib/kbs/alpha_memory.rb', line 25

def activate(fact)
  return unless @linked
  @items << fact
  @successors.each { |s| s.right_activate(fact) }
end

#deactivate(fact) ⇒ Object



31
32
33
34
35
# File 'lib/kbs/alpha_memory.rb', line 31

def deactivate(fact)
  return unless @linked
  @items.delete(fact)
  @successors.each { |s| s.right_deactivate(fact) if s.respond_to?(:right_deactivate) }
end

#relink!Object



20
21
22
23
# File 'lib/kbs/alpha_memory.rb', line 20

def relink!
  @linked = true
  @successors.each { |s| s.right_relink! if s.respond_to?(:right_relink!) }
end

#unlink!Object



15
16
17
18
# File 'lib/kbs/alpha_memory.rb', line 15

def unlink!
  @linked = false
  @successors.each { |s| s.right_unlink! if s.respond_to?(:right_unlink!) }
end