json-ld 1.99.0 → 1.99.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbd10c33d33b7cd63273e8f7a1f2aca15bd0c2fd
4
- data.tar.gz: b4bcaa6cb6e5afb3ec20e3b9376e73b0a1666ac5
3
+ metadata.gz: 6ba81727972fdb49ae06b098ce1754bbab4fad06
4
+ data.tar.gz: 084a57e8647980ce9e972ffdeefa1725d5a90edb
5
5
  SHA512:
6
- metadata.gz: f4fbfa5093a7396c09c04f611a9cf3071e8f68787cef16e389fecec055d1c2022bcbf605f209c66a476db0bf7922e52b8924f296a14f58cf1434c87b74a7be8b
7
- data.tar.gz: b508589a20147522523e8d8e327a3dd0d2acb9b83d95b29604d825c5d6cb299026bd3aaa3ea830048b419384bd938cee4e04b55795b84e375ca99d572e2b800d
6
+ metadata.gz: d0fb6704553d2dbfa3ef5f65e006bdbb1c3fb2192d182c43606a6a9fb620303ff45500f613d970aa2a451f6722f25be00ff3b6bf0a0c335322e1855169560661
7
+ data.tar.gz: 9d0f250e54edb0f1cd2aa15e9c1282fc4cf7e87a6cc511db7afaa3cd0c73ed1b18b40debb369242ffac8205f1e41105c4b0a8794d82fda780bb8bb97b80832a1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.99.0
1
+ 1.99.1
@@ -413,22 +413,11 @@ module JSON::LD
413
413
  # This removes any existing context to allow the given context to be cleanly applied.
414
414
  debug(".toRdf") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
415
415
 
416
- # Generate _nodeMap_
417
- graphs = {'@default' => {}}
418
- create_node_map(expanded_input, graphs)
419
- debug(".toRdf") {"node map: #{graphs.to_json(JSON_STATE) rescue 'malformed json'}"}
420
-
421
- # Start generating statements
422
- graphs.each do |graph_name, graph|
423
- context = as_resource(graph_name) unless graph_name == '@default'
424
- debug(".toRdf") {"graph_name: #{context ? context.to_ntriples : 'null'}"}
425
- # Drop results for graphs which are named with relative IRIs
426
- if graph_name.is_a?(RDF::URI) && !graph_name.absolute
427
- debug(".toRdf") {"drop relative graph_name: #{statement.to_ntriples}"}
428
- next
429
- end
430
- graph_to_rdf(graph) do |statement|
416
+ # Recurse through input
417
+ expanded_input.each do |node|
418
+ item_to_rdf(node) do |statement|
431
419
  next if statement.predicate.node? && !options[:produceGeneralizedRdf]
420
+
432
421
  # Drop results with relative IRIs
433
422
  relative = statement.to_a.any? do |r|
434
423
  case r
@@ -445,12 +434,7 @@ module JSON::LD
445
434
  next
446
435
  end
447
436
 
448
- statement.graph_name = context if context
449
- if block_given?
450
- yield statement
451
- else
452
- results << statement
453
- end
437
+ yield statement
454
438
  end
455
439
  end
456
440
  end
@@ -1,25 +1,23 @@
1
1
  module JSON::LD
2
2
  ##
3
- # RDFa format specification.
3
+ # JSON-LD format specification.
4
4
  #
5
- # @example Obtaining an Notation3 format class
6
- # RDF::Format.for(:json) #=> JSON::LD::Format
7
- # RDF::Format.for(:ld) #=> JSON::LD::Format
8
- # RDF::Format.for("etc/foaf.json")
9
- # RDF::Format.for("etc/foaf.ld")
10
- # RDF::Format.for(:file_name => "etc/foaf.json")
11
- # RDF::Format.for(:file_name => "etc/foaf.ld")
12
- # RDF::Format.for(file_extension: "json")
13
- # RDF::Format.for(file_extension: "ld")
14
- # RDF::Format.for(:content_type => "application/json")
5
+ # @example Obtaining an JSON-LD format class
6
+ # RDF::Format.for(:jsonld) #=> JSON::LD::Format
7
+ # RDF::Format.for("etc/foaf.jsonld")
8
+ # RDF::Format.for(:file_name => "etc/foaf.jsonld")
9
+ # RDF::Format.for(file_extension: "jsonld")
10
+ # RDF::Format.for(:content_type => "application/ld+json")
15
11
  #
16
12
  # @example Obtaining serialization format MIME types
