Class: KBS::NegationNode
- Inherits:
-
Object
- Object
- KBS::NegationNode
- Defined in:
- lib/kbs/negation_node.rb
Instance Attribute Summary collapse
-
#alpha_memory ⇒ Object
Returns the value of attribute alpha_memory.
-
#beta_memory ⇒ Object
Returns the value of attribute beta_memory.
-
#successors ⇒ Object
Returns the value of attribute successors.
-
#tests ⇒ Object
Returns the value of attribute tests.
Instance Method Summary collapse
-
#initialize(alpha_memory, beta_memory, tests = []) ⇒ NegationNode
constructor
A new instance of NegationNode.
- #left_activate(token) ⇒ Object
- #right_activate(fact) ⇒ Object
- #right_deactivate(fact) ⇒ Object
Constructor Details
#initialize(alpha_memory, beta_memory, tests = []) ⇒ NegationNode
Returns a new instance of NegationNode.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/kbs/negation_node.rb', line 7 def initialize(alpha_memory, beta_memory, tests = []) @alpha_memory = alpha_memory @beta_memory = beta_memory @successors = [] @tests = tests @tokens_with_matches = Hash.new { |h, k| h[k] = [] } alpha_memory.successors << self if alpha_memory beta_memory.successors << self if beta_memory end |
Instance Attribute Details
#alpha_memory ⇒ Object
Returns the value of attribute alpha_memory.
5 6 7 |
# File 'lib/kbs/negation_node.rb', line 5 def alpha_memory @alpha_memory end |
#beta_memory ⇒ Object
Returns the value of attribute beta_memory.
5 6 7 |
# File 'lib/kbs/negation_node.rb', line 5 def beta_memory @beta_memory end |
#successors ⇒ Object
Returns the value of attribute successors.
5 6 7 |
# File 'lib/kbs/negation_node.rb', line 5 def successors @successors end |
#tests ⇒ Object
Returns the value of attribute tests.
5 6 7 |
# File 'lib/kbs/negation_node.rb', line 5 def tests @tests end |
Instance Method Details
#left_activate(token) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kbs/negation_node.rb', line 18 def left_activate(token) matches = @alpha_memory.items.select { |fact| perform_join_tests(token, fact) } if matches.empty? new_token = Token.new(token, nil, self) token.children << new_token @successors.each { |s| s.activate(new_token) } else @tokens_with_matches[token] = matches end end |
#right_activate(fact) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kbs/negation_node.rb', line 30 def right_activate(fact) @beta_memory.tokens.each do |token| if perform_join_tests(token, fact) if @tokens_with_matches[token].empty? token.children.each do |child| @successors.each { |s| s.deactivate(child) if s.respond_to?(:deactivate) } end token.children.clear end @tokens_with_matches[token] << fact end end end |
#right_deactivate(fact) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/kbs/negation_node.rb', line 44 def right_deactivate(fact) @beta_memory.tokens.each do |token| if @tokens_with_matches[token].include?(fact) @tokens_with_matches[token].delete(fact) if @tokens_with_matches[token].empty? new_token = Token.new(token, nil, self) token.children << new_token @successors.each { |s| s.activate(new_token) } end end end end |