sparql 1.1.8 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -6
- data/VERSION +1 -1
- data/bin/sparql +97 -40
- data/lib/sparql/algebra/operator.rb +17 -11
- data/lib/sparql/algebra/operator/create.rb +0 -1
- data/lib/sparql/algebra/operator/with.rb +1 -1
- data/lib/sparql/algebra/query.rb +0 -1
- data/lib/sparql/grammar/parser11.rb +6 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1f482dd9f82cbd685ddf363d85fce672b73ffa2
|
4
|
+
data.tar.gz: 42dad47f92ec19e8620b4fe9056fd56393e4e4ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73afb94c540c89133b1321c7075de3e77e7cba8a36e21282e673caa058e3cbe4bdff247b0ac02530ba4fd55e059dd1c480a151d74e0c2415445496d710131615
|
7
|
+
data.tar.gz: 8a7377e7d6a9ecda3c16e821b62751ec84557c3dbdbac26e0e9bf3f9f99bf2aee9720f044f21b9ab5bb7d4b86c27b8b6a12328c0916e83fb578af6bb3d5e8d60
|
data/README.md
CHANGED
@@ -171,16 +171,19 @@ a full set of RDF formats.
|
|
171
171
|
|
172
172
|
### Command line processing
|
173
173
|
|
174
|
-
sparql --
|
175
|
-
sparql -e "SELECT * FROM <etc/doap.ttl> WHERE { ?s ?p ?o }"
|
174
|
+
sparql execute --dataset etc/doap.ttl etc/from_default.rq
|
175
|
+
sparql execute -e "SELECT * FROM <etc/doap.ttl> WHERE { ?s ?p ?o }"
|
176
176
|
|
177
177
|
# Generate SPARQL Algebra Expression (SSE) format
|
178
|
-
sparql
|
179
|
-
sparql
|
178
|
+
sparql parse etc/input.rq
|
179
|
+
sparql parse -e "SELECT * WHERE { ?s ?p ?o }"
|
180
180
|
|
181
181
|
# Run query using SSE input
|
182
|
-
sparql --
|
183
|
-
sparql --sse -e "(dataset (<etc/doap.ttl>) (bgp (triple ?s ?p ?o))))"
|
182
|
+
sparql execute --dataset etc/doap.ttl --sse etc/input.sse
|
183
|
+
sparql execute --sse -e "(dataset (<etc/doap.ttl>) (bgp (triple ?s ?p ?o))))"
|
184
|
+
|
185
|
+
# Run a local SPARQL server using a dataset
|
186
|
+
sparql server etc/doap.ttl
|
184
187
|
|
185
188
|
### Adding SPARQL content negotiation to a Rails 3.x application
|
186
189
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.9
|
data/bin/sparql
CHANGED
@@ -4,17 +4,26 @@ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", 'lib')))
|
|
4
4
|
require 'sparql'
|
5
5
|
begin
|
6
6
|
require 'linkeddata'
|
7
|
-
rescue LoadError
|
7
|
+
rescue LoadError
|
8
8
|
require 'rdf/ntriples'
|
9
9
|
end
|
10
10
|
require 'getoptlong'
|
11
11
|
|
12
|
+
def display_results(res, options)
|
13
|
+
puts res.inspect if options[:verbose]
|
14
|
+
puts case res
|
15
|
+
when RDF::Graph then res.dump(:ttl, base_uri: query.base_uri, prefixes: query.prefixes, standard_prefixes: true)
|
16
|
+
when RDF::Literal then res.inspect
|
17
|
+
else res.map {|s| s.bindings.map {|k,v| "#{k}: #{v}"}}.join("\n")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
12
21
|
def run(input, options = {})
|
13
22
|
if options[:debug]
|
14
|
-
puts "input graph:\n#{options[:
|
23
|
+
puts "input graph:\n#{options[:dataset].dump(:trig, standard_prefixes: true)}\n" if options[:dataset]
|
15
24
|
puts "query:\n#{input}\n"
|
16
25
|
end
|
17
|
-
options[:
|
26
|
+
options[:dataset] ||= RDF::Repository.new
|
18
27
|
|
19
28
|
if options[:verbose]
|
20
29
|
puts ("\nSPARQL:\n" + input)
|
@@ -30,67 +39,115 @@ def run(input, options = {})
|
|
30
39
|
puts ("\nSSE:\n" + query.to_sse) if options[:debug] || options[:to_sse]
|
31
40
|
|
32
41
|
unless options[:to_sse]
|
33
|
-
res = query.execute(options[:
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
42
|
+
res = query.execute(options[:dataset], debug: options[:debug])
|
43
|
+
display_results(res, options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def server(options)
|
48
|
+
require 'sinatra/sparql'
|
49
|
+
repository = options.fetch(:dataset, RDF::Repository.new)
|
50
|
+
|
51
|
+
app = Sinatra.new do
|
52
|
+
register Sinatra::SPARQL
|
53
|
+
set :repository, repository
|
54
|
+
|
55
|
+
get '/' do
|
56
|
+
if params["query"]
|
57
|
+
query = params["query"].to_s.match(/^http:/) ? RDF::Util::File.open_file(params["query"]) : ::URI.decode(params["query"].to_s)
|
58
|
+
SPARQL.execute(query, settings.repository)
|
59
|
+
else
|
60
|
+
settings.sparql_options.replace(standard_prefixes: true)
|
61
|
+
settings.sparql_options.merge!(:prefixes => {
|
62
|
+
ssd: "http://www.w3.org/ns/sparql-service-description#",
|
63
|
+
void: "http://rdfs.org/ns/void#"
|
64
|
+
})
|
65
|
+
service_description(repo: settings.repository, endpoint: url)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
post '/' do
|
70
|
+
SPARQL.execute(params['query'], settings.repository)
|
39
71
|
end
|
40
72
|
end
|
73
|
+
Rack::Server.start(app: app)
|
74
|
+
rescue LoadError
|
75
|
+
$stderr.puts "Running SPARQL server requires Rack to be in environment: #{$!.message}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def usage
|
79
|
+
puts "Usage: #{$0} execute [options] query-file Execute a query against the specified dataset"
|
80
|
+
puts " #{$0} parse [options] query-file Parse a query into SPARQL S-Expressions (SSE)"
|
81
|
+
puts " #{$0} query [options] end-point query-file Run the query against a remote end-point"
|
82
|
+
puts " #{$0} server [options] dataset-file Start a server initialized from the specified dataset"
|
83
|
+
puts "Options:"
|
84
|
+
puts " --execute,-e: Use option argument as the SPARQL input if no query-file given"
|
85
|
+
puts " --dataset: File containing RDF graph or dataset"
|
86
|
+
puts " --debug: Display detailed debug output"
|
87
|
+
puts " --port,-p Port on which to run server; defaults to 9292"
|
88
|
+
puts " --sse: Query input is in SSE format"
|
89
|
+
puts " --debug: Display detailed debug output"
|
90
|
+
puts " --update: Process query as a SPARQL Update"
|
91
|
+
puts " --verbose: Display details of processing"
|
92
|
+
puts " --help,-?: This message"
|
93
|
+
exit(0)
|
41
94
|
end
|
42
95
|
|
96
|
+
cmd, input = ARGV.shift, nil
|
97
|
+
|
43
98
|
opts = GetoptLong.new(
|
99
|
+
["--dataset", GetoptLong::REQUIRED_ARGUMENT],
|
44
100
|
["--debug", GetoptLong::NO_ARGUMENT],
|
45
|
-
["--
|
101
|
+
["--port", "-p", GetoptLong::REQUIRED_ARGUMENT],
|
46
102
|
["--verbose", GetoptLong::NO_ARGUMENT],
|
47
103
|
["--sse", GetoptLong::NO_ARGUMENT],
|
48
|
-
["--
|
104
|
+
["--update", GetoptLong::NO_ARGUMENT],
|
49
105
|
["--execute", "-e", GetoptLong::REQUIRED_ARGUMENT],
|
50
|
-
["--default-graph", "-g", GetoptLong::REQUIRED_ARGUMENT],
|
51
106
|
["--help", "-?", GetoptLong::NO_ARGUMENT]
|
52
107
|
)
|
53
108
|
|
54
109
|
options = {
|
55
|
-
|
110
|
+
dataset: RDF::Repository.new,
|
56
111
|
}
|
57
112
|
|
58
|
-
input = nil
|
59
|
-
|
60
113
|
opts.each do |opt, arg|
|
61
114
|
case opt
|
115
|
+
when '--dataset' then options[:dataset].load(arg)
|
62
116
|
when '--execute' then input = arg
|
63
|
-
when
|
64
|
-
when '--dump' then $dump = true
|
117
|
+
when '--port' then options[:port] = arg.to_i
|
65
118
|
when '--sse' then options[:sse] = true
|
66
|
-
when '--to-sse' then options[:to_sse] = true
|
67
119
|
when '--debug' then options[:debug] = true
|
68
120
|
when '--update' then options[:update] = true
|
69
121
|
when '--verbose' then options[:verbose] = true
|
70
|
-
when "--help"
|
71
|
-
puts "Usage: #{$0} [options] file-or-uri ..."
|
72
|
-
puts "Options:"
|
73
|
-
puts " --execute,-e: Use option argument as the SPARQL input if no files are given"
|
74
|
-
puts " --default-graph: Load default graph"
|
75
|
-
puts " --dump: Dump raw output, otherwise serialize to SSE"
|
76
|
-
puts " --debug: Display detailed debug output"
|
77
|
-
puts " --sse: Input is in SSE format"
|
78
|
-
puts " --to-sse: Generate SSE instead of running query"
|
79
|
-
puts " --debug: Display detailed debug output"
|
80
|
-
puts " --update: Process query as a SPARQL Update"
|
81
|
-
puts " --verbose: Display details of processing"
|
82
|
-
puts " --help,-?: This message"
|
83
|
-
exit(0)
|
122
|
+
when "--help" then usage
|
84
123
|
end
|
85
124
|
end
|
86
125
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
126
|
+
unless %w(execute query parse server help).include?(cmd)
|
127
|
+
$stderr.puts "Unrecognized command #{cmd}"
|
128
|
+
usage
|
129
|
+
end
|
130
|
+
|
131
|
+
case cmd
|
132
|
+
when 'execute', 'parse'
|
133
|
+
options[:to_sse] = true if cmd == 'parse'
|
134
|
+
input ||= ARGV.empty? ? $stdin.read : RDF::Util::File.open_file(ARGV.first).read
|
135
|
+
run(input, options)
|
136
|
+
when 'query'
|
137
|
+
endpoint = ARGV.shift
|
138
|
+
unless endpoint
|
139
|
+
$stderr.puts "Expected SPARQL endpoint URL"
|
140
|
+
usage
|
141
|
+
end
|
142
|
+
input ||= ARGV.empty? ? $stdin.read : RDF::Util::File.open_file(ARGV.first).read
|
143
|
+
SPARQL::Client.new(endpoint) do |client|
|
144
|
+
res = client.query(input)
|
145
|
+
display_results(res, options)
|
146
|
+
end
|
147
|
+
when 'server'
|
148
|
+
if data_file = ARGV.shift
|
149
|
+
options[:dataset] = RDF::Repository.load(data_file)
|
94
150
|
end
|
151
|
+
server(options)
|
152
|
+
else usage
|
95
153
|
end
|
96
|
-
puts
|
@@ -584,23 +584,29 @@ module SPARQL; module Algebra
|
|
584
584
|
end
|
585
585
|
|
586
586
|
##
|
587
|
-
#
|
587
|
+
# Enumerate via depth-first recursive descent over operands, yielding each operator
|
588
588
|
# @yield operator
|
589
589
|
# @yieldparam [Object] operator
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
operand
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
590
|
+
# @return [Enumerator]
|
591
|
+
def each_descendant(&block)
|
592
|
+
if block_given?
|
593
|
+
operands.each do |operand|
|
594
|
+
case operand
|
595
|
+
when Array
|
596
|
+
operand.each do |op|
|
597
|
+
op.each_descendant(&block) if op.respond_to?(:each_descendant)
|
598
|
+
block.call(op)
|
599
|
+
end
|
600
|
+
else
|
601
|
+
operand.each_descendant(&block) if operand.respond_to?(:each_descendant)
|
599
602
|
end
|
603
|
+
block.call(operand)
|
600
604
|
end
|
601
|
-
block.call(operand)
|
602
605
|
end
|
606
|
+
enum_for(:each_descendant)
|
603
607
|
end
|
608
|
+
alias_method :descendants, :each_descendant
|
609
|
+
alias_method :each, :each_descendant
|
604
610
|
|
605
611
|
##
|
606
612
|
# Parent expression, if any
|
@@ -37,7 +37,6 @@ module SPARQL; module Algebra
|
|
37
37
|
operands.shift if silent
|
38
38
|
|
39
39
|
iri = operands.first
|
40
|
-
#require 'byebug'; byebug
|
41
40
|
raise ArgumentError, "clear expected a single IRI" if operands.length != 1 || !iri.is_a?(RDF::URI)
|
42
41
|
if queryable.has_context?(iri)
|
43
42
|
raise IOError, "create operation graph #{iri.to_ntriples} exists" unless silent
|
data/lib/sparql/algebra/query.rb
CHANGED
@@ -552,6 +552,7 @@ module SPARQL::Grammar
|
|
552
552
|
end
|
553
553
|
production(:QuadData) do |input, data, callback|
|
554
554
|
# Transform using statements instead of patterns, and verify there are no variables
|
555
|
+
raise Error, "QuadData empty" unless data[:pattern]
|
555
556
|
raise Error, "QuadData contains variable operands: #{data[:pattern].to_sse}" if data[:pattern].first.variable?
|
556
557
|
self.nd_var_gen = "0"
|
557
558
|
input[:pattern] = data[:pattern]
|
@@ -881,8 +882,6 @@ module SPARQL::Grammar
|
|
881
882
|
|
882
883
|
# [85] VerbSimple ::= Var
|
883
884
|
production(:VerbSimple) do |input, data, callback|
|
884
|
-
#require 'byebug'; byebug
|
885
|
-
#data.values.each {|v| add_prod_datum(:Verb, v)}
|
886
885
|
input[:Verb] = data.values.flatten.first
|
887
886
|
end
|
888
887
|
|
@@ -1691,17 +1690,14 @@ module SPARQL::Grammar
|
|
1691
1690
|
# Create URIs
|
1692
1691
|
def iri(value)
|
1693
1692
|
# If we have a base URI, use that when constructing a new URI
|
1694
|
-
|
1695
|
-
|
1696
|
-
u
|
1693
|
+
value = RDF::URI(value)
|
1694
|
+
if base_uri && value.relative?
|
1695
|
+
u = base_uri.join(value)
|
1696
|
+
u.lexical = "<#{value}>" unless resolve_iris?
|
1697
1697
|
u
|
1698
1698
|
else
|
1699
|
-
|
1699
|
+
value
|
1700
1700
|
end
|
1701
|
-
|
1702
|
-
#iri.validate! if validate? && iri.respond_to?(:validate)
|
1703
|
-
#iri = RDF::URI.intern(iri) if intern?
|
1704
|
-
iri
|
1705
1701
|
end
|
1706
1702
|
|
1707
1703
|
def ns(prefix, suffix)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sparql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdf
|