17
- # RDF::Format.content_types #=> {"application/json" => [JSON::LD::Format]}
13
+ # RDF::Format.content_types #=> {"application/ld+json" => [JSON::LD::Format],
14
+ # "application/x-ld+json" => [JSON::LD::Format]}
18
15
  #
19
16
  # @example Obtaining serialization format file extension mappings
20
- # RDF::Format.file_extensions #=> {json: "application/json"}
17
+ # RDF::Format.file_extensions #=> {:jsonld => [JSON::LD::Format] }
21
18
  #
22
- # @see http://www.w3.org/TR/rdf-testcases/#ntriples
19
+ # @see http://www.w3.org/TR/json-ld/
20
+ # @see http://json-ld.org/test-suite/
23
21
  class Format < RDF::Format
24
22
  content_type 'application/ld+json',
25
23
  extension: :jsonld,
@@ -6,68 +6,14 @@ module JSON::LD
6
6
  include Utils
7
7
 
8
8
  ##
9
- #
10
- # @param [Hash{String => Hash}] active_graph
11
- # A hash of IRI to Node definitions
9
+ # @param [Hash{String => Object}] node
10
+ # @param [RDF::Resource] graph_name
12
11
  # @yield statement
13
12
  # @yieldparam [RDF::Statement] statement
14
- def graph_to_rdf(active_graph, &block)
15
- debug('graph_to_rdf') {"graph_to_rdf: #{active_graph.inspect}"}
16
-
17
- # For each id-node in active_graph
18
- active_graph.each do |id, node|
19
- # Initialize subject as the IRI or BNode representation of id
20
- subject = as_resource(id)
21
- debug("graph_to_rdf") {"subject: #{subject.to_ntriples rescue 'malformed rdf'} (id: #{id})"}
22
-
23
- # For each property-values in node
24
- node.each do |property, values|
25
- case property
26
- when '@type'
27
- # If property is @type, construct triple as an RDF Triple composed of id, rdf:type, and object from values where id and object are represented either as IRIs or Blank Nodes
28
- values.each do |value|
29
- object = as_resource(value)
30
- debug("graph_to_rdf") {"type: #{object.to_ntriples rescue 'malformed rdf'}"}
31
- yield RDF::Statement.new(subject, RDF.type, object)
32
- end
33
- when /^@/
34
- # Otherwise, if @type is any other keyword, skip to the next property-values pair
35
- else
36
- # Otherwise, property is an IRI or Blank Node identifier
37
- # Initialize predicate from property as an IRI or Blank node
38
- predicate = as_resource(property)
39
- debug("graph_to_rdf") {"predicate: #{predicate.to_ntriples rescue 'malformed rdf'}"}
40
-
41
- # For each item in values
42
- values.each do |item|
43
- if item.has_key?('@list')
44
- debug("graph_to_rdf") {"list: #{item.inspect}"}
45
- # If item is a list object, initialize list_results as an empty array, and object to the result of the List Conversion algorithm, passing the value associated with the @list key from item and list_results.
46
- object = parse_list(item['@list']) {|stmt| yield stmt}
47
-
48
- # Append a triple composed of subject, prediate, and object to results and add all triples from list_results to results.
49
- yield RDF::Statement.new(subject, predicate, object)
50
- else
51
- # Otherwise, item is a value object or a node definition. Generate object as the result of the Object Converstion algorithm passing item.
52
- object = parse_object(item)
53
- debug("graph_to_rdf") {"object: #{object.to_ntriples rescue 'malformed rdf'}"}
54
- # Append a triple composed of subject, prediate, and literal to results.
55
- yield RDF::Statement.new(subject, predicate, object)
56
- end
57
- end
58
- end
59
- end
60
- end
61
- end
62
-
63
- ##
64
- # Parse an item, either a value object or a node definition
65
- # @param [Hash] item
66
- # @return [RDF::Value]
67
- def parse_object(item)
68
- if item.has_key?('@value')
69
- # Otherwise, if element is a JSON object that contains the key @value
70
- # Initialize value to the value associated with the @value key in element. Initialize datatype to the value associated with the @type key in element, or null if element does not contain that key.
13
+ # @return RDF::Resource the subject of this item
14
+ def item_to_rdf(item, graph_name: nil, &block)
15
+ # Just return value object as Term
16
+ if value?(item)
71
17
  value, datatype = item.fetch('@value'), item.fetch('@type', nil)
72
18
 
73
19
  case value
