Class: Wongi::Engine::Token
- Inherits:
-
Object
- Object
- Wongi::Engine::Token
- Includes:
- CoreExt
- Defined in:
- lib/wongi-engine/token.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#generated_wmes ⇒ Object
readonly
Returns the value of attribute generated_wmes.
-
#ncc_results ⇒ Object
readonly
Returns the value of attribute ncc_results.
-
#neg_join_results ⇒ Object
readonly
Returns the value of attribute neg_join_results.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#opt_join_results ⇒ Object
readonly
Returns the value of attribute opt_join_results.
-
#overlay ⇒ Object
readonly
Returns the value of attribute overlay.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#wme ⇒ Object
readonly
Returns the value of attribute wme.
Instance Method Summary collapse
- #[](var) ⇒ Object
- #ancestors ⇒ Object
- #assignments ⇒ Object
- #destroy ⇒ Object
-
#duplicate?(other) ⇒ Boolean
TODO ignore assignments?.
-
#generated?(wme) ⇒ Boolean
for neg feedback loop protection.
-
#initialize(node, token, wme, assignments) ⇒ Token
constructor
A new instance of Token.
- #subst(variable, value) ⇒ Object
- #to_s ⇒ Object
Methods included from CoreExt
Constructor Details
#initialize(node, token, wme, assignments) ⇒ Token
Returns a new instance of Token.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wongi-engine/token.rb', line 19 def initialize node, token, wme, assignments @node, @parent, @wme, @assignments = node, token, wme, assignments @overlay = wme ? wme..highest(token.) : node.rete. @children = [] @deleted = false @neg_join_results = [] @opt_join_results = [] @ncc_results = [] @generated_wmes = [] token.children << self if token end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
7 8 9 |
# File 'lib/wongi-engine/token.rb', line 7 def children @children end |
#generated_wmes ⇒ Object (readonly)
Returns the value of attribute generated_wmes.
15 16 17 |
# File 'lib/wongi-engine/token.rb', line 15 def generated_wmes @generated_wmes end |
#ncc_results ⇒ Object (readonly)
Returns the value of attribute ncc_results.
14 15 16 |
# File 'lib/wongi-engine/token.rb', line 14 def ncc_results @ncc_results end |
#neg_join_results ⇒ Object (readonly)
Returns the value of attribute neg_join_results.
12 13 14 |
# File 'lib/wongi-engine/token.rb', line 12 def neg_join_results @neg_join_results end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
9 10 11 |
# File 'lib/wongi-engine/token.rb', line 9 def node @node end |
#opt_join_results ⇒ Object (readonly)
Returns the value of attribute opt_join_results.
13 14 15 |
# File 'lib/wongi-engine/token.rb', line 13 def opt_join_results @opt_join_results end |
#overlay ⇒ Object (readonly)
Returns the value of attribute overlay.
10 11 12 |
# File 'lib/wongi-engine/token.rb', line 10 def @overlay end |
#owner ⇒ Object
Returns the value of attribute owner.
11 12 13 |
# File 'lib/wongi-engine/token.rb', line 11 def owner @owner end |
#parent ⇒ Object
Returns the value of attribute parent.
11 12 13 |
# File 'lib/wongi-engine/token.rb', line 11 def parent @parent end |
#wme ⇒ Object (readonly)
Returns the value of attribute wme.
8 9 10 |
# File 'lib/wongi-engine/token.rb', line 8 def wme @wme end |
Instance Method Details
#[](var) ⇒ Object
50 51 52 53 54 |
# File 'lib/wongi-engine/token.rb', line 50 def [] var if a = assignments[ var ] a.respond_to?(:call) ? a.call( self ) : a end end |
#ancestors ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/wongi-engine/token.rb', line 31 def ancestors if parent parent.ancestors.unshift parent else [] end end |
#assignments ⇒ Object
46 47 48 |
# File 'lib/wongi-engine/token.rb', line 46 def assignments @cached_assignments ||= all_assignments end |
#destroy ⇒ Object
68 69 70 |
# File 'lib/wongi-engine/token.rb', line 68 def destroy deleted! end |
#duplicate?(other) ⇒ Boolean
TODO ignore assignments?
57 58 59 |
# File 'lib/wongi-engine/token.rb', line 57 def duplicate? other self.parent.equal?(other.parent) && @wme.equal?(other.wme) && self.assignments == other.assignments end |
#generated?(wme) ⇒ Boolean
for neg feedback loop protection
73 74 75 76 |
# File 'lib/wongi-engine/token.rb', line 73 def generated? wme return true if generated_wmes.any? { |w| w == wme } return children.any? { |t| t.generated? wme } end |
#subst(variable, value) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/wongi-engine/token.rb', line 39 def subst variable, value @cached_assignments = nil if @assignments.has_key? variable @assignments[ variable ] = value end end |
#to_s ⇒ Object
61 62 63 64 65 66 |
# File 'lib/wongi-engine/token.rb', line 61 def to_s str = "TOKEN [ #{object_id} parent=#{parent ? parent.object_id : 'nil'} " all_assignments.each_pair { |key, value| str << "#{key} => #{value} " } str << "]" str end |