@@ -231,6 +231,8 @@ class Parser
231231
232232 current [ :resource ] = current [ :collection ] . subject
233233 end
234+
235+ ( input [ :triples ] ||= [ ] ) . concat ( current [ :triples ] ) if current [ :triples ]
234236 input [ :subject ] = current [ :resource ] || current [ :iri ]
235237 end
236238
@@ -269,7 +271,7 @@ class Parser
269271 end
270272
271273 production ( :blankNodePropertyList ) do |input , current , callback |
272- input [ :resource ] = current [ :subject ]
274+ input [ :subject ] = input [ : resource] = current [ :subject ]
273275 ( input [ :triples ] ||= [ ] ) . concat ( current [ :triples ] ) if current [ :triples ]
274276 end
275277
@@ -282,6 +284,7 @@ class Parser
282284 production ( :collection ) do |input , current , callback |
283285 # Create an RDF list
284286 objects = current [ :object_list ]
287+ ( input [ :triples ] ||= [ ] ) . concat ( current [ :triples ] ) if current [ :triples ]
285288 input [ :collection ] = RDF ::List [ *objects ]
286289 end
287290
@@ -545,7 +548,11 @@ def bnode(id = nil)
545548 @options [ :anon_base ] = @options [ :anon_base ] . succ
546549 end
547550 # Don't use provided ID to avoid aliasing issues when re-serializing the graph, when the bnode identifiers are re-used
548- ( @bnode_cache ||= { } ) [ id . to_s ] ||= RDF ::Node . new
551+ ( @bnode_cache ||= { } ) [ id . to_s ] ||= begin
552+ new_bnode = RDF ::Node . new
553+ new_bnode . lexical = "_:#{ id } "
554+ new_bnode
555+ end
549556 end
550557 end
551558
@@ -589,4 +596,14 @@ def literal(value, options = {})
589596 RDF ::Literal . new ( value , options . merge ( validate : validate? ) )
590597 end
591598 end
592- end
599+ end
600+
601+
602+ # Update RDF::Node to set lexical representation of BNode
603+ ##
604+ # Extensions for RDF::URI
605+ class RDF ::Node
606+ # Original lexical value of this URI to allow for round-trip serialization.
607+ def lexical = ( value ) ; @lexical = value ; end
608+ def lexical ; @lexical ; end
609+ end
0 commit comments