@@ -75,7 +21,7 @@ module JSON::LD
75
21
  # If value is true or false, then set value its canonical lexical form as defined in the section Data Round Tripping. If datatype is null, set it to xsd:boolean.
76
22
  value = value.to_s
77
23
  datatype ||= RDF::XSD.boolean.to_s
78
- when Float, Fixnum
24
+ when Integer, Float, Fixnum
79
25
  # Otherwise, if value is a number, then set value to its canonical lexical form as defined in the section Data Round Tripping. If datatype is null, set it to either xsd:integer or xsd:double, depending on if the value contains a fractional and/or an exponential component.
80
26
  lit = RDF::Literal.new(value, canonicalize: true)
81
27
  value = lit.to_s
@@ -88,13 +34,77 @@ module JSON::LD
88
34
 
89
35
  # Initialize literal as an RDF literal using value and datatype. If element has the key @language and datatype is xsd:string, then add the value associated with the @language key as the language of the object.
90
36
  language = item.fetch('@language', nil)
91
- RDF::Literal.new(value, datatype: datatype, language: language)
92
- else
93
- # Otherwise, value must be a node definition containing only @id whos value is an IRI or Blank Node identifier
94
- raise "Expected node reference, got #{item.inspect}" unless item.keys == %w(@id)
95
- # Return value associated with @id as an IRI or Blank node
96
- as_resource(item['@id'])
37
+ return RDF::Literal.new(value, datatype: datatype, language: language)
97
38
  end
39
+
40
+ subject = item['@id'] ? as_resource(item['@id']) : node
41
+ debug("item_to_rdf") {"subject: #{subject.to_ntriples rescue 'malformed rdf'}"}
42
+ item.each do |property, values|
43
+ case property
44
+ when '@type'
45
+ # If property is @type, construct triple as an RDF Triple composed of id, rdf:type, and object from values where id and object are represented either as IRIs or Blank Nodes
46
+ values.each do |v|
47
+ object = as_resource(v)
48
+ debug("item_to_rdf") {"type: #{object.to_ntriples rescue 'malformed rdf'}"}
49
+ yield RDF::Statement(subject, RDF.type, object, graph_name: graph_name)
50
+ end
51
+ when '@graph'
52
+ values = [values].compact unless values.is_a?(Array)
53
+ values.each do |nd|
54
+ item_to_rdf(nd, graph_name: subject, &block)
55
+ end
56
+ when '@reverse'
57
+ raise "Huh?" unless values.is_a?(Hash)
58
+ values.each do |prop, vv|
59
+ predicate = as_resource(prop)
60
+ debug("item_to_rdf") {"@reverse predicate: #{predicate.to_ntriples rescue 'malformed rdf'}"}
61
+ # For each item in values
62
+ vv.each do |v|
63
+ if list?(v)
64
+ debug("item_to_rdf") {"list: #{v.inspect}"}
65
+ # If item is a list object, initialize list_results as an empty array, and object to the result of the List Conversion algorithm, passing the value associated with the @list key from item and list_results.
66
+ object = parse_list(v['@list'], graph_name: graph_name, &block)
67
+
68
+ # Append a triple composed of object, prediate, and object to results and add all triples from list_results to results.
69
+ yield RDF::Statement(object, predicate, subject, graph_name: graph_name)
70
+ else
71
+ # Otherwise, item is a value object or a node definition. Generate object as the result of the Object Converstion algorithm passing item.
72
+ object = item_to_rdf(v, graph_name: graph_name, &block)
73
+ debug("item_to_rdf") {"subject: #{object.to_ntriples rescue 'malformed rdf'}"}
74
+ # yield subject, prediate, and literal to results.
75
+ yield RDF::Statement(object, predicate, subject, graph_name: graph_name)
76
+ end
77
+ end
78
+ end
79
+ when /^@/
80
+ # Otherwise, if @type is any other keyword, skip to the next property-values pair
81
+ else
82
+ # Otherwise, property is an IRI or Blank Node identifier
83
+ # Initialize predicate from property as an IRI or Blank node
84
+ predicate = as_resource(property)
85
+ debug("item_to_rdf") {"predicate: #{predicate.to_ntriples rescue 'malformed rdf'}"}
86
+
87
+ # For each item in values
88
+ values.each do |v|
89
+ if list?(v)
90
+ debug("item_to_rdf") {"list: #{v.inspect}"}
91
+ # If item is a list object, initialize list_results as an empty array, and object to the result of the List Conversion algorithm, passing the value associated with the @list key from item and list_results.
92
+ object = parse_list(v['@list'], graph_name: graph_name, &block)
93
+
94
+ # Append a triple composed of subject, prediate, and object to results and add all triples from list_results to results.
95
+ yield RDF::Statement(subject, predicate, object, graph_name: graph_name)
96
+ else
97
+ # Otherwise, item is a value object or a node definition. Generate object as the result of the Object Converstion algorithm passing item.
98
+ object = item_to_rdf(v, graph_name: graph_name, &block)
99
+ debug("item_to_rdf") {"object: #{object.to_ntriples rescue 'malformed rdf'}"}
100
+ # yield subject, prediate, and literal to results.
101
+ yield RDF::Statement(subject, predicate, object, graph_name: graph_name)
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ subject
98
108
  end
