json-ld 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODMzNjFiMDVhYTdjNTk1OGQ3NTFiMzQwZjE0ZDViM2I1Mjk1YWI2Mw==
4
+ MjNiZjRiMzMwODgxOTgwNjdjMjFjMWNkNjY1ZDVlNDk0ODAzYjQ3YQ==
5
5
  data.tar.gz: !binary |-
6
- MGYyMDRhMjNiMWJkNDY1ODAyODk4Y2RkZTY2N2U2OGY3NWQ4YzM2OQ==
6
+ ZWFkOWE0MDU0ZTc0YzIyYzdkZGEwNDg0YTgxZjg1ZTc0MWU3MTYzMA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NTM0NTI4MzRmMzA1OTI2MDM1MzQ2ZTFkYWQ4MWM0OTM4MjkwMGE0NGU3ZGQ4
10
- ZmFlNjM5MzBlNGZkZjkyMjgyYmIzM2U3MWU5OTUxOTNmZGUwMjc3ODExYWRi
11
- M2Q5ZjdkMjU1M2NkY2MwZTgwNWYzNTE2N2UyMWVjNmY1NmYzYjU=
9
+ MDY1MDAxMDMzMmMzYjg4MzA2ODJjYTAxYjdlNmRjYzdkNGVlYTY3YTU1MTI4
10
+ NTMwMjQ3ZjYyNDIzNTkyYzUzMTkzNDJlMWI2MzUwZTY5NGE0NTczYTZiMjVh
11
+ YWE3MjQ1MzA0NjVmYmYxMGQ4NjJjYzQ0ZWVjOTg4YmEwOTJmZWY=
12
12
  data.tar.gz: !binary |-
13
- MjEyNzQ4MzM5MzNlNzc2ZGMwYTgxZjNiNjBjZDlhMWEzNWZmNzliN2E2Nzlm
14
- N2Y2OWJjZTIwNDFmODQ0ZmFkMGM1NDQwNDRjOTQ4MjNjMjJlNTgzZGY3NWE5
15
- NjQ3MDI4YTk4Y2RhYmQ0MmEyMDkxNDVjZmViMTM2MmNhMzM0NTQ=
13
+ MDNhODA1ODViOTlmZTVjZGUxYjBmYmM4NTg1ZGNkNjBhNjliMjA1MzNmMDVm
14
+ NTdlZjNmZGExZjkwNThmNzU0YWIwZTExMDIzODVkMjI1M2Q0YzNjYTAzNzU3
15
+ MDA0NmI5NjYyYWZiNWM0ZGY4OWE4ZTQ4MDBjODEzZjVmYzU2MDc=
data/README.md CHANGED
@@ -160,7 +160,7 @@ Install with `gem install json-ld`
160
160
  "foaf:nick": { "@list": [ "joe", "bob", "jaybe" ] }
161
161
  })
162
162
 
163
- graph = RDF::Graph.new << JSON::LD::API.toRDF(input)
163
+ graph = RDF::Graph.new << JSON::LD::API.toRdf(input)
164
164
 
165
165
  require 'rdf/turtle'
166
166
  graph.dump(:ttl, :prefixes => {:foaf => "http://xmlns.com/foaf/0.1/"})
@@ -190,7 +190,7 @@ Install with `gem install json-ld`
190
190
  })
191
191
 
192
192
  compacted = nil
193
- JSON::LD::API::fromRDF(input) do |expanded|
193
+ JSON::LD::API::fromRdf(input) do |expanded|
194
194
  compacted = JSON::LD::API.compact(expanded, context['@context'])
195
195
  end
196
196
  compacted =>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.7
1
+ 1.0.8
data/bin/jsonld CHANGED
@@ -20,7 +20,7 @@ def run(input, options)
20
20
  if options[:format] == :jsonld && options[:input_format] != :jsonld
21
21
  r = reader_class.new(input, options[:parser_options])
22
22
  g = RDF::Repository.new << r
23
- input = JSON::LD::API.fromRDF(g)
23
+ input = JSON::LD::API.fromRdf(g)
24
24
  end
25
25
 
