-
Notifications
You must be signed in to change notification settings - Fork 14
/
suite_helper.rb
271 lines (255 loc) · 8.66 KB
/
suite_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# Spira class for manipulating test-manifest style test suites.
# Used for Turtle tests
require 'rdf/turtle'
require 'json/ld'
require_relative 'support/extensions/isomorphic'
require_relative 'support/matchers/solutions'
require_relative 'support/models'
# For now, override RDF::Utils::File.open_file to look for the file locally before attempting to retrieve it
module RDF::Util
module File
REMOTE_PATH = "http://w3c.github.io/rdf-tests/sparql/"
LOCAL_PATH = ::File.expand_path("../rdf-tests/sparql/", __FILE__) + '/'
REMOTE_PATH_STAR = "https://w3c.github.io/rdf-star-cg/"
LOCAL_PATH_STAR = ::File.expand_path("../rdf-star-cg/", __FILE__) + '/'
REMOTE_PATH_12 = "https://w3c.github.io/sparql-12/"
LOCAL_PATH_12 = ::File.expand_path("../w3c-sparql-12/", __FILE__) + '/'
REMOTE_PATH_PROTO = "http://kasei.us/2009/09/sparql/data/"
LOCAL_PATH_PROTO = ::File.expand_path("../fixtures/", __FILE__) + '/'
class << self
alias_method :original_open_file, :open_file
end
##
# Override to use Patron for http and https, Kernel.open otherwise.
#
# @param [String] filename_or_url to open
# @param [Hash{Symbol => Object}] options
# @option options [Array, String] :headers
# HTTP Request headers.
# @return [IO] File stream
# @yield [IO] File stream
def self.open_file(filename_or_url, **options, &block)
case
when filename_or_url.to_s =~ /^file:/
path = filename_or_url[5..-1]
Kernel.open(path.to_s, options, &block)
when (filename_or_url.to_s =~ %r{^#{REMOTE_PATH}} && Dir.exist?(LOCAL_PATH))
#puts "attempt to open #{filename_or_url} locally"
localpath = filename_or_url.to_s.sub(REMOTE_PATH, LOCAL_PATH)
response = begin
::File.open(localpath)
rescue Errno::ENOENT => e
raise IOError, e.message
end
document_options = {
base_uri: RDF::URI(filename_or_url),
charset: Encoding::UTF_8,
code: 200,
headers: {}
}
#puts "use #{filename_or_url} locally"
document_options[:headers][:content_type] = case filename_or_url.to_s
when /\.ttl$/ then 'text/turtle'
when /\.nt$/ then 'application/n-triples'
when /\.jsonld$/ then 'application/ld+json'
else 'unknown'
end
document_options[:headers][:content_type] = response.content_type if response.respond_to?(:content_type)
# For overriding content type from test data
document_options[:headers][:content_type] = options[:contentType] if options[:contentType]
remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options)
if block_given?
yield remote_document
else
remote_document
end
when (filename_or_url.to_s =~ %r{^#{REMOTE_PATH_12}} && Dir.exist?(LOCAL_PATH_12))
#puts "attempt to open #{filename_or_url} locally"
localpath = filename_or_url.to_s.sub(REMOTE_PATH_12, LOCAL_PATH_12)
response = begin
::File.open(localpath)
rescue Errno::ENOENT => e
raise IOError, e.message
end
document_options = {
base_uri: RDF::URI(filename_or_url),
charset: Encoding::UTF_8,
code: 200,
headers: {}
}
#puts "use #{filename_or_url} locally"
document_options[:headers][:content_type] = case filename_or_url.to_s
when /\.ttl$/ then 'text/turtle'
when /\.nt$/ then 'application/n-triples'
when /\.jsonld$/ then 'application/ld+json'
else 'unknown'
end
document_options[:headers][:content_type] = response.content_type if response.respond_to?(:content_type)
# For overriding content type from test data
document_options[:headers][:content_type] = options[:contentType] if options[:contentType]
remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options)
if block_given?
yield remote_document
else
remote_document
end
when (filename_or_url.to_s =~ %r{^#{REMOTE_PATH_STAR}} && Dir.exist?(LOCAL_PATH_STAR))
#puts "attempt to open #{filename_or_url} locally"
localpath = filename_or_url.to_s.sub(REMOTE_PATH_STAR, LOCAL_PATH_STAR)
response = begin
::File.open(localpath)
rescue Errno::ENOENT => e
raise IOError, e.message
end
document_options = {
base_uri: RDF::URI(filename_or_url),
charset: Encoding::UTF_8,
code: 200,
headers: {}
}
#puts "use #{filename_or_url} locally"
document_options[:headers][:content_type] = case filename_or_url.to_s
when /\.ttl$/ then 'text/turtle'
when /\.nt$/ then 'application/n-triples'
when /\.jsonld$/ then 'application/ld+json'
else 'unknown'
end
document_options[:headers][:content_type] = response.content_type if response.respond_to?(:content_type)
# For overriding content type from test data
document_options[:headers][:content_type] = options[:contentType] if options[:contentType]
remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options)
if block_given?
yield remote_document
else
remote_document
end
when (filename_or_url.to_s =~ %r{^#{REMOTE_PATH_PROTO}} && Dir.exist?(LOCAL_PATH_PROTO))
#puts "attempt to open #{filename_or_url} locally"
localpath = filename_or_url.to_s.sub(REMOTE_PATH_PROTO, LOCAL_PATH_PROTO)
response = begin
::File.open(localpath)
rescue Errno::ENOENT => e
raise IOError, e.message
end
document_options = {
base_uri: RDF::URI(filename_or_url),
charset: Encoding::UTF_8,
code: 200,
headers: {}
}
#puts "use #{filename_or_url} locally"
document_options[:headers][:content_type] = case filename_or_url.to_s
when /\.ttl$/ then 'text/turtle'
when /\.nt$/ then 'application/n-triples'
when /\.jsonld$/ then 'application/ld+json'
else 'unknown'
end
document_options[:headers][:content_type] = response.content_type if response.respond_to?(:content_type)
# For overriding content type from test data
document_options[:headers][:content_type] = options[:contentType] if options[:contentType]
remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options)
if block_given?
yield remote_document
else
remote_document
end
else
original_open_file(filename_or_url, **options, &block)
end
end
end
end
module SPARQL::Spec
BASE = "http://w3c.github.io/rdf-tests/sparql/"
def self.sparql1_0_syntax_tests
%w(
syntax-sparql1
syntax-sparql2
syntax-sparql3
syntax-sparql4
syntax-sparql5
).map do |partial|
"#{BASE}sparql10/#{partial}/manifest.ttl"
end
end
def self.sparql1_0_tests
%w(
algebra
ask
basic
bnode-coreference
boolean-effective-value
bound
cast
construct
dataset
distinct
expr-builtin
expr-equals
expr-ops
graph
i18n
open-world
optional
optional-filter
reduced
regex
solution-seq
sort
triple-match
type-promotion
).map do |partial|
"#{BASE}sparql10/#{partial}/manifest.ttl"
end
end
def self.sparql1_1_tests
%w(
add
aggregates
basic-update
bind
bindings
cast
clear
construct
copy
csv-tsv-res
delete-data
delete-insert
delete-where
delete
drop
entailment
exists
functions
grouping
json-res
move
negation
project-expression
property-path
service
subquery
syntax-query
syntax-update-1
syntax-update-2
update-silent
syntax-fed
service-description
protocol
http-rdf-update
).map do |partial|
"#{BASE}sparql11/#{partial}/manifest.ttl"
end
end
def self.sparql_star_tests
%w(syntax/manifest eval/manifest).map do |man|
"https://w3c.github.io/rdf-star-cg/tests/sparql/#{man}.jsonld"
end
end
def self.sparql_12_tests
%w(xsd_functions property-path-min-max).map do |partial|
"https://w3c.github.io/sparql-12/tests/#{partial}/manifest.ttl"
end
end
end