amigo 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,15 @@
1
+ === 0.1.2 / 2010-05-17
2
+
3
+ * Fixed: Inadvertently reported select variables to be bound even if they weren't in the solution.
4
+
5
+ * Add vocabulary support along with some standard vocabularies.
6
+
7
+ * Implement URI#to_s.
8
+
9
+ === 0.1.1 / 2010-05-16
10
+
11
+ * Select should return a list not a set
12
+
1
13
  === 0.1.0 / 2010-05-14
2
14
 
3
15
  * Initial version
@@ -1,3 +1,5 @@
1
+ require 'amigo/uri'
2
+ require 'amigo/vocabulary'
1
3
  require 'amigo/triple'
2
4
  require 'amigo/store'
3
5
  require 'amigo/select'
@@ -12,7 +12,7 @@ module Amigo
12
12
  end
13
13
 
14
14
  def include?(name)
15
- @variables.include?(name)
15
+ @variables.include?(name) && @row.has_key?(name)
16
16
  end
17
17
 
18
18
  def [](name)
@@ -35,8 +35,7 @@ module Amigo
35
35
  private
36
36
 
37
37
  def method_missing(name, *args, &block)
38
- return self[name] if args.empty? && !block_given?
39
- super
38
+ self[name]
40
39
  end
41
40
 
42
41
  end
@@ -2,6 +2,10 @@ require 'hamster/immutable'
2
2
 
3
3
  module Amigo
4
4
 
5
+ def self.URI(uri)
6
+ URI.new(uri)
7
+ end
8
+
5
9
  class URI
6
10
 
7
11
  include Hamster::Immutable
@@ -33,6 +37,10 @@ module Amigo
33
37
  @uri.hash
34
38
  end
35
39
 
40
+ def to_s
41
+ @uri
42
+ end
43
+
36
44
  end
37
45
 
38
46
  end
@@ -1,5 +1,5 @@
1
1
  module Amigo
2
2
 
3
- VERSION = "0.1.1".freeze
3
+ VERSION = "0.1.2".freeze
4
4
 
5
5
  end
@@ -0,0 +1,46 @@
1
+ require 'amigo/uri'
2
+
3
+ module Amigo
4
+
5
+ class Vocabulary
6
+
7
+ def initialize(base_uri)
8
+ @base_uri = base_uri
9
+ end
10
+
11
+ def [](name)
12
+ respond_to?(name) ? send(name) : self << name
13
+ end
14
+
15
+ def type
16
+ self << "type"
17
+ end
18
+
19
+ protected
20
+
21
+ def <<(name)
22
+ URI.new("#{@base_uri}#{name}").tap do |uri|
23
+ (class << self; self; end).class_eval do
24
+ define_method(name) { |*args| uri }
25
+ end
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def method_missing(name, *args, &block)
32
+ self[name]
33
+ end
34
+
35
+ end
36
+
37
+ DC = Vocabulary.new("http://purl.org/dc/terms/")
38
+ FOAF = Vocabulary.new("http://xmlns.com/foaf/0.1/")
39
+ RDF = Vocabulary.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
40
+ RDFS = Vocabulary.new("http://www.w3.org/2000/01/rdf-schema#")
41
+ RSS = Vocabulary.new("http://purl.org/rss/1.0/")
42
+ OWL = Vocabulary.new("http://www.w3.org/2002/07/owl#")
43
+ XSD = Vocabulary.new("http://www.w3.org/2001/XMLSchema#")
44
+
45
+ end
46
+
@@ -140,11 +140,11 @@ module Amigo
140
140
  @solution = @result.first
141
141
  end
142
142
 
143
- it "correctly bind the the selected variables" do
143
+ it "correctly binds the the selected variables" do
144
144
  @solution[:title].should == "SPARQL Tutorial"
145
145
  end
146
146
 
147
- it "do not bind any non-selected variables" do
147
+ it "does not bind non-selected variables" do
148
148
  @solution.include?(:x).should == false
149
149
  @solution.include?(:y).should == false
150
150
  end
@@ -153,6 +153,44 @@ module Amigo
153
153
 
154
154
  end
155
155
 
156
+ describe "with selected variables not present in the results" do
157
+
158
+ before do
159
+ @result = Select.new(:title, :flibble).
160
+ where(:x, :y, :title).
161
+ execute(Hamster.set(Triple.new(URI.parse("ex_book:book1"), URI.parse("dc:title"), "SPARQL Tutorial")))
162
+ end
163
+
164
+ describe "the result" do
165
+
166
+ it "is a list" do
167
+ @result.class.should include(Hamster::List)
168
+ end
169
+
170
+ it "returns the correct number of solutions" do
171
+ @result.size.should == 1
172
+ end
173
+
174
+ end
175
+
176
+ describe "each solution" do
177
+
178
+ before do
179
+ @solution = @result.first
180
+ end
181
+
182
+ it "correctly binds the the selected variables" do
183
+ @solution[:title].should == "SPARQL Tutorial"
184
+ end
185
+
186
+ it "does not bind variables not present in the results" do
187
+ @solution.include?(:flibble).should == false
188
+ end
189
+
190
+ end
191
+
192
+ end
193
+
156
194
  describe "with joins" do
157
195
 
158
196
  before do
@@ -187,12 +225,12 @@ module Amigo
187
225
  @solution = @result.first
188
226
  end
189
227
 
190
- it "correctly bind the selected variables" do
228
+ it "correctly binds the selected variables" do
191
229
  @solution[:name].should == "Johnny Lee Outlaw"
192
230
  @solution[:mbox].should == URI.parse("mailto:jlow@example.com")