26
26
  prefixes = {}
@@ -363,7 +363,7 @@ module JSON::LD
363
363
  # @return [Array<RDF::Statement>] if no block given
364
364
  # @yield statement
365
365
  # @yieldparam [RDF::Statement] statement
366
- def self.toRDF(input, options = {}, &block)
366
+ def self.toRdf(input, options = {}, &block)
367
367
  results = []
368
368
  results.extend(RDF::Enumerable)
369
369
 
@@ -373,21 +373,21 @@ module JSON::LD
373
373
  API.new(expanded_input, nil, options) do
374
374
  # 1) Perform the Expansion Algorithm on the JSON-LD input.
375
375
  # This removes any existing context to allow the given context to be cleanly applied.
376
- debug(".toRDF") {"expanded input: #{expanded_input.to_json(JSON_STATE)}"}
376
+ debug(".toRdf") {"expanded input: #{expanded_input.to_json(JSON_STATE)}"}
377
377
 
378
378
  # Generate _nodeMap_
379
379
  node_map = Hash.ordered
380
380
  node_map['@default'] = Hash.ordered
381
381
  generate_node_map(expanded_input, node_map)
382
- debug(".toRDF") {"node map: #{node_map.to_json(JSON_STATE)}"}
382
+ debug(".toRdf") {"node map: #{node_map.to_json(JSON_STATE)}"}
383
383
 
384
384
  # Start generating statements
385
385
  node_map.each do |graph_name, graph|
386
386
  context = as_resource(graph_name) unless graph_name == '@default'
387
- debug(".toRDF") {"context: #{context ? context.to_ntriples : 'null'}"}
387
+ debug(".toRdf") {"context: #{context ? context.to_ntriples : 'null'}"}
388
388
  # Drop results for graphs which are named with relative IRIs
389
389
  if graph_name.is_a?(RDF::URI) && !graph_name.absolute
390
- debug(".toRDF") {"drop relative graph_name: #{statement.to_ntriples}"}
390
+ debug(".toRdf") {"drop relative graph_name: #{statement.to_ntriples}"}
391
391
  next
392
392
  end
393
393
  graph_to_rdf(graph).each do |statement|
@@ -404,7 +404,7 @@ module JSON::LD
404
404
  end
405
405
  end
406
406
  if relative
407
- debug(".toRDF") {"drop statement with relative IRIs: #{statement.to_ntriples}"}
407
+ debug(".toRdf") {"drop statement with relative IRIs: #{statement.to_ntriples}"}
408
408
  next
409
409
  end
410
410
 
@@ -433,7 +433,7 @@ module JSON::LD
433
433
  # The JSON-LD document in expanded form
434
434
  # @return [Array<Hash>]
435
435
  # The JSON-LD document in expanded form
436
- def self.fromRDF(input, options = {}, &block)
436
+ def self.fromRdf(input, options = {}, &block)
437
437
  options = {:useNativeTypes => false}.merge(options)
438
438
  result = nil
439
439
 
@@ -526,6 +526,12 @@ module JSON::LD
526
526
  end
527
527
  end
528
528
 
529
+ # Add class method aliases for backwards compatibility
530
+ class << self
531
+ alias :toRDF :toRdf
532
+ alias :fromRDF :fromRdf
533
+ end
534
+
529
535
  ##
530
536
  # A {RemoteDocument} is returned from a {documentLoader}.
531
537
  class RemoteDocument
@@ -25,6 +25,7 @@ module JSON::LD
25
25
  list = nil)
26
26
  depth do
27
27
  debug("node_map") {"active_graph: #{active_graph}, element: #{element.inspect}"}
28
+ debug(" =>") {"active_subject: #{active_subject.inspect}, active_property: #{active_property.inspect}, list: #{list.inspect}"}
28
29
  if element.is_a?(Array)
29
30
  # If element is an array, process each entry in element recursively by passing item for element, node map, active graph, active subject, active property, and list.