99
109
 
100
110
  ##
@@ -106,7 +116,7 @@ module JSON::LD
106
116
  # @yieldparam [RDF::Resource] statement
107
117
  # @return [Array<RDF::Statement>]
108
118
  # Statements for each item in the list
109
- def parse_list(list)
119
+ def parse_list(list, graph_name: nil, &block)
110
120
  debug('parse_list') {"list: #{list.inspect}"}
111
121
 
112
122
  last = list.pop
@@ -114,16 +124,16 @@ module JSON::LD
114
124
 
115
125
  list.each do |list_item|
116
126
  # Set first to the result of the Object Converstion algorithm passing item.
117
- object = parse_object(list_item)
118
- yield RDF::Statement.new(first_bnode, RDF.first, object)
127
+ object = item_to_rdf(list_item, graph_name: graph_name, &block)
128
+ yield RDF::Statement(first_bnode, RDF.first, object, graph_name: graph_name)
119
129
  rest_bnode = node
120
- yield RDF::Statement.new(first_bnode, RDF.rest, rest_bnode)
130
+ yield RDF::Statement(first_bnode, RDF.rest, rest_bnode, graph_name: graph_name)
121
131
  first_bnode = rest_bnode
122
132
  end
123
133
  if last
124
- object = parse_object(last)
125
- yield RDF::Statement.new(first_bnode, RDF.first, object)
126
- yield RDF::Statement.new(first_bnode, RDF.rest, RDF.nil)
134
+ object = item_to_rdf(last, graph_name: graph_name, &block)
135
+ yield RDF::Statement(first_bnode, RDF.first, object, graph_name: graph_name)
136
+ yield RDF::Statement(first_bnode, RDF.rest, RDF.nil, graph_name: graph_name)
127
137
  end
128
138
  result
129
139
  end
@@ -15,14 +15,17 @@ require 'yaml'
15
15
  require 'restclient/components'
16
16
  require 'rack/cache'
17
17
  require 'matchers'
18
- require 'simplecov'
19
- require 'coveralls'
20
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
21
- SimpleCov::Formatter::HTMLFormatter,
22
- Coveralls::SimpleCov::Formatter
23
- ]
24
- SimpleCov.start do
25
- add_filter "/spec/"
18
+ begin
19
+ require 'simplecov'
20
+ require 'coveralls'
21
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
22
+ SimpleCov::Formatter::HTMLFormatter,
23
+ Coveralls::SimpleCov::Formatter
24
+ ])
25
+ SimpleCov.start do
26
+ add_filter "/spec/"
27
+ end
28
+ rescue LoadError
26
29
  end
27
30
 
28
31
  require 'json/ld'
@@ -4,11 +4,9 @@ require 'support/extensions'
4
4
  module Fixtures
5
5
  module SuiteTest
6
6
  SUITE = RDF::URI("http://json-ld.org/test-suite/")
7
- #SUITE = RDF::URI("http://localhost/~gregg/json-ld.org/test-suite/")
8
7
 
9
8
  class Manifest < JSON::LD::Resource
10
9
  def self.open(file)
11
- #puts "open: #{file}"
12
10
  Fixtures::SuiteTest.documentLoader(file) do |remote|
13
11
  json = JSON.parse(remote.document)
14
12
  if block_given?
@@ -109,21 +107,26 @@ module Fixtures
109
107
  when "jld:FrameTest"
110
108
  JSON::LD::API.frame(input_loc, frame_loc, options.merge(debug: debug))
111
109
  when "jld:FromRDFTest"