193
231
  end
194
232
 
195
- it "does not bind any un-selected variables" do
233
+ it "does not bind un-selected variables" do
196
234
  @solution.include?(:x).should == false
197
235
  end
198
236
 
@@ -204,12 +242,12 @@ module Amigo
204
242
  @solution = @result.last
205
243
  end
206
244
 
207
- it "correctly bind the selected variables" do
245
+ it "correctly binds the selected variables" do
208
246
  @solution[:name].should == "Peter Goodguy"
209
247
  @solution[:mbox].should == URI.parse("mailto:peter@example.com")
210
248
  end
211
249
 
212
- it "does not bind any un-selected variables" do
250
+ it "does not bind un-selected variables" do
213
251
  @solution.include?(:x).should == false
214
252
  end
215
253
 
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ require 'amigo/store'
4
+
5
+ module Amigo
6
+
7
+ describe Store do
8
+
9
+ describe "#hash" do
10
+
11
+ describe "for the same content" do
12
+
13
+ before do
14
+ @a = Amigo.store.add("a", "b", "c").add("d", "e", "f")
15
+ @b = Amigo.store.add("a", "b", "c").add("d", "e", "f")
16
+ end
17
+
18
+ it "returns the same value" do
19
+ @a.hash.should == @b.hash
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ require 'amigo/uri'
4
+
5
+ module Amigo
6
+
7
+ describe URI do
8
+
9
+ describe "#to_s" do
10
+
11
+ [
12
+ ["http://www.example.com/", "http://www.example.com/"],
13
+ ["foaf:name", "foaf:name"],
14
+ ].each do |uri, expected|
15
+
16
+ describe "given #{uri.inspect}" do
17
+
18
+ before do
19
+ @uri = URI.new(uri)
20
+ end
21
+
22
+ it "returns #{expected.inspect}" do
23
+ @uri.to_s.should == expected
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ require 'amigo/uri'
4
+ require 'amigo/vocabulary'
5
+
6
+ module Amigo
7
+
8
+ describe Vocabulary do
9
+
10
+ before do
11
+ @vocabulary = Vocabulary.new("http://example.com/")
12
+ end
13
+
14
+ ["type", "foo", "bar", "baz"].each do |name|
15
+
16
+ describe "##{name}" do
17
+
18
+ before do
19
+ @uri = @vocabulary.send(name)
20
+ end
21
+
22
+ it "returns a URI" do
23
+ @uri.should == URI.new("http://example.com/#{name}")
24
+ end
25
+
26
+ it "returns the same URI each time" do
27
+ @uri.should equal(@vocabulary.send(name))
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+
36
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amigo
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 31
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 1
9
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Simon Harris
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-16 00:00:00 +10:00
18
+ date: 2010-05-17 00:00:00 +10:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: hamster
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 29
27
30
  segments:
28
31
  - 0
29
32
  - 3
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: rspec
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 27
41
46
  segments:
42
47
  - 1
43
48
  - 3
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: diff-lcs
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 23
55
62
  segments:
56
63
  - 1
57
64
  - 1
@@ -83,23 +90,27 @@ files:
83
90
  - lib/amigo/variable.rb
84
91
  - lib/amigo/variables.rb
85
92
  - lib/amigo/version.rb
93
+ - lib/amigo/vocabulary.rb
86
94
  - lib/amigo/where.rb
87
95
  - lib/amigo.rb
88
96
  - spec/amigo/select/execute_spec.rb
89
97
  - spec/amigo/select/immutable_spec.rb
90
98
  - spec/amigo/select/to_sparql_spec.rb
91
99
  - spec/amigo/select/to_sql_spec.rb
100
+ - spec/amigo/store/hash_spec.rb
92
101
  - spec/amigo/store/to_ntriples_spec.rb
93
102
  - spec/amigo/term/to_sparql_spec.rb
94
103
  - spec/amigo/triple/immutable_spec.rb
95
104
  - spec/amigo/triple/inspect_spec.rb
96
105
  - spec/amigo/triple/to_ntriple_spec.rb
97
106
  - spec/amigo/uri/to_ntriple_spec.rb
107
+ - spec/amigo/uri/to_s_spec.rb
98
108
  - spec/amigo/uri/to_sparql_spec.rb
99
109
  - spec/amigo/variable/to_sparql_spec.rb
100
110
  - spec/amigo/variables/immutable_spec.rb
101
111
  - spec/amigo/variables/include_spec.rb
102
112
  - spec/amigo/variables/to_sparql_spec.rb
113
+ - spec/amigo/vocabulary/lookup_spec.rb
103
114
  - spec/amigo/where/to_sparql_spec.rb
104
115
  - spec/spec.opts
105
116
  - spec/spec_helper.rb
@@ -118,25 +129,29 @@ rdoc_options: []
118
129
  require_paths:
119
130
  - lib
120
131
  required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
121
133
  requirements:
122
134
  - - ">="
123
135
  - !ruby/object:Gem::Version
136
+ hash: 57
124
137
  segments:
125
138
  - 1
126
139
  - 8
127
140
  - 7
128
141
  version: 1.8.7
129
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
130
144
  requirements:
131
145
  - - ">="
132
146
  - !ruby/object:Gem::Version
147
+ hash: 3
133
148
  segments:
134
149
  - 0
135
150
  version: "0"
136
151
  requirements: []
137
152
 
138
153
  rubyforge_project:
139
- rubygems_version: 1.3.6
154
+ rubygems_version: 1.3.7
140
155
  signing_key:
141
156
  specification_version: 3
142
157
  summary: In-memory triple store