Renames *Syntax into *Format

It is a simpler word that matches more the current usages
pull/46/head
Tpt 4 years ago
parent 7f418fffc3
commit 5640b0a32d
  1. 11
      js/src/store.rs
  2. 110
      lib/src/io/format.rs
  3. 10
      lib/src/io/mod.rs
  4. 63
      lib/src/io/read.rs
  5. 55
      lib/src/io/write.rs
  6. 8
      lib/src/lib.rs
  7. 4
      lib/src/sparql/mod.rs
  8. 83
      lib/src/sparql/model.rs
  9. 61
      lib/src/store/memory.rs
  10. 38
      lib/src/store/mod.rs
  11. 22
      lib/src/store/rocksdb.rs
  12. 26
      lib/src/store/sled.rs
  13. 11
      python/src/memory_store.rs
  14. 11
      python/src/sled_store.rs
  15. 23
      server/src/main.rs
  16. 13
      testsuite/src/files.rs
  17. 4
      testsuite/src/sparql_evaluator.rs
  18. 5
      wikibase/src/loader.rs
  19. 19
      wikibase/src/main.rs

@ -2,9 +2,10 @@ use crate::format_err;
use crate::model::*; use crate::model::*;
use crate::utils::to_err; use crate::utils::to_err;
use js_sys::{Array, Map}; use js_sys::{Array, Map};
use oxigraph::io::{DatasetFormat, GraphFormat};
use oxigraph::model::GraphName; use oxigraph::model::GraphName;
use oxigraph::sparql::{QueryOptions, QueryResult}; use oxigraph::sparql::{QueryOptions, QueryResult};
use oxigraph::{DatasetSyntax, GraphSyntax, MemoryStore}; use oxigraph::MemoryStore;
use std::convert::TryInto; use std::convert::TryInto;
use std::io::Cursor; use std::io::Cursor;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
@ -157,23 +158,23 @@ impl JsMemoryStore {
None None
}; };
if let Some(graph_syntax) = GraphSyntax::from_media_type(mime_type) { if let Some(graph_format) = GraphFormat::from_media_type(mime_type) {
self.store self.store
.load_graph( .load_graph(
Cursor::new(data), Cursor::new(data),
graph_syntax, graph_format,
&to_graph_name.unwrap_or(GraphName::DefaultGraph), &to_graph_name.unwrap_or(GraphName::DefaultGraph),
base_iri.as_deref(), base_iri.as_deref(),
) )
.map_err(to_err) .map_err(to_err)
} else if let Some(dataset_syntax) = DatasetSyntax::from_media_type(mime_type) { } else if let Some(dataset_format) = DatasetFormat::from_media_type(mime_type) {
if to_graph_name.is_some() { if to_graph_name.is_some() {
return Err(format_err!( return Err(format_err!(
"The target graph name parameter is not available for dataset formats" "The target graph name parameter is not available for dataset formats"
)); ));
} }
self.store self.store
.load_dataset(Cursor::new(data), dataset_syntax, base_iri.as_deref()) .load_dataset(Cursor::new(data), dataset_format, base_iri.as_deref())
.map_err(to_err) .map_err(to_err)
} else { } else {
Err(format_err!("Not supported MIME type: {}", mime_type)) Err(format_err!("Not supported MIME type: {}", mime_type))

@ -1,6 +1,6 @@
/// A file serialization format. /// A file serialization format.
/// ///
/// Is implemented by `GraphSyntax` for graph files and `DatasetSyntax` for dataset files. /// Is implemented by `GraphFormat` for graph files and `DatasetFormat` for dataset files.
#[deprecated(note = "Use directly the methods on the implementing types")] #[deprecated(note = "Use directly the methods on the implementing types")]
pub trait FileSyntax: Sized { pub trait FileSyntax: Sized {
/// Its canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/). /// Its canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
@ -12,16 +12,16 @@ pub trait FileSyntax: Sized {
/// Its [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension. /// Its [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension.
fn file_extension(self) -> &'static str; fn file_extension(self) -> &'static str;
/// Looks for a known syntax from a media type. /// Looks for a known format from a media type.
fn from_mime_type(media_type: &str) -> Option<Self>; fn from_mime_type(media_type: &str) -> Option<Self>;
} }
/// [RDF graph](https://www.w3.org/TR/rdf11-concepts/#dfn-graph) serialization formats. /// [RDF graph](https://www.w3.org/TR/rdf11-concepts/#dfn-graph) serialization formats.
/// ///
/// This enumeration is non exhaustive. New syntaxes like JSON-LD will be added in the future. /// This enumeration is non exhaustive. New formats like JSON-LD will be added in the future.
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum GraphSyntax { pub enum GraphFormat {
/// [N-Triples](https://www.w3.org/TR/n-triples/) /// [N-Triples](https://www.w3.org/TR/n-triples/)
NTriples, NTriples,
/// [Turtle](https://www.w3.org/TR/turtle/) /// [Turtle](https://www.w3.org/TR/turtle/)
@ -30,70 +30,70 @@ pub enum GraphSyntax {
RdfXml, RdfXml,
} }
impl GraphSyntax { impl GraphFormat {
/// The syntax canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/). /// The format canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
/// ///
/// ``` /// ```
/// use oxigraph::io::GraphSyntax; /// use oxigraph::io::GraphFormat;
/// ///
/// assert_eq!(GraphSyntax::NTriples.iri(), "http://www.w3.org/ns/formats/N-Triples") /// assert_eq!(GraphFormat::NTriples.iri(), "http://www.w3.org/ns/formats/N-Triples")
/// ``` /// ```
pub fn iri(self) -> &'static str { pub fn iri(self) -> &'static str {
match self { match self {
GraphSyntax::NTriples => "http://www.w3.org/ns/formats/N-Triples", GraphFormat::NTriples => "http://www.w3.org/ns/formats/N-Triples",
GraphSyntax::Turtle => "http://www.w3.org/ns/formats/Turtle", GraphFormat::Turtle => "http://www.w3.org/ns/formats/Turtle",
GraphSyntax::RdfXml => "http://www.w3.org/ns/formats/RDF_XML", GraphFormat::RdfXml => "http://www.w3.org/ns/formats/RDF_XML",
} }
} }
/// The syntax [IANA media type](https://tools.ietf.org/html/rfc2046). /// The format [IANA media type](https://tools.ietf.org/html/rfc2046).
/// ///
/// ``` /// ```
/// use oxigraph::io::GraphSyntax; /// use oxigraph::io::GraphFormat;
/// ///
/// assert_eq!(GraphSyntax::NTriples.media_type(), "application/n-triples") /// assert_eq!(GraphFormat::NTriples.media_type(), "application/n-triples")
/// ``` /// ```
pub fn media_type(self) -> &'static str { pub fn media_type(self) -> &'static str {
match self { match self {
GraphSyntax::NTriples => "application/n-triples", GraphFormat::NTriples => "application/n-triples",
GraphSyntax::Turtle => "text/turtle", GraphFormat::Turtle => "text/turtle",
GraphSyntax::RdfXml => "application/rdf+xml", GraphFormat::RdfXml => "application/rdf+xml",
} }
} }
/// The syntax [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension. /// The format [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension.
/// ///
/// ``` /// ```
/// use oxigraph::io::GraphSyntax; /// use oxigraph::io::GraphFormat;
/// ///
/// assert_eq!(GraphSyntax::NTriples.file_extension(), "nt") /// assert_eq!(GraphFormat::NTriples.file_extension(), "nt")
/// ``` /// ```
pub fn file_extension(self) -> &'static str { pub fn file_extension(self) -> &'static str {
match self { match self {
GraphSyntax::NTriples => "nt", GraphFormat::NTriples => "nt",
GraphSyntax::Turtle => "ttl", GraphFormat::Turtle => "ttl",
GraphSyntax::RdfXml => "rdf", GraphFormat::RdfXml => "rdf",
} }
} }
/// Looks for a known syntax from a media type. /// Looks for a known format from a media type.
/// ///
/// It supports some media type aliases. /// It supports some media type aliases.
/// For example "application/xml" is going to return `GraphSyntax::RdfXml` even if it is not its canonical media type. /// For example "application/xml" is going to return `GraphFormat::RdfXml` even if it is not its canonical media type.
/// ///
/// Example: /// Example:
/// ``` /// ```
/// use oxigraph::io::GraphSyntax; /// use oxigraph::io::GraphFormat;
/// ///
/// assert_eq!(GraphSyntax::from_media_type("text/turtle; charset=utf-8"), Some(GraphSyntax::Turtle)) /// assert_eq!(GraphFormat::from_media_type("text/turtle; charset=utf-8"), Some(GraphFormat::Turtle))
/// ``` /// ```
pub fn from_media_type(media_type: &str) -> Option<Self> { pub fn from_media_type(media_type: &str) -> Option<Self> {
if let Some(base_type) = media_type.split(';').next() { if let Some(base_type) = media_type.split(';').next() {
match base_type.trim() { match base_type.trim() {
"application/n-triples" | "text/plain" => Some(GraphSyntax::NTriples), "application/n-triples" | "text/plain" => Some(GraphFormat::NTriples),
"text/turtle" | "application/turtle" | "application/x-turtle" => { "text/turtle" | "application/turtle" | "application/x-turtle" => {
Some(GraphSyntax::Turtle) Some(GraphFormat::Turtle)
} }
"application/rdf+xml" | "application/xml" | "text/xml" => Some(GraphSyntax::RdfXml), "application/rdf+xml" | "application/xml" | "text/xml" => Some(GraphFormat::RdfXml),
_ => None, _ => None,
} }
} else { } else {
@ -103,7 +103,7 @@ impl GraphSyntax {
} }
#[allow(deprecated)] #[allow(deprecated)]
impl FileSyntax for GraphSyntax { impl FileSyntax for GraphFormat {
fn iri(self) -> &'static str { fn iri(self) -> &'static str {
self.iri() self.iri()
} }
@ -123,75 +123,75 @@ impl FileSyntax for GraphSyntax {
/// [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) serialization formats. /// [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) serialization formats.
/// ///
/// This enumeration is non exhaustive. New syntaxes like JSON-LD will be added in the future. /// This enumeration is non exhaustive. New formats like JSON-LD will be added in the future.
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum DatasetSyntax { pub enum DatasetFormat {
/// [N-Quads](https://www.w3.org/TR/n-quads/) /// [N-Quads](https://www.w3.org/TR/n-quads/)
NQuads, NQuads,
/// [TriG](https://www.w3.org/TR/trig/) /// [TriG](https://www.w3.org/TR/trig/)
TriG, TriG,
} }
impl DatasetSyntax { impl DatasetFormat {
/// The syntax canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/). /// The format canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
/// ///
/// ``` /// ```
/// use oxigraph::io::DatasetSyntax; /// use oxigraph::io::DatasetFormat;
/// ///
/// assert_eq!(DatasetSyntax::NQuads.iri(), "http://www.w3.org/ns/formats/N-Quads") /// assert_eq!(DatasetFormat::NQuads.iri(), "http://www.w3.org/ns/formats/N-Quads")
/// ``` /// ```
pub fn iri(self) -> &'static str { pub fn iri(self) -> &'static str {
match self { match self {
DatasetSyntax::NQuads => "http://www.w3.org/ns/formats/N-Quads", DatasetFormat::NQuads => "http://www.w3.org/ns/formats/N-Quads",
DatasetSyntax::TriG => "http://www.w3.org/ns/formats/TriG", DatasetFormat::TriG => "http://www.w3.org/ns/formats/TriG",
} }
} }
/// The syntax [IANA media type](https://tools.ietf.org/html/rfc2046). /// The format [IANA media type](https://tools.ietf.org/html/rfc2046).
/// ///
/// ``` /// ```
/// use oxigraph::io::DatasetSyntax; /// use oxigraph::io::DatasetFormat;
/// ///
/// assert_eq!(DatasetSyntax::NQuads.media_type(), "application/n-quads") /// assert_eq!(DatasetFormat::NQuads.media_type(), "application/n-quads")
/// ``` /// ```
pub fn media_type(self) -> &'static str { pub fn media_type(self) -> &'static str {
match self { match self {
DatasetSyntax::NQuads => "application/n-quads", DatasetFormat::NQuads => "application/n-quads",
DatasetSyntax::TriG => "application/trig", DatasetFormat::TriG => "application/trig",
} }
} }
/// The syntax [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension. /// The format [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension.
/// ///
/// ``` /// ```
/// use oxigraph::io::DatasetSyntax; /// use oxigraph::io::DatasetFormat;
/// ///
/// assert_eq!(DatasetSyntax::NQuads.file_extension(), "nq") /// assert_eq!(DatasetFormat::NQuads.file_extension(), "nq")
/// ``` /// ```
pub fn file_extension(self) -> &'static str { pub fn file_extension(self) -> &'static str {
match self { match self {
DatasetSyntax::NQuads => "nq", DatasetFormat::NQuads => "nq",
DatasetSyntax::TriG => "trig", DatasetFormat::TriG => "trig",
} }
} }
/// Looks for a known syntax from a media type. /// Looks for a known format from a media type.
/// ///
/// It supports some media type aliases. /// It supports some media type aliases.
/// ///
/// Example: /// Example:
/// ``` /// ```
/// use oxigraph::io::DatasetSyntax; /// use oxigraph::io::DatasetFormat;
/// ///
/// assert_eq!(DatasetSyntax::from_media_type("application/n-quads; charset=utf-8"), Some(DatasetSyntax::NQuads)) /// assert_eq!(DatasetFormat::from_media_type("application/n-quads; charset=utf-8"), Some(DatasetFormat::NQuads))
/// ``` /// ```
pub fn from_media_type(media_type: &str) -> Option<Self> { pub fn from_media_type(media_type: &str) -> Option<Self> {
if let Some(base_type) = media_type.split(';').next() { if let Some(base_type) = media_type.split(';').next() {
match base_type.trim() { match base_type.trim() {
"application/n-quads" | "text/x-nquads" | "text/nquads" => { "application/n-quads" | "text/x-nquads" | "text/nquads" => {
Some(DatasetSyntax::NQuads) Some(DatasetFormat::NQuads)
} }
"application/trig" | "application/x-trig" => Some(DatasetSyntax::TriG), "application/trig" | "application/x-trig" => Some(DatasetFormat::TriG),
_ => None, _ => None,
} }
} else { } else {
@ -201,7 +201,7 @@ impl DatasetSyntax {
} }
#[allow(deprecated)] #[allow(deprecated)]
impl FileSyntax for DatasetSyntax { impl FileSyntax for DatasetFormat {
fn iri(self) -> &'static str { fn iri(self) -> &'static str {
self.iri() self.iri()
} }

@ -1,14 +1,14 @@
//! Utilities to read and write RDF graphs and datasets //! Utilities to read and write RDF graphs and datasets
mod format;
pub mod read; pub mod read;
mod syntax;
pub mod write; pub mod write;
pub use self::format::DatasetFormat;
#[allow(deprecated)]
pub use self::format::FileSyntax;
pub use self::format::GraphFormat;
pub use self::read::DatasetParser; pub use self::read::DatasetParser;
pub use self::read::GraphParser; pub use self::read::GraphParser;
pub use self::syntax::DatasetSyntax;
#[allow(deprecated)]
pub use self::syntax::FileSyntax;
pub use self::syntax::GraphSyntax;
pub use self::write::DatasetSerializer; pub use self::write::DatasetSerializer;
pub use self::write::GraphSerializer; pub use self::write::GraphSerializer;

@ -1,8 +1,7 @@
//! Utilities to read RDF graphs and datasets //! Utilities to read RDF graphs and datasets
use super::GraphSyntax; use crate::io::{DatasetFormat, GraphFormat};
use crate::model::*; use crate::model::*;
use crate::DatasetSyntax;
use oxiri::{Iri, IriParseError}; use oxiri::{Iri, IriParseError};
use rio_api::model as rio; use rio_api::model as rio;
use rio_api::parser::{QuadsParser, TriplesParser}; use rio_api::parser::{QuadsParser, TriplesParser};
@ -16,17 +15,17 @@ use std::io::BufRead;
/// A reader for RDF graph serialization formats. /// A reader for RDF graph serialization formats.
/// ///
/// It currently supports the following formats: /// It currently supports the following formats:
/// * [N-Triples](https://www.w3.org/TR/n-triples/) (`GraphSyntax::NTriples`) /// * [N-Triples](https://www.w3.org/TR/n-triples/) (`GraphFormat::NTriples`)
/// * [Turtle](https://www.w3.org/TR/turtle/) (`GraphSyntax::Turtle`) /// * [Turtle](https://www.w3.org/TR/turtle/) (`GraphFormat::Turtle`)
/// * [RDF XML](https://www.w3.org/TR/rdf-syntax-grammar/) (`GraphSyntax::RdfXml`) /// * [RDF XML](https://www.w3.org/TR/rdf-syntax-grammar/) (`GraphFormat::RdfXml`)
/// ///
/// ``` /// ```
/// use oxigraph::io::{GraphSyntax, GraphParser}; /// use oxigraph::io::{GraphFormat, GraphParser};
/// use std::io::Cursor; /// use std::io::Cursor;
/// ///
/// let file = "<http://example.com/s> <http://example.com/p> <http://example.com/o> ."; /// let file = "<http://example.com/s> <http://example.com/p> <http://example.com/o> .";
/// ///
/// let parser = GraphParser::from_syntax(GraphSyntax::NTriples); /// let parser = GraphParser::from_format(GraphFormat::NTriples);
/// let triples = parser.read_triples(Cursor::new(file))?.collect::<Result<Vec<_>,_>>()?; /// let triples = parser.read_triples(Cursor::new(file))?.collect::<Result<Vec<_>,_>>()?;
/// ///
///assert_eq!(triples.len(), 1); ///assert_eq!(triples.len(), 1);
@ -34,14 +33,14 @@ use std::io::BufRead;
/// # std::io::Result::Ok(()) /// # std::io::Result::Ok(())
/// ``` /// ```
pub struct GraphParser { pub struct GraphParser {
syntax: GraphSyntax, format: GraphFormat,
base_iri: String, base_iri: String,
} }
impl GraphParser { impl GraphParser {
pub fn from_syntax(syntax: GraphSyntax) -> Self { pub fn from_format(format: GraphFormat) -> Self {
Self { Self {
syntax, format,
base_iri: String::new(), base_iri: String::new(),
} }
} }
@ -49,12 +48,12 @@ impl GraphParser {
/// Provides an IRI that could be used to resolve the file relative IRIs /// Provides an IRI that could be used to resolve the file relative IRIs
/// ///
/// ``` /// ```
/// use oxigraph::io::{GraphSyntax, GraphParser}; /// use oxigraph::io::{GraphFormat, GraphParser};
/// use std::io::Cursor; /// use std::io::Cursor;
/// ///
/// let file = "</s> </p> </o> ."; /// let file = "</s> </p> </o> .";
/// ///
/// let parser = GraphParser::from_syntax(GraphSyntax::Turtle).with_base_iri("http://example.com")?; /// let parser = GraphParser::from_format(GraphFormat::Turtle).with_base_iri("http://example.com")?;
/// let triples = parser.read_triples(Cursor::new(file))?.collect::<Result<Vec<_>,_>>()?; /// let triples = parser.read_triples(Cursor::new(file))?.collect::<Result<Vec<_>,_>>()?;
/// ///
///assert_eq!(triples.len(), 1); ///assert_eq!(triples.len(), 1);
@ -71,14 +70,14 @@ impl GraphParser {
//TODO: drop the error when possible //TODO: drop the error when possible
Ok(TripleReader { Ok(TripleReader {
mapper: RioMapper::default(), mapper: RioMapper::default(),
parser: match self.syntax { parser: match self.format {
GraphSyntax::NTriples => { GraphFormat::NTriples => {
TripleReaderKind::NTriples(NTriplesParser::new(reader).map_err(invalid_input)?) TripleReaderKind::NTriples(NTriplesParser::new(reader).map_err(invalid_input)?)
} }
GraphSyntax::Turtle => TripleReaderKind::Turtle( GraphFormat::Turtle => TripleReaderKind::Turtle(
TurtleParser::new(reader, &self.base_iri).map_err(invalid_input)?, TurtleParser::new(reader, &self.base_iri).map_err(invalid_input)?,
), ),
GraphSyntax::RdfXml => TripleReaderKind::RdfXml( GraphFormat::RdfXml => TripleReaderKind::RdfXml(
RdfXmlParser::new(reader, &self.base_iri).map_err(invalid_input)?, RdfXmlParser::new(reader, &self.base_iri).map_err(invalid_input)?,
), ),
}, },
@ -91,12 +90,12 @@ impl GraphParser {
/// Could be built using a `GraphParser`. /// Could be built using a `GraphParser`.
/// ///
/// ``` /// ```
/// use oxigraph::io::{GraphSyntax, GraphParser}; /// use oxigraph::io::{GraphFormat, GraphParser};
/// use std::io::Cursor; /// use std::io::Cursor;
/// ///
/// let file = "<http://example.com/s> <http://example.com/p> <http://example.com/o> ."; /// let file = "<http://example.com/s> <http://example.com/p> <http://example.com/o> .";
/// ///
/// let parser = GraphParser::from_syntax(GraphSyntax::NTriples); /// let parser = GraphParser::from_format(GraphFormat::NTriples);
/// let triples = parser.read_triples(Cursor::new(file))?.collect::<Result<Vec<_>,_>>()?; /// let triples = parser.read_triples(Cursor::new(file))?.collect::<Result<Vec<_>,_>>()?;
/// ///
///assert_eq!(triples.len(), 1); ///assert_eq!(triples.len(), 1);
@ -165,16 +164,16 @@ impl<R: BufRead> TripleReader<R> {
/// A reader for RDF dataset serialization formats. /// A reader for RDF dataset serialization formats.
/// ///
/// It currently supports the following formats: /// It currently supports the following formats:
/// * [N-Quads](https://www.w3.org/TR/n-quads/) (`DatasetSyntax::NQuads`) /// * [N-Quads](https://www.w3.org/TR/n-quads/) (`DatasetFormat::NQuads`)
/// * [TriG](https://www.w3.org/TR/trig/) (`DatasetSyntax::TriG`) /// * [TriG](https://www.w3.org/TR/trig/) (`DatasetFormat::TriG`)
/// ///
/// ``` /// ```
/// use oxigraph::io::{DatasetSyntax, DatasetParser}; /// use oxigraph::io::{DatasetFormat, DatasetParser};
/// use std::io::Cursor; /// use std::io::Cursor;
/// ///
/// let file = "<http://example.com/s> <http://example.com/p> <http://example.com/o> <http://example.com/g> ."; /// let file = "<http://example.com/s> <http://example.com/p> <http://example.com/o> <http://example.com/g> .";
/// ///
/// let parser = DatasetParser::from_syntax(DatasetSyntax::NQuads); /// let parser = DatasetParser::from_format(DatasetFormat::NQuads);
/// let quads = parser.read_quads(Cursor::new(file))?.collect::<Result<Vec<_>,_>>()?; /// let quads = parser.read_quads(Cursor::new(file))?.collect::<Result<Vec<_>,_>>()?;
/// ///
///assert_eq!(quads.len(), 1); ///assert_eq!(quads.len(), 1);
@ -182,14 +181,14 @@ impl<R: BufRead> TripleReader<R> {
/// # std::io::Result::Ok(()) /// # std::io::Result::Ok(())
/// ``` /// ```
pub struct DatasetParser { pub struct DatasetParser {
syntax: DatasetSyntax, format: DatasetFormat,
base_iri: String, base_iri: String,
} }
impl DatasetParser { impl DatasetParser {
pub fn from_syntax(syntax: DatasetSyntax) -> Self { pub fn from_format(format: DatasetFormat) -> Self {
Self { Self {
syntax, format,
base_iri: String::new(), base_iri: String::new(),
} }
} }
@ -197,12 +196,12 @@ impl DatasetParser {
/// Provides an IRI that could be used to resolve the file relative IRIs /// Provides an IRI that could be used to resolve the file relative IRIs
/// ///
/// ``` /// ```
/// use oxigraph::io::{DatasetSyntax, DatasetParser}; /// use oxigraph::io::{DatasetFormat, DatasetParser};
/// use std::io::Cursor; /// use std::io::Cursor;
/// ///
/// let file = "<g> { </s> </p> </o> }"; /// let file = "<g> { </s> </p> </o> }";
/// ///
/// let parser = DatasetParser::from_syntax(DatasetSyntax::TriG).with_base_iri("http://example.com")?; /// let parser = DatasetParser::from_format(DatasetFormat::TriG).with_base_iri("http://example.com")?;
/// let triples = parser.read_quads(Cursor::new(file))?.collect::<Result<Vec<_>,_>>()?; /// let triples = parser.read_quads(Cursor::new(file))?.collect::<Result<Vec<_>,_>>()?;
/// ///
///assert_eq!(triples.len(), 1); ///assert_eq!(triples.len(), 1);
@ -219,11 +218,11 @@ impl DatasetParser {
//TODO: drop the error when possible //TODO: drop the error when possible
Ok(QuadReader { Ok(QuadReader {
mapper: RioMapper::default(), mapper: RioMapper::default(),
parser: match self.syntax { parser: match self.format {
DatasetSyntax::NQuads => { DatasetFormat::NQuads => {
QuadReaderKind::NQuads(NQuadsParser::new(reader).map_err(invalid_input)?) QuadReaderKind::NQuads(NQuadsParser::new(reader).map_err(invalid_input)?)
} }
DatasetSyntax::TriG => QuadReaderKind::TriG( DatasetFormat::TriG => QuadReaderKind::TriG(
TriGParser::new(reader, &self.base_iri).map_err(invalid_input)?, TriGParser::new(reader, &self.base_iri).map_err(invalid_input)?,
), ),
}, },
@ -236,12 +235,12 @@ impl DatasetParser {
/// Could be built using a `DatasetParser`. /// Could be built using a `DatasetParser`.
/// ///
/// ``` /// ```
/// use oxigraph::io::{DatasetSyntax, DatasetParser}; /// use oxigraph::io::{DatasetFormat, DatasetParser};
/// use std::io::Cursor; /// use std::io::Cursor;
/// ///
/// let file = "<http://example.com/s> <http://example.com/p> <http://example.com/o> <http://example.com/g> ."; /// let file = "<http://example.com/s> <http://example.com/p> <http://example.com/o> <http://example.com/g> .";
/// ///
/// let parser = DatasetParser::from_syntax(DatasetSyntax::NQuads); /// let parser = DatasetParser::from_format(DatasetFormat::NQuads);
/// let quads = parser.read_quads(Cursor::new(file))?.collect::<Result<Vec<_>,_>>()?; /// let quads = parser.read_quads(Cursor::new(file))?.collect::<Result<Vec<_>,_>>()?;
/// ///
///assert_eq!(quads.len(), 1); ///assert_eq!(quads.len(), 1);

@ -1,8 +1,7 @@
//! Utilities to write RDF graphs and datasets //! Utilities to write RDF graphs and datasets
use super::GraphSyntax; use crate::io::{DatasetFormat, GraphFormat};
use crate::model::*; use crate::model::*;
use crate::DatasetSyntax;
use rio_api::formatter::{QuadsFormatter, TriplesFormatter}; use rio_api::formatter::{QuadsFormatter, TriplesFormatter};
use rio_turtle::{NQuadsFormatter, NTriplesFormatter, TriGFormatter, TurtleFormatter}; use rio_turtle::{NQuadsFormatter, NTriplesFormatter, TriGFormatter, TurtleFormatter};
use rio_xml::{RdfXmlError, RdfXmlFormatter}; use rio_xml::{RdfXmlError, RdfXmlFormatter};
@ -12,16 +11,16 @@ use std::io::Write;
/// A serializer for RDF graph serialization formats. /// A serializer for RDF graph serialization formats.
/// ///
/// It currently supports the following formats: /// It currently supports the following formats:
/// * [N-Triples](https://www.w3.org/TR/n-triples/) (`GraphSyntax::NTriples`) /// * [N-Triples](https://www.w3.org/TR/n-triples/) (`GraphFormat::NTriples`)
/// * [Turtle](https://www.w3.org/TR/turtle/) (`GraphSyntax::Turtle`) /// * [Turtle](https://www.w3.org/TR/turtle/) (`GraphFormat::Turtle`)
/// * [RDF XML](https://www.w3.org/TR/rdf-syntax-grammar/) (`GraphSyntax::RdfXml`) /// * [RDF XML](https://www.w3.org/TR/rdf-syntax-grammar/) (`GraphFormat::RdfXml`)
/// ///
/// ``` /// ```
/// use oxigraph::io::{GraphSyntax, GraphSerializer}; /// use oxigraph::io::{GraphFormat, GraphSerializer};
/// use oxigraph::model::*; /// use oxigraph::model::*;
/// ///
/// let mut buffer = Vec::new(); /// let mut buffer = Vec::new();
/// let mut writer = GraphSerializer::from_syntax(GraphSyntax::NTriples).triple_writer(&mut buffer)?; /// let mut writer = GraphSerializer::from_format(GraphFormat::NTriples).triple_writer(&mut buffer)?;
/// writer.write(&Triple { /// writer.write(&Triple {
/// subject: NamedNode::new("http://example.com/s")?.into(), /// subject: NamedNode::new("http://example.com/s")?.into(),
/// predicate: NamedNode::new("http://example.com/p")?, /// predicate: NamedNode::new("http://example.com/p")?,
@ -34,21 +33,21 @@ use std::io::Write;
/// ``` /// ```
#[allow(missing_copy_implementations)] #[allow(missing_copy_implementations)]
pub struct GraphSerializer { pub struct GraphSerializer {
syntax: GraphSyntax, format: GraphFormat,
} }
impl GraphSerializer { impl GraphSerializer {
pub fn from_syntax(syntax: GraphSyntax) -> Self { pub fn from_format(format: GraphFormat) -> Self {
Self { syntax } Self { format }
} }
/// Returns a `TripleWriter` allowing writing triples into the given `Write` implementation /// Returns a `TripleWriter` allowing writing triples into the given `Write` implementation
pub fn triple_writer<W: Write>(&self, writer: W) -> Result<TripleWriter<W>, io::Error> { pub fn triple_writer<W: Write>(&self, writer: W) -> Result<TripleWriter<W>, io::Error> {
Ok(TripleWriter { Ok(TripleWriter {
formatter: match self.syntax { formatter: match self.format {
GraphSyntax::NTriples => TripleWriterKind::NTriples(NTriplesFormatter::new(writer)), GraphFormat::NTriples => TripleWriterKind::NTriples(NTriplesFormatter::new(writer)),
GraphSyntax::Turtle => TripleWriterKind::Turtle(TurtleFormatter::new(writer)), GraphFormat::Turtle => TripleWriterKind::Turtle(TurtleFormatter::new(writer)),
GraphSyntax::RdfXml => { GraphFormat::RdfXml => {
TripleWriterKind::RdfXml(RdfXmlFormatter::new(writer).map_err(map_xml_err)?) TripleWriterKind::RdfXml(RdfXmlFormatter::new(writer).map_err(map_xml_err)?)
} }
}, },
@ -62,11 +61,11 @@ impl GraphSerializer {
/// Warning: Do not forget to run the `finish` method to properly write the last bytes of the file. /// Warning: Do not forget to run the `finish` method to properly write the last bytes of the file.
/// ///
/// ``` /// ```
/// use oxigraph::io::{GraphSyntax, GraphSerializer}; /// use oxigraph::io::{GraphFormat, GraphSerializer};
/// use oxigraph::model::*; /// use oxigraph::model::*;
/// ///
/// let mut buffer = Vec::new(); /// let mut buffer = Vec::new();
/// let mut writer = GraphSerializer::from_syntax(GraphSyntax::NTriples).triple_writer(&mut buffer)?; /// let mut writer = GraphSerializer::from_format(GraphFormat::NTriples).triple_writer(&mut buffer)?;
/// writer.write(&Triple { /// writer.write(&Triple {
/// subject: NamedNode::new("http://example.com/s")?.into(), /// subject: NamedNode::new("http://example.com/s")?.into(),
/// predicate: NamedNode::new("http://example.com/p")?, /// predicate: NamedNode::new("http://example.com/p")?,
@ -114,15 +113,15 @@ impl<W: Write> TripleWriter<W> {
/// A serializer for RDF graph serialization formats. /// A serializer for RDF graph serialization formats.
/// ///
/// It currently supports the following formats: /// It currently supports the following formats:
/// * [N-Quads](https://www.w3.org/TR/n-quads/) (`DatasetSyntax::NQuads`) /// * [N-Quads](https://www.w3.org/TR/n-quads/) (`DatasetFormat::NQuads`)
/// * [TriG](https://www.w3.org/TR/trig/) (`DatasetSyntax::TriG`) /// * [TriG](https://www.w3.org/TR/trig/) (`DatasetFormat::TriG`)
/// ///
/// ``` /// ```
/// use oxigraph::io::{DatasetSyntax, DatasetSerializer}; /// use oxigraph::io::{DatasetFormat, DatasetSerializer};
/// use oxigraph::model::*; /// use oxigraph::model::*;
/// ///
/// let mut buffer = Vec::new(); /// let mut buffer = Vec::new();
/// let mut writer = DatasetSerializer::from_syntax(DatasetSyntax::NQuads).quad_writer(&mut buffer)?; /// let mut writer = DatasetSerializer::from_format(DatasetFormat::NQuads).quad_writer(&mut buffer)?;
/// writer.write(&Quad { /// writer.write(&Quad {
/// subject: NamedNode::new("http://example.com/s")?.into(), /// subject: NamedNode::new("http://example.com/s")?.into(),
/// predicate: NamedNode::new("http://example.com/p")?, /// predicate: NamedNode::new("http://example.com/p")?,
@ -136,20 +135,20 @@ impl<W: Write> TripleWriter<W> {
/// ``` /// ```
#[allow(missing_copy_implementations)] #[allow(missing_copy_implementations)]
pub struct DatasetSerializer { pub struct DatasetSerializer {
syntax: DatasetSyntax, format: DatasetFormat,
} }
impl DatasetSerializer { impl DatasetSerializer {
pub fn from_syntax(syntax: DatasetSyntax) -> Self { pub fn from_format(format: DatasetFormat) -> Self {
Self { syntax } Self { format }
} }
/// Returns a `QuadWriter` allowing writing triples into the given `Write` implementation /// Returns a `QuadWriter` allowing writing triples into the given `Write` implementation
pub fn quad_writer<W: Write>(&self, writer: W) -> Result<QuadWriter<W>, io::Error> { pub fn quad_writer<W: Write>(&self, writer: W) -> Result<QuadWriter<W>, io::Error> {
Ok(QuadWriter { Ok(QuadWriter {
formatter: match self.syntax { formatter: match self.format {
DatasetSyntax::NQuads => QuadWriterKind::NQuads(NQuadsFormatter::new(writer)), DatasetFormat::NQuads => QuadWriterKind::NQuads(NQuadsFormatter::new(writer)),
DatasetSyntax::TriG => QuadWriterKind::TriG(TriGFormatter::new(writer)), DatasetFormat::TriG => QuadWriterKind::TriG(TriGFormatter::new(writer)),
}, },
}) })
} }
@ -161,11 +160,11 @@ impl DatasetSerializer {
/// Warning: Do not forget to run the `finish` method to properly write the last bytes of the file. /// Warning: Do not forget to run the `finish` method to properly write the last bytes of the file.
/// ///
/// ``` /// ```
/// use oxigraph::io::{DatasetSyntax, DatasetSerializer}; /// use oxigraph::io::{DatasetFormat, DatasetSerializer};
/// use oxigraph::model::*; /// use oxigraph::model::*;
/// ///
/// let mut buffer = Vec::new(); /// let mut buffer = Vec::new();
/// let mut writer = DatasetSerializer::from_syntax(DatasetSyntax::NQuads).quad_writer(&mut buffer)?; /// let mut writer = DatasetSerializer::from_format(DatasetFormat::NQuads).quad_writer(&mut buffer)?;
/// writer.write(&Quad { /// writer.write(&Quad {
/// subject: NamedNode::new("http://example.com/s")?.into(), /// subject: NamedNode::new("http://example.com/s")?.into(),
/// predicate: NamedNode::new("http://example.com/p")?, /// predicate: NamedNode::new("http://example.com/p")?,

@ -111,13 +111,13 @@ pub mod store;
pub use error::Error; pub use error::Error;
pub type Result<T> = ::std::result::Result<T, Error>; pub type Result<T> = ::std::result::Result<T, Error>;
#[deprecated(note = "Use oxigraph::io::DatasetSyntax instead")] #[deprecated(note = "Use oxigraph::io::DatasetFormat instead")]
pub use crate::io::DatasetSyntax; pub type DatasetSyntax = crate::io::DatasetFormat;
#[deprecated(note = "Use oxigraph::io::FileSyntax instead")] #[deprecated(note = "Use oxigraph::io::FileSyntax instead")]
#[allow(deprecated)] #[allow(deprecated)]
pub use crate::io::FileSyntax; pub use crate::io::FileSyntax;
#[deprecated(note = "Use oxigraph::io::GraphSyntax instead")] #[deprecated(note = "Use oxigraph::io::GraphFormat instead")]
pub use crate::io::GraphSyntax; pub type GraphSyntax = crate::io::GraphFormat;
pub use crate::store::memory::MemoryStore; pub use crate::store::memory::MemoryStore;
#[cfg(feature = "rocksdb")] #[cfg(feature = "rocksdb")]
pub use crate::store::rocksdb::RocksDbStore; pub use crate::store::rocksdb::RocksDbStore;

@ -25,7 +25,9 @@ pub use crate::sparql::model::QueryTriplesIterator;
#[deprecated(note = "Please directly use QuerySolutionsIterator type instead")] #[deprecated(note = "Please directly use QuerySolutionsIterator type instead")]
pub type BindingsIterator<'a> = QuerySolutionsIterator; pub type BindingsIterator<'a> = QuerySolutionsIterator;
pub use crate::sparql::model::QueryResult; pub use crate::sparql::model::QueryResult;
pub use crate::sparql::model::QueryResultSyntax; pub use crate::sparql::model::QueryResultFormat;
#[deprecated(note = "Use QueryResultFormat instead")]
pub type QueryResultSyntax = QueryResultFormat;
pub use crate::sparql::model::Variable; pub use crate::sparql::model::Variable;
pub use crate::sparql::parser::Query; pub use crate::sparql::parser::Query;
pub use crate::sparql::parser::SparqlParseError; pub use crate::sparql::parser::SparqlParseError;

@ -1,6 +1,6 @@
use crate::io::GraphSerializer; use crate::io::GraphSerializer;
#[allow(deprecated)] #[allow(deprecated)]
use crate::io::{FileSyntax, GraphSyntax}; use crate::io::{FileSyntax, GraphFormat};
use crate::model::*; use crate::model::*;
use crate::sparql::json_results::write_json_results; use crate::sparql::json_results::write_json_results;
use crate::sparql::xml_results::{read_xml_results, write_xml_results}; use crate::sparql::xml_results::{read_xml_results, write_xml_results};
@ -21,10 +21,10 @@ pub enum QueryResult {
} }
impl QueryResult { impl QueryResult {
pub fn read(reader: impl BufRead + 'static, syntax: QueryResultSyntax) -> Result<Self> { pub fn read(reader: impl BufRead + 'static, format: QueryResultFormat) -> Result<Self> {
match syntax { match format {
QueryResultSyntax::Xml => read_xml_results(reader), QueryResultFormat::Xml => read_xml_results(reader),
QueryResultSyntax::Json => Err(Error::msg( QueryResultFormat::Json => Err(Error::msg(
//TODO: implement //TODO: implement
"JSON SPARQL results format parsing has not been implemented yet", "JSON SPARQL results format parsing has not been implemented yet",
)), )),
@ -38,21 +38,21 @@ impl QueryResult {
/// ``` /// ```
/// use oxigraph::MemoryStore; /// use oxigraph::MemoryStore;
/// use oxigraph::model::*; /// use oxigraph::model::*;
/// use oxigraph::sparql::{QueryOptions, QueryResultSyntax}; /// use oxigraph::sparql::{QueryOptions, QueryResultFormat};
/// ///
/// let store = MemoryStore::new(); /// let store = MemoryStore::new();
/// let ex = NamedNode::new("http://example.com")?; /// let ex = NamedNode::new("http://example.com")?;
/// store.insert(Quad::new(ex.clone(), ex.clone(), ex.clone(), None)); /// store.insert(Quad::new(ex.clone(), ex.clone(), ex.clone(), None));
/// ///
/// let mut results = Vec::new(); /// let mut results = Vec::new();
/// store.query("SELECT ?s WHERE { ?s ?p ?o }", QueryOptions::default())?.write(&mut results, QueryResultSyntax::Json)?; /// store.query("SELECT ?s WHERE { ?s ?p ?o }", QueryOptions::default())?.write(&mut results, QueryResultFormat::Json)?;
/// assert_eq!(results, "{\"head\":{\"vars\":[\"s\"]},\"results\":{\"bindings\":[{\"s\":{\"type\":\"uri\",\"value\":\"http://example.com\"}}]}}".as_bytes()); /// assert_eq!(results, "{\"head\":{\"vars\":[\"s\"]},\"results\":{\"bindings\":[{\"s\":{\"type\":\"uri\",\"value\":\"http://example.com\"}}]}}".as_bytes());
/// # oxigraph::Result::Ok(()) /// # oxigraph::Result::Ok(())
/// ``` /// ```
pub fn write(self, writer: impl Write, syntax: QueryResultSyntax) -> Result<()> { pub fn write(self, writer: impl Write, format: QueryResultFormat) -> Result<()> {
match syntax { match format {
QueryResultSyntax::Xml => write_xml_results(self, writer), QueryResultFormat::Xml => write_xml_results(self, writer),
QueryResultSyntax::Json => write_json_results(self, writer), QueryResultFormat::Json => write_json_results(self, writer),
} }
} }
@ -61,7 +61,8 @@ impl QueryResult {
/// This method fails if it is called on the `Solution` or `Boolean` results /// This method fails if it is called on the `Solution` or `Boolean` results
/// ///
/// ``` /// ```
/// use oxigraph::{MemoryStore, GraphSyntax}; /// use oxigraph::MemoryStore;
/// use oxigraph::io::GraphFormat;
/// use oxigraph::sparql::QueryOptions; /// use oxigraph::sparql::QueryOptions;
/// use oxigraph::model::*; /// use oxigraph::model::*;
/// use std::io::Cursor; /// use std::io::Cursor;
@ -69,16 +70,16 @@ impl QueryResult {
/// let graph = "<http://example.com> <http://example.com> <http://example.com> .\n".as_bytes(); /// let graph = "<http://example.com> <http://example.com> <http://example.com> .\n".as_bytes();
/// ///
/// let store = MemoryStore::new(); /// let store = MemoryStore::new();
/// store.load_graph(Cursor::new(graph), GraphSyntax::NTriples, &GraphName::DefaultGraph, None)?; /// store.load_graph(Cursor::new(graph), GraphFormat::NTriples, &GraphName::DefaultGraph, None)?;
/// ///
/// let mut results = Vec::new(); /// let mut results = Vec::new();
/// store.query("CONSTRUCT WHERE { ?s ?p ?o }", QueryOptions::default())?.write_graph(&mut results, GraphSyntax::NTriples)?; /// store.query("CONSTRUCT WHERE { ?s ?p ?o }", QueryOptions::default())?.write_graph(&mut results, GraphFormat::NTriples)?;
/// assert_eq!(results, graph); /// assert_eq!(results, graph);
/// # oxigraph::Result::Ok(()) /// # oxigraph::Result::Ok(())
/// ``` /// ```
pub fn write_graph(self, write: impl Write, syntax: GraphSyntax) -> Result<()> { pub fn write_graph(self, write: impl Write, format: GraphFormat) -> Result<()> {
if let QueryResult::Graph(triples) = self { if let QueryResult::Graph(triples) = self {
let mut writer = GraphSerializer::from_syntax(syntax).triple_writer(write)?; let mut writer = GraphSerializer::from_format(format).triple_writer(write)?;
for triple in triples { for triple in triples {
writer.write(&triple?)?; writer.write(&triple?)?;
} }
@ -100,77 +101,77 @@ impl From<QuerySolutionsIterator> for QueryResult {
/// [SPARQL query](https://www.w3.org/TR/sparql11-query/) serialization formats /// [SPARQL query](https://www.w3.org/TR/sparql11-query/) serialization formats
/// ///
/// This enumeration is non exhaustive. New syntaxes like CSV will be added in the future. /// This enumeration is non exhaustive. New formats like CSV will be added in the future.
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum QueryResultSyntax { pub enum QueryResultFormat {
/// [SPARQL Query Results XML Format](http://www.w3.org/TR/rdf-sparql-XMLres/) /// [SPARQL Query Results XML Format](http://www.w3.org/TR/rdf-sparql-XMLres/)
Xml, Xml,
/// [SPARQL Query Results JSON Format](https://www.w3.org/TR/sparql11-results-json/) /// [SPARQL Query Results JSON Format](https://www.w3.org/TR/sparql11-results-json/)
Json, Json,
} }
impl QueryResultSyntax { impl QueryResultFormat {
/// The syntax canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/). /// The format canonical IRI according to the [Unique URIs for file formats registry](https://www.w3.org/ns/formats/).
/// ///
/// ``` /// ```
/// use oxigraph::sparql::QueryResultSyntax; /// use oxigraph::sparql::QueryResultFormat;
/// ///
/// assert_eq!(QueryResultSyntax::Json.iri(), "http://www.w3.org/ns/formats/SPARQL_Results_JSON") /// assert_eq!(QueryResultFormat::Json.iri(), "http://www.w3.org/ns/formats/SPARQL_Results_JSON")
/// ``` /// ```
pub fn iri(self) -> &'static str { pub fn iri(self) -> &'static str {
match self { match self {
QueryResultSyntax::Xml => "http://www.w3.org/ns/formats/SPARQL_Results_XML", QueryResultFormat::Xml => "http://www.w3.org/ns/formats/SPARQL_Results_XML",
QueryResultSyntax::Json => "http://www.w3.org/ns/formats/SPARQL_Results_JSON", QueryResultFormat::Json => "http://www.w3.org/ns/formats/SPARQL_Results_JSON",
} }
} }
/// The syntax [IANA media type](https://tools.ietf.org/html/rfc2046). /// The format [IANA media type](https://tools.ietf.org/html/rfc2046).
/// ///
/// ``` /// ```
/// use oxigraph::sparql::QueryResultSyntax; /// use oxigraph::sparql::QueryResultFormat;
/// ///
/// assert_eq!(QueryResultSyntax::Json.media_type(), "application/sparql-results+json") /// assert_eq!(QueryResultFormat::Json.media_type(), "application/sparql-results+json")
/// ``` /// ```
pub fn media_type(self) -> &'static str { pub fn media_type(self) -> &'static str {
match self { match self {
QueryResultSyntax::Xml => "application/sparql-results+xml", QueryResultFormat::Xml => "application/sparql-results+xml",
QueryResultSyntax::Json => "application/sparql-results+json", QueryResultFormat::Json => "application/sparql-results+json",
} }
} }
/// The syntax [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension. /// The format [IANA-registered](https://tools.ietf.org/html/rfc2046) file extension.
/// ///
/// ``` /// ```
/// use oxigraph::sparql::QueryResultSyntax; /// use oxigraph::sparql::QueryResultFormat;
/// ///
/// assert_eq!(QueryResultSyntax::Json.file_extension(), "srj") /// assert_eq!(QueryResultFormat::Json.file_extension(), "srj")
/// ``` /// ```
pub fn file_extension(self) -> &'static str { pub fn file_extension(self) -> &'static str {
match self { match self {
QueryResultSyntax::Xml => "srx", QueryResultFormat::Xml => "srx",
QueryResultSyntax::Json => "srj", QueryResultFormat::Json => "srj",
} }
} }
/// Looks for a known syntax from a media type. /// Looks for a known format from a media type.
/// ///
/// It supports some media type aliases. /// It supports some media type aliases.
/// For example "application/xml" is going to return `QueryResultSyntax::Xml` even if it is not its canonical media type. /// For example "application/xml" is going to return `QueryResultFormat::Xml` even if it is not its canonical media type.
/// ///
/// Example: /// Example:
/// ``` /// ```
/// use oxigraph::sparql::QueryResultSyntax; /// use oxigraph::sparql::QueryResultFormat;
/// ///
/// assert_eq!(QueryResultSyntax::from_media_type("application/sparql-results+json; charset=utf-8"), Some(QueryResultSyntax::Json)) /// assert_eq!(QueryResultFormat::from_media_type("application/sparql-results+json; charset=utf-8"), Some(QueryResultFormat::Json))
/// ``` /// ```
pub fn from_media_type(media_type: &str) -> Option<Self> { pub fn from_media_type(media_type: &str) -> Option<Self> {
if let Some(base_type) = media_type.split(';').next() { if let Some(base_type) = media_type.split(';').next() {
match base_type { match base_type {
"application/sparql-results+xml" | "application/xml" | "text/xml" => { "application/sparql-results+xml" | "application/xml" | "text/xml" => {
Some(QueryResultSyntax::Xml) Some(QueryResultFormat::Xml)
} }
"application/sparql-results+json" | "application/json" | "text/json" => { "application/sparql-results+json" | "application/json" | "text/json" => {
Some(QueryResultSyntax::Json) Some(QueryResultFormat::Json)
} }
_ => None, _ => None,
} }
@ -181,7 +182,7 @@ impl QueryResultSyntax {
} }
#[allow(deprecated)] #[allow(deprecated)]
impl FileSyntax for QueryResultSyntax { impl FileSyntax for QueryResultFormat {
fn iri(self) -> &'static str { fn iri(self) -> &'static str {
self.iri() self.iri()
} }

@ -1,13 +1,14 @@
//! In-memory store. //! In-memory store.
use crate::error::{Infallible, UnwrapInfallible}; use crate::error::{Infallible, UnwrapInfallible};
use crate::io::{DatasetFormat, GraphFormat};
use crate::model::*; use crate::model::*;
use crate::sparql::{Query, QueryOptions, QueryResult, SimplePreparedQuery}; use crate::sparql::{Query, QueryOptions, QueryResult, SimplePreparedQuery};
use crate::store::numeric_encoder::*; use crate::store::numeric_encoder::*;
use crate::store::{ use crate::store::{
dump_dataset, dump_graph, load_dataset, load_graph, ReadableEncodedStore, WritableEncodedStore, dump_dataset, dump_graph, load_dataset, load_graph, ReadableEncodedStore, WritableEncodedStore,
}; };
use crate::{DatasetSyntax, Error, GraphSyntax}; use crate::Error;
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::convert::TryInto; use std::convert::TryInto;
@ -251,14 +252,15 @@ impl MemoryStore {
/// ///
/// Usage example: /// Usage example:
/// ``` /// ```
/// use oxigraph::{MemoryStore, GraphSyntax}; /// use oxigraph::MemoryStore;
/// use oxigraph::io::GraphFormat;
/// use oxigraph::model::*; /// use oxigraph::model::*;
/// ///
/// let store = MemoryStore::new(); /// let store = MemoryStore::new();
/// ///
/// // insertion /// // insertion
/// let file = b"<http://example.com> <http://example.com> <http://example.com> ."; /// let file = b"<http://example.com> <http://example.com> <http://example.com> .";
/// store.load_graph(file.as_ref(), GraphSyntax::NTriples, &GraphName::DefaultGraph, None)?; /// store.load_graph(file.as_ref(), GraphFormat::NTriples, &GraphName::DefaultGraph, None)?;
/// ///
/// // quad filter /// // quad filter
/// let results: Vec<Quad> = store.quads_for_pattern(None, None, None, None).collect(); /// let results: Vec<Quad> = store.quads_for_pattern(None, None, None, None).collect();
@ -272,26 +274,27 @@ impl MemoryStore {
pub fn load_graph( pub fn load_graph(
&self, &self,
reader: impl BufRead, reader: impl BufRead,
syntax: GraphSyntax, format: GraphFormat,
to_graph_name: &GraphName, to_graph_name: &GraphName,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
let mut store = self; let mut store = self;
load_graph(&mut store, reader, syntax, to_graph_name, base_iri) load_graph(&mut store, reader, format, to_graph_name, base_iri)
} }
/// Loads a dataset file (i.e. quads) into the store. /// Loads a dataset file (i.e. quads) into the store.
/// ///
/// Usage example: /// Usage example:
/// ``` /// ```
/// use oxigraph::{MemoryStore, DatasetSyntax}; /// use oxigraph::MemoryStore;
/// use oxigraph::io::DatasetFormat;
/// use oxigraph::model::*; /// use oxigraph::model::*;
/// ///
/// let store = MemoryStore::new(); /// let store = MemoryStore::new();
/// ///
/// // insertion /// // insertion
/// let file = b"<http://example.com> <http://example.com> <http://example.com> <http://example.com> ."; /// let file = b"<http://example.com> <http://example.com> <http://example.com> <http://example.com> .";
/// store.load_dataset(file.as_ref(), DatasetSyntax::NQuads, None)?; /// store.load_dataset(file.as_ref(), DatasetFormat::NQuads, None)?;
/// ///
/// // quad filter /// // quad filter
/// let results: Vec<Quad> = store.quads_for_pattern(None, None, None, None).collect(); /// let results: Vec<Quad> = store.quads_for_pattern(None, None, None, None).collect();
@ -305,11 +308,11 @@ impl MemoryStore {
pub fn load_dataset( pub fn load_dataset(
&self, &self,
reader: impl BufRead, reader: impl BufRead,
syntax: DatasetSyntax, format: DatasetFormat,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
let mut store = self; let mut store = self;
load_dataset(&mut store, reader, syntax, base_iri) load_dataset(&mut store, reader, format, base_iri)
} }
/// Adds a quad to this store. /// Adds a quad to this store.
@ -341,16 +344,17 @@ impl MemoryStore {
/// ///
/// Usage example: /// Usage example:
/// ``` /// ```
/// use oxigraph::{MemoryStore, GraphSyntax}; /// use oxigraph::{MemoryStore};
/// use oxigraph::io::GraphFormat;
/// use oxigraph::model::GraphName; /// use oxigraph::model::GraphName;
/// ///
/// let file = "<http://example.com> <http://example.com> <http://example.com> .\n".as_bytes(); /// let file = "<http://example.com> <http://example.com> <http://example.com> .\n".as_bytes();
/// ///
/// let store = MemoryStore::new(); /// let store = MemoryStore::new();
/// store.load_graph(file, GraphSyntax::NTriples, &GraphName::DefaultGraph, None)?; /// store.load_graph(file, GraphFormat::NTriples, &GraphName::DefaultGraph, None)?;
/// ///
/// let mut buffer = Vec::new(); /// let mut buffer = Vec::new();
/// store.dump_graph(&mut buffer, GraphSyntax::NTriples, &GraphName::DefaultGraph)?; /// store.dump_graph(&mut buffer, GraphFormat::NTriples, &GraphName::DefaultGraph)?;
/// assert_eq!(file, buffer.as_slice()); /// assert_eq!(file, buffer.as_slice());
/// # oxigraph::Result::Ok(()) /// # oxigraph::Result::Ok(())
/// ``` /// ```
@ -360,14 +364,14 @@ impl MemoryStore {
pub fn dump_graph( pub fn dump_graph(
&self, &self,
writer: impl Write, writer: impl Write,
syntax: GraphSyntax, format: GraphFormat,
from_graph_name: &GraphName, from_graph_name: &GraphName,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
dump_graph( dump_graph(
self.quads_for_pattern(None, None, None, Some(from_graph_name)) self.quads_for_pattern(None, None, None, Some(from_graph_name))
.map(|q| Ok(q.into())), .map(|q| Ok(q.into())),
writer, writer,
syntax, format,
) )
} }
@ -375,26 +379,27 @@ impl MemoryStore {
/// ///
/// Usage example: /// Usage example:
/// ``` /// ```
/// use oxigraph::{MemoryStore, DatasetSyntax}; /// use oxigraph::MemoryStore;
/// use oxigraph::io::DatasetFormat;
/// ///
/// let file = "<http://example.com> <http://example.com> <http://example.com> <http://example.com> .\n".as_bytes(); /// let file = "<http://example.com> <http://example.com> <http://example.com> <http://example.com> .\n".as_bytes();
/// ///
/// let store = MemoryStore::new(); /// let store = MemoryStore::new();
/// store.load_dataset(file, DatasetSyntax::NQuads, None)?; /// store.load_dataset(file, DatasetFormat::NQuads, None)?;
/// ///
/// let mut buffer = Vec::new(); /// let mut buffer = Vec::new();
/// store.dump_dataset(&mut buffer, DatasetSyntax::NQuads)?; /// store.dump_dataset(&mut buffer, DatasetFormat::NQuads)?;
/// assert_eq!(file, buffer.as_slice()); /// assert_eq!(file, buffer.as_slice());
/// # oxigraph::Result::Ok(()) /// # oxigraph::Result::Ok(())
/// ``` /// ```
/// ///
/// Errors related to parameter validation like the base IRI use the `INVALID_INPUT` error kind. /// Errors related to parameter validation like the base IRI use the `INVALID_INPUT` error kind.
/// Errors related to a bad syntax in the loaded file use the `INVALID_DATA` error kind. /// Errors related to a bad syntax in the loaded file use the `INVALID_DATA` error kind.
pub fn dump_dataset(&self, writer: impl Write, syntax: DatasetSyntax) -> Result<(), io::Error> { pub fn dump_dataset(&self, writer: impl Write, format: DatasetFormat) -> Result<(), io::Error> {
dump_dataset( dump_dataset(
self.quads_for_pattern(None, None, None, None).map(Ok), self.quads_for_pattern(None, None, None, None).map(Ok),
writer, writer,
syntax, format,
) )
} }
@ -971,7 +976,8 @@ impl<'a> MemoryTransaction<'a> {
/// ///
/// Usage example: /// Usage example:
/// ``` /// ```
/// use oxigraph::{MemoryStore, GraphSyntax}; /// use oxigraph::MemoryStore;
/// use oxigraph::io::GraphFormat;
/// use oxigraph::model::*; /// use oxigraph::model::*;
/// ///
/// let store = MemoryStore::new(); /// let store = MemoryStore::new();
@ -979,7 +985,7 @@ impl<'a> MemoryTransaction<'a> {
/// // insertion /// // insertion
/// let file = b"<http://example.com> <http://example.com> <http://example.com> ."; /// let file = b"<http://example.com> <http://example.com> <http://example.com> .";
/// store.transaction(|transaction| { /// store.transaction(|transaction| {
/// transaction.load_graph(file.as_ref(), GraphSyntax::NTriples, &GraphName::DefaultGraph, None) /// transaction.load_graph(file.as_ref(), GraphFormat::NTriples, &GraphName::DefaultGraph, None)
/// })?; /// })?;
/// ///
/// // quad filter /// // quad filter
@ -991,25 +997,26 @@ impl<'a> MemoryTransaction<'a> {
pub fn load_graph( pub fn load_graph(
&mut self, &mut self,
reader: impl BufRead, reader: impl BufRead,
syntax: GraphSyntax, format: GraphFormat,
to_graph_name: &GraphName, to_graph_name: &GraphName,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
load_graph(self, reader, syntax, to_graph_name, base_iri) load_graph(self, reader, format, to_graph_name, base_iri)
} }
/// Loads a dataset file (i.e. quads) into the store during the transaction. /// Loads a dataset file (i.e. quads) into the store during the transaction.
/// ///
/// Usage example: /// Usage example:
/// ``` /// ```
/// use oxigraph::{MemoryStore, DatasetSyntax}; /// use oxigraph::MemoryStore;
/// use oxigraph::io::DatasetFormat;
/// use oxigraph::model::*; /// use oxigraph::model::*;
/// ///
/// let store = MemoryStore::new(); /// let store = MemoryStore::new();
/// ///
/// // insertion /// // insertion
/// let file = b"<http://example.com> <http://example.com> <http://example.com> <http://example.com> ."; /// let file = b"<http://example.com> <http://example.com> <http://example.com> <http://example.com> .";
/// store.load_dataset(file.as_ref(), DatasetSyntax::NQuads, None)?; /// store.load_dataset(file.as_ref(), DatasetFormat::NQuads, None)?;
/// ///
/// // quad filter /// // quad filter
/// let results: Vec<Quad> = store.quads_for_pattern(None, None, None, None).collect(); /// let results: Vec<Quad> = store.quads_for_pattern(None, None, None, None).collect();
@ -1020,10 +1027,10 @@ impl<'a> MemoryTransaction<'a> {
pub fn load_dataset( pub fn load_dataset(
&mut self, &mut self,
reader: impl BufRead, reader: impl BufRead,
syntax: DatasetSyntax, format: DatasetFormat,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
load_dataset(self, reader, syntax, base_iri) load_dataset(self, reader, format, base_iri)
} }
/// Adds a quad to this store during the transaction. /// Adds a quad to this store during the transaction.

@ -16,9 +16,9 @@ pub use crate::store::rocksdb::RocksDbStore;
#[cfg(feature = "sled")] #[cfg(feature = "sled")]
pub use crate::store::sled::SledStore; pub use crate::store::sled::SledStore;
use crate::io::{DatasetFormat, GraphFormat};
use crate::model::*; use crate::model::*;
use crate::store::numeric_encoder::*; use crate::store::numeric_encoder::*;
use crate::{DatasetSyntax, GraphSyntax};
use rio_api::formatter::{QuadsFormatter, TriplesFormatter}; use rio_api::formatter::{QuadsFormatter, TriplesFormatter};
use rio_api::parser::{QuadsParser, TriplesParser}; use rio_api::parser::{QuadsParser, TriplesParser};
use rio_turtle::{ use rio_turtle::{
@ -63,19 +63,19 @@ pub(crate) trait WritableEncodedStore: StrContainer {
fn load_graph<S: WritableEncodedStore>( fn load_graph<S: WritableEncodedStore>(
store: &mut S, store: &mut S,
reader: impl BufRead, reader: impl BufRead,
syntax: GraphSyntax, format: GraphFormat,
to_graph_name: &GraphName, to_graph_name: &GraphName,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
let base_iri = base_iri.unwrap_or(""); let base_iri = base_iri.unwrap_or("");
match syntax { match format {
GraphSyntax::NTriples => { GraphFormat::NTriples => {
load_from_triple_parser(store, NTriplesParser::new(reader), to_graph_name) load_from_triple_parser(store, NTriplesParser::new(reader), to_graph_name)
} }
GraphSyntax::Turtle => { GraphFormat::Turtle => {
load_from_triple_parser(store, TurtleParser::new(reader, base_iri), to_graph_name) load_from_triple_parser(store, TurtleParser::new(reader, base_iri), to_graph_name)
} }
GraphSyntax::RdfXml => { GraphFormat::RdfXml => {
load_from_triple_parser(store, RdfXmlParser::new(reader, base_iri), to_graph_name) load_from_triple_parser(store, RdfXmlParser::new(reader, base_iri), to_graph_name)
} }
} }
@ -110,24 +110,24 @@ where
fn dump_graph( fn dump_graph(
triples: impl Iterator<Item = Result<Triple, io::Error>>, triples: impl Iterator<Item = Result<Triple, io::Error>>,
writer: impl Write, writer: impl Write,
syntax: GraphSyntax, format: GraphFormat,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
match syntax { match format {
GraphSyntax::NTriples => { GraphFormat::NTriples => {
let mut formatter = NTriplesFormatter::new(writer); let mut formatter = NTriplesFormatter::new(writer);
for triple in triples { for triple in triples {
formatter.format(&(&triple?).into())?; formatter.format(&(&triple?).into())?;
} }
formatter.finish(); formatter.finish();
} }
GraphSyntax::Turtle => { GraphFormat::Turtle => {
let mut formatter = TurtleFormatter::new(writer); let mut formatter = TurtleFormatter::new(writer);
for triple in triples { for triple in triples {
formatter.format(&(&triple?).into())?; formatter.format(&(&triple?).into())?;
} }
formatter.finish()?; formatter.finish()?;
} }
GraphSyntax::RdfXml => { GraphFormat::RdfXml => {
let mut formatter = RdfXmlFormatter::new(writer).map_err(map_xml_err)?; let mut formatter = RdfXmlFormatter::new(writer).map_err(map_xml_err)?;
for triple in triples { for triple in triples {
formatter.format(&(&triple?).into()).map_err(map_xml_err)?; formatter.format(&(&triple?).into()).map_err(map_xml_err)?;
@ -145,13 +145,13 @@ fn map_xml_err(e: RdfXmlError) -> io::Error {
fn load_dataset<S: WritableEncodedStore>( fn load_dataset<S: WritableEncodedStore>(
store: &mut S, store: &mut S,
reader: impl BufRead, reader: impl BufRead,
syntax: DatasetSyntax, format: DatasetFormat,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
let base_iri = base_iri.unwrap_or(""); let base_iri = base_iri.unwrap_or("");
match syntax { match format {
DatasetSyntax::NQuads => load_from_quad_parser(store, NQuadsParser::new(reader)), DatasetFormat::NQuads => load_from_quad_parser(store, NQuadsParser::new(reader)),
DatasetSyntax::TriG => load_from_quad_parser(store, TriGParser::new(reader, base_iri)), DatasetFormat::TriG => load_from_quad_parser(store, TriGParser::new(reader, base_iri)),
} }
} }
@ -180,17 +180,17 @@ where
fn dump_dataset( fn dump_dataset(
quads: impl Iterator<Item = Result<Quad, io::Error>>, quads: impl Iterator<Item = Result<Quad, io::Error>>,
writer: impl Write, writer: impl Write,
syntax: DatasetSyntax, format: DatasetFormat,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
match syntax { match format {
DatasetSyntax::NQuads => { DatasetFormat::NQuads => {
let mut formatter = NQuadsFormatter::new(writer); let mut formatter = NQuadsFormatter::new(writer);
for quad in quads { for quad in quads {
formatter.format(&(&quad?).into())?; formatter.format(&(&quad?).into())?;
} }
formatter.finish(); formatter.finish();
} }
DatasetSyntax::TriG => { DatasetFormat::TriG => {
let mut formatter = TriGFormatter::new(writer); let mut formatter = TriGFormatter::new(writer);
for quad in quads { for quad in quads {
formatter.format(&(&quad?).into())?; formatter.format(&(&quad?).into())?;

@ -1,13 +1,13 @@
//! Store based on the [RocksDB](https://rocksdb.org/) key-value database. //! Store based on the [RocksDB](https://rocksdb.org/) key-value database.
use crate::error::{Infallible, UnwrapInfallible}; use crate::error::{Infallible, UnwrapInfallible};
use crate::io::{DatasetFormat, GraphFormat};
use crate::model::*; use crate::model::*;
use crate::sparql::{Query, QueryOptions, QueryResult, SimplePreparedQuery}; use crate::sparql::{Query, QueryOptions, QueryResult, SimplePreparedQuery};
use crate::store::numeric_encoder::*; use crate::store::numeric_encoder::*;
use crate::store::{ use crate::store::{
dump_dataset, dump_graph, load_dataset, load_graph, ReadableEncodedStore, WritableEncodedStore, dump_dataset, dump_graph, load_dataset, load_graph, ReadableEncodedStore, WritableEncodedStore,
}; };
use crate::{DatasetSyntax, GraphSyntax};
use rocksdb::*; use rocksdb::*;
use std::convert::TryInto; use std::convert::TryInto;
use std::io; use std::io;
@ -191,12 +191,12 @@ impl RocksDbStore {
pub fn load_graph( pub fn load_graph(
&self, &self,
reader: impl BufRead, reader: impl BufRead,
syntax: GraphSyntax, format: GraphFormat,
to_graph_name: &GraphName, to_graph_name: &GraphName,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), crate::Error> { ) -> Result<(), crate::Error> {
let mut transaction = self.auto_batch_writer(); let mut transaction = self.auto_batch_writer();
load_graph(&mut transaction, reader, syntax, to_graph_name, base_iri)?; load_graph(&mut transaction, reader, format, to_graph_name, base_iri)?;
Ok(transaction.apply()?) Ok(transaction.apply()?)
} }
@ -213,11 +213,11 @@ impl RocksDbStore {
pub fn load_dataset( pub fn load_dataset(
&self, &self,
reader: impl BufRead, reader: impl BufRead,
syntax: DatasetSyntax, format: DatasetFormat,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), crate::Error> { ) -> Result<(), crate::Error> {
let mut transaction = self.auto_batch_writer(); let mut transaction = self.auto_batch_writer();
load_dataset(&mut transaction, reader, syntax, base_iri)?; load_dataset(&mut transaction, reader, format, base_iri)?;
Ok(transaction.apply()?) Ok(transaction.apply()?)
} }
@ -243,21 +243,21 @@ impl RocksDbStore {
pub fn dump_graph( pub fn dump_graph(
&self, &self,
writer: impl Write, writer: impl Write,
syntax: GraphSyntax, format: GraphFormat,
from_graph_name: &GraphName, from_graph_name: &GraphName,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
dump_graph( dump_graph(
self.quads_for_pattern(None, None, None, Some(from_graph_name)) self.quads_for_pattern(None, None, None, Some(from_graph_name))
.map(|q| Ok(q?.into())), .map(|q| Ok(q?.into())),
writer, writer,
syntax, format,
) )
} }
/// Dumps the store dataset into a file. /// Dumps the store dataset into a file.
/// ///
/// See `MemoryStore` for a usage example. /// See `MemoryStore` for a usage example.
pub fn dump_dataset(&self, writer: impl Write, syntax: DatasetSyntax) -> Result<(), io::Error> { pub fn dump_dataset(&self, writer: impl Write, syntax: DatasetFormat) -> Result<(), io::Error> {
dump_dataset( dump_dataset(
self.quads_for_pattern(None, None, None, None), self.quads_for_pattern(None, None, None, None),
writer, writer,
@ -577,7 +577,7 @@ impl RocksDbTransaction<'_> {
pub fn load_graph( pub fn load_graph(
&mut self, &mut self,
reader: impl BufRead, reader: impl BufRead,
syntax: GraphSyntax, syntax: GraphFormat,
to_graph_name: &GraphName, to_graph_name: &GraphName,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
@ -597,10 +597,10 @@ impl RocksDbTransaction<'_> {
pub fn load_dataset( pub fn load_dataset(
&mut self, &mut self,
reader: impl BufRead, reader: impl BufRead,
syntax: DatasetSyntax, format: DatasetFormat,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
load_dataset(&mut self.inner, reader, syntax, base_iri) load_dataset(&mut self.inner, reader, format, base_iri)
} }
/// Adds a quad to this store during the transaction. /// Adds a quad to this store during the transaction.

@ -1,13 +1,13 @@
//! Store based on the [Sled](https://sled.rs/) key-value database. //! Store based on the [Sled](https://sled.rs/) key-value database.
use crate::error::{Infallible, UnwrapInfallible}; use crate::error::{Infallible, UnwrapInfallible};
use crate::io::{DatasetFormat, GraphFormat};
use crate::model::*; use crate::model::*;
use crate::sparql::{Query, QueryOptions, QueryResult, SimplePreparedQuery}; use crate::sparql::{Query, QueryOptions, QueryResult, SimplePreparedQuery};
use crate::store::numeric_encoder::*; use crate::store::numeric_encoder::*;
use crate::store::{ use crate::store::{
dump_dataset, dump_graph, load_dataset, load_graph, ReadableEncodedStore, WritableEncodedStore, dump_dataset, dump_graph, load_dataset, load_graph, ReadableEncodedStore, WritableEncodedStore,
}; };
use crate::{DatasetSyntax, GraphSyntax};
use sled::{Batch, Config, Iter, Tree}; use sled::{Batch, Config, Iter, Tree};
use std::convert::TryInto; use std::convert::TryInto;
use std::io::{BufRead, Cursor, Write}; use std::io::{BufRead, Cursor, Write};
@ -176,14 +176,14 @@ impl SledStore {
pub fn load_graph( pub fn load_graph(
&self, &self,
reader: impl BufRead, reader: impl BufRead,
syntax: GraphSyntax, format: GraphFormat,
to_graph_name: &GraphName, to_graph_name: &GraphName,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
load_graph( load_graph(
&mut DirectWriter::new(self), &mut DirectWriter::new(self),
reader, reader,
syntax, format,
to_graph_name, to_graph_name,
base_iri, base_iri,
) )
@ -202,10 +202,10 @@ impl SledStore {
pub fn load_dataset( pub fn load_dataset(
&self, &self,
reader: impl BufRead, reader: impl BufRead,
syntax: DatasetSyntax, format: DatasetFormat,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
load_dataset(&mut DirectWriter::new(self), reader, syntax, base_iri) load_dataset(&mut DirectWriter::new(self), reader, format, base_iri)
} }
/// Adds a quad to this store. /// Adds a quad to this store.
@ -227,25 +227,25 @@ impl SledStore {
pub fn dump_graph( pub fn dump_graph(
&self, &self,
writer: impl Write, writer: impl Write,
syntax: GraphSyntax, format: GraphFormat,
from_graph_name: &GraphName, from_graph_name: &GraphName,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
dump_graph( dump_graph(
self.quads_for_pattern(None, None, None, Some(from_graph_name)) self.quads_for_pattern(None, None, None, Some(from_graph_name))
.map(|q| Ok(q?.into())), .map(|q| Ok(q?.into())),
writer, writer,
syntax, format,
) )
} }
/// Dumps the store dataset into a file. /// Dumps the store dataset into a file.
/// ///
/// See `MemoryStore` for a usage example. /// See `MemoryStore` for a usage example.
pub fn dump_dataset(&self, writer: impl Write, syntax: DatasetSyntax) -> Result<(), io::Error> { pub fn dump_dataset(&self, writer: impl Write, format: DatasetFormat) -> Result<(), io::Error> {
dump_dataset( dump_dataset(
self.quads_for_pattern(None, None, None, None), self.quads_for_pattern(None, None, None, None),
writer, writer,
syntax, format,
) )
} }
@ -668,11 +668,11 @@ impl SledTransaction<'_> {
pub fn load_graph( pub fn load_graph(
&mut self, &mut self,
reader: impl BufRead, reader: impl BufRead,
syntax: GraphSyntax, format: GraphFormat,
to_graph_name: &GraphName, to_graph_name: &GraphName,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
load_graph(&mut self.inner, reader, syntax, to_graph_name, base_iri) load_graph(&mut self.inner, reader, format, to_graph_name, base_iri)
} }
/// Loads a dataset file (i.e. quads) into the store. into the store during the transaction. /// Loads a dataset file (i.e. quads) into the store. into the store during the transaction.
@ -688,10 +688,10 @@ impl SledTransaction<'_> {
pub fn load_dataset( pub fn load_dataset(
&mut self, &mut self,
reader: impl BufRead, reader: impl BufRead,
syntax: DatasetSyntax, format: DatasetFormat,
base_iri: Option<&str>, base_iri: Option<&str>,
) -> Result<(), io::Error> { ) -> Result<(), io::Error> {
load_dataset(&mut self.inner, reader, syntax, base_iri) load_dataset(&mut self.inner, reader, format, base_iri)
} }
/// Adds a quad to this store during the transaction. /// Adds a quad to this store during the transaction.

@ -1,8 +1,9 @@
use crate::model::*; use crate::model::*;
use crate::store_utils::*; use crate::store_utils::*;
use oxigraph::io::{DatasetFormat, GraphFormat};
use oxigraph::model::*; use oxigraph::model::*;
use oxigraph::sparql::QueryOptions; use oxigraph::sparql::QueryOptions;
use oxigraph::{DatasetSyntax, GraphSyntax, MemoryStore}; use oxigraph::MemoryStore;
use pyo3::basic::CompareOp; use pyo3::basic::CompareOp;
use pyo3::exceptions::{NotImplementedError, ValueError}; use pyo3::exceptions::{NotImplementedError, ValueError};
use pyo3::prelude::*; use pyo3::prelude::*;
@ -81,23 +82,23 @@ impl PyMemoryStore {
Some(base_iri) Some(base_iri)
}; };
if let Some(graph_syntax) = GraphSyntax::from_media_type(mime_type) { if let Some(graph_format) = GraphFormat::from_media_type(mime_type) {
self.inner self.inner
.load_graph( .load_graph(
Cursor::new(data), Cursor::new(data),
graph_syntax, graph_format,
&to_graph_name.unwrap_or(GraphName::DefaultGraph), &to_graph_name.unwrap_or(GraphName::DefaultGraph),
base_iri, base_iri,
) )
.map_err(map_io_err) .map_err(map_io_err)
} else if let Some(dataset_syntax) = DatasetSyntax::from_media_type(mime_type) { } else if let Some(dataset_format) = DatasetFormat::from_media_type(mime_type) {
if to_graph_name.is_some() { if to_graph_name.is_some() {
return Err(ValueError::py_err( return Err(ValueError::py_err(
"The target graph name parameter is not available for dataset formats", "The target graph name parameter is not available for dataset formats",
)); ));
} }
self.inner self.inner
.load_dataset(Cursor::new(data), dataset_syntax, base_iri) .load_dataset(Cursor::new(data), dataset_format, base_iri)
.map_err(map_io_err) .map_err(map_io_err)
} else { } else {
Err(ValueError::py_err(format!( Err(ValueError::py_err(format!(

@ -1,8 +1,9 @@
use crate::model::*; use crate::model::*;
use crate::store_utils::*; use crate::store_utils::*;
use oxigraph::io::{DatasetFormat, GraphFormat};
use oxigraph::model::*; use oxigraph::model::*;
use oxigraph::sparql::QueryOptions; use oxigraph::sparql::QueryOptions;
use oxigraph::{DatasetSyntax, GraphSyntax, SledStore}; use oxigraph::SledStore;
use pyo3::exceptions::ValueError; use pyo3::exceptions::ValueError;
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::types::PyTuple; use pyo3::types::PyTuple;
@ -83,23 +84,23 @@ impl PySledStore {
Some(base_iri) Some(base_iri)
}; };
if let Some(graph_syntax) = GraphSyntax::from_media_type(mime_type) { if let Some(graph_format) = GraphFormat::from_media_type(mime_type) {
self.inner self.inner
.load_graph( .load_graph(
Cursor::new(data), Cursor::new(data),
graph_syntax, graph_format,
&to_graph_name.unwrap_or(GraphName::DefaultGraph), &to_graph_name.unwrap_or(GraphName::DefaultGraph),
base_iri, base_iri,
) )
.map_err(map_io_err) .map_err(map_io_err)
} else if let Some(dataset_syntax) = DatasetSyntax::from_media_type(mime_type) { } else if let Some(dataset_format) = DatasetFormat::from_media_type(mime_type) {
if to_graph_name.is_some() { if to_graph_name.is_some() {
return Err(ValueError::py_err( return Err(ValueError::py_err(
"The target graph name parameter is not available for dataset formats", "The target graph name parameter is not available for dataset formats",
)); ));
} }
self.inner self.inner
.load_dataset(Cursor::new(data), dataset_syntax, base_iri) .load_dataset(Cursor::new(data), dataset_format, base_iri)
.map_err(map_io_err) .map_err(map_io_err)
} else { } else {
Err(ValueError::py_err(format!( Err(ValueError::py_err(format!(

@ -16,9 +16,10 @@ use async_std::net::{TcpListener, TcpStream};
use async_std::prelude::*; use async_std::prelude::*;
use async_std::task::{block_on, spawn, spawn_blocking}; use async_std::task::{block_on, spawn, spawn_blocking};
use http_types::{headers, Body, Error, Method, Mime, Request, Response, Result, StatusCode}; use http_types::{headers, Body, Error, Method, Mime, Request, Response, Result, StatusCode};
use oxigraph::io::{DatasetFormat, GraphFormat};
use oxigraph::model::GraphName; use oxigraph::model::GraphName;
use oxigraph::sparql::{Query, QueryOptions, QueryResult, QueryResultSyntax}; use oxigraph::sparql::{Query, QueryOptions, QueryResult, QueryResultFormat};
use oxigraph::{DatasetSyntax, GraphSyntax, RocksDbStore}; use oxigraph::RocksDbStore;
use std::str::FromStr; use std::str::FromStr;
use url::form_urlencoded; use url::form_urlencoded;
@ -60,7 +61,7 @@ async fn handle_request(request: Request, store: RocksDbStore) -> Result<Respons
} }
("/", Method::Post) => { ("/", Method::Post) => {
if let Some(content_type) = request.content_type() { if let Some(content_type) = request.content_type() {
match if let Some(format) = GraphSyntax::from_media_type(content_type.essence()) { match if let Some(format) = GraphFormat::from_media_type(content_type.essence()) {
spawn_blocking(move || { spawn_blocking(move || {
store.load_graph( store.load_graph(
SyncAsyncBufReader::from(request), SyncAsyncBufReader::from(request),
@ -69,7 +70,7 @@ async fn handle_request(request: Request, store: RocksDbStore) -> Result<Respons
None, None,
) )
}) })
} else if let Some(format) = DatasetSyntax::from_media_type(content_type.essence()) } else if let Some(format) = DatasetFormat::from_media_type(content_type.essence())
{ {
spawn_blocking(move || { spawn_blocking(move || {
store.load_dataset(SyncAsyncBufReader::from(request), format, None) store.load_dataset(SyncAsyncBufReader::from(request), format, None)
@ -175,11 +176,11 @@ async fn evaluate_sparql_query(
let format = content_negotiation( let format = content_negotiation(
request, request,
&[ &[
GraphSyntax::NTriples.media_type(), GraphFormat::NTriples.media_type(),
GraphSyntax::Turtle.media_type(), GraphFormat::Turtle.media_type(),
GraphSyntax::RdfXml.media_type(), GraphFormat::RdfXml.media_type(),
], ],
GraphSyntax::from_media_type, GraphFormat::from_media_type,
)?; )?;
let mut body = Vec::default(); let mut body = Vec::default();
results.write_graph(&mut body, format)?; results.write_graph(&mut body, format)?;
@ -190,10 +191,10 @@ async fn evaluate_sparql_query(
let format = content_negotiation( let format = content_negotiation(
request, request,
&[ &[
QueryResultSyntax::Xml.media_type(), QueryResultFormat::Xml.media_type(),
QueryResultSyntax::Json.media_type(), QueryResultFormat::Json.media_type(),
], ],
QueryResultSyntax::from_media_type, QueryResultFormat::from_media_type,
)?; )?;
let mut body = Vec::default(); let mut body = Vec::default();
results.write(&mut body, format)?; results.write(&mut body, format)?;

@ -1,6 +1,7 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use oxigraph::io::{DatasetFormat, GraphFormat};
use oxigraph::model::GraphName; use oxigraph::model::GraphName;
use oxigraph::{DatasetSyntax, GraphSyntax, MemoryStore}; use oxigraph::MemoryStore;
use std::fs::File; use std::fs::File;
use std::io::{BufRead, BufReader, Read}; use std::io::{BufRead, BufReader, Read};
use std::path::PathBuf; use std::path::PathBuf;
@ -42,28 +43,28 @@ pub fn load_to_store(url: &str, store: &MemoryStore, to_graph_name: &GraphName)
if url.ends_with(".nt") { if url.ends_with(".nt") {
store.load_graph( store.load_graph(
read_file(url)?, read_file(url)?,
GraphSyntax::NTriples, GraphFormat::NTriples,
to_graph_name, to_graph_name,
Some(url), Some(url),
)? )?
} else if url.ends_with(".ttl") { } else if url.ends_with(".ttl") {
store.load_graph( store.load_graph(
read_file(url)?, read_file(url)?,
GraphSyntax::Turtle, GraphFormat::Turtle,
to_graph_name, to_graph_name,
Some(url), Some(url),
)? )?
} else if url.ends_with(".rdf") { } else if url.ends_with(".rdf") {
store.load_graph( store.load_graph(
read_file(url)?, read_file(url)?,
GraphSyntax::RdfXml, GraphFormat::RdfXml,
to_graph_name, to_graph_name,
Some(url), Some(url),
)? )?
} else if url.ends_with(".nq") { } else if url.ends_with(".nq") {
store.load_dataset(read_file(url)?, DatasetSyntax::NQuads, Some(url))? store.load_dataset(read_file(url)?, DatasetFormat::NQuads, Some(url))?
} else if url.ends_with(".trig") { } else if url.ends_with(".trig") {
store.load_dataset(read_file(url)?, DatasetSyntax::TriG, Some(url))? store.load_dataset(read_file(url)?, DatasetFormat::TriG, Some(url))?
} else { } else {
return Err(anyhow!("Serialization type not found for {}", url)); return Err(anyhow!("Serialization type not found for {}", url));
} }

@ -131,12 +131,12 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> {
fn load_sparql_query_result(url: &str) -> Result<StaticQueryResults> { fn load_sparql_query_result(url: &str) -> Result<StaticQueryResults> {
if url.ends_with(".srx") { if url.ends_with(".srx") {
StaticQueryResults::from_query_results( StaticQueryResults::from_query_results(
QueryResult::read(read_file(url)?, QueryResultSyntax::Xml)?, QueryResult::read(read_file(url)?, QueryResultFormat::Xml)?,
false, false,
) )
} else if url.ends_with(".srj") { } else if url.ends_with(".srj") {
StaticQueryResults::from_query_results( StaticQueryResults::from_query_results(
QueryResult::read(read_file(url)?, QueryResultSyntax::Json)?, QueryResult::read(read_file(url)?, QueryResultFormat::Json)?,
false, false,
) )
} else { } else {

@ -4,8 +4,9 @@ use async_std::prelude::*;
use async_std::task::block_on; use async_std::task::block_on;
use chrono::{DateTime, Datelike, Utc}; use chrono::{DateTime, Datelike, Utc};
use http_types::{headers, Error, Method, Request, Response, Result, StatusCode}; use http_types::{headers, Error, Method, Request, Response, Result, StatusCode};
use oxigraph::io::GraphFormat;
use oxigraph::model::NamedNode; use oxigraph::model::NamedNode;
use oxigraph::{GraphSyntax, RocksDbStore}; use oxigraph::RocksDbStore;
use serde_json::Value; use serde_json::Value;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::io::{BufReader, Cursor, Read}; use std::io::{BufReader, Cursor, Read};
@ -271,7 +272,7 @@ impl WikibaseLoader {
transaction.load_graph( transaction.load_graph(
BufReader::new(data), BufReader::new(data),
GraphSyntax::NTriples, GraphFormat::NTriples,
&NamedNode::new(uri)?.into(), &NamedNode::new(uri)?.into(),
None, None,
)?; )?;

@ -16,8 +16,9 @@ use async_std::net::{TcpListener, TcpStream};
use async_std::prelude::*; use async_std::prelude::*;
use async_std::task::{spawn, spawn_blocking}; use async_std::task::{spawn, spawn_blocking};
use http_types::{headers, Body, Error, Method, Mime, Request, Response, Result, StatusCode}; use http_types::{headers, Body, Error, Method, Mime, Request, Response, Result, StatusCode};
use oxigraph::sparql::{Query, QueryOptions, QueryResult, QueryResultSyntax}; use oxigraph::io::GraphFormat;
use oxigraph::{GraphSyntax, RocksDbStore}; use oxigraph::sparql::{Query, QueryOptions, QueryResult, QueryResultFormat};
use oxigraph::RocksDbStore;
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration; use std::time::Duration;
use url::form_urlencoded; use url::form_urlencoded;
@ -184,11 +185,11 @@ async fn evaluate_sparql_query(
let format = content_negotiation( let format = content_negotiation(
request, request,
&[ &[
GraphSyntax::NTriples.media_type(), GraphFormat::NTriples.media_type(),
GraphSyntax::Turtle.media_type(), GraphFormat::Turtle.media_type(),
GraphSyntax::RdfXml.media_type(), GraphFormat::RdfXml.media_type(),
], ],
GraphSyntax::from_media_type, GraphFormat::from_media_type,
)?; )?;
let mut body = Vec::default(); let mut body = Vec::default();
results.write_graph(&mut body, format)?; results.write_graph(&mut body, format)?;
@ -199,10 +200,10 @@ async fn evaluate_sparql_query(
let format = content_negotiation( let format = content_negotiation(
request, request,
&[ &[
QueryResultSyntax::Xml.media_type(), QueryResultFormat::Xml.media_type(),
QueryResultSyntax::Json.media_type(), QueryResultFormat::Json.media_type(),
], ],
QueryResultSyntax::from_media_type, QueryResultFormat::from_media_type,
)?; )?;
let mut body = Vec::default(); let mut body = Vec::default();
results.write(&mut body, format)?; results.write(&mut body, format)?;

Loading…
Cancel
Save