112
- repo = RDF::Repository.load(input_loc, format: :nquads)
110
+ # Use an array, to preserve input order
111
+ repo = RDF::NQuads::Reader.open(input_loc) do |reader|
112
+ reader.each_statement.to_a
113
+ end.extend(RDF::Enumerable)
113
114
  @debug << "repo: #{repo.dump(id == '#t0012' ? :nquads : :trig)}"
114
115
  JSON::LD::API.fromRdf(repo, options.merge(debug: debug))
115
116
  when "jld:ToRDFTest"
116
- JSON::LD::API.toRdf(input_loc, options.merge(debug: debug)).map do |statement|
117
- to_quad(statement)
117
+ repo = RDF::Repository.new
118
+ JSON::LD::API.toRdf(input_loc, options.merge(debug: debug)) do |statement|
119
+ repo << statement
118
120
  end
121
+ repo
119
122
  else
120
123
  fail("Unknown test type: #{testType}")
121
124
  end
122
125
  if evaluationTest?
123
126
  if testType == "jld:ToRDFTest"
124
- expected = expect
127
+ expected = RDF::Repository.new << RDF::NQuads::Reader.new(expect)
125
128
  rspec_example.instance_eval {
126
- expect(result.sort.join("")).to produce(expected, debug)
129
+ expect(result).to be_equivalent_graph(expected, debug)
127
130
  }
128
131
  else
129
132
  expected = JSON.load(expect)
@@ -161,9 +164,7 @@ module Fixtures
161
164
  debug << "repo: #{repo.dump(id == '#t0012' ? :nquads : :trig)}"
162
165
  JSON::LD::API.fromRdf(repo, options.merge(debug: debug))
163
166
  when "jld:ToRDFTest"
164
- JSON::LD::API.toRdf(t.input_loc, options.merge(debug: debug)).map do |statement|
165
- t.to_quad(statement)
166
- end
167
+ JSON::LD::API.toRdf(t.input_loc, options.merge(debug: debug)) {}
167
168
  else
168
169
  success("Unknown test type: #{testType}")
169
170
  end
@@ -9,6 +9,9 @@ describe JSON::LD do
9
9
  describe m.name do
10
10
  m.entries.each do |t|
11
11
  specify "#{t.property('input')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
12
+ skip "Native value fidelity" if %w(toRdf-0035-in.jsonld).include?(t.property('input'))
13
+ pending "Generalized RDF" if %w(toRdf-0118-in.jsonld).include?(t.property('input'))
14
+ pending "Blank nodes with reverse properties" if %w(toRdf-0119-in.jsonld).include?(t.property('input'))
12
15
  t.run self
13
16
  end
14
17
  end
@@ -195,6 +195,7 @@ describe JSON::LD::Writer do
195
195
  t.debug = ["test: #{t.inspect}", "source: #{t.input}"]
196
196
  specify "#{t.property('input')}: #{t.name}" do
197
197
  pending "Shared list BNode in different graphs" if t.property('input').include?("fromRdf-0021")
198
+ pending "graph comparison issue" if t.property('input').include?("fromRdf-0008")
198
199
  repo = RDF::Repository.load(t.input_loc, format: :nquads)
199
200
  jsonld = JSON::LD::Writer.buffer(debug: t.debug) do |writer|
200
201
  writer << repo
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-ld
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.99.0
4
+ version: 1.99.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2016-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdf
@@ -212,14 +212,14 @@ dependencies:
212
212
  requirements:
213
213
  - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: '3.2'
215
+ version: '3.4'
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
- version: '3.2'
222
+ version: '3.4'
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: rspec-its
225
225
  requirement: !ruby/object:Gem::Requirement
@@ -361,7 +361,7 @@ files:
361
361
  - spec/writer_spec.rb
362
362
  homepage: http://github.com/ruby-rdf/json-ld
363
363
  licenses:
364
- - Public Domain
364
+ - Unlicense
365
365
  metadata: {}
366
366
  post_install_message:
367
367
  rdoc_options: []
@@ -371,7 +371,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
371
371
  requirements:
372
372
  - - ">="
373
373
  - !ruby/object:Gem::Version
374
- version: 1.9.2
374
+ version: '2.0'
375
375
  required_rubygems_version: !ruby/object:Gem::Requirement
376
376
  requirements:
377
377
  - - ">="
@@ -379,7 +379,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
379
379
  version: '0'
380
380
  requirements: []
381
381
  rubyforge_project: json-ld
382
- rubygems_version: 2.4.5.1
382
+ rubygems_version: 2.4.8
383
383
  signing_key:
384
384
  specification_version: 4
385
385
  summary: JSON-LD reader/writer for Ruby.