Class: Wongi::Engine::DSL::Action::StatementGenerator
- Defined in:
- lib/wongi-engine/dsl/action/statement_generator.rb
Instance Attribute Summary
Attributes inherited from Base
#name, #production, #rete, #rule
Instance Method Summary collapse
- #deexecute(token) ⇒ Object
- #execute(token) ⇒ Object
-
#initialize(template) ⇒ StatementGenerator
constructor
A new instance of StatementGenerator.
Methods included from CoreExt
Constructor Details
#initialize(template) ⇒ StatementGenerator
Returns a new instance of StatementGenerator.
5 6 7 |
# File 'lib/wongi-engine/dsl/action/statement_generator.rb', line 5 def initialize template @template = template end |
Instance Method Details
#deexecute(token) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wongi-engine/dsl/action/statement_generator.rb', line 33 def deexecute token token.generated_wmes.reject( &:manual? ).inject( [] ) do |list, wme| list.tap do |l| wme..delete token l << wme if wme..empty? end end.each do |wme| rete.retract wme, automatic: true end end |
#execute(token) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/wongi-engine/dsl/action/statement_generator.rb', line 9 def execute token subject, predicate, object = @template.resolve!(token) # link to rete here to ensure proper linking with token wme = WME.new subject, predicate, object, rete wme.manual = false production.tracer.trace( action: self, wme: wme ) if production.tracer if existing = rete.exists?( wme ) generated = existing..size if generated > 0 && ! token.generated_wmes.include?( existing ) token.generated_wmes << existing existing. << token end else token.generated_wmes << wme wme. << token # this MUST be done after we link the wme and the token # in order for neg rule invalidation to work rete << wme end end |