unific 0.9 → 0.10

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.
data/History.txt CHANGED
@@ -1,3 +1,15 @@
1
+ === 0.10 / 2012-01-30
2
+
3
+ * Added a simple example program -- a mock database using unification for
4
+ query
5
+
6
+ * more documentation improvements
7
+
8
+ * added a hack to handle Rulog::Functor specially during unification for the
9
+ moment; this will be handled more cleanly in the released version of rulog
10
+
11
+ * tested with Ruby 1.9.3 as well as 1.8.7
12
+
1
13
  === 0.9 / 2012-01-12
2
14
 
3
15
  * unific split out from the in-development rulog (Ruby With Logic) gem
data/Manifest.txt CHANGED
@@ -4,5 +4,6 @@ Manifest.txt
4
4
  README.rdoc
5
5
  README.txt
6
6
  Rakefile
7
+ examples/database.rb
7
8
  lib/unific.rb
8
9
  test/test_unific.rb
data/README.rdoc CHANGED
@@ -16,6 +16,16 @@ the in-development Rulog[http://github.com/jimwise/rulog]] (Ruby With Logic)
16
16
  gem), but can also be useful on its own as a pattern matching engine which
17
17
  can enforce consistency across multiple matches.
18
18
 
19
+ === How to Use This Gem
20
+
21
+ To get started, include this gem using
22
+
23
+ require 'rubygems'
24
+ require 'unific'
25
+
26
+ This gem provides the Unific module. This module provides several methods
27
+ which implement a unification engine.
28
+
19
29
  === What is Unfication?
20
30
 
21
31
  Unfication is a generalization of pattern matching -- it allows you to
@@ -32,7 +42,8 @@ is much more.
32
42
 
33
43
  So, what does it mean to unify two values?
34
44
 
35
- In the simplest case, we can compare two values:
45
+ In the simplest case, we can unify two values if they are equal (according
46
+ to ==):
36
47
 
37
48
  Unific::unify("foo", "foo")
38
49
  ==> succeeds, returns an empty environment, which is a true value (see below)
@@ -64,6 +75,9 @@ this implies that nested Enumerables are unified recursively:
64
75
  Unific::unify([["a", 42], ["b", 33]], [["a", 42], ["b", 33]])
65
76
  ==> returns an empty environment, which is a true value (see below)
66
77
 
78
+ As an exception, strings are _not_ unified recursively in this manner, even
79
+ though they _are_ Enumerables.
80
+
67
81
  So far, this does nothing that we could not do with the == operator... but
68
82
  there's more.
69
83
 
@@ -274,8 +288,8 @@ and generate the RDoc.
274
288
 
275
289
  == REQUIREMENTS:
276
290
 
277
- This gem should run fine under Ruby 1.8.7 or 1.9. If you experience any
278
- issues, please let me know.
291
+ This gem is tested and should run fine under Ruby 1.8.7 or 1.9. If you
292
+ experience any issues, please let me know.
279
293
 
280
294
  == LICENSE:
281
295
 
data/README.txt CHANGED
@@ -16,6 +16,16 @@ the in-development Rulog[http://github.com/jimwise/rulog]] (Ruby With Logic)
16
16
  gem), but can also be useful on its own as a pattern matching engine which
17
17
  can enforce consistency across multiple matches.
18
18
 
19
+ === How to Use This Gem
20
+
21
+ To get started, include this gem using
22
+
23
+ require 'rubygems'
24
+ require 'unific'
25
+
26
+ This gem provides the Unific module. This module provides several methods
27
+ which implement a unification engine.
28
+
19
29
  === What is Unfication?
20
30
 
21
31
  Unfication is a generalization of pattern matching -- it allows you to
@@ -32,7 +42,8 @@ is much more.
32
42
 
33
43
  So, what does it mean to unify two values?
34
44
 
35
- In the simplest case, we can compare two values:
45
+ In the simplest case, we can unify two values if they are equal (according
46
+ to ==):
36
47
 
37
48
  Unific::unify("foo", "foo")
38
49
  ==> succeeds, returns an empty environment, which is a true value (see below)
@@ -64,6 +75,9 @@ this implies that nested Enumerables are unified recursively:
64
75
  Unific::unify([["a", 42], ["b", 33]], [["a", 42], ["b", 33]])
65
76
  ==> returns an empty environment, which is a true value (see below)
66
77
 
78
+ As an exception, strings are _not_ unified recursively in this manner, even
79
+ though they _are_ Enumerables.
80
+
67
81
  So far, this does nothing that we could not do with the == operator... but
68
82
  there's more.
69
83
 
@@ -274,8 +288,8 @@ and generate the RDoc.
274
288
 
275
289
  == REQUIREMENTS:
276
290
 
277
- This gem should run fine under Ruby 1.8.7 or 1.9. If you experience any
278
- issues, please let me know.
291
+ This gem is tested and should run fine under Ruby 1.8.7 or 1.9. If you
292
+ experience any issues, please let me know.
279
293
 
280
294
  == LICENSE:
