Class: Wongi::Engine::NccPartner

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

Instance Attribute Summary collapse

Attributes inherited from BetaNode

#children, #parent, #rete

Instance Method Summary collapse

Methods inherited from BetaNode

#assignment_node, #beta_memory, #depth, #filter_node, #join_node, #ncc_node, #neg_node, #network, #optional_node, #refresh, #refresh_child

Methods included from CoreExt

included

Constructor Details

#initialize(parent) ⇒ NccPartner

Returns a new instance of NccPartner.



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

def initialize parent
  super
  #    @conjuncts = 0
  @tokens = []
end

Instance Attribute Details

#divergentObject

Returns the value of attribute divergent.



8
9
10
# File 'lib/wongi-engine/beta/ncc_partner.rb', line 8

def divergent
  @divergent
end

#nccObject

attr_accessor :conjuncts



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

def ncc
  @ncc
end

#tokensObject (readonly)

Returns the value of attribute tokens.



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

def tokens
  @tokens
end

Instance Method Details

#beta_activate(token) ⇒ Object



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

def beta_activate token
  t = Token.new token, nil, {}
  t.node = self
  # owner = ncc.tokens.find do |ncc_token|
  #   ncc_token.parent.node == divergent
  # end
  divergent_token = t.ancestors.find { |a| a.node == divergent }
  owner = ncc.tokens.find { |o| o.parent == divergent_token }
  if owner
    owner.ncc_results << t
    t.owner = owner
    owner.delete_children
  else
    tokens << t
  end
end

#delete_token(token) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/wongi-engine/beta/ncc_partner.rb', line 33

def delete_token token
  token.owner.ncc_results.delete token
  if token.owner.ncc_results.empty?
    ncc.children.each do |node|
      node.beta_activate token.owner, nil, {}
    end
  end

end