From a803daa64b54a693807cb0aa0d3a48726c2078b2 Mon Sep 17 00:00:00 2001 From: Tpt Date: Wed, 21 Aug 2019 15:00:16 +0200 Subject: [PATCH] Removes NamedNode::from_str --- lib/src/lib.rs | 2 +- lib/src/model/graph.rs | 2 +- lib/src/model/named_node.rs | 13 +-- lib/src/model/vocab.rs | 127 ++++++++++++++--------------- lib/src/repository.rs | 6 +- lib/src/rio.rs | 3 +- lib/src/sparql/xml_results.rs | 14 +--- lib/src/store/memory.rs | 2 +- lib/src/store/numeric_encoder.rs | 8 +- lib/src/store/rocksdb.rs | 2 +- lib/tests/rdf_test_cases.rs | 16 ++-- lib/tests/sparql_test_cases.rs | 133 +++++++++---------------------- 12 files changed, 122 insertions(+), 206 deletions(-) diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 98bca791..61bd2604 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -19,7 +19,7 @@ //! let connection = repository.connection().unwrap(); //! //! // insertion -//! let ex = NamedNode::from_str("http://example.com").unwrap(); +//! let ex = NamedNode::new("http://example.com"); //! let quad = Quad::new(ex.clone(), ex.clone(), ex.clone(), None); //! connection.insert(&quad); //! diff --git a/lib/src/model/graph.rs b/lib/src/model/graph.rs index ccb01fd6..9906717d 100644 --- a/lib/src/model/graph.rs +++ b/lib/src/model/graph.rs @@ -15,7 +15,7 @@ use std::iter::FromIterator; /// use std::str::FromStr; /// /// let mut graph = SimpleGraph::default(); -/// let ex = NamedNode::from_str("http://example.com").unwrap(); +/// let ex = NamedNode::new("http://example.com"); /// let triple = Triple::new(ex.clone(), ex.clone(), ex.clone()); /// graph.insert(triple.clone()); /// let results: Vec = graph.triples_for_subject(&ex.into()).cloned().collect(); diff --git a/lib/src/model/named_node.rs b/lib/src/model/named_node.rs index e518e689..fe6de622 100644 --- a/lib/src/model/named_node.rs +++ b/lib/src/model/named_node.rs @@ -1,8 +1,5 @@ -use crate::Error; -use crate::Result; use rio_api::model as rio; use std::fmt; -use std::str::FromStr; /// A RDF [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) /// @@ -16,7 +13,7 @@ use std::str::FromStr; /// /// assert_eq!( /// "", -/// NamedNode::from_str("http://example.com/foo").unwrap().to_string() +/// NamedNode::new("http://example.com/foo").to_string() /// ) /// ``` /// @@ -48,11 +45,3 @@ impl NamedNode { self.iri } } - -impl FromStr for NamedNode { - type Err = Error; - - fn from_str(s: &str) -> Result { - Ok(Self::new(s)) - } -} diff --git a/lib/src/model/vocab.rs b/lib/src/model/vocab.rs index 0cf3eb60..20ff974a 100644 --- a/lib/src/model/vocab.rs +++ b/lib/src/model/vocab.rs @@ -4,59 +4,58 @@ pub mod rdf { //! [RDF 1.1](https://www.w3.org/TR/rdf11-concepts/) vocabulary use crate::model::named_node::NamedNode; use lazy_static::lazy_static; - use std::str::FromStr; lazy_static! { /// The class of containers of alternatives. pub static ref ALT: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#Alt").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#Alt"); /// The class of unordered containers. pub static ref BAG: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag"); /// The first item in the subject RDF list. pub static ref FIRST: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#first").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#first"); /// The class of HTML literal values. pub static ref HTML: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML"); /// The class of language-tagged string literal values. pub static ref LANG_STRING: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"); /// The class of RDF Lists. pub static ref LIST: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#List").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#List"); pub static ref NIL: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"); /// The object of the subject RDF statement. pub static ref OBJECT: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#object").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#object"); /// The predicate of the subject RDF statement. pub static ref PREDICATE: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate"); /// The class of RDF properties. pub static ref PROPERTY: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#Property").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"); /// The rest of the subject RDF list after the first item. pub static ref REST: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"); /// The class of ordered containers. pub static ref SEQ: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq"); /// The class of RDF statements. pub static ref STATEMENT: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement"); /// The subject of the subject RDF statement. pub static ref SUBJECT: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#subject").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#subject"); /// The subject is an instance of a class. pub static ref TYPE: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#type").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); /// Idiomatic property used for structured values. pub static ref VALUE: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#value").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#value"); /// The class of XML literal values. pub static ref XML_LITERAL: NamedNode = - NamedNode::from_str("http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral").unwrap(); + NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"); } } @@ -64,54 +63,53 @@ pub mod rdfs { //! [RDFS](https://www.w3.org/TR/rdf-schema/) vocabulary use crate::model::named_node::NamedNode; use lazy_static::lazy_static; - use std::str::FromStr; lazy_static! { /// The class of classes. pub static ref CLASS: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#Class").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#Class"); /// A description of the subject resource. pub static ref COMMENT: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#comment").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#comment"); /// The class of RDF containers. pub static ref CONTAINER: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#Container").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#Container"); /// The class of container membership properties, rdf:_1, rdf:_2, ..., all of which are sub-properties of 'member'. pub static ref CONTAINER_MEMBERSHIP_PROPERTY: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#ContainerMembershipProperty").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#ContainerMembershipProperty"); /// The class of RDF datatypes. pub static ref DATATYPE: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#Datatype").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#Datatype"); /// A domain of the subject property. pub static ref DOMAIN: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#domain").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#domain"); /// The definition of the subject resource. pub static ref IS_DEFINED_BY: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#isDefinedBy").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#isDefinedBy"); /// A human-readable name for the subject. pub static ref LABEL: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#label").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#label"); /// The class of literal values, e.g. textual strings and integers. pub static ref LITERAL: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#Literal").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#Literal"); /// A member of the subject resource. pub static ref MEMBER: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#member").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#member"); /// A range of the subject property. pub static ref RANGE: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#range").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#range"); /// The class resource, everything. pub static ref RESOURCE: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#Resource").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#Resource"); /// Further information about the subject resource. pub static ref SEE_ALSO: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#seeAlso").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#seeAlso"); /// The subject is a subclass of a class. pub static ref SUB_CLASS_OF: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#subClassOf").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#subClassOf"); /// The subject is a subproperty of a property. pub static ref SUB_PROPERTY_OF: NamedNode = - NamedNode::from_str("http://www.w3.org/2000/01/rdf-schema#subPropertyOf").unwrap(); + NamedNode::new("http://www.w3.org/2000/01/rdf-schema#subPropertyOf"); } } @@ -119,98 +117,97 @@ pub mod xsd { //! `NamedNode`s for [RDF compatible XSD datatypes](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-compatible-xsd-types) use crate::model::named_node::NamedNode; use lazy_static::lazy_static; - use std::str::FromStr; lazy_static! { /// true, false pub static ref BOOLEAN: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#boolean").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#boolean"); /// 128…+127 (8 bit) pub static ref BYTE: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#byte").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#byte"); /// Dates (yyyy-mm-dd) with or without timezone pub static ref DATE: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#date").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#date"); /// Duration of time (days, hours, minutes, seconds only) pub static ref DAY_TIME_DURATION: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#dayTimeDuration").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#dayTimeDuration"); /// Date and time with or without timezone pub static ref DATE_TIME: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#dateTime").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#dateTime"); /// Date and time with required timezone pub static ref DATE_TIME_STAMP: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#dateTimeStamp").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#dateTimeStamp"); /// Arbitrary-precision decimal numbers pub static ref DECIMAL: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#decimal").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#decimal"); /// 64-bit floating point numbers incl. ±Inf, ±0, NaN pub static ref DOUBLE: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#double").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#double"); /// Duration of time pub static ref DURATION: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#duration").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#duration"); /// 32-bit floating point numbers incl. ±Inf, ±0, NaN pub static ref FLOAT: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#float").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#float"); /// Gregorian calendar day of the month pub static ref G_DAY: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#gDay").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#gDay"); /// Gregorian calendar month pub static ref G_MONTH: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#gMonth").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#gMonth"); /// Gregorian calendar month and day pub static ref G_MONTH_DAY: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#gMonthDay").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#gMonthDay"); /// Gregorian calendar year pub static ref G_YEAR: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#gYear").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#gYear"); /// Gregorian calendar year and month pub static ref G_YEAR_MONTH: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#gYearMonth").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#gYearMonth"); /// -2147483648…+2147483647 (32 bit) pub static ref INT: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#int").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#int"); /// Arbitrary-size integer numbers pub static ref INTEGER: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#integer").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#integer"); /// -9223372036854775808…+9223372036854775807 (64 bit) pub static ref LONG: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#long").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#long"); /// Integer numbers <0 pub static ref NEGATIVE_INTEGER: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#negativeInteger").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#negativeInteger"); /// Integer numbers ≥0 pub static ref NON_NEGATIVE_INTEGER: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#nonNegativeInteger").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#nonNegativeInteger"); /// Integer numbers ≤0 pub static ref NON_POSITIVE_INTEGER: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#nonPositiveInteger").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#nonPositiveInteger"); /// Integer numbers >0 pub static ref POSITIVE_INTEGER: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#positiveInteger").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#positiveInteger"); /// Times (hh:mm:ss.sss…) with or without timezone pub static ref TIME: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#time").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#time"); /// -32768…+32767 (16 bit) pub static ref SHORT: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#short").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#short"); /// Character strings (but not all Unicode character strings) pub static ref STRING: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#string").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#string"); /// 0…255 (8 bit) pub static ref UNSIGNED_BYTE: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#unsignedByte").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#unsignedByte"); /// 0…4294967295 (32 bit) pub static ref UNSIGNED_INT: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#unsignedInt").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#unsignedInt"); /// 0…18446744073709551615 (64 bit) pub static ref UNSIGNED_LONG: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#unsignedLong").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#unsignedLong"); /// 0…65535 (16 bit) pub static ref UNSIGNED_SHORT: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#unsignedShort").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#unsignedShort"); /// Duration of time (months and years only) pub static ref YEAR_MONTH_DURATION: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/XMLSchema#yearMonthDuration").unwrap(); + NamedNode::new("http://www.w3.org/2001/XMLSchema#yearMonthDuration"); } } diff --git a/lib/src/repository.rs b/lib/src/repository.rs index 273818f3..dd1d00d4 100644 --- a/lib/src/repository.rs +++ b/lib/src/repository.rs @@ -22,7 +22,7 @@ use std::io::Read; /// let connection = repository.connection().unwrap(); /// /// // insertion -/// let ex = NamedNode::from_str("http://example.com").unwrap(); +/// let ex = NamedNode::new("http://example.com"); /// let quad = Quad::new(ex.clone(), ex.clone(), ex.clone(), None); /// connection.insert(&quad); /// @@ -73,7 +73,7 @@ pub trait RepositoryConnection: Clone { /// let connection = repository.connection().unwrap(); /// /// // insertions - /// let ex = NamedNode::from_str("http://example.com").unwrap(); + /// let ex = NamedNode::new("http://example.com"); /// connection.insert(&Quad::new(ex.clone(), ex.clone(), ex.clone(), None)); /// /// // SPARQL query @@ -97,7 +97,7 @@ pub trait RepositoryConnection: Clone { /// let connection = repository.connection().unwrap(); /// /// // insertion - /// let ex = NamedNode::from_str("http://example.com").unwrap(); + /// let ex = NamedNode::new("http://example.com"); /// let quad = Quad::new(ex.clone(), ex.clone(), ex.clone(), None); /// connection.insert(&quad); /// diff --git a/lib/src/rio.rs b/lib/src/rio.rs index f2c4ab74..37991fcb 100644 --- a/lib/src/rio.rs +++ b/lib/src/rio.rs @@ -8,7 +8,6 @@ use rio_turtle::{NTriplesParser, TurtleParser}; use rio_xml::RdfXmlParser; use std::collections::BTreeMap; use std::io::BufRead; -use std::str::FromStr; /// Reads a [N-Triples](https://www.w3.org/TR/n-triples/) file from a Rust `BufRead` and returns an iterator of the read `Triple`s pub fn read_ntriples(reader: R) -> Result>> { @@ -68,7 +67,7 @@ fn convert_named_or_blank_node( } fn convert_named_node(value: rio::NamedNode) -> Result { - NamedNode::from_str(value.iri) + Ok(NamedNode::new(value.iri)) } fn convert_blank_node( diff --git a/lib/src/sparql/xml_results.rs b/lib/src/sparql/xml_results.rs index f472384e..79afb579 100644 --- a/lib/src/sparql/xml_results.rs +++ b/lib/src/sparql/xml_results.rs @@ -17,7 +17,6 @@ use std::collections::BTreeMap; use std::io::BufRead; use std::io::Write; use std::iter::empty; -use std::str::FromStr; pub fn write_xml_results(results: QueryResult<'_>, sink: W) -> Result { let mut writer = Writer::new(sink); @@ -345,11 +344,9 @@ impl Iterator for ResultsIterator { } else if attr.key == b"datatype" { match attr.unescaped_value() { Ok(val) => { - match NamedNode::from_str(&self.reader.decode(&val)) - { - Ok(dt) => datatype = Some(dt), - Err(error) => return Some(Err(error)), - } + datatype = Some(NamedNode::new( + self.reader.decode(&val).to_string(), + )); } Err(error) => return Some(Err(error.into())), } @@ -368,10 +365,7 @@ impl Iterator for ResultsIterator { }, Event::Text(event) => match event.unescaped() { Ok(data) => match state { - State::Uri => match NamedNode::from_str(&self.reader.decode(&data)) { - Ok(named_node) => term = Some(named_node.into()), - Err(error) => return Some(Err(error)), - }, + State::Uri => term = Some(NamedNode::new(self.reader.decode(&data)).into()), State::BNode => { term = Some( self.bnodes_map diff --git a/lib/src/store/memory.rs b/lib/src/store/memory.rs index 62ba7828..5379fca0 100644 --- a/lib/src/store/memory.rs +++ b/lib/src/store/memory.rs @@ -25,7 +25,7 @@ use std::sync::RwLockWriteGuard; /// let connection = repository.connection().unwrap(); /// /// // insertion -/// let ex = NamedNode::from_str("http://example.com").unwrap(); +/// let ex = NamedNode::new("http://example.com"); /// let quad = Quad::new(ex.clone(), ex.clone(), ex.clone(), None); /// connection.insert(&quad); /// diff --git a/lib/src/store/numeric_encoder.rs b/lib/src/store/numeric_encoder.rs index 2d3a8ea6..a5d92483 100644 --- a/lib/src/store/numeric_encoder.rs +++ b/lib/src/store/numeric_encoder.rs @@ -795,13 +795,11 @@ impl From> for MutexPoisonError { #[test] fn test_encoding() { - use std::str::FromStr; - let encoder: Encoder = Encoder::default(); let terms: Vec = vec![ - NamedNode::from_str("http://foo.com").unwrap().into(), - NamedNode::from_str("http://bar.com").unwrap().into(), - NamedNode::from_str("http://foo.com").unwrap().into(), + NamedNode::new("http://foo.com").into(), + NamedNode::new("http://bar.com").into(), + NamedNode::new("http://foo.com").into(), BlankNode::default().into(), Literal::new_simple_literal("foo").into(), Literal::from(true).into(), diff --git a/lib/src/store/rocksdb.rs b/lib/src/store/rocksdb.rs index 04e87321..db595c6f 100644 --- a/lib/src/store/rocksdb.rs +++ b/lib/src/store/rocksdb.rs @@ -35,7 +35,7 @@ use std::sync::Mutex; /// let connection = repository.connection().unwrap(); /// /// // insertion -/// let ex = NamedNode::from_str("http://example.com").unwrap(); +/// let ex = NamedNode::new("http://example.com"); /// let quad = Quad::new(ex.clone(), ex.clone(), ex.clone(), None); /// connection.insert(&quad); /// diff --git a/lib/tests/rdf_test_cases.rs b/lib/tests/rdf_test_cases.rs index 09d3a64c..99656e57 100644 --- a/lib/tests/rdf_test_cases.rs +++ b/lib/tests/rdf_test_cases.rs @@ -200,24 +200,18 @@ impl TestManifest { pub mod mf { use lazy_static::lazy_static; use rudf::model::NamedNode; - use std::str::FromStr; lazy_static! { pub static ref INCLUDE: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include"); pub static ref ENTRIES: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#entries") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#entries"); pub static ref NAME: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name"); pub static ref ACTION: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action"); pub static ref RESULT: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result"); } } diff --git a/lib/tests/sparql_test_cases.rs b/lib/tests/sparql_test_cases.rs index acf02bdf..8c51553d 100644 --- a/lib/tests/sparql_test_cases.rs +++ b/lib/tests/sparql_test_cases.rs @@ -15,7 +15,6 @@ use std::fmt; use std::fs::File; use std::io::{BufRead, BufReader}; use std::path::PathBuf; -use std::str::FromStr; #[test] fn sparql_w3c_syntax_testsuite() { @@ -23,11 +22,11 @@ fn sparql_w3c_syntax_testsuite() { let manifest_11_url = "http://www.w3.org/2009/sparql/docs/tests/data-sparql11/syntax-query/manifest.ttl"; let test_blacklist = vec![ - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/syntax-sparql2/manifest#syntax-form-construct02").unwrap(), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/syntax-sparql2/manifest#syntax-form-construct02"), //TODO: Deserialization of the serialization failing: - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/syntax-sparql2/manifest#syntax-form-construct04").unwrap(), - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/syntax-sparql2/manifest#syntax-function-04").unwrap(), - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/syntax-sparql1/manifest#syntax-qname-04").unwrap(), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/syntax-sparql2/manifest#syntax-form-construct04"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/syntax-sparql2/manifest#syntax-function-04"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/syntax-sparql1/manifest#syntax-qname-04"), ]; for test_result in TestManifest::new(manifest_10_url).chain(TestManifest::new(manifest_11_url)) @@ -90,63 +89,29 @@ fn sparql_w3c_query_evaluation_testsuite() { ]; let test_blacklist = vec![ //Multiple writing of the same xsd:integer. Our system does strong normalization. - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/distinct/manifest#distinct-1", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/distinct/manifest#distinct-9", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#dawg-str-1", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#dawg-str-2", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-equals/manifest#eq-graph-1", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-equals/manifest#eq-graph-2", - ).unwrap(), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/distinct/manifest#distinct-1"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/distinct/manifest#distinct-9"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#dawg-str-1"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#dawg-str-2"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-equals/manifest#eq-graph-1"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-equals/manifest#eq-graph-2"), //Multiple writing of the same xsd:double. Our system does strong normalization. - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#sameTerm", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#sameTerm-simple", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#sameTerm-eq", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#sameTerm-not-eq", - ).unwrap(), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#sameTerm"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#sameTerm-simple"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#sameTerm-eq"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#sameTerm-not-eq"), //Simple literal vs xsd:string. We apply RDF 1.1 - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/distinct/manifest#distinct-2").unwrap(), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/distinct/manifest#distinct-2"), //URI normalization: we are not normalizing well - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#normalization-1", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#normalization-2", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#normalization-3", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#kanji-1", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#kanji-2", - ).unwrap(), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#normalization-1"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#normalization-2"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#normalization-3"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#kanji-1"), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#kanji-2"), //Test on curly brace scoping with OPTIONAL filter - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional-filter/manifest#dawg-optional-filter-005-not-simplified", - ).unwrap(), + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional-filter/manifest#dawg-optional-filter-005-not-simplified"), //DATATYPE("foo"@en) returns rdf:langString in SPARQL 1.1 - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#dawg-datatype-2", - ).unwrap() + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#dawg-datatype-2") ]; for test_result in manifest_10_urls @@ -284,34 +249,24 @@ fn read_file(url: &str) -> Result { mod rs { use lazy_static::lazy_static; use rudf::model::NamedNode; - use std::str::FromStr; lazy_static! { pub static ref RESULT_SET: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/result-set#ResultSet") - .unwrap(); - pub static ref RESULT_VARIABLE: NamedNode = NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/result-set#resultVariable" - ) - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/result-set#ResultSet"); + pub static ref RESULT_VARIABLE: NamedNode = + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/result-set#resultVariable"); pub static ref SOLUTION: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/result-set#solution") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/result-set#solution"); pub static ref BINDING: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/result-set#binding") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/result-set#binding"); pub static ref VALUE: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/result-set#value") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/result-set#value"); pub static ref VARIABLE: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/result-set#variable") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/result-set#variable"); pub static ref INDEX: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/result-set#index") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/result-set#index"); pub static ref BOOLEAN: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/result-set#boolean") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/result-set#boolean"); } } @@ -443,42 +398,32 @@ impl TestManifest { pub mod mf { use lazy_static::lazy_static; use rudf::model::NamedNode; - use std::str::FromStr; lazy_static! { pub static ref INCLUDE: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include"); pub static ref ENTRIES: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#entries") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#entries"); pub static ref NAME: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name"); pub static ref ACTION: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action"); pub static ref RESULT: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result"); } } pub mod qt { use lazy_static::lazy_static; use rudf::model::NamedNode; - use std::str::FromStr; lazy_static! { pub static ref QUERY: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-query#query") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-query#query"); pub static ref DATA: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-query#data") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-query#data"); pub static ref GRAPH_DATA: NamedNode = - NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/test-query#graphData") - .unwrap(); + NamedNode::new("http://www.w3.org/2001/sw/DataAccess/tests/test-query#graphData"); } }