30
31
  element.map {|o|
@@ -90,7 +91,10 @@ module JSON::LD
90
91
  graph[id] ||= {'@id' => id}
91
92
 
92
93
  # If active property is not null, perform the following steps:
93
- if active_property
94
+ if node?(active_subject) || node_reference?(active_subject)
95
+ debug("node_map") {"active_subject is an object, merge into #{id}"}
96
+ merge_value(graph[id], active_property, active_subject)
97
+ elsif active_property
94
98
  # Create a new JSON object reference consisting of a single member @id whose value is id.
95
99
  reference = {'@id' => id}
96
100
 
@@ -125,13 +129,12 @@ module JSON::LD
125
129
  element.delete('@reverse').each do |property, values|
126
130
  values.each do |value|
127
131
  debug("node_map") {"@reverse(#{id}): #{value.inspect}"}
128
- # If value has a property member, append referenced node to its value; otherwise create a property member whose value is an array containing referenced node.
129
- merge_value(value, property, {'@id' => id})
130
-
131
132
  # Recursively invoke this algorithm passing value for element, node map, and active graph.
132
133
  generate_node_map(value,
133
134
  node_map,
134
- active_graph)
135
+ active_graph,
136
+ {'@id' => id},
137
+ property)
135
138
  end
136
139
  end
137
140
  end
@@ -47,5 +47,11 @@ module JSON::LD
47
47
  def self.to_sym
48
48
  :jsonld
49
49
  end
50
+
51
+ ##
52
+ # Override normal format name
53
+ def self.name
54
+ "JSON-LD"
55
+ end
50
56
  end
51
57
  end
@@ -113,7 +113,7 @@ module JSON::LD
113
113
  node.delete(:usages)
114
114
  result << node unless node_reference?(node)
115
115
  end
116
- debug("fromRDF") {result.to_json(JSON_STATE)}
116
+ debug("fromRdf") {result.to_json(JSON_STATE)}
117
117
  result
118
118
  end
119
119
  end
@@ -49,7 +49,7 @@ module JSON::LD
49
49
  # @private
50
50
  # @see RDF::Reader#each_statement
51
51
  def each_statement(&block)
52
- JSON::LD::API.toRDF(@doc, @options).each do |statement|
52
+ JSON::LD::API.toRdf(@doc, @options).each do |statement|
53
53
  # If RDF version is 1.0, fold literals with xsd:string to be just simple literals
54
54
  statement.object.datatype = nil if
55
55
  RDF::VERSION.to_s < "1.1" &&
@@ -147,7 +147,7 @@ module JSON::LD
147
147
  @debug = @options[:debug]
148
148
 
149
149
  debug("writer") { "serialize #{@repo.count} statements, #{@options.inspect}"}
150
- result = API.fromRDF(@repo, @options)
150
+ result = API.fromRdf(@repo, @options)
151
151
 
152
152
  # If we were provided a context, or prefixes, use them to compact the output
153
153
  context = RDF::Util::File.open_file(@options[:context]) if @options[:context].is_a?(String)
@@ -34,7 +34,7 @@ describe JSON::LD::API do
34
34
  jld.should produce(JSON.load(File.open(framed)), @debug)
35
35
  end if File.exist?(framed) && File.exist?(frame)
36
36
 
37
- it "toRDF" do
37
+ it "toRdf" do
38
38
  RDF::Repository.load(filename, :debug => @debug).should be_equivalent_graph(RDF::Repository.load(ttl), :trace => @debug)
39
39
  end if File.exist?(ttl)
40
40
  end
@@ -181,6 +181,35 @@ describe JSON::LD::API do
181
181
  }]
182
182
  }),
183
183
  :options => {}
184
+ },
185
+ "@reverse bnode issue (0045)" => {
186
+ :input => ::JSON.parse(%q{
187
+ {
188
+ "@context": {
189
+ "foo": "http://example.org/foo",
190
+ "bar": { "@reverse": "http://example.org/bar", "@type": "@id" }
191
+ },
192
+ "foo": "Foo",
193
+ "bar": [ "http://example.org/origin", "_:b0" ]
194
+ }
195
+ }),
196
+ :output => ::JSON.parse(%q{
197
+ [
198
+ {
199
+ "@id": "_:b0",
200
+ "http://example.org/foo": [ { "@value": "Foo" } ]
201
+ },
202
+ {
203
+ "@id": "_:b1",
204
+ "http://example.org/bar": [ { "@id": "_:b0" } ]
205
+ },
206
+ {
207
+ "@id": "http://example.org/origin",
208
+ "http://example.org/bar": [ { "@id": "_:b0" } ]
209
+ }
210
+ ]
211
+ }),
212
+ :options => {}
184
213
  }
