json-ld 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 54892ea3d40dc8dbea39f06ade6803302e8b01b0
4
+ data.tar.gz: 002b2860c421d7a56ebb4493bf0b7942db6edd6d
5
+ SHA512:
6
+ metadata.gz: 97bb1266a783b8f8a5e00df566185d40e13f4c0528599593c0fa0f2ecdecb277e90aaf29d31cf0a095bb0f712961545332c2b21cc1d0eac3912924cd733d2232
7
+ data.tar.gz: 4a86e9c48172c8794149ea858091323c695a4e96a0f785534303353ba04c9d9992eff880f0e49447f91b9a65bf71bf7021e0daf30fc2072385bf70c38b7c3c28
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/bin/jsonld CHANGED
@@ -26,17 +26,22 @@ def run(input, options)
26
26
  prefixes = {}
27
27
  start = Time.new
28
28
  if options[:expand]
29
- output = JSON::LD::API.expand(input, options[:context], nil, options)
29
+ output = JSON::LD::API.expand(input, options[:context], options)
30
30
  secs = Time.new - start
31
31
  options[:output].puts output.to_json(JSON::LD::JSON_STATE)
32
32
  STDERR.puts "Expanded in #{secs} seconds." unless options[:quiet]
33
33
  elsif options[:compact]
34
- output = JSON::LD::API.compact(input, options[:context], nil, options)
34
+ output = JSON::LD::API.compact(input, options[:context], options)
35
35
  secs = Time.new - start
36
36
  options[:output].puts output.to_json(JSON::LD::JSON_STATE)
37
37
  STDERR.puts "Compacted in #{secs} seconds." unless options[:quiet]
38
+ elsif options[:flatten]
39
+ output = JSON::LD::API.flatten(input, options[:context], options)
40
+ secs = Time.new - start
41
+ options[:output].puts output.to_json(JSON::LD::JSON_STATE)
42
+ STDERR.puts "Flattened in #{secs} seconds." unless options[:quiet]
38
43
  elsif options[:frame]
39
- output = JSON::LD::API.frame(input, options[:frame], nil, options)
44
+ output = JSON::LD::API.frame(input, options[:frame], options)
40
45
  secs = Time.new - start
41
46
  options[:output].puts output.to_json(JSON::LD::JSON_STATE)
42
47
  STDERR.puts "Framed in #{secs} seconds." unless options[:quiet]
@@ -76,6 +81,7 @@ OPT_ARGS = [
76
81
  ["--context", GetoptLong::REQUIRED_ARGUMENT,"Context to apply for expand, compact and converting from RDF"],
77
82
  ["--evaluate","-e", GetoptLong::REQUIRED_ARGUMENT,"Evaluate argument as a JSON-LD document"],
78
83
  ["--expand", GetoptLong::NO_ARGUMENT, "Expand document, using an optional --context"],
84
+ ["--flatten", GetoptLong::NO_ARGUMENT, "Flatten document, using an optional --context"],
79
85
  ["--format", GetoptLong::REQUIRED_ARGUMENT,"Specify output format when converting to RDF"],
80
86
  ["--frame", GetoptLong::REQUIRED_ARGUMENT,"Frame document, using the file or URL as a frame specification"],
81
87
  ["--input-format", GetoptLong::REQUIRED_ARGUMENT,"Format of the input document, when converting from RDF."],
@@ -112,6 +118,7 @@ opts.each do |opt, arg|
112
118
  when '--execute' then input = arg
113
119
  when '--expand' then options[:expand] = true
114
120
  when '--format' then options[:output_format] = arg.to_sym
121
+ when '--flatten' then options[:flatten] = arg
115
122
  when '--frame' then options[:frame] = arg
116
123
  when '--input-format' then options[:input_format] = arg.to_sym
117
124
  when '--output' then options[:output] = File.open(arg, "w")
@@ -24,7 +24,7 @@ module JSON::LD
24
24
  depth do
25
25
  debug("node_map") {"active_graph: #{active_graph}, element: #{element.inspect}"}
26
26
  if element.is_a?(Array)
27
- # If element is an array, process each entry in element recursively, using this algorithm and return
27
+ # 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.
28
28
  element.map {|o|
29
29
  generate_node_map(o,
30
30
  node_map,
@@ -37,7 +37,7 @@ module JSON::LD
37
37
  # Otherwise element is a JSON object. Reference the JSON object which is the value of the active graph member of node map using the variable graph. If the active subject is null, set node to null otherwise reference the active subject member of graph using the variable node.
38
38
  # Spec FIXME: initializing it to an empty JSON object, if necessary
39
39
  raise "Expected element to be a hash, was #{element.class}" unless element.is_a?(Hash)
40
- graph = node_map[active_graph] ||= Hash.ordered
40
+ graph = node_map[active_graph] ||= {}
41
41
  node = graph[active_subject] if active_subject
42
42
 
43
43
  # If element has an @type member, perform for each item the following steps:
@@ -77,6 +77,7 @@ module JSON::LD
77
77
  result)
78
78
 
79
79
  # Append result to the the value of the active property member of node.
80
+ debug("node_map") {"@list: #{result.inspect}"}
80
81
  merge_value(node, active_property, result)
81
82
  else
82
83
  # Otherwise element is a node object, perform the following steps:
@@ -88,14 +89,12 @@ module JSON::LD
88
89
  debug("node_map") {"id: #{id.inspect}"}
89
90
 
90
91
  # If graph does not contain a member id, create one and initialize it to a JSON object consisting of a single member @id whose value is set to id.
91
- graph[id] ||= Hash.ordered
92
- graph[id]['@id'] ||= id
92
+ graph[id] ||= {'@id' => id}
93
93
 
94
94
  # If active property is not null, perform the following steps:
95
95
  if active_property
96
96
  # Create a new JSON object reference consisting of a single member @id whose value is id.
97
- reference = Hash.ordered
98
- reference['@id'] = id
97
+ reference = {'@id' => id}
99
98
 
100
99
  # If list is null:
101
100
  unless list
@@ -148,6 +147,7 @@ module JSON::LD
148
147
 
149
148
  # Finally, for each key-value pair property-value in element ordered by property perform the following steps:
150
149
  element.keys.sort.each do |property|
150
+ #require 'debugger'; breakpoint
151
151
  value = element[property]
152
152
 
153
153
  # If property is a blank node identifier, replace it with a newly generated blank node identifier passing property for identifier.
@@ -161,8 +161,7 @@ module JSON::LD
161
161
  node_map,
162
162
  active_graph,
163
163
  id,
164
- property,
165
- list)
164
+ property)
166
165
  end
167
166
  end
168
167
  end
@@ -171,11 +171,38 @@ describe JSON::LD::API do
171
171
  }, {
172
172
  "@id": "http://www.wikipedia.org/"
173
173
  }])),
174
+ },
175
+ "Test Manifest (shortened)" => {
176
+ :input => ::JSON.parse(%q{
177
+ {
178
+ "@id": "",
179
+ "http://example/sequence": {"@list": [
180
+ {
181
+ "@id": "#t0001",
182
+ "http://example/name": "Keywords cannot be aliased to other keywords",
183
+ "http://example/input": {"@id": "error-expand-0001-in.jsonld"}
184
+ }
185
+ ]}
186
+ }
187
+ }),
188
+ :output => ::JSON.parse(%q{
189
+ [{
190
+ "@id": "",
191
+ "http://example/sequence": [{"@list": [{"@id": "#t0001"}]}]
192
+ }, {
193
+ "@id": "#t0001",
194
+ "http://example/input": [{"@id": "error-expand-0001-in.jsonld"}],
195
+ "http://example/name": [{"@value": "Keywords cannot be aliased to other keywords"}]
196
+ }, {
197
+ "@id": "error-expand-0001-in.jsonld"
198
+ }]
199
+ }),
200
+ :options => {}
174
201
  }
175
202
  }.each do |title, params|
176
203
  it title do
177
204
  @debug = []
178
- jld = JSON::LD::API.flatten(params[:input], nil, :debug => @debug)
205
+ jld = JSON::LD::API.flatten(params[:input], nil, (params[:options] || {}).merge(:debug => @debug))
179
206
  jld.should produce(params[:output], @debug)
180
207
  end
181
208
  end
metadata CHANGED
@@ -1,190 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-ld
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.0.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gregg Kellogg
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-10 00:00:00.000000000 Z
11
+ date: 2013-05-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rdf
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: json
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: 1.7.5
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: 1.7.5
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: equivalent-xml
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: 0.2.8
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: 0.2.8
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: open-uri-cached
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: 0.0.5
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: 0.0.5
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: yard
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: 0.8.3
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: 0.8.3
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rspec
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: 2.12.0
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: 2.12.0
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: rdf-spec
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '1.0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: '1.0'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: rdf-turtle
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - '>='
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - '>='
140
123
  - !ruby/object:Gem::Version
141
124
  version: '0'
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: rdf-trig
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
- - - ! '>='
129
+ - - '>='
148
130
  - !ruby/object:Gem::Version
149
131
  version: '0'
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
- - - ! '>='
136
+ - - '>='
156
137
  - !ruby/object:Gem::Version
157
138
  version: '0'
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: rdf-isomorphic
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
- - - ! '>='
143
+ - - '>='
164
144
  - !ruby/object:Gem::Version
165
145
  version: '0'
166
146
  type: :development
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
- - - ! '>='
150
+ - - '>='
172
151
  - !ruby/object:Gem::Version
173
152
  version: '0'
174
153
  - !ruby/object:Gem::Dependency
175
154
  name: rdf-xsd
176
155
  requirement: !ruby/object:Gem::Requirement
177
- none: false
178
156
  requirements:
179
- - - ! '>='
157
+ - - '>='
180
158
  - !ruby/object:Gem::Version
181
159
  version: '0'
182
160
  type: :development
183
161
  prerelease: false
184
162
  version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
163
  requirements:
187
- - - ! '>='
164
+ - - '>='
188
165
  - !ruby/object:Gem::Version
189
166
  version: '0'
190
167
  description: JSON::LD parses and serializes JSON-LD into RDF and implements expansion,
@@ -298,27 +275,26 @@ files:
298
275
  homepage: http://github.com/gkellogg/json-ld
299
276
  licenses:
300
277
  - Public Domain
278
+ metadata: {}
301
279
  post_install_message:
302
280
  rdoc_options: []
303
281
  require_paths:
304
282
  - lib
305
283
  required_ruby_version: !ruby/object:Gem::Requirement
306
- none: false
307
284
  requirements:
308
- - - ! '>='
285
+ - - '>='
309
286
  - !ruby/object:Gem::Version
310
287
  version: 1.9.3
311
288
  required_rubygems_version: !ruby/object:Gem::Requirement
312
- none: false
313
289
  requirements:
314
- - - ! '>='
290
+ - - '>='
315
291
  - !ruby/object:Gem::Version
316
292
  version: '0'
317
293
  requirements: []
318
294
  rubyforge_project: json-ld
319
- rubygems_version: 1.8.25
295
+ rubygems_version: 2.0.3
320
296
  signing_key:
321
- specification_version: 3
297
+ specification_version: 4
322
298
  summary: JSON-LD reader/writer for Ruby.
323
299
  test_files:
324
300
  - spec/api_spec.rb