Skip to content

Commit 31a02d8

Browse files
committed
Consolidate N-Triples and N-Triples Star grammars. Use LANGDIR terminal instead of LANGTAG.
1 parent 16c4086 commit 31a02d8

4 files changed

Lines changed: 30 additions & 40 deletions

File tree

README.md

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,28 @@ This is a pure-Ruby library for working with [Resource Description Framework
1414

1515
1. [Features](#features)
1616
2. [Differences between RDF 1.0 and RDF 1.1](#differences-between-rdf-1-0-and-rdf-1-1)
17-
3. [Tutorials](#tutorials)
18-
4. [Command Line](#command-line)
19-
5. [Examples](#examples)
20-
6. [Reader/Writer convenience methods](#reader/writer-convenience-methods)
21-
7. [RDF* (RDFStar)](#rdf*-(rdfstar))
22-
8. [Documentation](#documentation)
23-
9. [Dependencies](#dependencies)
24-
10. [Installation](#installation)
25-
11. [Download](#download)
26-
12. [Resources](#resources)
27-
13. [Mailing List](#mailing-list)
28-
14. [Authors](#authors)
29-
15. [Contributors](#contributors)
30-
16. [Contributing](#contributing)
31-
17. [License](#license)
17+
3. [Differences between RDF 1.1 and RDF 1.2](#differences-between-rdf-1-1-and-rdf-1-2)
18+
4. [Tutorials](#tutorials)
19+
5. [Command Line](#command-line)
20+
6. [Examples](#examples)
21+
7. [Reader/Writer convenience methods](#reader/writer-convenience-methods)
22+
8. [RDF 1.2](#rdf\_12)
23+
9. [Documentation](#documentation)
24+
10. [Dependencies](#dependencies)
25+
11. [Installation](#installation)
26+
12. [Download](#download)
27+
13. [Resources](#resources)
28+
14. [Mailing List](#mailing-list)
29+
15. [Authors](#authors)
30+
16. [Contributors](#contributors)
31+
17. [Contributing](#contributing)
32+
18. [License](#license)
3233

3334
## Features
3435

3536
* 100% pure Ruby with minimal dependencies and no bloat.
3637
* Fully compatible with [RDF 1.1][] specifications.
38+
* Provisional support for [RDF 1.2][] specifications.
3739
* 100% free and unencumbered [public domain](https://unlicense.org/) software.
3840
* Provides a clean, well-designed RDF object model and related APIs.
3941
* Supports parsing and serializing [N-Triples][] and [N-Quads][] out of the box, with more
@@ -49,7 +51,6 @@ This is a pure-Ruby library for working with [Resource Description Framework
4951
* Note, changes in mapping hashes to keyword arguments for Ruby 2.7+ may require that arguments be passed more explicitly, especially when the first argument is a Hash and there are optional keyword arguments. In this case, Hash argument may need to be explicitly included within `{}` and the optional keyword arguments may need to be specified using `**{}` if there are no keyword arguments.
5052
* Performs auto-detection of input to select appropriate Reader class if one
5153
cannot be determined from file characteristics.
52-
* Provisional support for [RDF*][].
5354

5455
### HTTP requests
5556

@@ -263,23 +264,24 @@ A separate [SPARQL][SPARQL doc] gem builds on basic BGP support to provide full
263264
foaf[:name] #=> RDF::URI("http://xmlns.com/foaf/0.1/name")
264265
foaf['mbox'] #=> RDF::URI("http://xmlns.com/foaf/0.1/mbox")
265266

266-
## RDF* (RDFStar)
267+
## RDF 1.2
267268

268-
[RDF.rb][] includes provisional support for [RDF*][] with an N-Triples/N-Quads syntax extension that uses inline statements in the _subject_ or _object_ position.
269+
[RDF.rb][] includes provisional support for [RDF 1.2][] with an N-Triples/N-Quads syntax for quoted triples in the _subject_ or _object_ position.
270+
[RDF.rb][] includes provisional support for [RDF 1.2][] directional language-tagged strings, which are literals of type `rdf:dirLangString` having both a `language` and `direction`.
269271

270272
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`.
271273

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

274-
### Serializing a Graph containing embedded statements
276+
### Serializing a Graph containing quoted triples
275277

276278
require 'rdf/ntriples'
277279
statement = RDF::Statement(RDF::URI('bob'), RDF::Vocab::FOAF.age, RDF::Literal(23))
278280
graph = RDF::Graph.new << [statement, RDF::URI("ex:certainty"), RDF::Literal(0.9)]
279281
graph.dump(:ntriples, validate: false)
280282
# => '<<<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> .'
281283

282-
### Reading a Graph containing embedded statements
284+
### Reading a Graph containing quoted triples
283285

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

@@ -289,13 +291,6 @@ By default, the N-Triples reader will reject a document containing a subject res
289291
end
290292
# => RDF::ReaderError
291293

292-
Readers support a boolean valued `rdfstar` option.
293-
294-
graph = RDF::Graph.new do |graph|
295-
RDF::NTriples::Reader.new(nt, rdfstar: true) {|reader| graph << reader}
296-
end
297-
graph.count #=> 1
298-
299294
## Documentation
300295

301296
<https://ruby-rdf.github.io/rdf>
@@ -517,7 +512,6 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
517512
[RDF::TriX]: https://ruby-rdf.github.io/rdf-trix
518513
[RDF::Turtle]: https://ruby-rdf.github.io/rdf-turtle
519514
[RDF::Raptor]: https://ruby-rdf.github.io/rdf-raptor
520-
[RDF*]: https://w3c.github.io/rdf-star/rdf-star-cg-spec.html
521515
[LinkedData]: https://ruby-rdf.github.io/linkeddata
522516
[JSON::LD]: https://ruby-rdf.github.io/json-ld
523517
[RestClient]: https://rubygems.org/gems/rest-client

etc/n-triples-star.ebnf

Lines changed: 0 additions & 7 deletions
This file was deleted.

etc/n-triples.ebnf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ triple ::= subject predicate object '.'
33
subject ::= IRIREF | BLANK_NODE_LABEL | quotedTriple
44
predicate ::= IRIREF
55
object ::= IRIREF | BLANK_NODE_LABEL | literal | quotedTriple
6-
literal ::= STRING_LITERAL_QUOTE ('^^' IRIREF | LANGTAG )?
6+
literal ::= STRING_LITERAL_QUOTE ('^^' IRIREF | LANGDIR )?
77
quotedTriple ::= '<<' subject predicate object '>>'
88

99
@terminals
1010

1111
IRIREF ::= '<' ([^#x00-#x20<>"{}|^`\] | UCHAR)* '>'
1212
BLANK_NODE_LABEL ::= '_:' ( PN_CHARS_U | [0-9] ) ((PN_CHARS|'.')* PN_CHARS)?
13-
LANGTAG ::= "@" [a-zA-Z]+ ( "-" [a-zA-Z0-9]+ )* ('--' ('ltr'|'rtl'))?`
13+
LANGDIR ::= "@" [a-zA-Z]+ ( "-" [a-zA-Z0-9]+ )* ('--' ('ltr'|'rtl'))?`
1414
STRING_LITERAL_QUOTE ::= '"' ( [^#x22#x5C#xA#xD] | ECHAR | UCHAR )* '"'
1515
UCHAR ::= ( "\u" HEX HEX HEX HEX )
1616
| ( "\U" HEX HEX HEX HEX HEX HEX HEX HEX )

lib/rdf/ntriples/reader.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Reader < RDF::Reader
6767

6868
IRIREF = /<((?:#{IRI_RANGE}|#{UCHAR})*)>/.freeze
6969
BLANK_NODE_LABEL = /_:((?:[0-9]|#{PN_CHARS_U})(?:(?:#{PN_CHARS}|\.)*#{PN_CHARS})?)/.freeze
70-
LANGTAG = /@([a-zA-Z]+(?:-[a-zA-Z0-9]+)*(?:--[a-zA-Z0-9]+)?)/.freeze
70+
LANGDIR = /@([a-zA-Z]+(?:-[a-zA-Z0-9]+)*(?:--[a-zA-Z0-9]+)?)/.freeze
7171
STRING_LITERAL_QUOTE = /"((?:[^\"\\\n\r]|#{ECHAR}|#{UCHAR})*)"/.freeze
7272

7373
ST_START = /^<</.freeze
@@ -78,7 +78,7 @@ class Reader < RDF::Reader
7878
NODEID = /^#{BLANK_NODE_LABEL}/.freeze
7979
URIREF = /^#{IRIREF}/.freeze
8080
LITERAL_PLAIN = /^#{STRING_LITERAL_QUOTE}/.freeze
81-
LITERAL_WITH_LANGUAGE = /^#{STRING_LITERAL_QUOTE}#{LANGTAG}/.freeze
81+
LITERAL_WITH_LANGUAGE = /^#{STRING_LITERAL_QUOTE}#{LANGDIR}/.freeze
8282
LITERAL_WITH_DATATYPE = /^#{STRING_LITERAL_QUOTE}\^\^#{IRIREF}/.freeze
8383
DATATYPE_URI = /^\^\^#{IRIREF}/.freeze
8484
LITERAL = Regexp.union(LITERAL_WITH_LANGUAGE, LITERAL_WITH_DATATYPE, LITERAL_PLAIN).freeze
@@ -87,6 +87,9 @@ class Reader < RDF::Reader
8787
OBJECT = Regexp.union(URIREF, NODEID, LITERAL).freeze
8888
END_OF_STATEMENT = /^\s*\.\s*(?:#.*)?$/.freeze
8989

90+
# LANGTAG is deprecated
91+
LANGTAG = LANGDIR
92+
9093
##
9194
# Reconstructs an RDF value from its serialized N-Triples
9295
# representation.
@@ -291,7 +294,7 @@ def read_literal
291294
if literal_str = match(LITERAL_PLAIN)
292295
literal_str = self.class.unescape(literal_str)
293296
literal = case
294-
when lang_dir = match(LANGTAG)
297+
when lang_dir = match(LANGDIR)
295298
language, direction = lang_dir.split('--')
296299
RDF::Literal.new(literal_str, language: language, direction: direction)
297300
when datatype = match(/^(\^\^)/) # FIXME

0 commit comments

Comments
 (0)