Skip to content

Commit

Permalink
Restrict subject and object of a reifiedTriple per latest spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Sep 18, 2024
1 parent e105077 commit 6506e92
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
9 changes: 6 additions & 3 deletions etc/turtle.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ iri ::= IRIREF | PrefixedName
PrefixedName ::= PNAME_LN | PNAME_NS
BlankNode ::= BLANK_NODE_LABEL | ANON
reifier ::= '~' (iri | BlankNode)?
reifiedTriple ::= '<<' (subject | reifiedTriple) predicate object reifier? '>>'
tripleTerm ::= '<<(' ttSubject predicate ttObject ')>>'
reifiedTriple ::= '<<' rtSubject verb rtObject reifier? '>>'
rtSubject ::= iri | BlankNode | reifiedTriple
rtObject ::= iri | BlankNode | literal | tripleTerm | reifiedTriple
tripleTerm ::= '<<(' ttSubject verb ttObject ')>>'
ttSubject ::= iri | BlankNode
ttObject ::= iri | BlankNode | literal | tripleTerm
annotation ::= (reifier | '{|' predicateObjectList '|}')*
annotation ::= (reifier | annotationBlock)*
annotationBlock ::= '{|' predicateObjectList '|}'

@terminals

Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/turtle/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def read_reifiedTriple
@lexer.shift # eat <<
subject = read_ttSubject || read_reifiedTriple || error("Failed to parse subject", production: :reifiedTriple, token: @lexer.first)
predicate = read_verb || error("Failed to parse predicate", production: :reifiedTriple, token: @lexer.first)
object = read_object || error("Failed to parse object", production: :reifiedTriple, token: @lexer.first)
object = read_ttObject || read_tripleTerm || read_reifiedTriple || error("Failed to parse object", production: :reifiedTriple, token: @lexer.first)
tt = RDF::Statement(subject, predicate, object, tripleTerm: true)

# An optional reifier. If not specified it is a new blank node.
Expand Down
23 changes: 23 additions & 0 deletions spec/reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,29 @@
_:bn2 <http://example/q> <http://example/r> .
)
],
'included triple terms': [
%(
PREFIX : <http://example/>
:s :p <<( :s1 :p1 <<( :s2 :p2 :o2 )>> )>>, <<( :s3 :p3 :o3)>> .
),
%(
<http://example/s> <http://example/p> <<(<http://example/s1> <http://example/p1> <<(<http://example/s2> <http://example/p2> <http://example/o2>)>>)>> .
<http://example/s> <http://example/p> <<(<http://example/s3> <http://example/p3> <http://example/o3>)>>
)
],
'included reified triples': [
%(
PREFIX : <http://example/>
:s :p << :s1 :p1 << :s2 :p2 :o2 >> >>, << :s3 :p3 :o3 >> .
),
%(
<http://example/s> <http://example/p> _:r0 .
_:r1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<( <http://example/s2> <http://example/p2> <http://example/o2> )>> .
_:r0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<( <http://example/s1> <http://example/p1> _:r1 )>> .
<http://example/s> <http://example/p> _:r2 .
_:r2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<( <http://example/s3> <http://example/p3> <http://example/o3> )>> .
)
],
}.each do |name, (ttl, nt)|
it name do
if nt.is_a?(String)
Expand Down

0 comments on commit 6506e92

Please sign in to comment.