185
214
  }.each do |title, params|
186
215
  it title do
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
  require 'rdf/spec/writer'
5
5
 
6
6
  describe JSON::LD::API do
7
- describe ".fromRDF" do
7
+ describe ".fromRdf" do
8
8
  context "simple tests" do
9
9
  it "One subject IRI object" do
10
10
  input = %(<http://a/b> <http://a/c> <http://a/d> .)
@@ -374,6 +374,6 @@ describe JSON::LD::API do
374
374
  g = ntstr.is_a?(String) ? parse(ntstr, options) : ntstr
375
375
  @debug << g.dump(:trig)
376
376
  statements = g.each_statement.to_a
377
- JSON::LD::API.fromRDF(statements, options.merge(:debug => @debug))
377
+ JSON::LD::API.fromRdf(statements, options.merge(:debug => @debug))
378
378
  end
379
379
  end
@@ -108,9 +108,9 @@ module Fixtures
108
108
  when "jld:FromRDFTest"
109
109
  repo = RDF::Repository.load(input_loc, :format => :nquads)
110
110
  debug << "repo: #{repo.dump(id == '#t0012' ? :nquads : :trig)}"
111
- JSON::LD::API.fromRDF(repo, options.merge(:debug => debug))
111
+ JSON::LD::API.fromRdf(repo, options.merge(:debug => debug))
112
112
  when "jld:ToRDFTest"
113
- JSON::LD::API.toRDF(input_loc, options.merge(:debug => debug)).map do |statement|
113
+ JSON::LD::API.toRdf(input_loc, options.merge(:debug => debug)).map do |statement|
114
114
  to_quad(statement)
115
115
  end
116
116
  else
@@ -156,9 +156,9 @@ module Fixtures
156
156
  when "jld:FromRDFTest"
157
157
  repo = RDF::Repository.load(t.input_loc)
158
158
  debug << "repo: #{repo.dump(id == '#t0012' ? :nquads : :trig)}"
159
- JSON::LD::API.fromRDF(repo, options.merge(:debug => debug))
159
+ JSON::LD::API.fromRdf(repo, options.merge(:debug => debug))
160
160
  when "jld:ToRDFTest"
161
- JSON::LD::API.toRDF(t.input_loc, options.merge(:debug => debug)).map do |statement|
161
+ JSON::LD::API.toRdf(t.input_loc, options.merge(:debug => debug)).map do |statement|
162
162
  t.to_quad(statement)
163
163
  end
164
164
  else
@@ -3,9 +3,13 @@ $:.unshift "."
3
3
  require 'spec_helper'
4
4
 
5
5
  describe JSON::LD::API do
6
- before(:each) { @debug = []}
6
+ before(:each) {@debug = []}
7
+
8
+ context ".toRdf" do
9
+ it "should implement RDF::Enumerable" do
10
+ expect(JSON::LD::API.toRdf({})).to be_a(RDF::Enumerable)
11
+ end
7
12
 
8
- context ".toRDF" do
9
13
  context "unnamed nodes" do
10
14
  {
11
15
  "no @id" => [
@@ -646,7 +650,7 @@ describe JSON::LD::API do
646
650
  @debug = []
647
651
  graph = options[:graph] || RDF::Graph.new
648
652
  options = {:debug => @debug, :validate => true, :canonicalize => false}.merge(options)
649
- JSON::LD::API.toRDF(StringIO.new(input), options) {|st| graph << st}
653
+ JSON::LD::API.toRdf(StringIO.new(input), options) {|st| graph << st}
650
654
  graph
651
655
  end
652
656
  end
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.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-01 00:00:00.000000000 Z
11
+ date: 2013-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdf