From 8ca5d58e71a8697e003f96006ca587fcda9d70d2 Mon Sep 17 00:00:00 2001 From: Tpt Date: Sat, 24 Jun 2023 15:30:16 +0200 Subject: [PATCH] Improves oxttl documentation --- Cargo.lock | 2 +- lib/Cargo.toml | 2 +- lib/oxttl/Cargo.toml | 6 ++--- lib/oxttl/README.md | 54 +++++++++++++++++++++++++++++++++++++++ lib/oxttl/src/lib.rs | 6 +++++ lib/oxttl/src/n3.rs | 21 ++++++--------- lib/oxttl/src/nquads.rs | 44 +++++++++++++------------------ lib/oxttl/src/ntriples.rs | 44 +++++++++++++------------------ lib/oxttl/src/trig.rs | 44 +++++++++++++------------------ lib/oxttl/src/turtle.rs | 44 +++++++++++++------------------ 10 files changed, 145 insertions(+), 122 deletions(-) create mode 100644 lib/oxttl/README.md diff --git a/Cargo.lock b/Cargo.lock index 3ab7ed54..affef9d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1049,7 +1049,7 @@ dependencies = [ [[package]] name = "oxttl" -version = "0.1.0" +version = "0.1.0-alpha.1-dev" dependencies = [ "memchr", "oxilangtag", diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 224cf7b4..9c3fb465 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -39,7 +39,7 @@ lazy_static = "1" json-event-parser = "0.1" oxrdf = { version = "0.2.0-alpha.1-dev", path = "oxrdf", features = ["rdf-star", "oxsdatatypes"] } oxsdatatypes = { version = "0.2.0-alpha.1-dev", path="oxsdatatypes" } -oxttl = { version = "0.1.0" , path = "oxttl", features = ["rdf-star"] } +oxttl = { version = "0.1.0-alpha.1-dev" , path = "oxttl", features = ["rdf-star"] } spargebra = { version = "0.3.0-alpha.1-dev", path = "spargebra", features = ["rdf-star", "sep-0002", "sep-0006"] } sparopt = { version = "0.1.0-alpha.1-dev", path="sparopt", features = ["rdf-star", "sep-0002", "sep-0006"] } sparesults = { version = "0.2.0-alpha.1-dev", path = "sparesults", features = ["rdf-star"] } diff --git a/lib/oxttl/Cargo.toml b/lib/oxttl/Cargo.toml index bc8105c3..09d2798d 100644 --- a/lib/oxttl/Cargo.toml +++ b/lib/oxttl/Cargo.toml @@ -1,14 +1,14 @@ [package] name = "oxttl" -version = "0.1.0" +version = "0.1.0-alpha.1-dev" authors = ["Tpt "] license = "MIT OR Apache-2.0" readme = "README.md" -keywords = ["SPARQL"] +keywords = ["N-Triples", "N-Quads", "Turtle", "TriG", "N3", "RDF"] repository = "https://github.com/oxigraph/oxigraph/tree/master/lib/oxttl" homepage = "https://oxigraph.org/" description = """ -N-Triples parser +Parser for languages related to RDF Turtle (N-Triples, N-Quads, Turtle, TriG and N3) """ edition = "2021" rust-version = "1.65" diff --git a/lib/oxttl/README.md b/lib/oxttl/README.md new file mode 100644 index 00000000..e99dd2fc --- /dev/null +++ b/lib/oxttl/README.md @@ -0,0 +1,54 @@ +OxTTL +===== + +[![Latest Version](https://img.shields.io/crates/v/oxttl.svg)](https://crates.io/crates/oxttl) +[![Released API docs](https://docs.rs/oxttl/badge.svg)](https://docs.rs/oxttl) +[![Crates.io downloads](https://img.shields.io/crates/d/oxttl)](https://crates.io/crates/oxttl) +[![actions status](https://github.com/oxigraph/oxigraph/workflows/build/badge.svg)](https://github.com/oxigraph/oxigraph/actions) +[![Gitter](https://badges.gitter.im/oxigraph/community.svg)](https://gitter.im/oxigraph/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) + +Oxttl is a set of parsers and serializers for [Turtle](https://www.w3.org/TR/turtle/), [TriG](https://www.w3.org/TR/trig/), [N-Triples](https://www.w3.org/TR/n-triples/), [N-Quads](https://www.w3.org/TR/n-quads/) and [N3](https://w3c.github.io/N3/spec/). + +Support for [SPARQL-star](https://w3c.github.io/rdf-star/cg-spec/2021-12-17.html) is also available behind the `rdf-star`feature for all languages but N3 ([Turtle-star](https://w3c.github.io/rdf-star/cg-spec/2021-12-17.html#turtle-star), [TriG-star](https://w3c.github.io/rdf-star/cg-spec/2021-12-17.html#trig-star), [N-Triples-star](https://w3c.github.io/rdf-star/cg-spec/2021-12-17.html#n-triples-star) and [N-Quads-star](https://w3c.github.io/rdf-star/cg-spec/2021-12-17.html#n-quads-star)) + +It is designed as a low level parser compatible with both synchronous and asynchronous I/O. + +Usage example counting the number of people in a Turtle file: +```rust +use oxrdf::{NamedNodeRef, vocab::rdf}; +use oxttl::TurtleParser; + +let file = b"@base . +@prefix schema: . + a schema:Person ; + schema:name \"Foo\" . + a schema:Person ; + schema:name \"Bar\" ."; + +let schema_person = NamedNodeRef::new("http://schema.org/Person").unwrap(); +let mut count = 0; +for triple in TurtleParser::new().parse_from_read(file.as_ref()) { + let triple = triple.unwrap(); + if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { + count += 1; + } +} +assert_eq!(2, count); +``` + + +## License + +This project is licensed under either of + +* Apache License, Version 2.0, ([LICENSE-APACHE](../LICENSE-APACHE) or + ``) +* MIT license ([LICENSE-MIT](../LICENSE-MIT) or + ``) + +at your option. + + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Oxigraph by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/lib/oxttl/src/lib.rs b/lib/oxttl/src/lib.rs index e0d1ce90..11bafc29 100644 --- a/lib/oxttl/src/lib.rs +++ b/lib/oxttl/src/lib.rs @@ -1,3 +1,9 @@ +#![doc = include_str!("../README.md")] +#![doc(test(attr(deny(warnings))))] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![doc(html_favicon_url = "https://raw.githubusercontent.com/oxigraph/oxigraph/main/logo.svg")] +#![doc(html_logo_url = "https://raw.githubusercontent.com/oxigraph/oxigraph/main/logo.svg")] + mod lexer; mod line_formats; pub mod n3; diff --git a/lib/oxttl/src/n3.rs b/lib/oxttl/src/n3.rs index 9722e500..3bd7e3d6 100644 --- a/lib/oxttl/src/n3.rs +++ b/lib/oxttl/src/n3.rs @@ -177,8 +177,7 @@ impl From for N3Quad { /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNode; -/// use oxttl::ParseError; +/// use oxrdf::{NamedNode, vocab::rdf}; /// use oxttl::n3::{N3Parser, N3Term}; /// /// let file = b"@base . @@ -188,7 +187,7 @@ impl From for N3Quad { /// a schema:Person ; /// schema:name \"Bar\" ."; /// -/// let rdf_type = N3Term::NamedNode(NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?); +/// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned()); /// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?); /// let mut count = 0; /// for triple in N3Parser::new().parse_from_read(file.as_ref()) { @@ -235,7 +234,6 @@ impl N3Parser { /// Count the number of people: /// ``` /// use oxrdf::NamedNode; - /// use oxttl::ParseError; /// use oxttl::n3::{N3Parser, N3Term}; /// /// let file = b"@base . @@ -267,8 +265,7 @@ impl N3Parser { /// /// Count the number of people: /// ``` - /// use oxrdf::NamedNode; - /// use oxttl::ParseError; + /// use oxrdf::{NamedNode, vocab::rdf}; /// use oxttl::n3::{N3Parser, N3Term}; /// /// let file: [&[u8]; 5] = [b"@base ", @@ -278,7 +275,7 @@ impl N3Parser { /// b" a schema:Person ; schema:name \"Bar\" ." /// ]; /// - /// let rdf_type = N3Term::NamedNode(NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?); + /// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned()); /// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?); /// let mut count = 0; /// let mut parser = N3Parser::new().parse(); @@ -312,8 +309,7 @@ impl N3Parser { /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNode; -/// use oxttl::ParseError; +/// use oxrdf::{NamedNode, vocab::rdf}; /// use oxttl::n3::{N3Parser, N3Term}; /// /// let file = b"@base . @@ -323,7 +319,7 @@ impl N3Parser { /// a schema:Person ; /// schema:name \"Bar\" ."; /// -/// let rdf_type = N3Term::NamedNode(NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?); +/// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned()); /// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?); /// let mut count = 0; /// for triple in N3Parser::new().parse_from_read(file.as_ref()) { @@ -351,8 +347,7 @@ impl Iterator for FromReadN3Reader { /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNode; -/// use oxttl::ParseError; +/// use oxrdf::{NamedNode, vocab::rdf}; /// use oxttl::n3::{N3Parser, N3Term}; /// /// let file: [&[u8]; 5] = [b"@base ", @@ -362,7 +357,7 @@ impl Iterator for FromReadN3Reader { /// b" a schema:Person ; schema:name \"Bar\" ." /// ]; /// -/// let rdf_type = N3Term::NamedNode(NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?); +/// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned()); /// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?); /// let mut count = 0; /// let mut parser = N3Parser::new().parse(); diff --git a/lib/oxttl/src/nquads.rs b/lib/oxttl/src/nquads.rs index c3357a38..ce8c3a2a 100644 --- a/lib/oxttl/src/nquads.rs +++ b/lib/oxttl/src/nquads.rs @@ -11,20 +11,19 @@ use std::io::{self, Read, Write}; /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNodeRef; -/// use oxttl::{NQuadsParser, ParseError}; +/// use oxrdf::{NamedNodeRef, vocab::rdf}; +/// use oxttl::NQuadsParser; /// /// let file = b" . /// \"Foo\" . /// . /// \"Bar\" ."; /// -/// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// for quad in NQuadsParser::new().parse_from_read(file.as_ref()) { /// let quad = quad?; -/// if quad.predicate == rdf_type && quad.object == schema_person.into() { +/// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// count += 1; /// } /// } @@ -57,20 +56,19 @@ impl NQuadsParser { /// /// Count the number of people: /// ``` - /// use oxrdf::NamedNodeRef; - /// use oxttl::{NQuadsParser, ParseError}; + /// use oxrdf::{NamedNodeRef, vocab::rdf}; + /// use oxttl::NQuadsParser; /// /// let file = b" . /// \"Foo\" . /// . /// \"Bar\" ."; /// - /// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// for quad in NQuadsParser::new().parse_from_read(file.as_ref()) { /// let quad = quad?; - /// if quad.predicate == rdf_type && quad.object == schema_person.into() { + /// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// count += 1; /// } /// } @@ -87,8 +85,8 @@ impl NQuadsParser { /// /// Count the number of people: /// ``` - /// use oxrdf::NamedNodeRef; - /// use oxttl::{NQuadsParser, ParseError}; + /// use oxrdf::{NamedNodeRef, vocab::rdf}; + /// use oxttl::NQuadsParser; /// /// let file: [&[u8]; 4] = [ /// b" .\n", @@ -97,7 +95,6 @@ impl NQuadsParser { /// b" \"Bar\" .\n" /// ]; /// - /// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// let mut parser = NQuadsParser::new().parse(); @@ -112,7 +109,7 @@ impl NQuadsParser { /// // We read as many quads from the parser as possible /// while let Some(quad) = parser.read_next() { /// let quad = quad?; - /// if quad.predicate == rdf_type && quad.object == schema_person.into() { + /// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// count += 1; /// } /// } @@ -136,20 +133,19 @@ impl NQuadsParser { /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNodeRef; -/// use oxttl::{NQuadsParser, ParseError}; +/// use oxrdf::{NamedNodeRef, vocab::rdf}; +/// use oxttl::NQuadsParser; /// /// let file = b" . /// \"Foo\" . /// . /// \"Bar\" ."; /// -/// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// for quad in NQuadsParser::new().parse_from_read(file.as_ref()) { /// let quad = quad?; -/// if quad.predicate == rdf_type && quad.object == schema_person.into() { +/// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// count += 1; /// } /// } @@ -172,8 +168,8 @@ impl Iterator for FromReadNQuadsReader { /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNodeRef; -/// use oxttl::{NQuadsParser, ParseError}; +/// use oxrdf::{NamedNodeRef, vocab::rdf}; +/// use oxttl::NQuadsParser; /// /// let file: [&[u8]; 4] = [ /// b" .\n", @@ -182,7 +178,6 @@ impl Iterator for FromReadNQuadsReader { /// b" \"Bar\" .\n" /// ]; /// -/// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// let mut parser = NQuadsParser::new().parse(); @@ -197,7 +192,7 @@ impl Iterator for FromReadNQuadsReader { /// // We read as many quads from the parser as possible /// while let Some(quad) = parser.read_next() { /// let quad = quad?; -/// if quad.predicate == rdf_type && quad.object == schema_person.into() { +/// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// count += 1; /// } /// } @@ -244,8 +239,7 @@ impl LowLevelNQuadsReader { /// use oxrdf::{NamedNodeRef, QuadRef}; /// use oxttl::NQuadsSerializer; /// -/// let mut buf = Vec::new(); -/// let mut writer = NQuadsSerializer::new().serialize_to_write(buf); +/// let mut writer = NQuadsSerializer::new().serialize_to_write(Vec::new()); /// writer.write_quad(QuadRef::new( /// NamedNodeRef::new("http://example.com#me")?, /// NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?, @@ -274,8 +268,7 @@ impl NQuadsSerializer { /// use oxrdf::{NamedNodeRef, QuadRef}; /// use oxttl::NQuadsSerializer; /// - /// let mut buf = Vec::new(); - /// let mut writer = NQuadsSerializer::new().serialize_to_write(buf); + /// let mut writer = NQuadsSerializer::new().serialize_to_write(Vec::new()); /// writer.write_quad(QuadRef::new( /// NamedNodeRef::new("http://example.com#me")?, /// NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?, @@ -327,8 +320,7 @@ impl NQuadsSerializer { /// use oxrdf::{NamedNodeRef, QuadRef}; /// use oxttl::NQuadsSerializer; /// -/// let mut buf = Vec::new(); -/// let mut writer = NQuadsSerializer::new().serialize_to_write(buf); +/// let mut writer = NQuadsSerializer::new().serialize_to_write(Vec::new()); /// writer.write_quad(QuadRef::new( /// NamedNodeRef::new("http://example.com#me")?, /// NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?, diff --git a/lib/oxttl/src/ntriples.rs b/lib/oxttl/src/ntriples.rs index fb6692fc..daaa2d5c 100644 --- a/lib/oxttl/src/ntriples.rs +++ b/lib/oxttl/src/ntriples.rs @@ -12,20 +12,19 @@ use std::io::{self, Read, Write}; /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNodeRef; -/// use oxttl::{NTriplesParser, ParseError}; +/// use oxrdf::{NamedNodeRef, vocab::rdf}; +/// use oxttl::NTriplesParser; /// /// let file = b" . /// \"Foo\" . /// . /// \"Bar\" ."; /// -/// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// for triple in NTriplesParser::new().parse_from_read(file.as_ref()) { /// let triple = triple?; -/// if triple.predicate == rdf_type && triple.object == schema_person.into() { +/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// count += 1; /// } /// } @@ -58,20 +57,19 @@ impl NTriplesParser { /// /// Count the number of people: /// ``` - /// use oxrdf::NamedNodeRef; - /// use oxttl::{NTriplesParser, ParseError}; + /// use oxrdf::{NamedNodeRef, vocab::rdf}; + /// use oxttl::NTriplesParser; /// /// let file = b" . /// \"Foo\" . /// . /// \"Bar\" ."; /// - /// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// for triple in NTriplesParser::new().parse_from_read(file.as_ref()) { /// let triple = triple?; - /// if triple.predicate == rdf_type && triple.object == schema_person.into() { + /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// count += 1; /// } /// } @@ -88,8 +86,8 @@ impl NTriplesParser { /// /// Count the number of people: /// ``` - /// use oxrdf::NamedNodeRef; - /// use oxttl::{NTriplesParser, ParseError}; + /// use oxrdf::{NamedNodeRef, vocab::rdf}; + /// use oxttl::NTriplesParser; /// /// let file: [&[u8]; 4] = [ /// b" .\n", @@ -98,7 +96,6 @@ impl NTriplesParser { /// b" \"Bar\" .\n" /// ]; /// - /// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// let mut parser = NTriplesParser::new().parse(); @@ -113,7 +110,7 @@ impl NTriplesParser { /// // We read as many triples from the parser as possible /// while let Some(triple) = parser.read_next() { /// let triple = triple?; - /// if triple.predicate == rdf_type && triple.object == schema_person.into() { + /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// count += 1; /// } /// } @@ -137,20 +134,19 @@ impl NTriplesParser { /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNodeRef; -/// use oxttl::{NTriplesParser, ParseError}; +/// use oxrdf::{NamedNodeRef, vocab::rdf}; +/// use oxttl::NTriplesParser; /// /// let file = b" . /// \"Foo\" . /// . /// \"Bar\" ."; /// -/// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// for triple in NTriplesParser::new().parse_from_read(file.as_ref()) { /// let triple = triple?; -/// if triple.predicate == rdf_type && triple.object == schema_person.into() { +/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// count += 1; /// } /// } @@ -173,8 +169,8 @@ impl Iterator for FromReadNTriplesReader { /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNodeRef; -/// use oxttl::{NTriplesParser, ParseError}; +/// use oxrdf::{NamedNodeRef, vocab::rdf}; +/// use oxttl::NTriplesParser; /// /// let file: [&[u8]; 4] = [ /// b" .\n", @@ -183,7 +179,6 @@ impl Iterator for FromReadNTriplesReader { /// b" \"Bar\" .\n" /// ]; /// -/// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// let mut parser = NTriplesParser::new().parse(); @@ -198,7 +193,7 @@ impl Iterator for FromReadNTriplesReader { /// // We read as many triples from the parser as possible /// while let Some(triple) = parser.read_next() { /// let triple = triple?; -/// if triple.predicate == rdf_type && triple.object == schema_person.into() { +/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// count += 1; /// } /// } @@ -245,8 +240,7 @@ impl LowLevelNTriplesReader { /// use oxrdf::{NamedNodeRef, TripleRef}; /// use oxttl::NTriplesSerializer; /// -/// let mut buf = Vec::new(); -/// let mut writer = NTriplesSerializer::new().serialize_to_write(buf); +/// let mut writer = NTriplesSerializer::new().serialize_to_write(Vec::new()); /// writer.write_triple(TripleRef::new( /// NamedNodeRef::new("http://example.com#me")?, /// NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?, @@ -274,8 +268,7 @@ impl NTriplesSerializer { /// use oxrdf::{NamedNodeRef, TripleRef}; /// use oxttl::NTriplesSerializer; /// - /// let mut buf = Vec::new(); - /// let mut writer = NTriplesSerializer::new().serialize_to_write(buf); + /// let mut writer = NTriplesSerializer::new().serialize_to_write(Vec::new()); /// writer.write_triple(TripleRef::new( /// NamedNodeRef::new("http://example.com#me")?, /// NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?, @@ -325,8 +318,7 @@ impl NTriplesSerializer { /// use oxrdf::{NamedNodeRef, TripleRef}; /// use oxttl::NTriplesSerializer; /// -/// let mut buf = Vec::new(); -/// let mut writer = NTriplesSerializer::new().serialize_to_write(buf); +/// let mut writer = NTriplesSerializer::new().serialize_to_write(Vec::new()); /// writer.write_triple(TripleRef::new( /// NamedNodeRef::new("http://example.com#me")?, /// NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?, diff --git a/lib/oxttl/src/trig.rs b/lib/oxttl/src/trig.rs index 692d6543..2702ef98 100644 --- a/lib/oxttl/src/trig.rs +++ b/lib/oxttl/src/trig.rs @@ -14,8 +14,8 @@ use std::io::{self, Read, Write}; /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNodeRef; -/// use oxttl::{TriGParser, ParseError}; +/// use oxrdf::{NamedNodeRef, vocab::rdf}; +/// use oxttl::TriGParser; /// /// let file = b"@base . /// @prefix schema: . @@ -24,12 +24,11 @@ use std::io::{self, Read, Write}; /// a schema:Person ; /// schema:name \"Bar\" ."; /// -/// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// for quad in TriGParser::new().parse_from_read(file.as_ref()) { /// let quad = quad?; -/// if quad.predicate == rdf_type && quad.object == schema_person.into() { +/// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// count += 1; /// } /// } @@ -81,8 +80,8 @@ impl TriGParser { /// /// Count the number of people: /// ``` - /// use oxrdf::NamedNodeRef; - /// use oxttl::{TriGParser, ParseError}; + /// use oxrdf::{NamedNodeRef, vocab::rdf}; + /// use oxttl::TriGParser; /// /// let file = b"@base . /// @prefix schema: . @@ -91,12 +90,11 @@ impl TriGParser { /// a schema:Person ; /// schema:name \"Bar\" ."; /// - /// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// for quad in TriGParser::new().parse_from_read(file.as_ref()) { /// let quad = quad?; - /// if quad.predicate == rdf_type && quad.object == schema_person.into() { + /// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// count += 1; /// } /// } @@ -113,8 +111,8 @@ impl TriGParser { /// /// Count the number of people: /// ``` - /// use oxrdf::NamedNodeRef; - /// use oxttl::{TriGParser, ParseError}; + /// use oxrdf::{NamedNodeRef, vocab::rdf}; + /// use oxttl::TriGParser; /// /// let file: [&[u8]; 5] = [b"@base ", /// b". @prefix schema: .", @@ -123,7 +121,6 @@ impl TriGParser { /// b" a schema:Person ; schema:name \"Bar\" ." /// ]; /// - /// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// let mut parser = TriGParser::new().parse(); @@ -138,7 +135,7 @@ impl TriGParser { /// // We read as many quads from the parser as possible /// while let Some(quad) = parser.read_next() { /// let quad = quad?; - /// if quad.predicate == rdf_type && quad.object == schema_person.into() { + /// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// count += 1; /// } /// } @@ -163,8 +160,8 @@ impl TriGParser { /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNodeRef; -/// use oxttl::{TriGParser, ParseError}; +/// use oxrdf::{NamedNodeRef, vocab::rdf}; +/// use oxttl::TriGParser; /// /// let file = b"@base . /// @prefix schema: . @@ -173,12 +170,11 @@ impl TriGParser { /// a schema:Person ; /// schema:name \"Bar\" ."; /// -/// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// for quad in TriGParser::new().parse_from_read(file.as_ref()) { /// let quad = quad?; -/// if quad.predicate == rdf_type && quad.object == schema_person.into() { +/// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// count += 1; /// } /// } @@ -201,8 +197,8 @@ impl Iterator for FromReadTriGReader { /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNodeRef; -/// use oxttl::{TriGParser, ParseError}; +/// use oxrdf::{NamedNodeRef, vocab::rdf}; +/// use oxttl::TriGParser; /// /// let file: [&[u8]; 5] = [b"@base ", /// b". @prefix schema: .", @@ -211,7 +207,6 @@ impl Iterator for FromReadTriGReader { /// b" a schema:Person ; schema:name \"Bar\" ." /// ]; /// -/// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// let mut parser = TriGParser::new().parse(); @@ -226,7 +221,7 @@ impl Iterator for FromReadTriGReader { /// // We read as many quads from the parser as possible /// while let Some(quad) = parser.read_next() { /// let quad = quad?; -/// if quad.predicate == rdf_type && quad.object == schema_person.into() { +/// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// count += 1; /// } /// } @@ -273,8 +268,7 @@ impl LowLevelTriGReader { /// use oxrdf::{NamedNodeRef, QuadRef}; /// use oxttl::TriGSerializer; /// -/// let mut buf = Vec::new(); -/// let mut writer = TriGSerializer::new().serialize_to_write(buf); +/// let mut writer = TriGSerializer::new().serialize_to_write(Vec::new()); /// writer.write_quad(QuadRef::new( /// NamedNodeRef::new("http://example.com#me")?, /// NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?, @@ -303,8 +297,7 @@ impl TriGSerializer { /// use oxrdf::{NamedNodeRef, QuadRef}; /// use oxttl::TriGSerializer; /// - /// let mut buf = Vec::new(); - /// let mut writer = TriGSerializer::new().serialize_to_write(buf); + /// let mut writer = TriGSerializer::new().serialize_to_write(Vec::new()); /// writer.write_quad(QuadRef::new( /// NamedNodeRef::new("http://example.com#me")?, /// NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?, @@ -360,8 +353,7 @@ impl TriGSerializer { /// use oxrdf::{NamedNodeRef, QuadRef}; /// use oxttl::TriGSerializer; /// -/// let mut buf = Vec::new(); -/// let mut writer = TriGSerializer::new().serialize_to_write(buf); +/// let mut writer = TriGSerializer::new().serialize_to_write(Vec::new()); /// writer.write_quad(QuadRef::new( /// NamedNodeRef::new("http://example.com#me")?, /// NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?, diff --git a/lib/oxttl/src/turtle.rs b/lib/oxttl/src/turtle.rs index 275cec28..65967613 100644 --- a/lib/oxttl/src/turtle.rs +++ b/lib/oxttl/src/turtle.rs @@ -15,8 +15,8 @@ use std::io::{self, Read, Write}; /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNodeRef; -/// use oxttl::{TurtleParser, ParseError}; +/// use oxrdf::{NamedNodeRef, vocab::rdf}; +/// use oxttl::TurtleParser; /// /// let file = b"@base . /// @prefix schema: . @@ -25,12 +25,11 @@ use std::io::{self, Read, Write}; /// a schema:Person ; /// schema:name \"Bar\" ."; /// -/// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// for triple in TurtleParser::new().parse_from_read(file.as_ref()) { /// let triple = triple?; -/// if triple.predicate == rdf_type && triple.object == schema_person.into() { +/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// count += 1; /// } /// } @@ -82,8 +81,8 @@ impl TurtleParser { /// /// Count the number of people: /// ``` - /// use oxrdf::NamedNodeRef; - /// use oxttl::{TurtleParser, ParseError}; + /// use oxrdf::{NamedNodeRef, vocab::rdf}; + /// use oxttl::TurtleParser; /// /// let file = b"@base . /// @prefix schema: . @@ -92,12 +91,11 @@ impl TurtleParser { /// a schema:Person ; /// schema:name \"Bar\" ."; /// - /// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// for triple in TurtleParser::new().parse_from_read(file.as_ref()) { /// let triple = triple?; - /// if triple.predicate == rdf_type && triple.object == schema_person.into() { + /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// count += 1; /// } /// } @@ -114,8 +112,8 @@ impl TurtleParser { /// /// Count the number of people: /// ``` - /// use oxrdf::NamedNodeRef; - /// use oxttl::{TurtleParser, ParseError}; + /// use oxrdf::{NamedNodeRef, vocab::rdf}; + /// use oxttl::TurtleParser; /// /// let file: [&[u8]; 5] = [b"@base ", /// b". @prefix schema: .", @@ -124,7 +122,6 @@ impl TurtleParser { /// b" a schema:Person ; schema:name \"Bar\" ." /// ]; /// - /// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// let mut parser = TurtleParser::new().parse(); @@ -139,7 +136,7 @@ impl TurtleParser { /// // We read as many triples from the parser as possible /// while let Some(triple) = parser.read_next() { /// let triple = triple?; - /// if triple.predicate == rdf_type && triple.object == schema_person.into() { + /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// count += 1; /// } /// } @@ -164,8 +161,8 @@ impl TurtleParser { /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNodeRef; -/// use oxttl::{TurtleParser, ParseError}; +/// use oxrdf::{NamedNodeRef, vocab::rdf}; +/// use oxttl::TurtleParser; /// /// let file = b"@base . /// @prefix schema: . @@ -174,12 +171,11 @@ impl TurtleParser { /// a schema:Person ; /// schema:name \"Bar\" ."; /// -/// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// for triple in TurtleParser::new().parse_from_read(file.as_ref()) { /// let triple = triple?; -/// if triple.predicate == rdf_type && triple.object == schema_person.into() { +/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// count += 1; /// } /// } @@ -202,8 +198,8 @@ impl Iterator for FromReadTurtleReader { /// /// Count the number of people: /// ``` -/// use oxrdf::NamedNodeRef; -/// use oxttl::{TurtleParser, ParseError}; +/// use oxrdf::{NamedNodeRef, vocab::rdf}; +/// use oxttl::TurtleParser; /// /// let file: [&[u8]; 5] = [b"@base ", /// b". @prefix schema: .", @@ -212,7 +208,6 @@ impl Iterator for FromReadTurtleReader { /// b" a schema:Person ; schema:name \"Bar\" ." /// ]; /// -/// let rdf_type = NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let mut count = 0; /// let mut parser = TurtleParser::new().parse(); @@ -227,7 +222,7 @@ impl Iterator for FromReadTurtleReader { /// // We read as many triples from the parser as possible /// while let Some(triple) = parser.read_next() { /// let triple = triple?; -/// if triple.predicate == rdf_type && triple.object == schema_person.into() { +/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// count += 1; /// } /// } @@ -274,8 +269,7 @@ impl LowLevelTurtleReader { /// use oxrdf::{NamedNodeRef, TripleRef}; /// use oxttl::TurtleSerializer; /// -/// let mut buf = Vec::new(); -/// let mut writer = TurtleSerializer::new().serialize_to_write(buf); +/// let mut writer = TurtleSerializer::new().serialize_to_write(Vec::new()); /// writer.write_triple(TripleRef::new( /// NamedNodeRef::new("http://example.com#me")?, /// NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?, @@ -305,8 +299,7 @@ impl TurtleSerializer { /// use oxrdf::{NamedNodeRef, TripleRef}; /// use oxttl::TurtleSerializer; /// - /// let mut buf = Vec::new(); - /// let mut writer = TurtleSerializer::new().serialize_to_write(buf); + /// let mut writer = TurtleSerializer::new().serialize_to_write(Vec::new()); /// writer.write_triple(TripleRef::new( /// NamedNodeRef::new("http://example.com#me")?, /// NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?, @@ -357,8 +350,7 @@ impl TurtleSerializer { /// use oxrdf::{NamedNodeRef, TripleRef}; /// use oxttl::TurtleSerializer; /// -/// let mut buf = Vec::new(); -/// let mut writer = TurtleSerializer::new().serialize_to_write(buf); +/// let mut writer = TurtleSerializer::new().serialize_to_write(Vec::new()); /// writer.write_triple(TripleRef::new( /// NamedNodeRef::new("http://example.com#me")?, /// NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?,