Skip to content

Commit

Permalink
More moves towards Triple Terms vs Quoted Triples.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Aug 26, 2024
1 parent d5b00f1 commit 12aee59
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,24 @@ Internally, an `RDF::Statement` is treated as another resource, along with `RDF:

**Note: This feature is subject to change or elimination as the standards process progresses.**

### Serializing a Graph containing quoted triples
### Serializing a Graph containing triple terms

require 'rdf/ntriples'
statement = RDF::Statement(RDF::URI('bob'), RDF::Vocab::FOAF.age, RDF::Literal(23))
graph = RDF::Graph.new << [statement, RDF::URI("ex:certainty"), RDF::Literal(0.9)]
reifier = RDF::Node.new
graph = RDF::Graph.new do |g|
g << [reifier, RDF.reifies, statement]
g << [reifier, RDF::URI("ex:certainty"), RDF::Literal(0.9)]
end
graph.dump(:ntriples, validate: false)
# => '<<<bob> <http://xmlns.com/foaf/0.1/age> "23"^^<http://www.w3.org/2001/XMLSchema#integer>>> <ex:certainty> "0.9"^^<http://www.w3.org/2001/XMLSchema#double> .'
# ==> '_:bn <http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<(<bob> <http://xmlns.com/foaf/0.1/age> "23"^^<http://www.w3.org/2001/XMLSchema#integer>)>> .
_:bn <ex:certainty> "0.9"^^<http://www.w3.org/2001/XMLSchema#double> .'

### Reading a Graph containing quoted triples
### Reading a Graph containing triple terms

By default, the N-Triples reader will reject a document containing a subject resource.

nt = '<<<bob> <http://xmlns.com/foaf/0.1/age> "23"^^<http://www.w3.org/2001/XMLSchema#integer>>> <ex:certainty> "0.9"^^<http://www.w3.org/2001/XMLSchema#double> .'
nt = '<<(<bob> <http://xmlns.com/foaf/0.1/age> "23"^^<http://www.w3.org/2001/XMLSchema#integer>)>> <ex:certainty> "0.9"^^<http://www.w3.org/2001/XMLSchema#double> .'
graph = RDF::Graph.new do |graph|
RDF::NTriples::Reader.new(nt) {|reader| graph << reader}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/model/statement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def to_h(subject_key = :subject, predicate_key = :predicate, object_key = :objec
def to_s
(graph_name ? to_quad : to_triple).map do |term|
if term.is_a?(Statement)
"<<#{term.to_s[0..-3]}>>"
"<<(#{term.to_s[0..-3]})>>"
elsif term.respond_to?(:to_base)
term.to_base
else
Expand Down
6 changes: 3 additions & 3 deletions lib/rdf/ntriples/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module RDF::NTriples
#
# ** RDF=star
#
# Supports statements as resources using `<<s p o>>`.
# Supports statements as resources using `<<(s p o)>>`.
#
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
# @see http://www.w3.org/TR/n-triples/
Expand Down Expand Up @@ -73,8 +73,8 @@ class Reader < RDF::Reader
TT_START = /^<<\(/.freeze
TT_END = /^\s*\)>>/.freeze

QT_START = /^<</.freeze
QT_END = /^\s*>>/.freeze
QT_START = /^<</.freeze # DEPRECATED
QT_END = /^\s*>>/.freeze # DEPRECATED

# @see http://www.w3.org/TR/rdf-testcases/#ntrip_grammar
COMMENT = /^#\s*(.*)$/.freeze
Expand Down

0 comments on commit 12aee59

Please sign in to comment.