wongi-engine 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +349 -0
  5. data/Rakefile +2 -0
  6. data/examples/ex01.rb +23 -0
  7. data/examples/ex02.rb +36 -0
  8. data/examples/graphviz.rb +15 -0
  9. data/examples/timeline.rb +48 -0
  10. data/lib/wongi-engine.rb +22 -0
  11. data/lib/wongi-engine/alpha_memory.rb +46 -0
  12. data/lib/wongi-engine/beta.rb +10 -0
  13. data/lib/wongi-engine/beta/beta_memory.rb +48 -0
  14. data/lib/wongi-engine/beta/beta_node.rb +164 -0
  15. data/lib/wongi-engine/beta/filter_node.rb +109 -0
  16. data/lib/wongi-engine/beta/join_node.rb +127 -0
  17. data/lib/wongi-engine/beta/ncc_node.rb +46 -0
  18. data/lib/wongi-engine/beta/ncc_partner.rb +43 -0
  19. data/lib/wongi-engine/beta/neg_node.rb +58 -0
  20. data/lib/wongi-engine/beta/optional_node.rb +43 -0
  21. data/lib/wongi-engine/beta/or_node.rb +76 -0
  22. data/lib/wongi-engine/beta/production_node.rb +31 -0
  23. data/lib/wongi-engine/core_ext.rb +57 -0
  24. data/lib/wongi-engine/dsl.rb +112 -0
  25. data/lib/wongi-engine/dsl/action.rb +12 -0
  26. data/lib/wongi-engine/dsl/actions/error_generator.rb +42 -0
  27. data/lib/wongi-engine/dsl/actions/simple_action.rb +23 -0
  28. data/lib/wongi-engine/dsl/actions/simple_collector.rb +51 -0
  29. data/lib/wongi-engine/dsl/actions/statement_generator.rb +52 -0
  30. data/lib/wongi-engine/dsl/actions/trace_action.rb +52 -0
  31. data/lib/wongi-engine/dsl/any_rule.rb +48 -0
  32. data/lib/wongi-engine/dsl/dsl_builder.rb +44 -0
  33. data/lib/wongi-engine/dsl/dsl_extensions.rb +43 -0
  34. data/lib/wongi-engine/dsl/extension_clause.rb +36 -0
  35. data/lib/wongi-engine/dsl/generation_clause.rb +15 -0
  36. data/lib/wongi-engine/dsl/generic_production_rule.rb +78 -0
  37. data/lib/wongi-engine/dsl/ncc_production_rule.rb +21 -0
  38. data/lib/wongi-engine/dsl/production_rule.rb +4 -0
  39. data/lib/wongi-engine/dsl/query.rb +24 -0
  40. data/lib/wongi-engine/graph.rb +71 -0
  41. data/lib/wongi-engine/model_context.rb +13 -0
  42. data/lib/wongi-engine/network.rb +416 -0
  43. data/lib/wongi-engine/network/collectable.rb +42 -0
  44. data/lib/wongi-engine/network/debug.rb +25 -0
  45. data/lib/wongi-engine/ruleset.rb +74 -0
  46. data/lib/wongi-engine/template.rb +111 -0
  47. data/lib/wongi-engine/token.rb +137 -0
  48. data/lib/wongi-engine/version.rb +5 -0
  49. data/lib/wongi-engine/wme.rb +134 -0
  50. data/lib/wongi-engine/wme_match_data.rb +34 -0
  51. data/spec/dataset_spec.rb +26 -0
  52. data/spec/dsl_spec.rb +9 -0
  53. data/spec/high_level_spec.rb +341 -0
  54. data/spec/ruleset_spec.rb +54 -0
  55. data/spec/simple_action_spec.rb +40 -0
  56. data/spec/spec_helper.rb +1 -0
  57. data/spec/wme_spec.rb +83 -0
  58. data/wongi-engine.gemspec +19 -0
  59. metadata +110 -0
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wongi::Engine::SimpleAction do
4
+
5
+ before :each do
6
+ @rete = Wongi::Engine::Network.new
7
+ end
8
+
9
+ def rete
10
+ @rete
11
+ end
12
+
13
+ it 'should work with blocks' do
14
+
15
+ count = 0
16
+
17
+ rete.rule do
18
+ forall {
19
+ has 1, 2, :X
20
+ }
21
+ make {
22
+ action {
23
+ count += 1
24
+ }
25
+ }
26
+ end
27
+
28
+ count.should == 0
29
+
30
+ rete << [1, 2, 3]
31
+
32
+ count.should == 1
33
+
34
+ rete << [1, 2, 4]
35
+
36
+ count.should == 2
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1 @@
1
+ require 'wongi-engine'
data/spec/wme_spec.rb ADDED
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wongi::Engine::WME do
4
+
5
+ def capitalizing_rete
6
+ rete = mock 'rete'
7
+ rete.should_receive(:import).with("a").and_return("A")
8
+ rete.should_receive(:import).with("b").and_return("B")
9
+ rete.should_receive(:import).with("c").and_return("C")
10
+ rete
11
+ end
12
+
13
+ subject {
14
+ Wongi::Engine::WME.new "a", "b", "c"
15
+ }
16
+
17
+ context 'a new WME' do
18
+
19
+ it 'should initialize and expose members' do
20
+ subject.subject.should == "a"
21
+ subject.predicate.should == "b"
22
+ subject.object.should == "c"
23
+ end
24
+
25
+ it 'should use the rete to import members' do
26
+
27
+ rete = capitalizing_rete
28
+
29
+ wme = Wongi::Engine::WME.new "a", "b", "c", rete
30
+
31
+ wme.subject.should == "A"
32
+ wme.predicate.should == "B"
33
+ wme.object.should == "C"
34
+
35
+ end
36
+
37
+
38
+ specify {
39
+ subject.should be_manual
40
+ }
41
+
42
+ specify {
43
+ subject.should_not be_generated
44
+ }
45
+
46
+ end
47
+
48
+ it 'should be able to import into rete' do
49
+
50
+ rete = capitalizing_rete
51
+
52
+ imported = subject.import_into rete
53
+
54
+ imported.subject.should == "A"
55
+ imported.predicate.should == "B"
56
+ imported.object.should == "C"
57
+
58
+ end
59
+
60
+ it 'should compare instances' do
61
+
62
+ wme1 = Wongi::Engine::WME.new "a", "b", "c"
63
+ wme2 = Wongi::Engine::WME.new "a", "b", "c"
64
+ wme3 = Wongi::Engine::WME.new "a", "b", "d"
65
+
66
+ wme1.should == wme2
67
+ wme1.should_not == wme3
68
+
69
+ end
70
+
71
+ it 'should not match against non-templates' do
72
+ lambda { subject =~ [1, 2, 3] }.should raise_error
73
+ end
74
+
75
+ it 'should match against templates' do
76
+ t1 = Wongi::Engine::Template.new "a", :_, :_
77
+ t2 = Wongi::Engine::Template.new "b", :_, :_
78
+
79
+ subject.should =~ t1
80
+ subject.should_not =~ t2
81
+ end
82
+
83
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/wongi-engine/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Valeri Sokolov"]
6
+ gem.email = ["ulfurinn@ulfurinn.net"]
7
+ gem.description = %q{A rule engine.}
8
+ gem.summary = %q{A rule engine.}
9
+ gem.homepage = "https://github.com/ulfurinn/wongi-engine"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "wongi-engine"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Wongi::Engine::VERSION
17
+
18
+ #gem.add_dependency "wongi-rdf"
19
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wongi-engine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Valeri Sokolov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A rule engine.
15
+ email:
16
+ - ulfurinn@ulfurinn.net
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - examples/ex01.rb
27
+ - examples/ex02.rb
28
+ - examples/graphviz.rb
29
+ - examples/timeline.rb
30
+ - lib/wongi-engine.rb
31
+ - lib/wongi-engine/alpha_memory.rb
32
+ - lib/wongi-engine/beta.rb
33
+ - lib/wongi-engine/beta/beta_memory.rb
34
+ - lib/wongi-engine/beta/beta_node.rb
35
+ - lib/wongi-engine/beta/filter_node.rb
36
+ - lib/wongi-engine/beta/join_node.rb
37
+ - lib/wongi-engine/beta/ncc_node.rb
38
+ - lib/wongi-engine/beta/ncc_partner.rb
39
+ - lib/wongi-engine/beta/neg_node.rb
40
+ - lib/wongi-engine/beta/optional_node.rb
41
+ - lib/wongi-engine/beta/or_node.rb
42
+ - lib/wongi-engine/beta/production_node.rb
43
+ - lib/wongi-engine/core_ext.rb
44
+ - lib/wongi-engine/dsl.rb
45
+ - lib/wongi-engine/dsl/action.rb
46
+ - lib/wongi-engine/dsl/actions/error_generator.rb
47
+ - lib/wongi-engine/dsl/actions/simple_action.rb
48
+ - lib/wongi-engine/dsl/actions/simple_collector.rb
49
+ - lib/wongi-engine/dsl/actions/statement_generator.rb
50
+ - lib/wongi-engine/dsl/actions/trace_action.rb
51
+ - lib/wongi-engine/dsl/any_rule.rb
52
+ - lib/wongi-engine/dsl/dsl_builder.rb
53
+ - lib/wongi-engine/dsl/dsl_extensions.rb
54
+ - lib/wongi-engine/dsl/extension_clause.rb
55
+ - lib/wongi-engine/dsl/generation_clause.rb
56
+ - lib/wongi-engine/dsl/generic_production_rule.rb
57
+ - lib/wongi-engine/dsl/ncc_production_rule.rb
58
+ - lib/wongi-engine/dsl/production_rule.rb
59
+ - lib/wongi-engine/dsl/query.rb
60
+ - lib/wongi-engine/graph.rb
61
+ - lib/wongi-engine/model_context.rb
62
+ - lib/wongi-engine/network.rb
63
+ - lib/wongi-engine/network/collectable.rb
64
+ - lib/wongi-engine/network/debug.rb
65
+ - lib/wongi-engine/ruleset.rb
66
+ - lib/wongi-engine/template.rb
67
+ - lib/wongi-engine/token.rb
68
+ - lib/wongi-engine/version.rb
69
+ - lib/wongi-engine/wme.rb
70
+ - lib/wongi-engine/wme_match_data.rb
71
+ - spec/dataset_spec.rb
72
+ - spec/dsl_spec.rb
73
+ - spec/high_level_spec.rb
74
+ - spec/ruleset_spec.rb
75
+ - spec/simple_action_spec.rb
76
+ - spec/spec_helper.rb
77
+ - spec/wme_spec.rb
78
+ - wongi-engine.gemspec
79
+ homepage: https://github.com/ulfurinn/wongi-engine
80
+ licenses: []
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 1.8.24
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: A rule engine.
103
+ test_files:
104
+ - spec/dataset_spec.rb
105
+ - spec/dsl_spec.rb
106
+ - spec/high_level_spec.rb
107
+ - spec/ruleset_spec.rb
108
+ - spec/simple_action_spec.rb
109
+ - spec/spec_helper.rb
110
+ - spec/wme_spec.rb