rdf-tabular 2.2.2 → 3.1.0
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rdf/tabular/literal.rb +1 -1
- data/lib/rdf/tabular/metadata.rb +47 -47
- data/lib/rdf/tabular/reader.rb +15 -15
- data/spec/metadata_spec.rb +2 -8
- data/spec/suite_helper.rb +2 -2
- data/spec/suite_spec.rb +4 -5
- metadata +21 -28
- data/lib/rdf/tabular/json.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d840e057cd2f7f01a882004f99001f8cd1465592d1e2a50245f4d129ba3d16f
|
4
|
+
data.tar.gz: 7e719cc19261cd4a282d320cd94a79c0d32188418275f59b468b80f724b8a942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7e6027430e8da553654e349ecad2903a730ff75d94a22b96c14406ec97c11333fedfe643e245b4aa695ac7b2fce49a3b285a5539d1bb604bf94a1170a2e126d
|
7
|
+
data.tar.gz: 8efb5950cbdfdd4f3e65aec2848c395110d1f29f74ffaf25e22333983a8e27ac1261ea92cde7961280d22af7d210899e9d40d9c12affe4ab58fabb3ecd6732d5
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.1.0
|
data/lib/rdf/tabular/literal.rb
CHANGED
@@ -13,7 +13,7 @@ module RDF::Tabular
|
|
13
13
|
##
|
14
14
|
# @param [Object] value
|
15
15
|
# @option options [String] :lexical (nil)
|
16
|
-
def initialize(value, options
|
16
|
+
def initialize(value, **options)
|
17
17
|
@datatype = options[:datatype] || DATATYPE
|
18
18
|
@string = options[:lexical] if options.has_key?(:lexical)
|
19
19
|
if value.is_a?(String)
|
data/lib/rdf/tabular/metadata.rb
CHANGED
@@ -136,15 +136,15 @@ module RDF::Tabular
|
|
136
136
|
# see `RDF::Util::File.open_file` in RDF.rb and {new}
|
137
137
|
# @yield [Metadata]
|
138
138
|
# @raise [IOError] if file not found
|
139
|
-
def self.open(path, options
|
139
|
+
def self.open(path, **options)
|
140
140
|
options = options.merge(
|
141
141
|
headers: {
|
142
142
|
'Accept' => 'application/ld+json, application/json'
|
143
143
|
}
|
144
144
|
)
|
145
145
|
path = "file:" + path unless path =~ /^\w+:/
|
146
|
-
RDF::Util::File.open_file(path, options) do |file|
|
147
|
-
self.new(file, options.merge(base: path, filenames: path))
|
146
|
+
RDF::Util::File.open_file(path, **options) do |file|
|
147
|
+
self.new(file, **options.merge(base: path, filenames: path))
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
@@ -173,16 +173,16 @@ module RDF::Tabular
|
|
173
173
|
# @option options [RDF::URI] :base
|
174
174
|
# The Base URL to use when expanding the document. This overrides the value of `input` if it is a URL. If not specified and `input` is not an URL, the base URL defaults to the current document URL if in a browser context, or the empty string if there is no document context.
|
175
175
|
# @return [Metadata]
|
176
|
-
def self.for_input(input, options
|
176
|
+
def self.for_input(input, **options)
|
177
177
|
base = options[:base]
|
178
178
|
|
179
179
|
# Use user metadata, if provided
|
180
180
|
metadata = case options[:metadata]
|
181
181
|
when Metadata then options[:metadata]
|
182
182
|
when Hash
|
183
|
-
Metadata.new(options[:metadata], options.merge(reason: "load user metadata: #{options[:metadata].inspect}"))
|
183
|
+
Metadata.new(options[:metadata], **options.merge(reason: "load user metadata: #{options[:metadata].inspect}"))
|
184
184
|
when String, RDF::URI
|
185
|
-
Metadata.open(options[:metadata], options.merge(filenames: options[:metadata], reason: "load user metadata: #{options[:metadata].inspect}"))
|
185
|
+
Metadata.open(options[:metadata], **options.merge(filenames: options[:metadata], reason: "load user metadata: #{options[:metadata].inspect}"))
|
186
186
|
end
|
187
187
|
|
188
188
|
# Search for metadata until found
|
@@ -191,13 +191,13 @@ module RDF::Tabular
|
|
191
191
|
if !metadata && input.respond_to?(:links) &&
|
192
192
|
link = input.links.find_link(%w(rel describedby))
|
193
193
|
link_loc = RDF::URI(base).join(link.href).to_s
|
194
|
-
md = Metadata.open(link_loc, options.merge(filenames: link_loc, reason: "load linked metadata: #{link_loc}"))
|
194
|
+
md = Metadata.open(link_loc, **options.merge(filenames: link_loc, reason: "load linked metadata: #{link_loc}"))
|
195
195
|
if md
|
196
196
|
# Metadata must describe file to be useful
|
197
197
|
if md.describes_file?(base)
|
198
198
|
metadata = md
|
199
199
|
else
|
200
|
-
log_warn("Found metadata at #{link_loc}, which does not describe #{base}, ignoring", options)
|
200
|
+
log_warn("Found metadata at #{link_loc}, which does not describe #{base}, ignoring", **options)
|
201
201
|
end
|
202
202
|
end
|
203
203
|
end
|
@@ -206,28 +206,28 @@ module RDF::Tabular
|
|
206
206
|
# If we still don't have metadata, load the site-wide configuration file and use templates found there as locations
|
207
207
|
if !metadata && base
|
208
208
|
templates = site_wide_config(base)
|
209
|
-
log_debug("for_input", options) {"templates: #{templates.map(&:to_s).inspect}"}
|
209
|
+
log_debug("for_input", **options) {"templates: #{templates.map(&:to_s).inspect}"}
|
210
210
|
locs = templates.map do |template|
|
211
211
|
t = Addressable::Template.new(template)
|
212
212
|
RDF::URI(base).join(t.expand(url: base).to_s)
|
213
213
|
end
|
214
|
-
log_debug("for_input", options) {"locs: #{locs.map(&:to_s).inspect}"}
|
214
|
+
log_debug("for_input", **options) {"locs: #{locs.map(&:to_s).inspect}"}
|
215
215
|
|
216
216
|
locs.each do |loc|
|
217
217
|
metadata ||= begin
|
218
|
-
md = Metadata.open(loc, options.merge(filenames: loc, reason: "load found metadata: #{loc}"))
|
218
|
+
md = Metadata.open(loc, **options.merge(filenames: loc, reason: "load found metadata: #{loc}"))
|
219
219
|
# Metadata must describe file to be useful
|
220
220
|
if md
|
221
221
|
# Metadata must describe file to be useful
|
222
222
|
if md.describes_file?(base)
|
223
223
|
md
|
224
224
|
else
|
225
|
-
log_warn("Found metadata at #{loc}, which does not describe #{base}, ignoring", options)
|
225
|
+
log_warn("Found metadata at #{loc}, which does not describe #{base}, ignoring", **options)
|
226
226
|
nil
|
227
227
|
end
|
228
228
|
end
|
229
229
|
rescue IOError
|
230
|
-
log_debug("for_input", options) {"failed to load found metadata #{loc}: #{$!}"}
|
230
|
+
log_debug("for_input", **options) {"failed to load found metadata #{loc}: #{$!}"}
|
231
231
|
nil
|
232
232
|
end
|
233
233
|
end
|
@@ -236,8 +236,8 @@ module RDF::Tabular
|
|
236
236
|
# Return either the merge or user- and found-metadata, any of these, or an empty TableGroup
|
237
237
|
metadata = case
|
238
238
|
when metadata then metadata
|
239
|
-
when base then TableGroup.new({"@context" => "http://www.w3.org/ns/csvw", tables: [{url: base}]}, options)
|
240
|
-
else TableGroup.new({"@context" => "http://www.w3.org/ns/csvw", tables: [{url: nil}]}, options)
|
239
|
+
when base then TableGroup.new({"@context" => "http://www.w3.org/ns/csvw", tables: [{url: base}]}, **options)
|
240
|
+
else TableGroup.new({"@context" => "http://www.w3.org/ns/csvw", tables: [{url: nil}]}, **options)
|
241
241
|
end
|
242
242
|
|
243
243
|
# Make TableGroup, if not already
|
@@ -246,7 +246,7 @@ module RDF::Tabular
|
|
246
246
|
|
247
247
|
##
|
248
248
|
# @private
|
249
|
-
def self.new(input, options
|
249
|
+
def self.new(input, **options)
|
250
250
|
# Triveal case
|
251
251
|
return input if input.is_a?(Metadata)
|
252
252
|
|
@@ -297,7 +297,7 @@ module RDF::Tabular
|
|
297
297
|
end
|
298
298
|
|
299
299
|
md = klass.allocate
|
300
|
-
md.send(:initialize, object, options)
|
300
|
+
md.send(:initialize, object, **options)
|
301
301
|
md
|
302
302
|
rescue ::JSON::ParserError
|
303
303
|
raise Error, "Expected input to be a JSON Object"
|
@@ -318,7 +318,7 @@ module RDF::Tabular
|
|
318
318
|
# @option options [Boolean] :validate Strict metadata validation
|
319
319
|
# @raise [Error]
|
320
320
|
# @return [Metadata]
|
321
|
-
def initialize(input, options
|
321
|
+
def initialize(input, **options)
|
322
322
|
@options = options.dup
|
323
323
|
|
324
324
|
# Parent of this Metadata, if any
|
@@ -467,16 +467,16 @@ module RDF::Tabular
|
|
467
467
|
object[:tableSchema] = case value
|
468
468
|
when String
|
469
469
|
link = context.base.join(value).to_s
|
470
|
-
md = Schema.open(link,
|
470
|
+
md = Schema.open(link, **@options.merge(parent: self, context: nil, normalize: true))
|
471
471
|
md[:@id] ||= link
|
472
472
|
md
|
473
473
|
when Hash
|
474
|
-
Schema.new(value,
|
474
|
+
Schema.new(value, **@options.merge(parent: self, context: nil))
|
475
475
|
when Schema
|
476
476
|
value
|
477
477
|
else
|
478
478
|
log_warn "#{type} has invalid property 'tableSchema' (#{value.inspect}): expected a URL or object"
|
479
|
-
Schema.new({},
|
479
|
+
Schema.new({}, **@options.merge(parent: self, context: nil))
|
480
480
|
end
|
481
481
|
end
|
482
482
|
|
@@ -491,7 +491,7 @@ module RDF::Tabular
|
|
491
491
|
when object[:dialect] then object[:dialect]
|
492
492
|
when parent then parent.dialect
|
493
493
|
when is_a?(Table) || is_a?(TableGroup)
|
494
|
-
d = Dialect.new({},
|
494
|
+
d = Dialect.new({}, **@options.merge(parent: self, context: nil))
|
495
495
|
self.dialect = d unless self.parent
|
496
496
|
d
|
497
497
|
else
|
@@ -514,11 +514,11 @@ module RDF::Tabular
|
|
514
514
|
@dialect = object[:dialect] = case value
|
515
515
|
when String
|
516
516
|
link = context.base.join(value).to_s
|
517
|
-
md = Metadata.open(link,
|
517
|
+
md = Metadata.open(link, **@options.merge(parent: self, context: nil, normalize: true))
|
518
518
|
md[:@id] ||= link
|
519
519
|
md
|
520
520
|
when Hash
|
521
|
-
Dialect.new(value,
|
521
|
+
Dialect.new(value, **@options.merge(parent: self, context: nil))
|
522
522
|
when Dialect
|
523
523
|
value
|
524
524
|
else
|
@@ -532,8 +532,8 @@ module RDF::Tabular
|
|
532
532
|
# @raise [Error] if datatype is not valid
|
533
533
|
def datatype=(value)
|
534
534
|
val = case value
|
535
|
-
when Hash then Datatype.new(value,
|
536
|
-
else Datatype.new({base: value},
|
535
|
+
when Hash then Datatype.new(value, **@options.merge(parent: self))
|
536
|
+
else Datatype.new({base: value}, **@options.merge(parent: self))
|
537
537
|
end
|
538
538
|
|
539
539
|
if val.valid? || value.is_a?(Hash)
|
@@ -872,7 +872,7 @@ module RDF::Tabular
|
|
872
872
|
csv << data unless data.empty?
|
873
873
|
end
|
874
874
|
else
|
875
|
-
csv = ::CSV.new(input, csv_options)
|
875
|
+
csv = ::CSV.new(input, **csv_options)
|
876
876
|
# Skip skipRows and headerRowCount
|
877
877
|
skipped = (dialect.skipRows.to_i + dialect.headerRowCount)
|
878
878
|
(1..skipped).each {csv.shift}
|
@@ -891,7 +891,7 @@ module RDF::Tabular
|
|
891
891
|
next
|
892
892
|
end
|
893
893
|
number += 1
|
894
|
-
row = Row.new(data, self, number, number + skipped,
|
894
|
+
row = Row.new(data, self, number, number + skipped, **@options)
|
895
895
|
(self.object[:rows] ||= []) << row if @options[:validate] # Keep track of rows when validating
|
896
896
|
yield(row)
|
897
897
|
end
|
@@ -1036,7 +1036,7 @@ module RDF::Tabular
|
|
1036
1036
|
end
|
1037
1037
|
index = 0
|
1038
1038
|
object_columns.all? do |cb|
|
1039
|
-
ca = non_virtual_columns[index] || Column.new({},
|
1039
|
+
ca = non_virtual_columns[index] || Column.new({}, **@options)
|
1040
1040
|
ta = ca.titles || {}
|
1041
1041
|
tb = cb.titles || {}
|
1042
1042
|
if !ca.object.has_key?(:name) && !cb.object.has_key?(:name) && ta.empty? && tb.empty?
|
@@ -1235,13 +1235,13 @@ module RDF::Tabular
|
|
1235
1235
|
end
|
1236
1236
|
|
1237
1237
|
# General setter for array properties
|
1238
|
-
def set_array_value(key, value, klass, options
|
1238
|
+
def set_array_value(key, value, klass, **options)
|
1239
1239
|
object[key] = case value
|
1240
1240
|
when Array
|
1241
1241
|
value.map do |v|
|
1242
1242
|
case v
|
1243
1243
|
when Hash
|
1244
|
-
klass.new(v,
|
1244
|
+
klass.new(v, **@options.merge(options).merge(parent: self, context: nil))
|
1245
1245
|
else v
|
1246
1246
|
end
|
1247
1247
|
end
|
@@ -1282,11 +1282,11 @@ module RDF::Tabular
|
|
1282
1282
|
class DebugContext
|
1283
1283
|
include RDF::Util::Logger
|
1284
1284
|
end
|
1285
|
-
def self.log_debug(*args, &block)
|
1286
|
-
DebugContext.new.log_debug(*args, &block)
|
1285
|
+
def self.log_debug(*args, **options, &block)
|
1286
|
+
DebugContext.new.log_debug(*args, **options, &block)
|
1287
1287
|
end
|
1288
|
-
def self.log_warn(*args)
|
1289
|
-
DebugContext.new.log_warn(*args)
|
1288
|
+
def self.log_warn(*args, **options)
|
1289
|
+
DebugContext.new.log_warn(*args, **options)
|
1290
1290
|
end
|
1291
1291
|
end
|
1292
1292
|
|
@@ -1434,7 +1434,7 @@ module RDF::Tabular
|
|
1434
1434
|
content['@context'] = object.delete(:@context) if object[:@context]
|
1435
1435
|
ctx = @context
|
1436
1436
|
remove_instance_variable(:@context) if instance_variables.include?(:@context)
|
1437
|
-
tg = TableGroup.new(content,
|
1437
|
+
tg = TableGroup.new(content, **@options.merge(context: ctx, filenames: @filenames, base: base))
|
1438
1438
|
@parent = tg # Link from parent
|
1439
1439
|
tg
|
1440
1440
|
end
|
@@ -1489,7 +1489,7 @@ module RDF::Tabular
|
|
1489
1489
|
number += 1
|
1490
1490
|
case v
|
1491
1491
|
when Hash
|
1492
|
-
Column.new(v,
|
1492
|
+
Column.new(v, **@options.merge(
|
1493
1493
|
table: (parent if parent.is_a?(Table)),
|
1494
1494
|
parent: self,
|
1495
1495
|
context: nil,
|
@@ -1621,8 +1621,8 @@ module RDF::Tabular
|
|
1621
1621
|
def name
|
1622
1622
|
self[:name] || if titles && (ts = titles[context.default_language || 'und'] || titles[self.lang || 'und'])
|
1623
1623
|
n = Array(ts).first
|
1624
|
-
n0 = URI.encode(n[0,1], /[^a-zA-Z0-9]/).encode("utf-8")
|
1625
|
-
n1 = URI.encode(n[1..-1], /[^\w\.]/).encode("utf-8")
|
1624
|
+
n0 = RDF::URI.encode(n[0,1], /[^a-zA-Z0-9]/).encode("utf-8")
|
1625
|
+
n1 = RDF::URI.encode(n[1..-1], /[^\w\.]/).encode("utf-8")
|
1626
1626
|
"#{n0}#{n1}"
|
1627
1627
|
end || "_col.#{number}"
|
1628
1628
|
end
|
@@ -1783,12 +1783,12 @@ module RDF::Tabular
|
|
1783
1783
|
# @option options [String] :lang, language to set in table, if any
|
1784
1784
|
# @return [Metadata] Tabular metadata
|
1785
1785
|
# @see http://w3c.github.io/csvw/syntax/#parsing
|
1786
|
-
def embedded_metadata(input, metadata, options
|
1786
|
+
def embedded_metadata(input, metadata, **options)
|
1787
1787
|
options = options.dup
|
1788
1788
|
options.delete(:context) # Don't accidentally use a passed context
|
1789
1789
|
# Normalize input to an IO object
|
1790
1790
|
if input.is_a?(String)
|
1791
|
-
return ::RDF::Util::File.open_file(input) {|f| embedded_metadata(f, metadata, options.merge(base: input.to_s))}
|
1791
|
+
return ::RDF::Util::File.open_file(input) {|f| embedded_metadata(f, metadata, **options.merge(base: input.to_s))}
|
1792
1792
|
end
|
1793
1793
|
|
1794
1794
|
table = {
|
@@ -1841,7 +1841,7 @@ module RDF::Tabular
|
|
1841
1841
|
end
|
1842
1842
|
end
|
1843
1843
|
else
|
1844
|
-
csv = ::CSV.new(input, csv_options)
|
1844
|
+
csv = ::CSV.new(input, **csv_options)
|
1845
1845
|
(1..skipRows.to_i).each do
|
1846
1846
|
value = csv.shift.join(delimiter) # Skip initial lines, these form comment annotations
|
1847
1847
|
# Trim value
|
@@ -1876,7 +1876,7 @@ module RDF::Tabular
|
|
1876
1876
|
log_debug("embedded_metadata") {"table: #{table.inspect}"}
|
1877
1877
|
input.rewind if input.respond_to?(:rewind)
|
1878
1878
|
|
1879
|
-
Table.new(table, options.merge(reason: "load embedded metadata: #{table['@id']}"))
|
1879
|
+
Table.new(table, **options.merge(reason: "load embedded metadata: #{table['@id']}"))
|
1880
1880
|
end
|
1881
1881
|
end
|
1882
1882
|
|
@@ -2026,7 +2026,7 @@ module RDF::Tabular
|
|
2026
2026
|
# @param [Hash{Symbol => Object}] options ({})
|
2027
2027
|
# @option options [Boolean] :validate check for PK/FK consistency
|
2028
2028
|
# @return [Row]
|
2029
|
-
def initialize(row, metadata, number, source_number, options
|
2029
|
+
def initialize(row, metadata, number, source_number, **options)
|
2030
2030
|
@table = metadata
|
2031
2031
|
@number = number
|
2032
2032
|
@sourceNumber = source_number
|
@@ -2058,13 +2058,13 @@ module RDF::Tabular
|
|
2058
2058
|
|
2059
2059
|
# create column if necessary
|
2060
2060
|
columns[index - skipColumns] ||=
|
2061
|
-
Column.new({}, options.merge(table: metadata, parent: metadata.tableSchema, number: index + 1 - skipColumns))
|
2061
|
+
Column.new({}, **options.merge(table: metadata, parent: metadata.tableSchema, number: index + 1 - skipColumns))
|
2062
2062
|
|
2063
2063
|
column = columns[index - skipColumns]
|
2064
2064
|
|
2065
2065
|
@values << cell = Cell.new(metadata, column, self, value)
|
2066
2066
|
|
2067
|
-
datatype = column.datatype || Datatype.new({base: "string"}, options.merge(parent: column))
|
2067
|
+
datatype = column.datatype || Datatype.new({base: "string"}, **options.merge(parent: column))
|
2068
2068
|
value = value.gsub(/\r\n\t/, ' ') unless %w(string json xml html anyAtomicType).include?(datatype.base)
|
2069
2069
|
value = value.strip.gsub(/\s+/, ' ') unless %w(string json xml html anyAtomicType normalizedString).include?(datatype.base)
|
2070
2070
|
# if the resulting string is an empty string, apply the remaining steps to the string given by the default property
|
@@ -2110,7 +2110,7 @@ module RDF::Tabular
|
|
2110
2110
|
# Map URLs for row
|
2111
2111
|
@values.each_with_index do |cell, index|
|
2112
2112
|
mapped_values = map_values.merge(
|
2113
|
-
"_name" =>
|
2113
|
+
"_name" => CGI.unescape(cell.column.name),
|
2114
2114
|
"_column" => cell.column.number,
|
2115
2115
|
"_sourceColumn" => cell.column.sourceNumber
|
2116
2116
|
)
|
data/lib/rdf/tabular/reader.rb
CHANGED
@@ -63,7 +63,7 @@ module RDF::Tabular
|
|
63
63
|
# @yieldparam [RDF::Reader] reader
|
64
64
|
# @yieldreturn [void] ignored
|
65
65
|
# @raise [RDF::ReaderError] if the CSV document cannot be loaded
|
66
|
-
def initialize(input = $stdin, options
|
66
|
+
def initialize(input = $stdin, **options, &block)
|
67
67
|
super do
|
68
68
|
# Base would be how we are to take this
|
69
69
|
@options[:base] ||= base_uri.to_s if base_uri
|
@@ -89,7 +89,7 @@ module RDF::Tabular
|
|
89
89
|
# If input is JSON, then the input is the metadata
|
90
90
|
content_type = @input.respond_to?(:content_type) ? @input.content_type : ""
|
91
91
|
if @options[:base] =~ /\.json(?:ld)?$/ || content_type =~ %r(application/(csvm\+|ld\+)?json)
|
92
|
-
@metadata = Metadata.new(@input,
|
92
|
+
@metadata = Metadata.new(@input, filenames: @options[:base], **@options)
|
93
93
|
# If @metadata is for a Table, turn it into a TableGroup
|
94
94
|
@metadata = @metadata.to_table_group if @metadata.is_a?(Table)
|
95
95
|
@metadata.normalize!
|
@@ -102,7 +102,7 @@ module RDF::Tabular
|
|
102
102
|
def script.content_type; "application/csvm+json"; end
|
103
103
|
log_debug("Reader#initialize") {"Process HTML script block"}
|
104
104
|
@input = script
|
105
|
-
@metadata = Metadata.new(@input,
|
105
|
+
@metadata = Metadata.new(@input, filenames: @options[:base], **@options)
|
106
106
|
# If @metadata is for a Table, turn it into a TableGroup
|
107
107
|
@metadata = @metadata.to_table_group if @metadata.is_a?(Table)
|
108
108
|
@metadata.normalize!
|
@@ -119,7 +119,7 @@ module RDF::Tabular
|
|
119
119
|
dialect.separator = "\t" if (input.content_type == "text/tsv" rescue nil)
|
120
120
|
embed_options = @options.dup
|
121
121
|
embed_options[:lang] = dialect_metadata.lang if dialect_metadata.lang
|
122
|
-
embedded_metadata = dialect.embedded_metadata(input, @options[:metadata], embed_options)
|
122
|
+
embedded_metadata = dialect.embedded_metadata(input, @options[:metadata], **embed_options)
|
123
123
|
|
124
124
|
if (@metadata = @options[:metadata]) && @metadata.tableSchema
|
125
125
|
@metadata.verify_compatible!(embedded_metadata)
|
@@ -136,7 +136,7 @@ module RDF::Tabular
|
|
136
136
|
else
|
137
137
|
# It's tabluar data. Find metadata and proceed as if it was specified in the first place
|
138
138
|
@options[:original_input] = @input unless @options[:metadata]
|
139
|
-
@input = @metadata = Metadata.for_input(@input,
|
139
|
+
@input = @metadata = Metadata.for_input(@input, **@options).normalize!
|
140
140
|
end
|
141
141
|
|
142
142
|
log_debug("Reader#initialize") {"input: #{input}, metadata: #{metadata.inspect}"}
|
@@ -186,7 +186,7 @@ module RDF::Tabular
|
|
186
186
|
if options[:original_input] && !input.describes_file?(options[:base_uri])
|
187
187
|
table_resource = RDF::Node.new
|
188
188
|
add_statement(0, table_group, CSVW.table, table_resource) unless minimal?
|
189
|
-
Reader.new(options[:original_input], options.merge(
|
189
|
+
Reader.new(options[:original_input], **options.merge(
|
190
190
|
metadata: input.tables.first,
|
191
191
|
base: input.tables.first.url,
|
192
192
|
no_found_metadata: true,
|
@@ -205,7 +205,7 @@ module RDF::Tabular
|
|
205
205
|
end.flatten.compact
|
206
206
|
table_resource = table.id || RDF::Node.new
|
207
207
|
add_statement(0, table_group, CSVW.table, table_resource) unless minimal?
|
208
|
-
Reader.open(table.url, options.merge(
|
208
|
+
Reader.open(table.url, **options.merge(
|
209
209
|
metadata: table,
|
210
210
|
base: table.url,
|
211
211
|
no_found_metadata: true,
|
@@ -421,9 +421,9 @@ module RDF::Tabular
|
|
421
421
|
|
422
422
|
res = if io
|
423
423
|
::JSON::dump_default_options = json_state
|
424
|
-
::JSON.dump(self.send(hash_fn, options), io)
|
424
|
+
::JSON.dump(self.send(hash_fn, **options), io)
|
425
425
|
else
|
426
|
-
hash = self.send(hash_fn, options)
|
426
|
+
hash = self.send(hash_fn, **options)
|
427
427
|
::JSON.generate(hash, json_state)
|
428
428
|
end
|
429
429
|
|
@@ -443,7 +443,7 @@ module RDF::Tabular
|
|
443
443
|
#
|
444
444
|
# @param [Hash{Symbol => Object}] options
|
445
445
|
# @return [Hash, Array]
|
446
|
-
def to_hash(options
|
446
|
+
def to_hash(**options)
|
447
447
|
# Construct metadata from that passed from file open, along with information from the file.
|
448
448
|
if input.is_a?(Metadata)
|
449
449
|
log_debug("each_statement: metadata") {input.inspect}
|
@@ -467,13 +467,13 @@ module RDF::Tabular
|
|
467
467
|
table_group['tables'] = tables
|
468
468
|
|
469
469
|
if options[:original_input] && !input.describes_file?(options[:base_uri])
|
470
|
-
Reader.new(options[:original_input], options.merge(
|
470
|
+
Reader.new(options[:original_input], **options.merge(
|
471
471
|
metadata: input.tables.first,
|
472
472
|
base: input.tables.first.url,
|
473
473
|
minimal: minimal?,
|
474
474
|
no_found_metadata: true,
|
475
475
|
)) do |r|
|
476
|
-
case t = r.to_hash(options)
|
476
|
+
case t = r.to_hash(**options)
|
477
477
|
when Array then tables += t unless input.tables.first.suppressOutput
|
478
478
|
when Hash then tables << t unless input.tables.first.suppressOutput
|
479
479
|
end
|
@@ -481,13 +481,13 @@ module RDF::Tabular
|
|
481
481
|
else
|
482
482
|
input.each_table do |table|
|
483
483
|
next if table.suppressOutput && !validate?
|
484
|
-
Reader.open(table.url, options.merge(
|
484
|
+
Reader.open(table.url, **options.merge(
|
485
485
|
metadata: table,
|
486
486
|
base: table.url,
|
487
487
|
minimal: minimal?,
|
488
488
|
no_found_metadata: true,
|
489
489
|
)) do |r|
|
490
|
-
case t = r.to_hash(options)
|
490
|
+
case t = r.to_hash(**options)
|
491
491
|
when Array then tables += t unless table.suppressOutput
|
492
492
|
when Hash then tables << t unless table.suppressOutput
|
493
493
|
end
|
@@ -560,7 +560,7 @@ module RDF::Tabular
|
|
560
560
|
co['@id'] = subject.to_s unless subject == 'null'
|
561
561
|
prop = case cell.propertyUrl
|
562
562
|
when RDF.type then '@type'
|
563
|
-
when nil then
|
563
|
+
when nil then CGI.unescape(column.name) # Use URI-decoded name
|
564
564
|
else
|
565
565
|
# Compact the property to a term or prefixed name
|
566
566
|
metadata.context.compact_iri(cell.propertyUrl, vocab: true)
|
data/spec/metadata_spec.rb
CHANGED
@@ -838,12 +838,6 @@ describe RDF::Tabular::Metadata do
|
|
838
838
|
":type Schema" => [{}, {type: :Schema}, RDF::Tabular::Schema],
|
839
839
|
":type Column" => [{}, {type: :Column}, RDF::Tabular::Column],
|
840
840
|
":type Dialect" => [{}, {type: :Dialect}, RDF::Tabular::Dialect],
|
841
|
-
"@type TableGroup" => [{}, {"@type" => "TableGroup"}, RDF::Tabular::TableGroup],
|
842
|
-
"@type Table" => [{"@type" => "Table"}, RDF::Tabular::Table],
|
843
|
-
"@type Template" => [{"@type" => "Template"}, RDF::Tabular::Transformation],
|
844
|
-
"@type Schema" => [{"@type" => "Schema"}, RDF::Tabular::Schema],
|
845
|
-
"@type Column" => [{"@type" => "Column"}, RDF::Tabular::Column],
|
846
|
-
"@type Dialect" => [{"@type" => "Dialect"}, RDF::Tabular::Dialect],
|
847
841
|
"tables TableGroup" => [{"tables" => []}, RDF::Tabular::TableGroup],
|
848
842
|
"dialect Table" => [{"dialect" => {}}, RDF::Tabular::Table],
|
849
843
|
"tableSchema Table" => [{"tableSchema" => {}}, RDF::Tabular::Table],
|
@@ -874,7 +868,7 @@ describe RDF::Tabular::Metadata do
|
|
874
868
|
options ||= {}
|
875
869
|
options[:logger] = logger
|
876
870
|
options[:context] ||= 'http://www.w3.org/ns/csvw'
|
877
|
-
expect(described_class.new(input, options)).to be_a(klass)
|
871
|
+
expect(described_class.new(input, **options)).to be_a(klass)
|
878
872
|
expect(logger.to_s).not_to match(/ERROR|WARN/)
|
879
873
|
end
|
880
874
|
end
|
@@ -1379,7 +1373,7 @@ describe RDF::Tabular::Metadata do
|
|
1379
1373
|
context "Unsupported datatypes" do
|
1380
1374
|
%w(anyType anySimpleType ENTITIES IDREFS NMTOKENS ENTITY ID IDREF NOTATAION foo).each do |base|
|
1381
1375
|
it "detects #{base} as unsupported" do
|
1382
|
-
|
1376
|
+
RDF::Tabular::Table.new({
|
1383
1377
|
url: "http://example.com/table.csv",
|
1384
1378
|
tableSchema: {
|
1385
1379
|
columns: [{
|
data/spec/suite_helper.rb
CHANGED
@@ -23,7 +23,7 @@ module RDF::Util
|
|
23
23
|
# HTTP Request headers.
|
24
24
|
# @return [IO] File stream
|
25
25
|
# @yield [IO] File stream
|
26
|
-
def self.open_file(filename_or_url, options
|
26
|
+
def self.open_file(filename_or_url, **options, &block)
|
27
27
|
case
|
28
28
|
when filename_or_url.to_s =~ /^file:/
|
29
29
|
path = filename_or_url.to_s[5..-1]
|
@@ -73,7 +73,7 @@ module RDF::Util
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
else
|
76
|
-
original_open_file(filename_or_url, options) do |remote_document|
|
76
|
+
original_open_file(filename_or_url, **options) do |remote_document|
|
77
77
|
# Add Link header, if necessary
|
78
78
|
remote_document.headers[:link] = options[:httpLink] if options[:httpLink]
|
79
79
|
|
data/spec/suite_spec.rb
CHANGED
@@ -25,11 +25,10 @@ describe RDF::Tabular::Reader do
|
|
25
25
|
t.logger.info "source:\n#{t.input}"
|
26
26
|
begin
|
27
27
|
RDF::Tabular::Reader.open(t.action,
|
28
|
-
t.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
)
|
28
|
+
base_uri: t.base,
|
29
|
+
validate: t.validation?,
|
30
|
+
logger: t.logger,
|
31
|
+
**t.reader_options
|
33
32
|
) do |reader|
|
34
33
|
expect(reader).to be_a RDF::Reader
|
35
34
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-tabular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcp47
|
@@ -36,62 +36,56 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '3.
|
39
|
+
version: '3.1'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '3.
|
46
|
+
version: '3.1'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdf-vocab
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '3.
|
53
|
+
version: '3.1'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '3.
|
60
|
+
version: '3.1'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rdf-xsd
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '3.
|
67
|
+
version: '3.1'
|
68
68
|
type: :runtime
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '3.
|
74
|
+
version: '3.1'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: json-ld
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '2.1'
|
82
|
-
- - "<"
|
79
|
+
- - "~>"
|
83
80
|
- !ruby/object:Gem::Version
|
84
|
-
version: '
|
81
|
+
version: '3.1'
|
85
82
|
type: :runtime
|
86
83
|
prerelease: false
|
87
84
|
version_requirements: !ruby/object:Gem::Requirement
|
88
85
|
requirements:
|
89
|
-
- - "
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version: '2.1'
|
92
|
-
- - "<"
|
86
|
+
- - "~>"
|
93
87
|
- !ruby/object:Gem::Version
|
94
|
-
version: '
|
88
|
+
version: '3.1'
|
95
89
|
- !ruby/object:Gem::Dependency
|
96
90
|
name: addressable
|
97
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,56 +148,56 @@ dependencies:
|
|
154
148
|
requirements:
|
155
149
|
- - "~>"
|
156
150
|
- !ruby/object:Gem::Version
|
157
|
-
version: '3.
|
151
|
+
version: '3.1'
|
158
152
|
type: :development
|
159
153
|
prerelease: false
|
160
154
|
version_requirements: !ruby/object:Gem::Requirement
|
161
155
|
requirements:
|
162
156
|
- - "~>"
|
163
157
|
- !ruby/object:Gem::Version
|
164
|
-
version: '3.
|
158
|
+
version: '3.1'
|
165
159
|
- !ruby/object:Gem::Dependency
|
166
160
|
name: rdf-spec
|
167
161
|
requirement: !ruby/object:Gem::Requirement
|
168
162
|
requirements:
|
169
163
|
- - "~>"
|
170
164
|
- !ruby/object:Gem::Version
|
171
|
-
version: '3.
|
165
|
+
version: '3.1'
|
172
166
|
type: :development
|
173
167
|
prerelease: false
|
174
168
|
version_requirements: !ruby/object:Gem::Requirement
|
175
169
|
requirements:
|
176
170
|
- - "~>"
|
177
171
|
- !ruby/object:Gem::Version
|
178
|
-
version: '3.
|
172
|
+
version: '3.1'
|
179
173
|
- !ruby/object:Gem::Dependency
|
180
174
|
name: rdf-turtle
|
181
175
|
requirement: !ruby/object:Gem::Requirement
|
182
176
|
requirements:
|
183
177
|
- - "~>"
|
184
178
|
- !ruby/object:Gem::Version
|
185
|
-
version: '3.
|
179
|
+
version: '3.1'
|
186
180
|
type: :development
|
187
181
|
prerelease: false
|
188
182
|
version_requirements: !ruby/object:Gem::Requirement
|
189
183
|
requirements:
|
190
184
|
- - "~>"
|
191
185
|
- !ruby/object:Gem::Version
|
192
|
-
version: '3.
|
186
|
+
version: '3.1'
|
193
187
|
- !ruby/object:Gem::Dependency
|
194
188
|
name: sparql
|
195
189
|
requirement: !ruby/object:Gem::Requirement
|
196
190
|
requirements:
|
197
191
|
- - "~>"
|
198
192
|
- !ruby/object:Gem::Version
|
199
|
-
version: '3.
|
193
|
+
version: '3.1'
|
200
194
|
type: :development
|
201
195
|
prerelease: false
|
202
196
|
version_requirements: !ruby/object:Gem::Requirement
|
203
197
|
requirements:
|
204
198
|
- - "~>"
|
205
199
|
- !ruby/object:Gem::Version
|
206
|
-
version: '3.
|
200
|
+
version: '3.1'
|
207
201
|
- !ruby/object:Gem::Dependency
|
208
202
|
name: webmock
|
209
203
|
requirement: !ruby/object:Gem::Requirement
|
@@ -256,7 +250,6 @@ files:
|
|
256
250
|
- lib/rdf/tabular.rb
|
257
251
|
- lib/rdf/tabular/csvw.rb
|
258
252
|
- lib/rdf/tabular/format.rb
|
259
|
-
- lib/rdf/tabular/json.rb
|
260
253
|
- lib/rdf/tabular/literal.rb
|
261
254
|
- lib/rdf/tabular/metadata.rb
|
262
255
|
- lib/rdf/tabular/reader.rb
|
@@ -346,7 +339,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
346
339
|
- !ruby/object:Gem::Version
|
347
340
|
version: '0'
|
348
341
|
requirements: []
|
349
|
-
rubygems_version: 3.0.
|
342
|
+
rubygems_version: 3.0.6
|
350
343
|
signing_key:
|
351
344
|
specification_version: 4
|
352
345
|
summary: Tabular Data RDF Reader and JSON serializer.
|
data/lib/rdf/tabular/json.rb
DELETED
File without changes
|