Last active
September 12, 2015 13:00
-
-
Save abargnesi/5ca65987b955e44ae3de to your computer and use it in GitHub Desktop.
Assign called for each reference in gen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'wongi-engine' | |
| require 'uuid' | |
| engine = Wongi::Engine.create | |
| uuid = UUID.generate.to_sym | |
| engine << [ uuid, :value, nil ] | |
| engine << [ uuid, :type, "Date" ] | |
| uuid = UUID.generate.to_sym | |
| engine << [ uuid, :value, nil ] | |
| engine << [ uuid, :type, "Date" ] | |
| puts 'Facts:' | |
| engine.wmes.map { |fact| | |
| puts fact | |
| } | |
| puts "\n" | |
| engine.rule 'date rule' do | |
| for_all { | |
| has :Datum, :value, nil | |
| has :Datum, :type, "Date" | |
| assign :OutValue do |token| | |
| puts 'assign OutValue' | |
| '2015-09-12' | |
| end | |
| assign :NewDatum do |token| | |
| puts 'assign NewDatum' | |
| UUID.generate.to_sym | |
| end | |
| } | |
| do! { | |
| gen :NewDatum, :value, :OutValue | |
| gen :NewDatum, :name, "Date" | |
| } | |
| end | |
| puts 'All Facts:' | |
| puts engine.select(:_, :_, :_) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'wongi-engine' | |
| require 'uuid' | |
| engine = Wongi::Engine.create | |
| uuid = UUID.generate.to_sym | |
| engine << [ uuid, :value, nil ] | |
| engine << [ uuid, :type, "Date" ] | |
| uuid = UUID.generate.to_sym | |
| engine << [ uuid, :value, nil ] | |
| engine << [ uuid, :type, "Date" ] | |
| puts 'Facts:' | |
| engine.wmes.map { |fact| | |
| puts fact | |
| } | |
| puts "\n" | |
| value_hash = {} | |
| engine.rule 'date rule' do | |
| for_all { | |
| has :Datum, :value, nil | |
| has :Datum, :type, "Date" | |
| assign :OutValue do |token| | |
| puts 'assign OutValue' | |
| '2015-09-12' | |
| end | |
| assign :NewDatum do |token| | |
| # We save the mapping of Datum to NewDatum so we use a single | |
| # value in the 'gen' calls below. | |
| value_hash[token[:Datum]] ||= UUID.generate.to_sym | |
| end | |
| } | |
| do! { | |
| gen :NewDatum, :value, :OutValue | |
| gen :NewDatum, :name, "Date" | |
| } | |
| end | |
| puts 'All Facts:' | |
| puts engine.select(:_, :_, :_) |
Author
Author
The NewDatum assign is called four times because it is referenced twice and matches against 2 sets of facts. I would like NewDatum to be the same value for each set of generated facts.
Author
The data_machine_2.rb example is successful because a new UUID is mapped to the token[:Datum].
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: