Class: Wongi::Engine::BetaNode
- Inherits:
-
Object
- Object
- Wongi::Engine::BetaNode
show all
- Includes:
- CoreExt
- Defined in:
- lib/wongi-engine/beta/beta_node.rb
Direct Known Subclasses
AggregateNode, AssignmentNode, FilterNode, JoinNode, NccNode, NccPartner, NegNode, OptionalNode, OrNode, ProductionNode, RootNode
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from CoreExt
included
Constructor Details
#initialize(parent = nil) ⇒ BetaNode
Returns a new instance of BetaNode.
12
13
14
15
16
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 12
def initialize(parent = nil)
@parent = parent
@children = []
parent.children << self if parent
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
8
9
10
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 8
def children
@children
end
|
7
8
9
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 7
def parent
@parent
end
|
#rete ⇒ Object
30
31
32
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 30
def rete
@rete ||= (parent.rete if parent)
end
|
Instance Method Details
#assignment_node(variable, body) ⇒ Object
42
43
44
45
46
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 42
def assignment_node(variable, body)
node = AssignmentNode.new self, variable, body
node.refresh
node
end
|
#beta_deactivate_children(token: nil, wme: nil, children: self.children) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 52
def beta_deactivate_children(token: nil, wme: nil, children: self.children)
children.each do |child|
child.tokens.select { (token.nil? || _1.child_of?(token)) && (wme.nil? || _1.wme == wme) }.each do |child_token|
child.beta_deactivate(child_token)
end
end
end
|
#depth ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 22
def depth
@depth ||= if parent.nil?
0
else
parent.depth + 1
end
end
|
#empty? ⇒ Boolean
82
83
84
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 82
def empty?
tokens.first.nil?
end
|
#overlay ⇒ Object
78
79
80
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 78
def overlay
rete.current_overlay
end
|
#refresh ⇒ Object
48
49
50
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 48
def refresh
parent.refresh_child self
end
|
#root? ⇒ Boolean
18
19
20
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 18
def root?
parent.nil?
end
|
#size ⇒ Object
86
87
88
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 86
def size
tokens.count
end
|
#tokens ⇒ Object
74
75
76
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 74
def tokens
overlay.node_tokens(self)
end
|