json-ld 0.1.5.2 → 0.1.6
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.
- data/History.markdown +7 -0
- data/VERSION +1 -1
- data/lib/json/ld/api.rb +86 -7
- data/lib/json/ld/compact.rb +1 -1
- data/lib/json/ld/evaluation_context.rb +11 -26
- data/lib/json/ld/expand.rb +5 -5
- data/lib/json/ld/flatten.rb +109 -0
- data/lib/json/ld/frame.rb +52 -135
- data/lib/json/ld/from_rdf.rb +16 -17
- data/lib/json/ld/utils.rb +5 -5
- data/spec/compact_spec.rb +1 -1
- data/spec/evaluation_context_spec.rb +1 -13
- data/spec/expand_spec.rb +68 -0
- data/spec/flatten_spec.rb +180 -0
- data/spec/frame_spec.rb +107 -133
- data/spec/from_rdf_spec.rb +5 -29
- metadata +5 -2
data/lib/json/ld/from_rdf.rb
CHANGED
@@ -11,13 +11,13 @@ module JSON::LD
|
|
11
11
|
# @param [Array<RDF::Statement>, RDF::Enumerable] input
|
12
12
|
# @return [Array<Hash>] the JSON-LD document in normalized form
|
13
13
|
def from_statements(input)
|
14
|
-
defaultGraph = {:
|
14
|
+
defaultGraph = {:nodes => {}, :listMap => {}, :name => ''}
|
15
15
|
graphs = {'' => defaultGraph}
|
16
16
|
|
17
17
|
value = nil
|
18
18
|
ec = EvaluationContext.new
|
19
19
|
|
20
|
-
# Create a map for
|
20
|
+
# Create a map for node to object representation
|
21
21
|
|
22
22
|
# For each triple in input
|
23
23
|
input.each do |statement|
|
@@ -27,7 +27,7 @@ module JSON::LD
|
|
27
27
|
name = statement.context ? ec.expand_iri(statement.context).to_s : ''
|
28
28
|
|
29
29
|
# Create a graph entry as needed
|
30
|
-
graph = graphs[name] ||= {:
|
30
|
+
graph = graphs[name] ||= {:nodes => {}, :listMap => {}, :name => name}
|
31
31
|
|
32
32
|
case statement.predicate
|
33
33
|
when RDF.first
|
@@ -57,15 +57,15 @@ module JSON::LD
|
|
57
57
|
end
|
58
58
|
|
59
59
|
# Add entry to default graph for name unless it is empty
|
60
|
-
defaultGraph[:
|
60
|
+
defaultGraph[:nodes][name] ||= {'@id' => name} unless name.empty?
|
61
61
|
|
62
|
-
# Get value from graph
|
63
|
-
debug("@id") { "new subject: #{subject}"} unless graph[:
|
64
|
-
value = graph[:
|
62
|
+
# Get value from graph nodes for subject, initializing it to a new node declaration for subject if it does not exist
|
63
|
+
debug("@id") { "new subject: #{subject}"} unless graph[:nodes].has_key?(subject)
|
64
|
+
value = graph[:nodes][subject] ||= {'@id' => subject}
|
65
65
|
|
66
66
|
# If property is http://www.w3.org/1999/02/22-rdf-syntax-ns#type
|
67
|
-
# and the
|
68
|
-
if statement.predicate == RDF.type && !@options[:
|
67
|
+
# and the notType option is not true
|
68
|
+
if statement.predicate == RDF.type && !@options[:notType]
|
69
69
|
object = ec.expand_iri(statement.object).to_s
|
70
70
|
debug("@type") { object.inspect}
|
71
71
|
# append the string representation of object to the array value for the key @type, creating
|
@@ -78,11 +78,10 @@ module JSON::LD
|
|
78
78
|
key = ec.expand_iri(statement.predicate).to_s
|
79
79
|
(value[key] ||= []) << {"@list" => []}
|
80
80
|
else
|
81
|
-
# Otherwise, let key be the string representation of predicate and
|
82
|
-
#
|
83
|
-
# described in Value Expansion.
|
81
|
+
# Otherwise, let key be the string representation of predicate and let object representation
|
82
|
+
# be object represented in expanded form as described in Value Expansion.
|
84
83
|
key = ec.expand_iri(statement.predicate).to_s
|
85
|
-
object = ec.expand_value(key, statement.object,
|
84
|
+
object = ec.expand_value(key, statement.object, :native => false)
|
86
85
|
if blank_node?(object)
|
87
86
|
# if object is an Unnamed Node, set as the head element in the listMap
|
88
87
|
# entry for object
|
@@ -122,15 +121,15 @@ module JSON::LD
|
|
122
121
|
|
123
122
|
# Build graphs in @id order
|
124
123
|
debug("graphs") {graphs.to_json(JSON_STATE)}
|
125
|
-
array = defaultGraph[:
|
126
|
-
entry = defaultGraph[:
|
124
|
+
array = defaultGraph[:nodes].keys.sort.map do |subject|
|
125
|
+
entry = defaultGraph[:nodes][subject]
|
127
126
|
debug("=> default") {entry.to_json(JSON_STATE)}
|
128
127
|
|
129
128
|
# If subject is a named graph, add serialized subject defintions
|
130
129
|
if graphs.has_key?(subject) && !subject.empty?
|
131
|
-
entry['@graph'] = graphs[subject][:
|
130
|
+
entry['@graph'] = graphs[subject][:nodes].keys.sort.map do |s|
|
132
131
|
debug("=> #{s.inspect}")
|
133
|
-
graphs[subject][:
|
132
|
+
graphs[subject][:nodes][s]
|
134
133
|
end
|
135
134
|
end
|
136
135
|
|
data/lib/json/ld/utils.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
module JSON::LD
|
2
2
|
module Utils
|
3
3
|
##
|
4
|
-
# Is value a
|
4
|
+
# Is value a node? A value is a node if
|
5
5
|
# * it is a Hash
|
6
6
|
# * it is not a @value, @set or @list
|
7
7
|
# * it has more than 1 key or any key is not @id
|
8
8
|
# @param [Object] value
|
9
9
|
# @return [Boolean]
|
10
|
-
def
|
10
|
+
def node?(value)
|
11
11
|
value.is_a?(Hash) &&
|
12
12
|
(value.keys & %w(@value @list @set)).empty? &&
|
13
13
|
!(value.keys - ['@id']).empty?
|
14
14
|
end
|
15
15
|
|
16
16
|
##
|
17
|
-
# Is value a
|
17
|
+
# Is value a node reference?
|
18
18
|
# @param [Object] value
|
19
19
|
# @return [Boolean]
|
20
|
-
def
|
20
|
+
def node_reference?(value)
|
21
21
|
value.is_a?(Hash) && value.keys == %w(@id)
|
22
22
|
end
|
23
23
|
|
@@ -27,7 +27,7 @@ module JSON::LD
|
|
27
27
|
# @param [Object] value
|
28
28
|
# @return [Boolean]
|
29
29
|
def blank_node?(value)
|
30
|
-
(
|
30
|
+
(node?(value) || node_reference?(value)) && value.fetch('@id', '_:')[0,2] == '_:'
|
31
31
|
end
|
32
32
|
|
33
33
|
##
|
data/spec/compact_spec.rb
CHANGED
@@ -373,7 +373,7 @@ describe JSON::LD::API do
|
|
373
373
|
]
|
374
374
|
}
|
375
375
|
},
|
376
|
-
"Uses expanded
|
376
|
+
"Uses expanded node definitions for node references" => {
|
377
377
|
:input => [
|
378
378
|
{"@id" => "http://example.com/foo"},
|
379
379
|
{"@id" => "http://example.com/bar"}
|
@@ -32,7 +32,7 @@ describe JSON::LD::EvaluationContext do
|
|
32
32
|
|
33
33
|
it "fails given a missing remote @context" do
|
34
34
|
RDF::Util::File.stub(:open_file).with("http://example.com/context").and_raise(IOError)
|
35
|
-
lambda {subject.parse("http://example.com/context")}.should raise_error(JSON::LD::InvalidContext, /Failed to
|
35
|
+
lambda {subject.parse("http://example.com/context")}.should raise_error(JSON::LD::InvalidContext, /Failed to parse remote context/)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "creates mappings" do
|
@@ -49,18 +49,6 @@ describe JSON::LD::EvaluationContext do
|
|
49
49
|
ec = subject.parse(StringIO.new("{}"))
|
50
50
|
ec.mappings.should produce({}, @debug)
|
51
51
|
end
|
52
|
-
|
53
|
-
it "parses a referenced context at a relative URI" do
|
54
|
-
c1 = StringIO.new(%({"@context": "context"}))
|
55
|
-
RDF::Util::File.stub(:open_file).with("http://example.com/c1").and_yield(c1)
|
56
|
-
RDF::Util::File.stub(:open_file).with("http://example.com/context").and_yield(@ctx)
|
57
|
-
ec = subject.parse("http://example.com/c1")
|
58
|
-
ec.mappings.should produce({
|
59
|
-
"name" => "http://xmlns.com/foaf/0.1/name",
|
60
|
-
"homepage" => "http://xmlns.com/foaf/0.1/homepage",
|
61
|
-
"avatar" => "http://xmlns.com/foaf/0.1/avatar"
|
62
|
-
}, @debug)
|
63
|
-
end
|
64
52
|
end
|
65
53
|
|
66
54
|
context "EvaluationContext" do
|
data/spec/expand_spec.rb
CHANGED
@@ -416,6 +416,74 @@ describe JSON::LD::API do
|
|
416
416
|
end
|
417
417
|
end
|
418
418
|
|
419
|
+
context "default vocabulary" do
|
420
|
+
{
|
421
|
+
"property" => {
|
422
|
+
:input => {
|
423
|
+
"@context" => {"@vocab" => "http://example.com/"},
|
424
|
+
"verb" => {"@value" => "foo"}
|
425
|
+
},
|
426
|
+
:output => [{
|
427
|
+
"http://example.com/verb" => [{"@value" => "foo"}]
|
428
|
+
}]
|
429
|
+
},
|
430
|
+
"datatype" => {
|
431
|
+
:input => {
|
432
|
+
"@context" => {"@vocab" => "http://example.com/"},
|
433
|
+
"http://example.org/verb" => {"@value" => "foo", "@type" => "string"}
|
434
|
+
},
|
435
|
+
:output => [
|
436
|
+
"http://example.org/verb" => [{"@value" => "foo", "@type" => "http://example.com/string"}]
|
437
|
+
]
|
438
|
+
},
|
439
|
+
"expand-0028" => {
|
440
|
+
:input => {
|
441
|
+
"@context" => {
|
442
|
+
"@vocab" => "http://example.org/vocab#",
|
443
|
+
"date" => { "@type" => "dateTime" }
|
444
|
+
},
|
445
|
+
"@id" => "example1",
|
446
|
+
"@type" => "test",
|
447
|
+
"date" => "2011-01-25T00:00:00Z",
|
448
|
+
"embed" => {
|
449
|
+
"@id" => "example2",
|
450
|
+
"expandedDate" => { "@value" => "2012-08-01T00:00:00Z", "@type" => "dateTime" }
|
451
|
+
}
|
452
|
+
},
|
453
|
+
:output => [
|
454
|
+
{
|
455
|
+
"@id" => "http://foo/bar/example1",
|
456
|
+
"@type" => ["http://example.org/vocab#test"],
|
457
|
+
"http://example.org/vocab#date" => [
|
458
|
+
{
|
459
|
+
"@value" => "2011-01-25T00:00:00Z",
|
460
|
+
"@type" => "http://example.org/vocab#dateTime"
|
461
|
+
}
|
462
|
+
],
|
463
|
+
"http://example.org/vocab#embed" => [
|
464
|
+
{
|
465
|
+
"@id" => "http://foo/bar/example2",
|
466
|
+
"http://example.org/vocab#expandedDate" => [
|
467
|
+
{
|
468
|
+
"@value" => "2012-08-01T00:00:00Z",
|
469
|
+
"@type" => "http://example.org/vocab#dateTime"
|
470
|
+
}
|
471
|
+
]
|
472
|
+
}
|
473
|
+
]
|
474
|
+
}
|
475
|
+
]
|
476
|
+
}
|
477
|
+
}.each do |title, params|
|
478
|
+
it title do
|
479
|
+
jld = JSON::LD::API.expand(params[:input], nil, nil,
|
480
|
+
:base => "http://foo/bar/",
|
481
|
+
:debug => @debug)
|
482
|
+
jld.should produce(params[:output], @debug)
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
419
487
|
context "unmapped properties" do
|
420
488
|
{
|
421
489
|
"unmapped key" => {
|
@@ -0,0 +1,180 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$:.unshift "."
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe JSON::LD::API do
|
6
|
+
before(:each) { @debug = []}
|
7
|
+
|
8
|
+
describe "#generate_node_map" do
|
9
|
+
{
|
10
|
+
"single object" => {
|
11
|
+
:input => {"@id" => "http://example.com", "@type" => RDF::RDFS.Resource.to_s},
|
12
|
+
:subjects => %w(http://example.com),
|
13
|
+
:output => {
|
14
|
+
"http://example.com" => {
|
15
|
+
"@id" => "http://example.com", "@type" => [RDF::RDFS.Resource.to_s]
|
16
|
+
}
|
17
|
+
}
|
18
|
+
},
|
19
|
+
"embedded object" => {
|
20
|
+
:input => {
|
21
|
+
"@context" => {"foaf" => RDF::FOAF.to_s},
|
22
|
+
"@id" => "http://greggkellogg.net/foaf",
|
23
|
+
"@type" => ["foaf:PersonalProfile"],
|
24
|
+
"foaf:primaryTopic" => [{
|
25
|
+
"@id" => "http://greggkellogg.net/foaf#me",
|
26
|
+
"@type" => ["foaf:Person"]
|
27
|
+
}]
|
28
|
+
},
|
29
|
+
:subjects => %w(http://greggkellogg.net/foaf http://greggkellogg.net/foaf#me),
|
30
|
+
:output => {
|
31
|
+
"http://greggkellogg.net/foaf" => {
|
32
|
+
"@id" => "http://greggkellogg.net/foaf",
|
33
|
+
"@type" => [RDF::FOAF.PersonalProfile.to_s],
|
34
|
+
RDF::FOAF.primaryTopic.to_s => [{"@id" => "http://greggkellogg.net/foaf#me"}]
|
35
|
+
},
|
36
|
+
"http://greggkellogg.net/foaf#me" => {
|
37
|
+
"@id" => "http://greggkellogg.net/foaf#me",
|
38
|
+
"@type" => [RDF::FOAF.Person.to_s]
|
39
|
+
}
|
40
|
+
}
|
41
|
+
},
|
42
|
+
"embedded anon" => {
|
43
|
+
:input => {
|
44
|
+
"@context" => {"foaf" => RDF::FOAF.to_s},
|
45
|
+
"@id" => "http://greggkellogg.net/foaf",
|
46
|
+
"@type" => "foaf:PersonalProfile",
|
47
|
+
"foaf:primaryTopic" => {
|
48
|
+
"@type" => "foaf:Person"
|
49
|
+
}
|
50
|
+
},
|
51
|
+
:subjects => %w(http://greggkellogg.net/foaf _:t0),
|
52
|
+
:output => {
|
53
|
+
"_:t0" => {
|
54
|
+
"@id" => "_:t0",
|
55
|
+
"@type" => [RDF::FOAF.Person.to_s]
|
56
|
+
},
|
57
|
+
"http://greggkellogg.net/foaf" => {
|
58
|
+
"@id" => "http://greggkellogg.net/foaf",
|
59
|
+
"@type" => [RDF::FOAF.PersonalProfile.to_s],
|
60
|
+
RDF::FOAF.primaryTopic.to_s => [{"@id" => "_:t0"}]
|
61
|
+
},
|
62
|
+
}
|
63
|
+
},
|
64
|
+
"anon in list" => {
|
65
|
+
:input => [{
|
66
|
+
"@id" => "_:a",
|
67
|
+
"http://example.com/list" => [{"@list" => [{"@id" => "_:b"}]}]
|
68
|
+
}, {
|
69
|
+
"@id" => "_:b",
|
70
|
+
"http://example.com/name" => "foo"
|
71
|
+
}],
|
72
|
+
:subjects => %w(_:t0 _:t1),
|
73
|
+
:output => {
|
74
|
+
"_:t0" => {
|
75
|
+
"@id" => "_:t0",
|
76
|
+
"http://example.com/list" => [
|
77
|
+
{
|
78
|
+
"@list" => [
|
79
|
+
{
|
80
|
+
"@id" => "_:t1"
|
81
|
+
}
|
82
|
+
]
|
83
|
+
}
|
84
|
+
]
|
85
|
+
},
|
86
|
+
"_:t1" => {
|
87
|
+
"@id" => "_:t1",
|
88
|
+
"http://example.com/name" => [
|
89
|
+
{
|
90
|
+
"@value" => "foo"
|
91
|
+
}
|
92
|
+
]
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}.each do |title, params|
|
97
|
+
it title do
|
98
|
+
@debug = []
|
99
|
+
@node_map = Hash.ordered
|
100
|
+
graph = params[:graph] || '@merged'
|
101
|
+
jld = nil
|
102
|
+
JSON::LD::API.new(params[:input], nil, :debug => @debug) do |api|
|
103
|
+
expanded_value = api.expand(api.value, nil, api.context)
|
104
|
+
api.generate_node_map(expanded_value,
|
105
|
+
@node_map,
|
106
|
+
graph,
|
107
|
+
nil,
|
108
|
+
JSON::LD::BlankNodeNamer.new("t"))
|
109
|
+
end
|
110
|
+
@node_map.keys.should produce([graph], @debug)
|
111
|
+
subjects = @node_map[graph]
|
112
|
+
subjects.keys.should produce(params[:subjects], @debug)
|
113
|
+
subjects.should produce(params[:output], @debug)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe ".flatten" do
|
119
|
+
{
|
120
|
+
"single object" => {
|
121
|
+
:input => {"@id" => "http://example.com", "@type" => RDF::RDFS.Resource.to_s},
|
122
|
+
:output => [{"@id" => "http://example.com", "@type" => [RDF::RDFS.Resource.to_s]}]
|
123
|
+
},
|
124
|
+
"embedded object" => {
|
125
|
+
:input => {
|
126
|
+
"@context" => {
|
127
|
+
"foaf" => RDF::FOAF.to_s
|
128
|
+
},
|
129
|
+
"@id" => "http://greggkellogg.net/foaf",
|
130
|
+
"@type" => ["foaf:PersonalProfile"],
|
131
|
+
"foaf:primaryTopic" => [{
|
132
|
+
"@id" => "http://greggkellogg.net/foaf#me",
|
133
|
+
"@type" => ["foaf:Person"]
|
134
|
+
}]
|
135
|
+
},
|
136
|
+
:output => [
|
137
|
+
{
|
138
|
+
"@id" => "http://greggkellogg.net/foaf",
|
139
|
+
"@type" => [RDF::FOAF.PersonalProfile.to_s],
|
140
|
+
RDF::FOAF.primaryTopic.to_s => [{"@id" => "http://greggkellogg.net/foaf#me"}]
|
141
|
+
},
|
142
|
+
{
|
143
|
+
"@id" => "http://greggkellogg.net/foaf#me",
|
144
|
+
"@type" => [RDF::FOAF.Person.to_s]
|
145
|
+
}
|
146
|
+
]
|
147
|
+
},
|
148
|
+
"embedded anon" => {
|
149
|
+
:input => {
|
150
|
+
"@context" => {
|
151
|
+
"foaf" => RDF::FOAF.to_s
|
152
|
+
},
|
153
|
+
"@id" => "http://greggkellogg.net/foaf",
|
154
|
+
"@type" => "foaf:PersonalProfile",
|
155
|
+
"foaf:primaryTopic" => {
|
156
|
+
"@type" => "foaf:Person"
|
157
|
+
}
|
158
|
+
},
|
159
|
+
:output => [
|
160
|
+
{
|
161
|
+
"@id" => "_:t0",
|
162
|
+
"@type" => [RDF::FOAF.Person.to_s]
|
163
|
+
},
|
164
|
+
{
|
165
|
+
"@id" => "http://greggkellogg.net/foaf",
|
166
|
+
"@type" => [RDF::FOAF.PersonalProfile.to_s],
|
167
|
+
RDF::FOAF.primaryTopic.to_s => [{"@id" => "_:t0"}]
|
168
|
+
},
|
169
|
+
]
|
170
|
+
}
|
171
|
+
}.each do |title, params|
|
172
|
+
it title do
|
173
|
+
@debug = []
|
174
|
+
graph = params[:graph] || '@merged'
|
175
|
+
jld = JSON::LD::API.flatten(params[:input], graph, nil, nil, :debug => @debug)
|
176
|
+
jld.should produce(params[:output], @debug)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
data/spec/frame_spec.rb
CHANGED
@@ -388,154 +388,128 @@ describe JSON::LD::API do
|
|
388
388
|
}
|
389
389
|
]
|
390
390
|
}
|
391
|
-
}
|
392
|
-
}.each do |title, params|
|
393
|
-
it title do
|
394
|
-
@debug = []
|
395
|
-
begin
|
396
|
-
jld = JSON::LD::API.frame(params[:input], params[:frame], nil, :debug => @debug)
|
397
|
-
jld.should produce(params[:output], @debug)
|
398
|
-
rescue JSON::LD::ProcessingError, JSON::LD::InvalidContext, JSON::LD::InvalidFrame => e
|
399
|
-
fail("#{e.class}: #{e.message}\n" +
|
400
|
-
"#{@debug.join("\n")}\n" +
|
401
|
-
"Backtrace:\n#{e.backtrace.join("\n")}")
|
402
|
-
end
|
403
|
-
end
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
describe "#get_framing_subjects" do
|
408
|
-
{
|
409
|
-
"single object" => {
|
410
|
-
:input => {"@id" => "http://example.com", "@type" => RDF::RDFS.Resource.to_s},
|
411
|
-
:subjects => %w(http://example.com),
|
412
|
-
:output => {
|
413
|
-
"http://example.com" => {
|
414
|
-
"@id" => "http://example.com", "@type" => [RDF::RDFS.Resource.to_s]
|
415
|
-
}
|
416
|
-
}
|
417
|
-
},
|
418
|
-
"embedded object" => {
|
419
|
-
:input => {
|
420
|
-
"@context" => {"foaf" => RDF::FOAF.to_s},
|
421
|
-
"@id" => "http://greggkellogg.net/foaf",
|
422
|
-
"@type" => ["foaf:PersonalProfile"],
|
423
|
-
"foaf:primaryTopic" => [{
|
424
|
-
"@id" => "http://greggkellogg.net/foaf#me",
|
425
|
-
"@type" => ["foaf:Person"]
|
426
|
-
}]
|
427
|
-
},
|
428
|
-
:subjects => %w(http://greggkellogg.net/foaf http://greggkellogg.net/foaf#me),
|
429
|
-
:output => {
|
430
|
-
"http://greggkellogg.net/foaf" => {
|
431
|
-
"@id" => "http://greggkellogg.net/foaf",
|
432
|
-
"@type" => [RDF::FOAF.PersonalProfile.to_s],
|
433
|
-
RDF::FOAF.primaryTopic.to_s => [{"@id" => "http://greggkellogg.net/foaf#me"}]
|
434
|
-
},
|
435
|
-
"http://greggkellogg.net/foaf#me" => {
|
436
|
-
"@id" => "http://greggkellogg.net/foaf#me",
|
437
|
-
"@type" => [RDF::FOAF.Person.to_s]
|
438
|
-
}
|
439
|
-
}
|
440
|
-
},
|
441
|
-
"embedded anon" => {
|
442
|
-
:input => {
|
443
|
-
"@context" => {"foaf" => RDF::FOAF.to_s},
|
444
|
-
"@id" => "http://greggkellogg.net/foaf",
|
445
|
-
"@type" => "foaf:PersonalProfile",
|
446
|
-
"foaf:primaryTopic" => {
|
447
|
-
"@type" => "foaf:Person"
|
448
|
-
}
|
449
|
-
},
|
450
|
-
:subjects => %w(http://greggkellogg.net/foaf _:t0),
|
451
|
-
:output => {
|
452
|
-
"_:t0" => {
|
453
|
-
"@id" => "_:t0",
|
454
|
-
"@type" => [RDF::FOAF.Person.to_s]
|
455
|
-
},
|
456
|
-
"http://greggkellogg.net/foaf" => {
|
457
|
-
"@id" => "http://greggkellogg.net/foaf",
|
458
|
-
"@type" => [RDF::FOAF.PersonalProfile.to_s],
|
459
|
-
RDF::FOAF.primaryTopic.to_s => [{"@id" => "_:t0"}]
|
460
|
-
},
|
461
|
-
}
|
462
391
|
},
|
463
|
-
|
464
|
-
|
465
|
-
@debug = []
|
466
|
-
@subjects = Hash.ordered
|
467
|
-
jld = nil
|
468
|
-
JSON::LD::API.new(params[:input], nil, :debug => @debug) do |api|
|
469
|
-
expanded_value = api.expand(api.value, nil, api.context)
|
470
|
-
api.get_framing_subjects(@subjects, expanded_value, JSON::LD::BlankNodeNamer.new("t"))
|
471
|
-
end
|
472
|
-
@subjects.keys.should produce(params[:subjects], @debug)
|
473
|
-
@subjects.should produce(params[:output], @debug)
|
474
|
-
end
|
475
|
-
end
|
476
|
-
end
|
477
|
-
|
478
|
-
describe ".flatten" do
|
479
|
-
{
|
480
|
-
"single object" => {
|
481
|
-
:input => {"@id" => "http://example.com", "@type" => RDF::RDFS.Resource.to_s},
|
482
|
-
:output => [{"@id" => "http://example.com", "@type" => [RDF::RDFS.Resource.to_s]}]
|
483
|
-
},
|
484
|
-
"embedded object" => {
|
485
|
-
:input => {
|
392
|
+
"microdata manifest" => {
|
393
|
+
:frame => {
|
486
394
|
"@context" => {
|
487
|
-
"
|
395
|
+
"xsd" => "http://www.w3.org/2001/XMLSchema#",
|
396
|
+
"rdfs" => "http://www.w3.org/2000/01/rdf-schema#",
|
397
|
+
"mf" => "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#",
|
398
|
+
"mq" => "http://www.w3.org/2001/sw/DataAccess/tests/test-query#",
|
399
|
+
|
400
|
+
"comment" => "rdfs:comment",
|
401
|
+
"entries" => {"@id" => "mf:entries", "@container" => "@list"},
|
402
|
+
"name" => "mf:name",
|
403
|
+
"action" => "mf:action",
|
404
|
+
"data" => {"@id" => "mq:data", "@type" => "@id"},
|
405
|
+
"query" => {"@id" => "mq:query", "@type" => "@id"},
|
406
|
+
"result" => {"@id" => "mf:result", "@type" => "xsd:boolean"}
|
488
407
|
},
|
489
|
-
"@
|
490
|
-
"
|
491
|
-
|
492
|
-
"
|
493
|
-
|
408
|
+
"@type" => "mf:Manifest",
|
409
|
+
"entries" => [{
|
410
|
+
"@type" => "mf:ManifestEntry",
|
411
|
+
"action" => {
|
412
|
+
"@type" => "mq:QueryTest"
|
413
|
+
}
|
494
414
|
}]
|
495
415
|
},
|
496
|
-
:output => [
|
497
|
-
{
|
498
|
-
"@id" => "http://greggkellogg.net/foaf",
|
499
|
-
"@type" => [RDF::FOAF.PersonalProfile.to_s],
|
500
|
-
RDF::FOAF.primaryTopic.to_s => [{"@id" => "http://greggkellogg.net/foaf#me"}]
|
501
|
-
},
|
502
|
-
{
|
503
|
-
"@id" => "http://greggkellogg.net/foaf#me",
|
504
|
-
"@type" => [RDF::FOAF.Person.to_s]
|
505
|
-
}
|
506
|
-
]
|
507
|
-
},
|
508
|
-
"embedded anon" => {
|
509
416
|
:input => {
|
510
417
|
"@context" => {
|
511
|
-
"
|
418
|
+
"md" => "http://www.w3.org/ns/md#",
|
419
|
+
"mf" => "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#",
|
420
|
+
"mq" => "http://www.w3.org/2001/sw/DataAccess/tests/test-query#",
|
421
|
+
"rdfs" => "http://www.w3.org/2000/01/rdf-schema#"
|
512
422
|
},
|
513
|
-
"@
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
423
|
+
"@graph" => [
|
424
|
+
{
|
425
|
+
"@id" => "_:manifest",
|
426
|
+
"@type" => "mf:Manifest",
|
427
|
+
"mf:entries" => {"@list" => [
|
428
|
+
{"@id" => "_:entry"}
|
429
|
+
]},
|
430
|
+
"rdfs:comment" => "Positive processor tests"
|
431
|
+
},
|
432
|
+
{
|
433
|
+
"@id" => "_:entry",
|
434
|
+
"@type" => "mf:ManifestEntry",
|
435
|
+
"mf:action" => {"@id" => "_:query"},
|
436
|
+
"mf:name" => "Test 0001",
|
437
|
+
"mf:result" => "true",
|
438
|
+
"rdfs:comment" => "Item with no itemtype and literal itemprop"
|
439
|
+
},
|
440
|
+
{
|
441
|
+
"@id" => "_:query",
|
442
|
+
"@type" => "mq:QueryTest",
|
443
|
+
"mq:data" => {
|
444
|
+
"@id" => "http://www.w3.org/TR/microdata-rdf/tests/0001.html"
|
445
|
+
},
|
446
|
+
"mq:query" => {
|
447
|
+
"@id" => "http://www.w3.org/TR/microdata-rdf/tests/0001.ttl"
|
448
|
+
}
|
449
|
+
}
|
450
|
+
]
|
518
451
|
},
|
519
|
-
:output =>
|
520
|
-
{
|
521
|
-
"
|
522
|
-
"
|
523
|
-
|
524
|
-
|
525
|
-
"
|
526
|
-
"
|
527
|
-
|
452
|
+
:output => {
|
453
|
+
"@context" => {
|
454
|
+
"xsd" => "http://www.w3.org/2001/XMLSchema#",
|
455
|
+
"rdfs" => "http://www.w3.org/2000/01/rdf-schema#",
|
456
|
+
"mf" => "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#",
|
457
|
+
"mq" => "http://www.w3.org/2001/sw/DataAccess/tests/test-query#",
|
458
|
+
"comment" => "rdfs:comment",
|
459
|
+
"entries" => {
|
460
|
+
"@id" => "mf:entries",
|
461
|
+
"@container" => "@list"
|
462
|
+
},
|
463
|
+
"name" => "mf:name",
|
464
|
+
"action" => "mf:action",
|
465
|
+
"data" => {
|
466
|
+
"@id" => "mq:data",
|
467
|
+
"@type" => "@id"
|
468
|
+
},
|
469
|
+
"query" => {
|
470
|
+
"@id" => "mq:query",
|
471
|
+
"@type" => "@id"
|
472
|
+
},
|
473
|
+
"result" => {
|
474
|
+
"@id" => "mf:result",
|
475
|
+
"@type" => "xsd:boolean"
|
476
|
+
}
|
528
477
|
},
|
529
|
-
|
478
|
+
"@graph" => [
|
479
|
+
{
|
480
|
+
"@id" => "_:t0",
|
481
|
+
"@type" => "mf:Manifest",
|
482
|
+
"comment" => "Positive processor tests",
|
483
|
+
"entries" => [
|
484
|
+
{
|
485
|
+
"@id" => "_:t1",
|
486
|
+
"@type" => "mf:ManifestEntry",
|
487
|
+
"action" => {
|
488
|
+
"@id" => "_:t2",
|
489
|
+
"@type" => "mq:QueryTest",
|
490
|
+
"data" => "http://www.w3.org/TR/microdata-rdf/tests/0001.html",
|
491
|
+
"query" => "http://www.w3.org/TR/microdata-rdf/tests/0001.ttl"
|
492
|
+
},
|
493
|
+
"comment" => "Item with no itemtype and literal itemprop",
|
494
|
+
"mf:result" => "true",
|
495
|
+
"name" => "Test 0001"
|
496
|
+
}
|
497
|
+
]
|
498
|
+
}
|
499
|
+
]
|
500
|
+
}
|
530
501
|
}
|
531
502
|
}.each do |title, params|
|
532
503
|
it title do
|
533
504
|
@debug = []
|
534
|
-
|
535
|
-
|
536
|
-
jld
|
505
|
+
begin
|
506
|
+
jld = JSON::LD::API.frame(params[:input], params[:frame], nil, :debug => @debug)
|
507
|
+
jld.should produce(params[:output], @debug)
|
508
|
+
rescue JSON::LD::ProcessingError, JSON::LD::InvalidContext, JSON::LD::InvalidFrame => e
|
509
|
+
fail("#{e.class}: #{e.message}\n" +
|
510
|
+
"#{@debug.join("\n")}\n" +
|
511
|
+
"Backtrace:\n#{e.backtrace.join("\n")}")
|
537
512
|
end
|
538
|
-
jld.should produce(params[:output], @debug)
|
539
513
|
end
|
540
514
|
end
|
541
515
|
end
|