Skip to content

Commit 40655ec

Browse files
committed
Update link to JSON-LD* and consolidate rdfstar mode.
1 parent 0f71200 commit 40655ec

File tree

7 files changed

+24
-107
lines changed

7 files changed

+24
-107
lines changed

README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ JSON::LD can now be used to create a _context_ from an RDFS/OWL definition, and
1414

1515
* If the [jsonlint][] gem is installed, it will be used when validating an input document.
1616
* If available, uses [Nokogiri][] and/or [Nokogumbo][] for parsing HTML, falls back to REXML otherwise.
17-
* Provisional support for [JSON-LD*][RDF*].
17+
* Provisional support for [JSON-LD*][JSON-LD*].
1818

1919
[Implementation Report](file.earl.html)
2020

@@ -38,7 +38,7 @@ The [MultiJson](https://rubygems.org/gems/multi_json) gem is used for parsing JS
3838

3939
### JSON-LD* (RDFStar)
4040

41-
The {JSON::LD::API.toRdf} and {JSON::LD::API.fromRdf} API methods, along with the {JSON::LD::Reader} and {JSON::LD::Writer}, include provisional support for [JSON-LD*][RDF*].
41+
The {JSON::LD::API.toRdf} and {JSON::LD::API.fromRdf} API methods, along with the {JSON::LD::Reader} and {JSON::LD::Writer}, include provisional support for [JSON-LD*][JSON-LD*].
4242

4343
Internally, an `RDF::Statement` is treated as another resource, along with `RDF::URI` and `RDF::Node`, which allows an `RDF::Statement` to have a `#subject` or `#object` which is also an `RDF::Statement`.
4444

@@ -82,17 +82,10 @@ By default, {JSON::LD::API.toRdf} (and {JSON::LD::Reader}) will reject a documen
8282
graph = RDF::Graph.new << JSON::LD::API.toRdf(input)
8383
# => JSON::LD::JsonLdError::InvalidIdValue
8484

85-
{JSON::LD::API.toRdf} (and {JSON::LD::Reader}) support a `rdfstar` option with either `:PG` (Property Graph) or `:SA` (Separate Assertions) modes. In `:PG` mode, statements that are used in the subject or object positions are also implicitly added to the graph:
85+
{JSON::LD::API.toRdf} (and {JSON::LD::Reader}) support a boolean valued `rdfstar` option; only one statement is asserted, although the reified statement is contained within the graph.
8686

8787
graph = RDF::Graph.new do |graph|
88-
JSON::LD::Reader.new(jsonld, rdfstar: :PG) {|reader| graph << reader}
89-
end
90-
graph.count #=> 2
91-
92-
When using the `:SA` mode, only one statement is asserted, although the reified statement is contained within the graph.
93-
94-
graph = RDF::Graph.new do |graph|
95-
JSON::LD::Reader.new(jsonld, rdfstar: :PG) {|reader| graph << reader}
88+
JSON::LD::Reader.new(jsonld, rdfstar: true) {|reader| graph << reader}
9689
end
9790
graph.count #=> 1
9891

@@ -629,7 +622,7 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
629622
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
630623
[PDD]: https://unlicense.org/#unlicensing-contributions
631624
[RDF.rb]: https://rubygems.org/gems/rdf
632-
[RDF*]: https://lists.w3.org/Archives/Public/public-rdf-star/
625+
[JSON-LD*]: https://json-ld.github.io/json-ld-star/
633626
[Rack::LinkedData]: https://rubygems.org/gems/rack-linkeddata
634627
[Backports]: https://rubygems.org/gems/backports
635628
[JSON-LD]: https://www.w3.org/TR/json-ld11/ "JSON-LD 1.1"

lib/json/ld/api.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,8 @@ class API
8989
# @option options [String] :processingMode
9090
# Processing mode, json-ld-1.0 or json-ld-1.1.
9191
# If `processingMode` is not specified, a mode of `json-ld-1.0` or `json-ld-1.1` is set, the context used for `expansion` or `compaction`.
92-
# @option options [:PG, :SA] rdfstar (nil)
92+
# @option options [Boolean] rdfstar (false)
9393
# support parsing JSON-LD* statement resources.
94-
# If `:PG`, referenced statements are also emitted (toRdf).
95-
# If `:SA`, referenced statements are not emitted.
9694
# @option options [Boolean] :rename_bnodes (true)
9795
# Rename bnodes as part of expansion, or keep them the same.
9896
# @option options [Boolean] :unique_bnodes (false)
@@ -502,11 +500,6 @@ def self.toRdf(input, expanded: false, **options, &block)
502500
end
503501

504502
yield statement
505-
506-
# If in Property Graph mode for RDF* and statement has an embedded triple, yield those embedded triples as well.
507-
if options[:rdfstar] == :PG && statement.to_a.any?(&:statement?)
508-
each_pg_statement(statement, &block)
509-
end
510503
end
511504
end
512505
end

lib/json/ld/expand.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,7 @@ def expand_object(input, active_property, context, output_object,
281281
elsif @options[:rdfstar]
282282
# Result must have just a single statement
283283
rei_node = expand(value, active_property, context, log_depth: log_depth.to_i + 1)
284-
old_star, @options[:rdfstar] = @options[:rdfstar], :SA
285284
statements = to_enum(:item_to_rdf, rei_node)
286-
@options[:rdfstar] = old_star # :PG would emit too many statements
287285
raise JsonLdError::InvalidEmbeddedNode,
288286
"Embedded node with #{statements.size} statements" unless
289287
statements.count == 1

lib/json/ld/to_rdf.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,6 @@ def parse_list(list, graph_name: nil, &block)
182182
result
183183
end
184184

185-
##
186-
# Recursively emit embedded statements in Property Graph mode
187-
#
188-
# @param [RDF::Statement] statement
189-
def each_pg_statement(statement, &block)
190-
if statement.subject.statement?
191-
block.call(statement.subject)
192-
each_pg_statement(statement.subject, &block)
193-
end
194-
195-
if statement.object.statement?
196-
block.call(statement.object)
197-
each_pg_statement(statement.object, &block)
198-
end
199-
end
200-
201185
##
202186
# Create a new named node using the sequence
203187
def node

script/parse

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ OPT_ARGS = [
116116
["--output", "-o", GetoptLong::REQUIRED_ARGUMENT, "Where to store output (default STDOUT)"],
117117
["--profile", GetoptLong::NO_ARGUMENT, "Run profiler with output to doc/profiles/"],
118118
["--quiet", GetoptLong::NO_ARGUMENT, "Reduce output"],
119-
["--rdfstar", GetoptLong::REQUIRED_ARGUMENT, "RDF* mode, SA or PG"],
119+
["--rdfstar", GetoptLong::NO_ARGUMENT, "RDF* mode"],
120120
["--stream", GetoptLong::NO_ARGUMENT, "Streaming reader/writer"],
121121
["--uri", GetoptLong::REQUIRED_ARGUMENT, "Run with argument value as base"],
122122
["--validate", GetoptLong::NO_ARGUMENT, "Validate input"],
@@ -157,9 +157,7 @@ opts.each do |opt, arg|
157157
when '--quiet'
158158
options[:quiet] = true
159159
logger.level = Logger::FATAL
160-
when '--rdfstar'
161-
parser_options[:rdfstar] = arg.to_sym
162-
usage unless [:PG, :SA].include?(parser_options[:rdfstar])
160+
when '--rdfstar' then parser_options[:rdfstar] = true
163161
when '--stream' then parser_options[:stream] = true
164162
when '--uri' then parser_options[:base] = arg
165163
when '--validate' then parser_options[:validate] = true

spec/expand_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3620,7 +3620,7 @@
36203620
}])
36213621
},
36223622
}.each do |title, params|
3623-
it(title) {run_expand params.merge(rdfstar: :SA)}
3623+
it(title) {run_expand params.merge(rdfstar: true)}
36243624
end
36253625
end
36263626

spec/to_rdf_spec.rb

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,13 +1199,9 @@
11991199
},
12001200
"ex:prop": "value2"
12011201
}),
1202-
sa: %(
1202+
expected: %(
12031203
<<_:b0 <ex:prop> "value">> <ex:prop> "value2" .
12041204
),
1205-
pg: %(
1206-
<<_:b0 <ex:prop> "value">> <ex:prop> "value2" .
1207-
_:b0 <ex:prop> "value" .
1208-
),
12091205
},
12101206
"node with embedded subject having IRI @id": {
12111207
input: %({
@@ -1215,12 +1211,8 @@
12151211
},
12161212
"ex:prop": "value2"
12171213
}),
1218-
sa: %(
1219-
<<<ex:rei> <ex:prop> "value">> <ex:prop> "value2" .
1220-
),
1221-
pg: %(
1214+
expected: %(
12221215
<<<ex:rei> <ex:prop> "value">> <ex:prop> "value2" .
1223-
<ex:rei> <ex:prop> "value" .
12241216
),
12251217
},
12261218
"node with embedded subject having BNode @id": {
@@ -1231,12 +1223,8 @@
12311223
},
12321224
"ex:prop": "value2"
12331225
}),
1234-
sa: %(
1235-
<<_:b0 <ex:prop> "value">> <ex:prop> "value2" .
1236-
),
1237-
pg: %(
1226+
expected: %(
12381227
<<_:b0 <ex:prop> "value">> <ex:prop> "value2" .
1239-
_:b0 <ex:prop> "value" .
12401228
),
12411229
},
12421230
"node with embedded subject having a type": {
@@ -1247,13 +1235,9 @@
12471235
},
12481236
"ex:prop": "value2"
12491237
}),
1250-
sa: %(
1238+
expected: %(
12511239
<<<ex:rei> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <ex:Type>>> <ex:prop> "value2" .
12521240
),
1253-
pg: %(
1254-
<<<ex:rei> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <ex:Type>>> <ex:prop> "value2" .
1255-
<ex:rei> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <ex:Type> .
1256-
),
12571241
},
12581242
"node with embedded subject having an IRI value": {
12591243
input: %({
@@ -1263,12 +1247,8 @@
12631247
},
12641248
"ex:prop": "value2"
12651249
}),
1266-
sa: %(
1267-
<<<ex:rei> <ex:prop> <ex:value>>> <ex:prop> "value2" .
1268-
),
1269-
pg: %(
1250+
expected: %(
12701251
<<<ex:rei> <ex:prop> <ex:value>>> <ex:prop> "value2" .
1271-
<ex:rei> <ex:prop> <ex:value> .
12721252
),
12731253
},
12741254
"node with embedded subject having an BNode value": {
@@ -1279,12 +1259,8 @@
12791259
},
12801260
"ex:prop": "value2"
12811261
}),
1282-
sa: %(
1283-
<<<ex:rei> <ex:prop> _:b0>> <ex:prop> "value2" .
1284-
),
1285-
pg: %(
1262+
expected: %(
12861263
<<<ex:rei> <ex:prop> _:b0>> <ex:prop> "value2" .
1287-
<ex:rei> <ex:prop> _:b0 .
12881264
),
12891265
},
12901266
"node with recursive embedded subject": {
@@ -1298,14 +1274,9 @@
12981274
},
12991275
"ex:prop": "value2"
13001276
}),
1301-
sa: %(
1277+
expected: %(
13021278
<<<<<ex:rei> <ex:prop> "value3">> <ex:prop> "value">> <ex:prop> "value2" .
13031279
),
1304-
pg: %(
1305-
<<<<<ex:rei> <ex:prop> "value3">> <ex:prop> "value">> <ex:prop> "value2" .
1306-
<<<ex:rei> <ex:prop> "value3">> <ex:prop> "value" .
1307-
<ex:rei> <ex:prop> "value3" .
1308-
),
13091280
},
13101281
"illegal node with subject having no property": {
13111282
input: %({
@@ -1357,12 +1328,8 @@
13571328
}
13581329
}
13591330
}),
1360-
sa: %(
1361-
<ex:subj> <ex:value> <<<ex:rei> <ex:prop> "value">> .
1362-
),
1363-
pg: %(
1331+
expected: %(
13641332
<ex:subj> <ex:value> <<<ex:rei> <ex:prop> "value">> .
1365-
<ex:rei> <ex:prop> "value" .
13661333
),
13671334
},
13681335
"node with embedded object having properties": {
@@ -1376,15 +1343,10 @@
13761343
"ex:prop": "value2"
13771344
}
13781345
}),
1379-
sa: %(
1346+
expected: %(
13801347
<ex:subj> <ex:value> <<<ex:rei> <ex:prop> "value">> .
13811348
<<<ex:rei> <ex:prop> "value">> <ex:prop> "value2" .
13821349
),
1383-
pg: %(
1384-
<ex:subj> <ex:value> <<<ex:rei> <ex:prop> "value">> .
1385-
<<<ex:rei> <ex:prop> "value">> <ex:prop> "value2" .
1386-
<ex:rei> <ex:prop> "value" .
1387-
),
13881350
},
13891351
"node with recursive embedded object": {
13901352
input: %({
@@ -1400,31 +1362,20 @@
14001362
"ex:prop": "value2"
14011363
}
14021364
}),
1403-
sa: %(
1365+
expected: %(
14041366
<ex:subj> <ex:value> <<<<<ex:rei> <ex:prop> "value3">> <ex:prop> "value">> .
14051367
<<<<<ex:rei> <ex:prop> "value3">> <ex:prop> "value">> <ex:prop> "value2" .
14061368
),
1407-
pg: %(
1408-
<ex:subj> <ex:value> <<<<<ex:rei> <ex:prop> "value3">> <ex:prop> "value">> .
1409-
<<<ex:rei> <ex:prop> "value3">> <ex:prop> "value" .
1410-
<ex:rei> <ex:prop> "value3" .
1411-
<<<<<ex:rei> <ex:prop> "value3">> <ex:prop> "value">> <ex:prop> "value2" .
1412-
),
14131369
},
14141370
}.each do |title, params|
14151371
context(title) do
1416-
it "Separate Assertions" do
1417-
output_graph = RDF::Graph.new {|g| g << RDF::NTriples::Reader.new(params[:sa], rdfstar: :SA)}
1418-
run_to_rdf params.merge(rdfstar: :SA, output: output_graph)
1419-
end if params[:sa]
1420-
1421-
it "Property Graph" do
1422-
output_graph = RDF::Graph.new {|g| g << RDF::NTriples::Reader.new(params[:pg], rdfstar: :SA)}
1423-
run_to_rdf params.merge(rdfstar: :PG, output: output_graph)
1424-
end if params[:pg]
1372+
it "Generates statements" do
1373+
output_graph = RDF::Graph.new {|g| g << RDF::NTriples::Reader.new(params[:expected], rdfstar: true)}
1374+
run_to_rdf params.merge(rdfstar: true, output: output_graph)
1375+
end if params[:expected]
14251376

14261377
it "Exception" do
1427-
run_to_rdf params.merge(rdfstar: :SA)
1378+
run_to_rdf params.merge(rdfstar: true)
14281379
end if params[:exception]
14291380
end
14301381
end

0 commit comments

Comments
 (0)