281
295
 
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'unific'
5
+
6
+ KEYS = [ :first, :last, :age, :occupation ]
7
+ DATA = [
8
+ { :first => "John", :last => "Smith", :age => 40, :occupation => "yak shaver" },
9
+ { :first => "Joe", :last => "Bloe", :age => 30, :occupation => "cat herder" },
10
+ { :first => "Jack", :last => "White", :age => 40, :occupation => "telephone sanitizer" },
11
+ { :first => "John", :last => "NotSmith", :age => 90, :occupation => "inspirational speaker" }
12
+ ]
13
+
14
+ # q is a hash with one or more values filled in
15
+ def query q
16
+ q2 = q.clone
17
+ KEYS.each {|k| q2[k] ||= Unific::_}
18
+ r = DATA.select {|d| Unific::unify d, q2}
19
+ end
20
+
21
+ johns = query :first => "John"
22
+ forties = query :age => 40
23
+ john_forties = query :first => "John", :age => 40
24
+
25
+ puts "People named John:"
26
+ johns.each {|d| puts "found: #{d[:first]} #{d[:last]}"}
27
+
28
+ puts
29
+
30
+ puts "Forty-year-olds:"
31
+ forties.each {|d| puts "found: #{d[:first]} #{d[:last]}"}
32
+
33
+ puts
34
+
35
+ puts "Forty-year-old people named John:"
36
+ john_forties.each {|d| puts "found: #{d[:first]} #{d[:last]}"}
data/lib/unific.rb CHANGED
@@ -2,7 +2,7 @@ require 'singleton'
2
2
 
3
3
  module Unific
4
4
 
5
- VERSION = '0.9'
5
+ VERSION = '0.10'
6
6
 
7
7
  # An environment (set of variable bindings) resulting from unification
8
8
  class Env
@@ -138,6 +138,12 @@ module Unific
138
138
  end
139
139
  end
140
140
 
141
+ # forward definition, see comment below
142
+ module ::Rulog #:nodoc:
143
+ end
144
+ class ::Rulog::Functor #:nodoc:
145
+ end
146
+
141
147
  # private helper for instantiate and rename
142
148
  # given an argument, if it is an:
143
149
  # a.) var, replace it with the result of calling a block on it
@@ -149,7 +155,8 @@ module Unific
149
155
  s
150
156
  when Var
151
157
  block.call(s)
152
- # XXX XXX rulog had handling for Functor here, we may need to provide something similar?
158
+ when Rulog::Functor # XXX XXX messy -- this is the only place Unific knows about the rest of Rulog
159
+ Rulog::Functor.new _traverse(s.f, &block), *_traverse(s.args, &block)
153
160
  when String
154
161
  # in ruby 1.8, strings are enumerable, but we want them to be ground
155
162
  s
data/test/test_unific.rb CHANGED
@@ -34,7 +34,6 @@ class TestUnific < Test::Unit::TestCase
34
34
  assert Unific::unify(Unific::_, Unific::Var.new);
35
35
  assert Unific::unify([Unific::_, 2], [1, 2]).unify([2, Unific::_], [2, 3])
36
36
  v1 = Unific::Var.new("v1")
37
- e1 = Unific::Env.new
38
37
  e2 = Unific::unify(v1, 42);
39
38
  assert Unific::unify(v1, Unific::_, e2);
40
39
  assert Unific::unify([1, 2, 3], Unific::_)
metadata CHANGED
@@ -1,112 +1,94 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: unific
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.10'
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 9
9
- version: "0.9"
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Jim Wise
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-01-12 00:00:00 Z
18
- dependencies:
19
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
20
15
  name: rdoc
21
- prerelease: false
22
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &69349280 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
18
+ requirements:
25
19
  - - ~>
26
- - !ruby/object:Gem::Version
27
- hash: 19
28
- segments:
29
- - 3
30
- - 10
31
- version: "3.10"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
32
22
  type: :development
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: hoe
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *69349280
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ requirement: &69349010 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
29
+ requirements:
40
30
  - - ~>
41
- - !ruby/object:Gem::Version
42
- hash: 27
43
- segments:
44
- - 2
45
- - 12
46
- version: "2.12"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.13'
47
33
  type: :development
48
- version_requirements: *id002
49
- description: |-
50
- Unific is a ruby unification engine.
51
-
34
+ prerelease: false
35
+ version_requirements: *69349010
36
+ description: ! 'Unific is a ruby unification engine.
37
+
38
+
52
39
  A unification engine is an essential part of a logic programming environment
40
+
53
41
  (the whole logic programming environment this is taken from is available as
42
+
54
43
  the in-development Rulog[http://github.com/jimwise/rulog]] (Ruby With Logic)
44
+
55
45
  gem), but can also be useful on its own as a pattern matching engine which
56
- can enforce consistency across multiple matches.
57
- email:
46
+
47
+ can enforce consistency across multiple matches.'
48
+ email:
58
49
  - jwise@draga.com
59
50
  executables: []
60
-
61
51
  extensions: []
62
-
63
- extra_rdoc_files:
52
+ extra_rdoc_files:
64
53
  - History.txt
65
54
  - Manifest.txt
66
55
  - README.txt
67
- files:
56
+ files:
68
57
  - .autotest
69
58
  - History.txt
70
59
  - Manifest.txt
71
60
  - README.rdoc
72
61
  - README.txt
73
62
  - Rakefile
63
+ - examples/database.rb
74
64
  - lib/unific.rb
75
65
  - test/test_unific.rb
76
66
  - .gemtest
77
67
  homepage: https://github.com/jimwise/unific
78
68
  licenses: []
79
-
80
69
  post_install_message:
81
- rdoc_options:
70
+ rdoc_options:
82
71
  - --main
83
72
  - README.txt
84
- require_paths:
73
+ require_paths:
85
74
  - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
75
+ required_ruby_version: !ruby/object:Gem::Requirement
87
76
  none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
- version: "0"
95
- required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
82
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
- version: "0"
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
104
87
  requirements: []
105
-
106
88
  rubyforge_project: unific
107
- rubygems_version: 1.8.13
89
+ rubygems_version: 1.8.15
108
90
  signing_key:
109
91
  specification_version: 3
110
92
  summary: Unific is a ruby unification engine
111
- test_files:
93
+ test_files:
112
94
  - test/test_unific.rb