rdf-virtuoso 0.0.12 → 0.0.13
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/README.md +5 -4
- data/lib/active_rdf/persistence.rb +12 -13
- data/lib/active_rdf/version.rb +1 -1
- data/lib/rdf/virtuoso/query.rb +25 -8
- data/lib/rdf/virtuoso/version.rb +1 -1
- data/spec/active_rdf/persistence_spec.rb +6 -6
- data/spec/query_spec.rb +9 -2
- data/spec/repository_spec.rb +0 -2
- metadata +17 -17
data/README.md
CHANGED
@@ -16,8 +16,9 @@ This example assumes you have a local installation of Virtoso running at standar
|
|
16
16
|
|
17
17
|
#### Setup Repository connection connection with auth
|
18
18
|
|
19
|
-
uri
|
20
|
-
|
19
|
+
uri = "http://localhost:8890/sparql"
|
20
|
+
update_uri = "http://localhost:8890/sparql-auth"
|
21
|
+
repo = RDF::Virtuoso::Repository.new(uri, :update_uri => update_uri, :username => 'admin', :password => 'secret', :auth_method => 'digest')
|
21
22
|
|
22
23
|
:auth_method can be 'digest' or 'basic'. a repository connection without auth requires only uri
|
23
24
|
|
@@ -28,7 +29,7 @@ This example assumes you have a local installation of Virtoso running at standar
|
|
28
29
|
subject = RDF::URI.new("http://subject")
|
29
30
|
|
30
31
|
query = QUERY.insert([subject, :p, "object"]).graph(graph).where([subject, :p, :o])
|
31
|
-
result =
|
32
|
+
result = repo.insert(query)
|
32
33
|
|
33
34
|
#### A count query example
|
34
35
|
|
@@ -51,7 +52,7 @@ or you can use the RDF::Virtuoso::Prefixes class in a query:
|
|
51
52
|
type = RDF::FOO.Document
|
52
53
|
|
53
54
|
query = QUERY.select.where([:s, type, :o]).count(:s).prefixes(prefixes).graph(graph)
|
54
|
-
result =
|
55
|
+
result = repo.select(query)
|
55
56
|
|
56
57
|
Results will be an array of RDF::Query::Solution that can be accessed by bindings or iterated
|
57
58
|
|
@@ -16,13 +16,13 @@ module ActiveRDF
|
|
16
16
|
end
|
17
17
|
|
18
18
|
module ClassMethods
|
19
|
-
|
20
19
|
def connection
|
21
20
|
# TODO: make this behave like AM/AR Connection
|
22
|
-
CLIENT
|
21
|
+
#CLIENT
|
22
|
+
REPOSITORY
|
23
23
|
end
|
24
24
|
|
25
|
-
def create(attrs = nil)
|
25
|
+
def create(attrs = nil)
|
26
26
|
object = new(attrs)
|
27
27
|
object.save
|
28
28
|
object
|
@@ -56,9 +56,10 @@ module ActiveRDF
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def count
|
59
|
-
query = "SELECT COUNT(DISTINCT ?s) WHERE { GRAPH <#{self.graph}> { ?s a <#{self.type}> }}"
|
60
|
-
|
61
|
-
result.
|
59
|
+
#query = "SELECT COUNT(DISTINCT ?s) WHERE { GRAPH <#{self.graph}> { ?s a <#{self.type}> }}"
|
60
|
+
query = RDF::Virtuoso::Query.select(:s).count(:s).distinct.where([:s, RDF.type, self.type ])
|
61
|
+
result = connection.select(query)
|
62
|
+
result.first[:count].to_i
|
62
63
|
end
|
63
64
|
|
64
65
|
def find(object_or_id, conditions = {})
|
@@ -78,7 +79,7 @@ module ActiveRDF
|
|
78
79
|
|
79
80
|
def execute(sql)
|
80
81
|
results = []
|
81
|
-
solutions =
|
82
|
+
solutions = connection.select(sql)
|
82
83
|
solutions.each do |solution|
|
83
84
|
record = new
|
84
85
|
solution.each_binding do |name, value|
|
@@ -103,7 +104,8 @@ module ActiveRDF
|
|
103
104
|
end
|
104
105
|
|
105
106
|
def destroy_all
|
106
|
-
query = "DELETE FROM <#{self.graph}> { ?s ?p ?o } WHERE { GRAPH <#{self.graph}> { ?s a <#{self.type}> . ?s ?p ?o } }"
|
107
|
+
#query = "DELETE FROM <#{self.graph}> { ?s ?p ?o } WHERE { GRAPH <#{self.graph}> { ?s a <#{self.type}> . ?s ?p ?o } }"
|
108
|
+
query = RDF::Virtuoso::Query.delete([:s, :p, :o]).graph(self.graph).where([:s, RDF.type, self.type],[:s, :p, :o])
|
107
109
|
connection.delete(query)
|
108
110
|
end
|
109
111
|
|
@@ -129,11 +131,8 @@ module ActiveRDF
|
|
129
131
|
|
130
132
|
def destroy
|
131
133
|
subject = subject_for(self.id)
|
132
|
-
|
133
|
-
|
134
|
-
DELETE FROM <#{graph}> { <#{subject}> ?p ?o }
|
135
|
-
WHERE { <#{subject}> ?p ?o }
|
136
|
-
q
|
134
|
+
#p subject
|
135
|
+
query = RDF::Virtuoso::Query.delete([subject, :p, :o]).graph(graph).where([subject, :p, :o])
|
137
136
|
result = connection.delete(query)
|
138
137
|
end
|
139
138
|
|
data/lib/active_rdf/version.rb
CHANGED
data/lib/rdf/virtuoso/query.rb
CHANGED
@@ -83,7 +83,6 @@ module RDF::Virtuoso
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def self.insert(*patterns)
|
86
|
-
# options = variables.last.is_a?(Hash) ? variables.pop : {}
|
87
86
|
options = patterns.last.is_a?(Hash) ? patterns.pop : {}
|
88
87
|
self.new(:insert, options).insert(*patterns)
|
89
88
|
end
|
@@ -385,7 +384,10 @@ module RDF::Virtuoso
|
|
385
384
|
end
|
386
385
|
|
387
386
|
##
|
388
|
-
# @private
|
387
|
+
# @private
|
388
|
+
# make RDF::Query::Pattern from triple array if not already done
|
389
|
+
# include :context in Statement
|
390
|
+
# @return [RDF::Query::Pattern]
|
389
391
|
def build_patterns(patterns)
|
390
392
|
patterns.map do |pattern|
|
391
393
|
case pattern
|
@@ -540,10 +542,21 @@ module RDF::Virtuoso
|
|
540
542
|
|
541
543
|
unless patterns.empty? && ([:describe, :insert_data, :delete_data, :create, :clear, :drop].include?(form))
|
542
544
|
buffer << 'WHERE {'
|
543
|
-
|
545
|
+
|
544
546
|
buffer << '{' if options[:unions]
|
545
|
-
|
546
|
-
|
547
|
+
|
548
|
+
# iterate patterns
|
549
|
+
# does patterns have :context hash? build with GRAPH statement
|
550
|
+
if patterns.any? { |p| p.has_context? }
|
551
|
+
patterns.each do | pattern|
|
552
|
+
buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))} {"
|
553
|
+
buffer << serialize_patterns(pattern)
|
554
|
+
buffer << '}'
|
555
|
+
end
|
556
|
+
else
|
557
|
+
buffer += serialize_patterns(patterns)
|
558
|
+
end
|
559
|
+
|
547
560
|
if options[:optionals]
|
548
561
|
options[:optionals].each do |patterns|
|
549
562
|
buffer << 'OPTIONAL {'
|
@@ -591,8 +604,12 @@ module RDF::Virtuoso
|
|
591
604
|
##
|
592
605
|
# @private
|
593
606
|
def serialize_patterns(patterns)
|
594
|
-
patterns.
|
595
|
-
|
607
|
+
if patterns.is_a?(RDF::Query::Pattern)
|
608
|
+
patterns.to_triple.map { |v| serialize_value(v) }.join(' ') << " ."
|
609
|
+
else
|
610
|
+
patterns.map do |p|
|
611
|
+
p.to_triple.map { |v| serialize_value(v) }.join(' ') << " ."
|
612
|
+
end
|
596
613
|
end
|
597
614
|
end
|
598
615
|
|
@@ -624,7 +641,7 @@ module RDF::Virtuoso
|
|
624
641
|
# the N-Triples serializer is fine unless it's a variable:
|
625
642
|
case
|
626
643
|
when value.is_a?(String) then value.inspect
|
627
|
-
when value.
|
644
|
+
when value.is_a?(RDF::Query::Variable) then value.to_s
|
628
645
|
else RDF::NTriples.serialize(value)
|
629
646
|
end
|
630
647
|
end
|
data/lib/rdf/virtuoso/version.rb
CHANGED
@@ -17,12 +17,12 @@ describe ActiveRDF::Persistence do
|
|
17
17
|
|
18
18
|
it "formats the destroy query correctly" do
|
19
19
|
subject = resource.subject_for(resource.id)
|
20
|
-
query =
|
21
|
-
|
22
|
-
DELETE FROM <#{resource.graph}> { <#{subject}> ?p ?o }
|
23
|
-
WHERE { <#{subject}> ?p ?o }
|
24
|
-
q
|
25
|
-
|
20
|
+
# query =
|
21
|
+
#<<-q
|
22
|
+
#DELETE FROM <#{resource.graph}> { <#{subject}> ?p ?o }
|
23
|
+
#WHERE { <#{subject}> ?p ?o }
|
24
|
+
#q
|
25
|
+
query = RDF::Virtuoso::Query.delete([subject, :p, :o]).graph(resource.graph).where([subject, :p, :o])
|
26
26
|
resource.connection.should_receive(:delete).with(query)
|
27
27
|
resource.destroy
|
28
28
|
end
|
data/spec/query_spec.rb
CHANGED
@@ -127,7 +127,14 @@ describe RDF::Virtuoso::Query do
|
|
127
127
|
).to_s.should ==
|
128
128
|
"SELECT * WHERE { ?s ?p ?o . ?s <#{RDF.type}> <#{RDF::DC.Document}> . }"
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
|
+
it "should support SELECT WHERE patterns from different GRAPH contexts" do
|
132
|
+
@graph1 = "http://example1.org/"
|
133
|
+
@graph2 = "http://example2.org/"
|
134
|
+
@query.select.where([:s, :p, :o, :context => @graph1],[:s, RDF.type, RDF::DC.Document, :context => @graph2]).to_s.should ==
|
135
|
+
"SELECT * WHERE { GRAPH <#{@graph1}> { ?s ?p ?o . } GRAPH <#{@graph2}> { ?s <#{RDF.type}> <#{RDF::DC.Document}> . } }"
|
136
|
+
end
|
137
|
+
|
131
138
|
it "should support string objects in SPARQL queries" do
|
132
139
|
@query.select.where([:s, :p, "dummyobject"]).to_s.should == "SELECT * WHERE { ?s ?p \"dummyobject\" . }"
|
133
140
|
end
|
@@ -158,7 +165,7 @@ describe RDF::Virtuoso::Query do
|
|
158
165
|
@query.select.count(:s).where([:s, :p, :o]).to_s.should == "SELECT (COUNT (?s) AS ?count) WHERE { ?s ?p ?o . }"
|
159
166
|
end
|
160
167
|
|
161
|
-
it "should support aggregates SUM, MIN, MAX, AVG, SAMPLE" do
|
168
|
+
it "should support aggregates SUM, MIN, MAX, AVG, SAMPLE, GROUP_CONCAT, GROUP_DIGEST" do
|
162
169
|
@query.select.where([:s, :p, :o]).sum(:s).to_s.should == "SELECT (SUM (?s) AS ?sum) WHERE { ?s ?p ?o . }"
|
163
170
|
@query.select.where([:s, :p, :o]).min(:s).to_s.should == "SELECT (MIN (?s) AS ?min) WHERE { ?s ?p ?o . }"
|
164
171
|
@query.select.where([:s, :p, :o]).max(:s).to_s.should == "SELECT (MAX (?s) AS ?max) WHERE { ?s ?p ?o . }"
|
data/spec/repository_spec.rb
CHANGED
@@ -9,8 +9,6 @@ describe RDF::Virtuoso do
|
|
9
9
|
context "when connecting to a Virtuoso server" do
|
10
10
|
it "should support connecting to a Virtuoso SPARQL endpoint" do
|
11
11
|
repo = RDF::Virtuoso::Repository.new(@uri)
|
12
|
-
p repo
|
13
|
-
|
14
12
|
repo.instance_variable_get("@sparul_endpoint").should == "/sparql"
|
15
13
|
end
|
16
14
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-virtuoso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-08-
|
13
|
+
date: 2012-08-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -83,7 +83,7 @@ dependencies:
|
|
83
83
|
requirements:
|
84
84
|
- - ~>
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version: 3.2.
|
86
|
+
version: 3.2.3
|
87
87
|
type: :runtime
|
88
88
|
prerelease: false
|
89
89
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -91,7 +91,7 @@ dependencies:
|
|
91
91
|
requirements:
|
92
92
|
- - ~>
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version: 3.2.
|
94
|
+
version: 3.2.3
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: active_attr
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,17 +161,17 @@ dependencies:
|
|
161
161
|
requirement: !ruby/object:Gem::Requirement
|
162
162
|
none: false
|
163
163
|
requirements:
|
164
|
-
- -
|
164
|
+
- - ~>
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0.8.
|
166
|
+
version: 0.8.2
|
167
167
|
type: :runtime
|
168
168
|
prerelease: false
|
169
169
|
version_requirements: !ruby/object:Gem::Requirement
|
170
170
|
none: false
|
171
171
|
requirements:
|
172
|
-
- -
|
172
|
+
- - ~>
|
173
173
|
- !ruby/object:Gem::Version
|
174
|
-
version: 0.8.
|
174
|
+
version: 0.8.2
|
175
175
|
- !ruby/object:Gem::Dependency
|
176
176
|
name: api_smith
|
177
177
|
requirement: !ruby/object:Gem::Requirement
|
@@ -197,25 +197,25 @@ extensions: []
|
|
197
197
|
extra_rdoc_files: []
|
198
198
|
files:
|
199
199
|
- README.md
|
200
|
-
- lib/
|
200
|
+
- lib/active_rdf.rb
|
201
201
|
- lib/rdf/virtuoso/version.rb
|
202
|
-
- lib/rdf/virtuoso/
|
202
|
+
- lib/rdf/virtuoso/query.rb
|
203
203
|
- lib/rdf/virtuoso/prefixes.rb
|
204
204
|
- lib/rdf/virtuoso/repository.rb
|
205
|
-
- lib/rdf/virtuoso/
|
206
|
-
- lib/
|
207
|
-
- lib/active_rdf/version.rb
|
208
|
-
- lib/active_rdf/reflections.rb
|
209
|
-
- lib/active_rdf/association_reflection.rb
|
205
|
+
- lib/rdf/virtuoso/parser.rb
|
206
|
+
- lib/rdf/virtuoso.rb
|
210
207
|
- lib/active_rdf/persistence.rb
|
208
|
+
- lib/active_rdf/reflections.rb
|
209
|
+
- lib/active_rdf/version.rb
|
211
210
|
- lib/active_rdf/errors.rb
|
212
|
-
- lib/active_rdf/
|
211
|
+
- lib/active_rdf/association_reflection.rb
|
213
212
|
- lib/active_rdf/exceptions.rb
|
213
|
+
- lib/active_rdf/model.rb
|
214
214
|
- spec/repository_spec.rb
|
215
|
+
- spec/prefixes_spec.rb
|
215
216
|
- spec/query_spec.rb
|
216
217
|
- spec/spec_helper.rb
|
217
218
|
- spec/active_rdf/persistence_spec.rb
|
218
|
-
- spec/prefixes_spec.rb
|
219
219
|
homepage: https://github.com/digibib/rdf-virtuoso
|
220
220
|
licenses: []
|
221
221
|
post_install_message:
|