diff --git a/lib/src/io/read.rs b/lib/src/io/read.rs index 32066e8c..d4056a10 100644 --- a/lib/src/io/read.rs +++ b/lib/src/io/read.rs @@ -330,7 +330,7 @@ impl<'a> RioMapper { } } - fn named_or_blank_node(&mut self, node: rio::NamedOrBlankNode<'a>) -> NamedOrBlankNode { + fn subject(&mut self, node: rio::NamedOrBlankNode<'a>) -> Subject { match node { rio::NamedOrBlankNode::NamedNode(node) => self.named_node(node).into(), rio::NamedOrBlankNode::BlankNode(node) => self.blank_node(node).into(), @@ -347,7 +347,7 @@ impl<'a> RioMapper { fn triple(&mut self, triple: &rio::Triple<'a>) -> Triple { Triple { - subject: self.named_or_blank_node(triple.subject), + subject: self.subject(triple.subject), predicate: self.named_node(triple.predicate), object: self.term(triple.object), } @@ -363,7 +363,7 @@ impl<'a> RioMapper { fn quad(&mut self, quad: &rio::Quad<'a>) -> Quad { Quad { - subject: self.named_or_blank_node(quad.subject), + subject: self.subject(quad.subject), predicate: self.named_node(quad.predicate), object: self.term(quad.object), graph_name: self.graph_name(quad.graph_name), diff --git a/lib/src/model/dataset.rs b/lib/src/model/dataset.rs index 27b617cb..dc0534dc 100644 --- a/lib/src/model/dataset.rs +++ b/lib/src/model/dataset.rs @@ -27,7 +27,7 @@ use crate::io::{ DatasetFormat, DatasetParser, DatasetSerializer, GraphFormat, GraphParser, GraphSerializer, }; use crate::model::interning::*; -use crate::model::NamedOrBlankNodeRef; +use crate::model::SubjectRef; use crate::model::*; use lasso::Rodeo; use std::collections::hash_map::DefaultHasher; @@ -69,7 +69,7 @@ pub struct Dataset { interner: Rodeo, gspo: BTreeSet<( InternedGraphName, - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, )>, @@ -77,16 +77,16 @@ pub struct Dataset { InternedGraphName, InternedNamedNode, InternedTerm, - InternedNamedOrBlankNode, + InternedSubject, )>, gosp: BTreeSet<( InternedGraphName, InternedTerm, - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, )>, spog: BTreeSet<( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, @@ -94,12 +94,12 @@ pub struct Dataset { posg: BTreeSet<( InternedNamedNode, InternedTerm, - InternedNamedOrBlankNode, + InternedSubject, InternedGraphName, )>, ospg: BTreeSet<( InternedTerm, - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedGraphName, )>, @@ -177,21 +177,21 @@ impl Dataset { pub fn quads_for_subject<'a, 'b>( &'a self, - subject: impl Into>, + subject: impl Into>, ) -> impl Iterator> + 'a { let subject = self - .encoded_named_or_blank_node(subject) - .unwrap_or_else(InternedNamedOrBlankNode::impossible); + .encoded_subject(subject) + .unwrap_or_else(InternedSubject::impossible); self.interned_quads_for_subject(subject) .map(move |q| self.decode_spog(q)) } fn interned_quads_for_subject( &self, - subject: InternedNamedOrBlankNode, + subject: InternedSubject, ) -> impl Iterator< Item = ( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, @@ -231,7 +231,7 @@ impl Dataset { predicate: InternedNamedNode, ) -> impl Iterator< Item = ( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, @@ -242,13 +242,13 @@ impl Dataset { &( predicate, InternedTerm::first(), - InternedNamedOrBlankNode::first(), + InternedSubject::first(), InternedGraphName::first(), ) ..&( predicate.next(), InternedTerm::first(), - InternedNamedOrBlankNode::first(), + InternedSubject::first(), InternedGraphName::first(), ), ) @@ -273,7 +273,7 @@ impl Dataset { object: InternedTerm, ) -> impl Iterator< Item = ( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, @@ -283,13 +283,13 @@ impl Dataset { .range( &( object, - InternedNamedOrBlankNode::first(), + InternedSubject::first(), InternedNamedNode::first(), InternedGraphName::first(), ) ..&( object.next(), - InternedNamedOrBlankNode::first(), + InternedSubject::first(), InternedNamedNode::first(), InternedGraphName::first(), ), @@ -303,7 +303,7 @@ impl Dataset { graph_name: InternedGraphName, ) -> impl Iterator< Item = ( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, @@ -313,13 +313,13 @@ impl Dataset { .range( &( graph_name, - InternedNamedOrBlankNode::first(), + InternedSubject::first(), InternedNamedNode::first(), InternedTerm::first(), ) ..&( graph_name.next(), - InternedNamedOrBlankNode::first(), + InternedSubject::first(), InternedNamedNode::first(), InternedTerm::first(), ), @@ -356,7 +356,7 @@ impl Dataset { fn insert_encoded( &mut self, quad: ( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, @@ -383,7 +383,7 @@ impl Dataset { fn remove_encoded( &mut self, quad: ( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, @@ -483,13 +483,13 @@ impl Dataset { &mut self, quad: QuadRef<'_>, ) -> ( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, ) { ( - InternedNamedOrBlankNode::encoded_into(quad.subject, &mut self.interner), + InternedSubject::encoded_into(quad.subject, &mut self.interner), InternedNamedNode::encoded_into(quad.predicate, &mut self.interner), InternedTerm::encoded_into(quad.object, &mut self.interner), InternedGraphName::encoded_into(quad.graph_name, &mut self.interner), @@ -500,13 +500,13 @@ impl Dataset { &self, quad: QuadRef<'_>, ) -> Option<( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, )> { Some(( - self.encoded_named_or_blank_node(quad.subject)?, + self.encoded_subject(quad.subject)?, self.encoded_named_node(quad.predicate)?, self.encoded_term(quad.object)?, self.encoded_graph_name(quad.graph_name)?, @@ -520,11 +520,11 @@ impl Dataset { InternedNamedNode::encoded_from(node.into(), &self.interner) } - pub(super) fn encoded_named_or_blank_node<'a>( + pub(super) fn encoded_subject<'a>( &self, - node: impl Into>, - ) -> Option { - InternedNamedOrBlankNode::encoded_from(node.into(), &self.interner) + node: impl Into>, + ) -> Option { + InternedSubject::encoded_from(node.into(), &self.interner) } pub(super) fn encoded_term<'a>(&self, term: impl Into>) -> Option { @@ -541,7 +541,7 @@ impl Dataset { fn decode_spog( &self, quad: ( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, @@ -597,7 +597,7 @@ impl Dataset { fn blank_nodes(&self) -> HashSet { let mut bnodes = HashSet::new(); for (g, s, _, o) in &self.gspo { - if let InternedNamedOrBlankNode::BlankNode(bnode) = s { + if let InternedSubject::BlankNode(bnode) = s { bnodes.insert(*bnode); } if let InternedTerm::BlankNode(bnode) = o { @@ -625,7 +625,7 @@ impl Dataset { let mut new_hashes = HashMap::new(); for (bnode, old_hash) in &hashes { for (_, p, o, g) in - self.interned_quads_for_subject(InternedNamedOrBlankNode::BlankNode(*bnode)) + self.interned_quads_for_subject(InternedSubject::BlankNode(*bnode)) { to_hash.push(( self.hash_named_node(p), @@ -637,7 +637,7 @@ impl Dataset { for (s, p, _, g) in self.interned_quads_for_object(InternedTerm::BlankNode(*bnode)) { to_hash.push(( - self.hash_named_or_blank_node(s, &hashes), + self.hash_subject(s, &hashes), self.hash_named_node(p), self.hash_graph_name(g, &hashes), 1, @@ -647,7 +647,7 @@ impl Dataset { self.interned_quads_for_graph_name(InternedGraphName::BlankNode(*bnode)) { to_hash.push(( - self.hash_named_or_blank_node(s, &hashes), + self.hash_subject(s, &hashes), self.hash_named_node(p), self.hash_term(o, &hashes), 2, @@ -674,12 +674,12 @@ impl Dataset { self.hash_tuple(node.decode_from(&self.interner)) } - fn hash_named_or_blank_node( + fn hash_subject( &self, - node: InternedNamedOrBlankNode, + node: InternedSubject, bnodes_hash: &HashMap, ) -> u64 { - if let InternedNamedOrBlankNode::BlankNode(bnode) = node { + if let InternedSubject::BlankNode(bnode) = node { *bnodes_hash.get(&bnode).unwrap() } else { self.hash_tuple(node.decode_from(&self.interner)) @@ -717,7 +717,7 @@ impl Dataset { hash: &HashMap, partition: &[(u64, Vec)], ) -> Vec<( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, @@ -755,7 +755,7 @@ impl Dataset { &mut self, hashes: &HashMap, ) -> Vec<( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, @@ -765,8 +765,8 @@ impl Dataset { .into_iter() .map(|(s, p, o, g)| { ( - if let InternedNamedOrBlankNode::BlankNode(bnode) = s { - InternedNamedOrBlankNode::BlankNode(self.map_bnode(bnode, hashes)) + if let InternedSubject::BlankNode(bnode) = s { + InternedSubject::BlankNode(self.map_bnode(bnode, hashes)) } else { s }, @@ -894,13 +894,13 @@ impl<'a> GraphView<'a> { let iter = self.dataset.gspo.range( &( self.graph_name, - InternedNamedOrBlankNode::first(), + InternedSubject::first(), InternedNamedNode::first(), InternedTerm::first(), ) ..&( self.graph_name.next(), - InternedNamedOrBlankNode::first(), + InternedSubject::first(), InternedNamedNode::first(), InternedTerm::first(), ), @@ -913,16 +913,16 @@ impl<'a> GraphView<'a> { pub fn triples_for_subject<'b>( self, - subject: impl Into>, + subject: impl Into>, ) -> impl Iterator> + 'a { - self.triples_for_interned_subject(self.dataset.encoded_named_or_blank_node(subject)) + self.triples_for_interned_subject(self.dataset.encoded_subject(subject)) } pub(super) fn triples_for_interned_subject( self, - subject: Option, + subject: Option, ) -> impl Iterator> + 'a { - let subject = subject.unwrap_or_else(InternedNamedOrBlankNode::impossible); + let subject = subject.unwrap_or_else(InternedSubject::impossible); self.dataset .gspo .range( @@ -944,21 +944,21 @@ impl<'a> GraphView<'a> { pub fn objects_for_subject_predicate<'b>( self, - subject: impl Into>, + subject: impl Into>, predicate: impl Into>, ) -> impl Iterator> + 'a { self.objects_for_interned_subject_predicate( - self.dataset.encoded_named_or_blank_node(subject), + self.dataset.encoded_subject(subject), self.dataset.encoded_named_node(predicate), ) } pub fn objects_for_interned_subject_predicate( self, - subject: Option, + subject: Option, predicate: Option, ) -> impl Iterator> + 'a { - let subject = subject.unwrap_or_else(InternedNamedOrBlankNode::impossible); + let subject = subject.unwrap_or_else(InternedSubject::impossible); let predicate = predicate.unwrap_or_else(InternedNamedNode::impossible); self.dataset .gspo @@ -976,7 +976,7 @@ impl<'a> GraphView<'a> { pub fn object_for_subject_predicate<'b>( self, - subject: impl Into>, + subject: impl Into>, predicate: impl Into>, ) -> Option> { self.objects_for_subject_predicate(subject, predicate) @@ -985,21 +985,21 @@ impl<'a> GraphView<'a> { pub fn predicates_for_subject_object<'b>( self, - subject: impl Into>, + subject: impl Into>, object: impl Into>, ) -> impl Iterator> + 'a { self.predicates_for_interned_subject_object( - self.dataset.encoded_named_or_blank_node(subject), + self.dataset.encoded_subject(subject), self.dataset.encoded_term(object), ) } pub(super) fn predicates_for_interned_subject_object( self, - subject: Option, + subject: Option, object: Option, ) -> impl Iterator> + 'a { - let subject = subject.unwrap_or_else(InternedNamedOrBlankNode::impossible); + let subject = subject.unwrap_or_else(InternedSubject::impossible); let object = object.unwrap_or_else(InternedTerm::impossible); self.dataset .gosp @@ -1034,13 +1034,13 @@ impl<'a> GraphView<'a> { self.graph_name, predicate, InternedTerm::first(), - InternedNamedOrBlankNode::first(), + InternedSubject::first(), ) ..&( self.graph_name, predicate.next(), InternedTerm::first(), - InternedNamedOrBlankNode::first(), + InternedSubject::first(), ), ) .map(move |q| self.decode_gpos(*q)) @@ -1050,7 +1050,7 @@ impl<'a> GraphView<'a> { self, predicate: impl Into>, object: impl Into>, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a { self.subjects_for_interned_predicate_object( self.dataset.encoded_named_node(predicate), self.dataset.encoded_term(object), @@ -1061,23 +1061,18 @@ impl<'a> GraphView<'a> { self, predicate: Option, object: Option, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a { let predicate = predicate.unwrap_or_else(InternedNamedNode::impossible); let object = object.unwrap_or_else(InternedTerm::impossible); self.dataset .gpos .range( - &( - self.graph_name, - predicate, - object, - InternedNamedOrBlankNode::first(), - ) + &(self.graph_name, predicate, object, InternedSubject::first()) ..&( self.graph_name, predicate, object.next(), - InternedNamedOrBlankNode::first(), + InternedSubject::first(), ), ) .map(move |q| q.3.decode_from(&self.dataset.interner)) @@ -1087,7 +1082,7 @@ impl<'a> GraphView<'a> { self, predicate: impl Into>, object: impl Into>, - ) -> Option> { + ) -> Option> { self.subjects_for_predicate_object(predicate, object).next() } @@ -1109,13 +1104,13 @@ impl<'a> GraphView<'a> { &( self.graph_name, object, - InternedNamedOrBlankNode::first(), + InternedSubject::first(), InternedNamedNode::first(), ) ..&( self.graph_name, object.next(), - InternedNamedOrBlankNode::first(), + InternedSubject::first(), InternedNamedNode::first(), ), ) @@ -1169,9 +1164,9 @@ impl<'a> GraphView<'a> { fn encoded_triple( &self, triple: TripleRef<'_>, - ) -> Option<(InternedNamedOrBlankNode, InternedNamedNode, InternedTerm)> { + ) -> Option<(InternedSubject, InternedNamedNode, InternedTerm)> { Some(( - self.dataset.encoded_named_or_blank_node(triple.subject)?, + self.dataset.encoded_subject(triple.subject)?, self.dataset.encoded_named_node(triple.predicate)?, self.dataset.encoded_term(triple.object)?, )) @@ -1181,7 +1176,7 @@ impl<'a> GraphView<'a> { self, quad: ( InternedGraphName, - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, ), @@ -1199,7 +1194,7 @@ impl<'a> GraphView<'a> { InternedGraphName, InternedNamedNode, InternedTerm, - InternedNamedOrBlankNode, + InternedSubject, ), ) -> TripleRef<'a> { self.decode_gspo((quad.0, quad.3, quad.1, quad.2)) @@ -1210,7 +1205,7 @@ impl<'a> GraphView<'a> { quad: ( InternedGraphName, InternedTerm, - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, ), ) -> TripleRef<'a> { @@ -1344,9 +1339,9 @@ impl<'a> GraphViewMut<'a> { fn encode_triple( &mut self, triple: TripleRef<'_>, - ) -> (InternedNamedOrBlankNode, InternedNamedNode, InternedTerm) { + ) -> (InternedSubject, InternedNamedNode, InternedTerm) { ( - InternedNamedOrBlankNode::encoded_into(triple.subject, &mut self.dataset.interner), + InternedSubject::encoded_into(triple.subject, &mut self.dataset.interner), InternedNamedNode::encoded_into(triple.predicate, &mut self.dataset.interner), InternedTerm::encoded_into(triple.object, &mut self.dataset.interner), ) @@ -1359,26 +1354,26 @@ impl<'a> GraphViewMut<'a> { pub fn triples_for_subject<'b>( &'a self, - subject: impl Into>, + subject: impl Into>, ) -> impl Iterator> + 'a { self.read() - .triples_for_interned_subject(self.dataset.encoded_named_or_blank_node(subject)) + .triples_for_interned_subject(self.dataset.encoded_subject(subject)) } pub fn objects_for_subject_predicate<'b>( &'a self, - subject: impl Into>, + subject: impl Into>, predicate: impl Into>, ) -> impl Iterator> + 'a { self.read().objects_for_interned_subject_predicate( - self.dataset.encoded_named_or_blank_node(subject), + self.dataset.encoded_subject(subject), self.dataset.encoded_named_node(predicate), ) } pub fn object_for_subject_predicate<'b>( &'a self, - subject: impl Into>, + subject: impl Into>, predicate: impl Into>, ) -> Option> { self.read().object_for_subject_predicate(subject, predicate) @@ -1386,11 +1381,11 @@ impl<'a> GraphViewMut<'a> { pub fn predicates_for_subject_object<'b>( &'a self, - subject: impl Into>, + subject: impl Into>, object: impl Into>, ) -> impl Iterator> + 'a { self.read().predicates_for_interned_subject_object( - self.dataset.encoded_named_or_blank_node(subject), + self.dataset.encoded_subject(subject), self.dataset.encoded_term(object), ) } @@ -1407,7 +1402,7 @@ impl<'a> GraphViewMut<'a> { &'a self, predicate: impl Into>, object: impl Into>, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a { self.read().subjects_for_interned_predicate_object( self.dataset.encoded_named_node(predicate), self.dataset.encoded_term(object), @@ -1418,7 +1413,7 @@ impl<'a> GraphViewMut<'a> { &'a self, predicate: impl Into>, object: impl Into>, - ) -> Option> { + ) -> Option> { self.read().subject_for_predicate_object(predicate, object) } @@ -1509,7 +1504,7 @@ pub struct Iter<'a> { inner: std::collections::btree_set::Iter< 'a, ( - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, InternedGraphName, @@ -1532,7 +1527,7 @@ pub struct GraphViewIter<'a> { 'a, ( InternedGraphName, - InternedNamedOrBlankNode, + InternedSubject, InternedNamedNode, InternedTerm, ), diff --git a/lib/src/model/graph.rs b/lib/src/model/graph.rs index 9b25042e..557238d1 100644 --- a/lib/src/model/graph.rs +++ b/lib/src/model/graph.rs @@ -76,26 +76,26 @@ impl Graph { pub fn triples_for_subject<'a, 'b>( &'a self, - subject: impl Into>, + subject: impl Into>, ) -> impl Iterator> + 'a { self.graph() - .triples_for_interned_subject(self.dataset.encoded_named_or_blank_node(subject)) + .triples_for_interned_subject(self.dataset.encoded_subject(subject)) } pub fn objects_for_subject_predicate<'a, 'b>( &'a self, - subject: impl Into>, + subject: impl Into>, predicate: impl Into>, ) -> impl Iterator> + 'a { self.graph().objects_for_interned_subject_predicate( - self.dataset.encoded_named_or_blank_node(subject), + self.dataset.encoded_subject(subject), self.dataset.encoded_named_node(predicate), ) } pub fn object_for_subject_predicate<'a, 'b>( &'a self, - subject: impl Into>, + subject: impl Into>, predicate: impl Into>, ) -> Option> { self.graph() @@ -105,11 +105,11 @@ impl Graph { pub fn predicates_for_subject_object<'a, 'b>( &'a self, - subject: impl Into>, + subject: impl Into>, object: impl Into>, ) -> impl Iterator> + 'a { self.graph().predicates_for_interned_subject_object( - self.dataset.encoded_named_or_blank_node(subject), + self.dataset.encoded_subject(subject), self.dataset.encoded_term(object), ) } @@ -126,7 +126,7 @@ impl Graph { &'a self, predicate: impl Into>, object: impl Into>, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a { self.graph().subjects_for_interned_predicate_object( self.dataset.encoded_named_node(predicate), self.dataset.encoded_term(object), @@ -137,7 +137,7 @@ impl Graph { &'a self, predicate: impl Into>, object: impl Into>, - ) -> Option> { + ) -> Option> { self.graph().subject_for_predicate_object(predicate, object) } diff --git a/lib/src/model/interning.rs b/lib/src/model/interning.rs index 93ad232c..abdccea9 100644 --- a/lib/src/model/interning.rs +++ b/lib/src/model/interning.rs @@ -166,38 +166,38 @@ impl InternedLiteral { } #[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Copy, Hash)] -pub enum InternedNamedOrBlankNode { +pub enum InternedSubject { NamedNode(InternedNamedNode), BlankNode(InternedBlankNode), } -impl InternedNamedOrBlankNode { - pub fn encoded_into(node: NamedOrBlankNodeRef<'_>, interner: &mut Rodeo) -> Self { +impl InternedSubject { + pub fn encoded_into(node: SubjectRef<'_>, interner: &mut Rodeo) -> Self { match node { - NamedOrBlankNodeRef::NamedNode(node) => { + SubjectRef::NamedNode(node) => { Self::NamedNode(InternedNamedNode::encoded_into(node, interner)) } - NamedOrBlankNodeRef::BlankNode(node) => { + SubjectRef::BlankNode(node) => { Self::BlankNode(InternedBlankNode::encoded_into(node, interner)) } } } - pub fn encoded_from(node: NamedOrBlankNodeRef<'_>, interner: &Rodeo) -> Option { + pub fn encoded_from(node: SubjectRef<'_>, interner: &Rodeo) -> Option { Some(match node { - NamedOrBlankNodeRef::NamedNode(node) => { + SubjectRef::NamedNode(node) => { Self::NamedNode(InternedNamedNode::encoded_from(node, interner)?) } - NamedOrBlankNodeRef::BlankNode(node) => { + SubjectRef::BlankNode(node) => { Self::BlankNode(InternedBlankNode::encoded_from(node, interner)?) } }) } - pub fn decode_from<'a>(&self, interner: &'a Rodeo) -> NamedOrBlankNodeRef<'a> { + pub fn decode_from<'a>(&self, interner: &'a Rodeo) -> SubjectRef<'a> { match self { - Self::NamedNode(node) => NamedOrBlankNodeRef::NamedNode(node.decode_from(interner)), - Self::BlankNode(node) => NamedOrBlankNodeRef::BlankNode(node.decode_from(interner)), + Self::NamedNode(node) => SubjectRef::NamedNode(node.decode_from(interner)), + Self::BlankNode(node) => SubjectRef::BlankNode(node.decode_from(interner)), } } diff --git a/lib/src/model/mod.rs b/lib/src/model/mod.rs index 220fdbb0..044c7ec1 100644 --- a/lib/src/model/mod.rs +++ b/lib/src/model/mod.rs @@ -22,8 +22,7 @@ pub use self::literal::{Literal, LiteralRef}; pub use self::named_node::{NamedNode, NamedNodeRef}; pub use self::parser::TermParseError; pub use self::triple::{ - GraphName, GraphNameRef, NamedOrBlankNode, NamedOrBlankNodeRef, Quad, QuadRef, Term, TermRef, - Triple, TripleRef, + GraphName, GraphNameRef, Quad, QuadRef, Subject, SubjectRef, Term, TermRef, Triple, TripleRef, }; pub use oxilangtag::LanguageTagParseError; pub use oxiri::IriParseError; diff --git a/lib/src/model/sophia.rs b/lib/src/model/sophia.rs index aa29b4e6..135f1e16 100644 --- a/lib/src/model/sophia.rs +++ b/lib/src/model/sophia.rs @@ -189,9 +189,9 @@ impl<'a> From> for Option> { } } -impl TTerm for NamedOrBlankNode { +impl TTerm for Subject { fn kind(&self) -> TermKind { - use NamedOrBlankNode::*; + use Subject::*; match self { NamedNode(_) => TermKind::Iri, BlankNode(_) => TermKind::BlankNode, @@ -199,7 +199,7 @@ impl TTerm for NamedOrBlankNode { } fn value_raw(&self) -> RawValue<'_> { - use NamedOrBlankNode::*; + use Subject::*; match self { NamedNode(n) => n.value_raw(), BlankNode(n) => n.value_raw(), @@ -207,7 +207,7 @@ impl TTerm for NamedOrBlankNode { } fn as_dyn(&self) -> &dyn TTerm { - use NamedOrBlankNode::*; + use Subject::*; match self { NamedNode(n) => n.as_dyn(), BlankNode(n) => n.as_dyn(), @@ -215,7 +215,7 @@ impl TTerm for NamedOrBlankNode { } } -impl TryCopyTerm for NamedOrBlankNode { +impl TryCopyTerm for Subject { type Error = SophiaToOxigraphConversionError; fn try_copy(other: &T) -> Result @@ -230,9 +230,9 @@ impl TryCopyTerm for NamedOrBlankNode { } } -impl<'a> TTerm for NamedOrBlankNodeRef<'a> { +impl<'a> TTerm for SubjectRef<'a> { fn kind(&self) -> TermKind { - use NamedOrBlankNodeRef::*; + use SubjectRef::*; match self { NamedNode(_) => TermKind::Iri, BlankNode(_) => TermKind::BlankNode, @@ -240,7 +240,7 @@ impl<'a> TTerm for NamedOrBlankNodeRef<'a> { } fn value_raw(&self) -> RawValue<'_> { - use NamedOrBlankNodeRef::*; + use SubjectRef::*; match self { NamedNode(n) => n.value_raw(), BlankNode(n) => n.value_raw(), @@ -248,7 +248,7 @@ impl<'a> TTerm for NamedOrBlankNodeRef<'a> { } fn as_dyn(&self) -> &dyn TTerm { - use NamedOrBlankNodeRef::*; + use SubjectRef::*; match self { NamedNode(n) => n.as_dyn(), BlankNode(n) => n.as_dyn(), diff --git a/lib/src/model/triple.rs b/lib/src/model/triple.rs index 9c5272fb..2908253a 100644 --- a/lib/src/model/triple.rs +++ b/lib/src/model/triple.rs @@ -7,12 +7,12 @@ use std::fmt; /// The owned union of [IRIs](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) and [blank nodes](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node). #[derive(Eq, PartialEq, Debug, Clone, Hash)] -pub enum NamedOrBlankNode { +pub enum Subject { NamedNode(NamedNode), BlankNode(BlankNode), } -impl NamedOrBlankNode { +impl Subject { #[inline] pub fn is_named_node(&self) -> bool { self.as_ref().is_named_node() @@ -24,43 +24,43 @@ impl NamedOrBlankNode { } #[inline] - pub fn as_ref(&self) -> NamedOrBlankNodeRef<'_> { + pub fn as_ref(&self) -> SubjectRef<'_> { match self { - Self::NamedNode(node) => NamedOrBlankNodeRef::NamedNode(node.as_ref()), - Self::BlankNode(node) => NamedOrBlankNodeRef::BlankNode(node.as_ref()), + Self::NamedNode(node) => SubjectRef::NamedNode(node.as_ref()), + Self::BlankNode(node) => SubjectRef::BlankNode(node.as_ref()), } } } -impl fmt::Display for NamedOrBlankNode { +impl fmt::Display for Subject { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.as_ref().fmt(f) } } -impl From for NamedOrBlankNode { +impl From for Subject { #[inline] fn from(node: NamedNode) -> Self { Self::NamedNode(node) } } -impl From> for NamedOrBlankNode { +impl From> for Subject { #[inline] fn from(node: NamedNodeRef<'_>) -> Self { node.into_owned().into() } } -impl From for NamedOrBlankNode { +impl From for Subject { #[inline] fn from(node: BlankNode) -> Self { Self::BlankNode(node) } } -impl From> for NamedOrBlankNode { +impl From> for Subject { #[inline] fn from(node: BlankNodeRef<'_>) -> Self { node.into_owned().into() @@ -69,12 +69,12 @@ impl From> for NamedOrBlankNode { /// The borrowed union of [IRIs](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) and [blank nodes](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node). #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] -pub enum NamedOrBlankNodeRef<'a> { +pub enum SubjectRef<'a> { NamedNode(NamedNodeRef<'a>), BlankNode(BlankNodeRef<'a>), } -impl<'a> NamedOrBlankNodeRef<'a> { +impl<'a> SubjectRef<'a> { #[inline] pub fn is_named_node(&self) -> bool { match self { @@ -92,15 +92,15 @@ impl<'a> NamedOrBlankNodeRef<'a> { } #[inline] - pub fn into_owned(self) -> NamedOrBlankNode { + pub fn into_owned(self) -> Subject { match self { - Self::NamedNode(node) => NamedOrBlankNode::NamedNode(node.into_owned()), - Self::BlankNode(node) => NamedOrBlankNode::BlankNode(node.into_owned()), + Self::NamedNode(node) => Subject::NamedNode(node.into_owned()), + Self::BlankNode(node) => Subject::BlankNode(node.into_owned()), } } } -impl fmt::Display for NamedOrBlankNodeRef<'_> { +impl fmt::Display for SubjectRef<'_> { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -110,54 +110,54 @@ impl fmt::Display for NamedOrBlankNodeRef<'_> { } } -impl<'a> From> for NamedOrBlankNodeRef<'a> { +impl<'a> From> for SubjectRef<'a> { #[inline] fn from(node: NamedNodeRef<'a>) -> Self { Self::NamedNode(node) } } -impl<'a> From<&'a NamedNode> for NamedOrBlankNodeRef<'a> { +impl<'a> From<&'a NamedNode> for SubjectRef<'a> { #[inline] fn from(node: &'a NamedNode) -> Self { node.as_ref().into() } } -impl<'a> From> for NamedOrBlankNodeRef<'a> { +impl<'a> From> for SubjectRef<'a> { #[inline] fn from(node: BlankNodeRef<'a>) -> Self { Self::BlankNode(node) } } -impl<'a> From<&'a BlankNode> for NamedOrBlankNodeRef<'a> { +impl<'a> From<&'a BlankNode> for SubjectRef<'a> { #[inline] fn from(node: &'a BlankNode) -> Self { node.as_ref().into() } } -impl<'a> From<&'a NamedOrBlankNode> for NamedOrBlankNodeRef<'a> { +impl<'a> From<&'a Subject> for SubjectRef<'a> { #[inline] - fn from(node: &'a NamedOrBlankNode) -> Self { + fn from(node: &'a Subject) -> Self { node.as_ref() } } -impl<'a> From> for NamedOrBlankNode { +impl<'a> From> for Subject { #[inline] - fn from(node: NamedOrBlankNodeRef<'a>) -> Self { + fn from(node: SubjectRef<'a>) -> Self { node.into_owned() } } -impl<'a> From> for rio::NamedOrBlankNode<'a> { +impl<'a> From> for rio::NamedOrBlankNode<'a> { #[inline] - fn from(node: NamedOrBlankNodeRef<'a>) -> Self { + fn from(node: SubjectRef<'a>) -> Self { match node { - NamedOrBlankNodeRef::NamedNode(node) => rio::NamedNode::from(node).into(), - NamedOrBlankNodeRef::BlankNode(node) => rio::BlankNode::from(node).into(), + SubjectRef::NamedNode(node) => rio::NamedNode::from(node).into(), + SubjectRef::BlankNode(node) => rio::BlankNode::from(node).into(), } } } @@ -246,19 +246,19 @@ impl From> for Term { } } -impl From for Term { +impl From for Term { #[inline] - fn from(node: NamedOrBlankNode) -> Self { + fn from(node: Subject) -> Self { match node { - NamedOrBlankNode::NamedNode(node) => node.into(), - NamedOrBlankNode::BlankNode(node) => node.into(), + Subject::NamedNode(node) => node.into(), + Subject::BlankNode(node) => node.into(), } } } -impl From> for Term { +impl From> for Term { #[inline] - fn from(node: NamedOrBlankNodeRef<'_>) -> Self { + fn from(node: SubjectRef<'_>) -> Self { node.into_owned().into() } } @@ -351,19 +351,19 @@ impl<'a> From<&'a Literal> for TermRef<'a> { } } -impl<'a> From> for TermRef<'a> { +impl<'a> From> for TermRef<'a> { #[inline] - fn from(node: NamedOrBlankNodeRef<'a>) -> Self { + fn from(node: SubjectRef<'a>) -> Self { match node { - NamedOrBlankNodeRef::NamedNode(node) => node.into(), - NamedOrBlankNodeRef::BlankNode(node) => node.into(), + SubjectRef::NamedNode(node) => node.into(), + SubjectRef::BlankNode(node) => node.into(), } } } -impl<'a> From<&'a NamedOrBlankNode> for TermRef<'a> { +impl<'a> From<&'a Subject> for TermRef<'a> { #[inline] - fn from(node: &'a NamedOrBlankNode) -> Self { + fn from(node: &'a Subject) -> Self { node.as_ref().into() } } @@ -397,7 +397,7 @@ impl<'a> From> for rio::Term<'a> { #[derive(Eq, PartialEq, Debug, Clone, Hash)] pub struct Triple { /// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple - pub subject: NamedOrBlankNode, + pub subject: Subject, /// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple pub predicate: NamedNode, @@ -410,7 +410,7 @@ impl Triple { /// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) #[inline] pub fn new( - subject: impl Into, + subject: impl Into, predicate: impl Into, object: impl Into, ) -> Self { @@ -453,7 +453,7 @@ impl fmt::Display for Triple { #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] pub struct TripleRef<'a> { /// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple - pub subject: NamedOrBlankNodeRef<'a>, + pub subject: SubjectRef<'a>, /// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple pub predicate: NamedNodeRef<'a>, @@ -466,7 +466,7 @@ impl<'a> TripleRef<'a> { /// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) #[inline] pub fn new( - subject: impl Into>, + subject: impl Into>, predicate: impl Into>, object: impl Into>, ) -> Self { @@ -600,26 +600,26 @@ impl From> for GraphName { } } -impl From for GraphName { +impl From for GraphName { #[inline] - fn from(node: NamedOrBlankNode) -> Self { + fn from(node: Subject) -> Self { match node { - NamedOrBlankNode::NamedNode(node) => node.into(), - NamedOrBlankNode::BlankNode(node) => node.into(), + Subject::NamedNode(node) => node.into(), + Subject::BlankNode(node) => node.into(), } } } -impl From> for GraphName { +impl From> for GraphName { #[inline] - fn from(node: NamedOrBlankNodeRef<'_>) -> Self { + fn from(node: SubjectRef<'_>) -> Self { node.into_owned().into() } } -impl From> for GraphName { +impl From> for GraphName { #[inline] - fn from(name: Option) -> Self { + fn from(name: Option) -> Self { if let Some(node) = name { node.into() } else { @@ -628,7 +628,7 @@ impl From> for GraphName { } } -impl From for Option { +impl From for Option { #[inline] fn from(name: GraphName) -> Self { match name { @@ -713,19 +713,19 @@ impl<'a> From<&'a BlankNode> for GraphNameRef<'a> { } } -impl<'a> From> for GraphNameRef<'a> { +impl<'a> From> for GraphNameRef<'a> { #[inline] - fn from(node: NamedOrBlankNodeRef<'a>) -> Self { + fn from(node: SubjectRef<'a>) -> Self { match node { - NamedOrBlankNodeRef::NamedNode(node) => node.into(), - NamedOrBlankNodeRef::BlankNode(node) => node.into(), + SubjectRef::NamedNode(node) => node.into(), + SubjectRef::BlankNode(node) => node.into(), } } } -impl<'a> From<&'a NamedOrBlankNode> for GraphNameRef<'a> { +impl<'a> From<&'a Subject> for GraphNameRef<'a> { #[inline] - fn from(node: &'a NamedOrBlankNode) -> Self { + fn from(node: &'a Subject) -> Self { node.as_ref().into() } } @@ -744,9 +744,9 @@ impl<'a> From> for GraphName { } } -impl<'a> From>> for GraphNameRef<'a> { +impl<'a> From>> for GraphNameRef<'a> { #[inline] - fn from(name: Option>) -> Self { + fn from(name: Option>) -> Self { if let Some(node) = name { node.into() } else { @@ -755,7 +755,7 @@ impl<'a> From>> for GraphNameRef<'a> { } } -impl<'a> From> for Option> { +impl<'a> From> for Option> { #[inline] fn from(name: GraphNameRef<'a>) -> Self { match name { @@ -781,7 +781,7 @@ impl<'a> From> for Option> { #[derive(Eq, PartialEq, Debug, Clone, Hash)] pub struct Quad { /// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple - pub subject: NamedOrBlankNode, + pub subject: Subject, /// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple pub predicate: NamedNode, @@ -797,7 +797,7 @@ impl Quad { /// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) #[inline] pub fn new( - subject: impl Into, + subject: impl Into, predicate: impl Into, object: impl Into, graph_name: impl Into, @@ -843,7 +843,7 @@ impl From for Triple { #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] pub struct QuadRef<'a> { /// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple - pub subject: NamedOrBlankNodeRef<'a>, + pub subject: SubjectRef<'a>, /// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple pub predicate: NamedNodeRef<'a>, @@ -859,7 +859,7 @@ impl<'a> QuadRef<'a> { /// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) #[inline] pub fn new( - subject: impl Into>, + subject: impl Into>, predicate: impl Into>, object: impl Into>, graph_name: impl Into>, diff --git a/lib/src/sophia.rs b/lib/src/sophia.rs index d0558918..a9bb9408 100644 --- a/lib/src/sophia.rs +++ b/lib/src/sophia.rs @@ -1,8 +1,7 @@ //! This crate provides implementation of [Sophia](https://docs.rs/sophia/) traits for the `store` module. use crate::model::{ - BlankNodeRef, GraphNameRef, LiteralRef, NamedNodeRef, NamedOrBlankNodeRef, Quad, QuadRef, Term, - TermRef, + BlankNodeRef, GraphNameRef, LiteralRef, NamedNodeRef, Quad, QuadRef, SubjectRef, Term, TermRef, }; use crate::sparql::{EvaluationError, QueryResults}; use crate::store::Store; @@ -449,7 +448,7 @@ fn io_err_map(err: EvaluationError) -> Error { } } -fn convert_subject<'a, T>(term: &'a T, buffer: &'a mut String) -> Option> +fn convert_subject<'a, T>(term: &'a T, buffer: &'a mut String) -> Option> where T: TTerm + ?Sized + 'a, { diff --git a/lib/src/sparql/algebra.rs b/lib/src/sparql/algebra.rs index 44f17ae2..38a116d1 100644 --- a/lib/src/sparql/algebra.rs +++ b/lib/src/sparql/algebra.rs @@ -171,7 +171,7 @@ impl<'a> TryFrom<&'a String> for Update { #[derive(Eq, PartialEq, Debug, Clone, Hash)] pub struct QueryDataset { default: Option>, - named: Option>, + named: Option>, } impl QueryDataset { @@ -255,7 +255,7 @@ impl QueryDataset { } /// Returns the list of the available named graphs for the query or `None` if all graphs are available - pub fn available_named_graphs(&self) -> Option<&[NamedOrBlankNode]> { + pub fn available_named_graphs(&self) -> Option<&[Subject]> { self.named.as_deref() } @@ -272,7 +272,7 @@ impl QueryDataset { /// /// # Result::Ok::<_, Box>(()) /// ``` - pub fn set_available_named_graphs(&mut self, named_graphs: Vec) { + pub fn set_available_named_graphs(&mut self, named_graphs: Vec) { self.named = Some(named_graphs); } } diff --git a/lib/src/sparql/dataset.rs b/lib/src/sparql/dataset.rs index 38fa8ca0..61cb8c7e 100644 --- a/lib/src/sparql/dataset.rs +++ b/lib/src/sparql/dataset.rs @@ -1,8 +1,8 @@ use crate::sparql::algebra::QueryDataset; use crate::sparql::EvaluationError; use crate::storage::numeric_encoder::{ - get_encoded_graph_name, get_encoded_named_or_blank_node, EncodedQuad, EncodedTerm, - StrContainer, StrHash, StrLookup, + get_encoded_graph_name, get_encoded_subject, EncodedQuad, EncodedTerm, StrContainer, StrHash, + StrLookup, }; use crate::storage::Storage; use std::cell::RefCell; @@ -28,7 +28,7 @@ impl DatasetView { named: dataset.available_named_graphs().map(|graphs| { graphs .iter() - .map(|g| get_encoded_named_or_blank_node(g.as_ref())) + .map(|g| get_encoded_subject(g.as_ref())) .collect::>() }), }; diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index e184bf10..5098d292 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -2668,7 +2668,7 @@ fn decode_triple( object: &EncodedTerm, ) -> Result { Ok(Triple::new( - decoder.decode_named_or_blank_node(subject)?, + decoder.decode_subject(subject)?, decoder.decode_named_node(predicate)?, decoder.decode_term(object)?, )) diff --git a/lib/src/sparql/update.rs b/lib/src/sparql/update.rs index 82222ea8..cd19b98d 100644 --- a/lib/src/sparql/update.rs +++ b/lib/src/sparql/update.rs @@ -19,8 +19,8 @@ use oxiri::Iri; use spargebra::algebra::{GraphPattern, GraphTarget}; use spargebra::term::{ BlankNode, GraphName, GraphNamePattern, GroundQuad, GroundQuadPattern, GroundTerm, - GroundTermPattern, Literal, NamedNode, NamedNodePattern, NamedOrBlankNode, Quad, QuadPattern, - Term, TermPattern, Variable, + GroundTermPattern, Literal, NamedNode, NamedNodePattern, Quad, QuadPattern, Subject, Term, + TermPattern, Variable, }; use spargebra::GraphUpdateOperation; use std::collections::HashMap; @@ -301,10 +301,8 @@ impl<'a> SimpleUpdateEvaluator<'a> { ) -> Result, EvaluationError> { Ok(Some(EncodedQuad { subject: match &quad.subject { - NamedOrBlankNode::NamedNode(subject) => { - self.encode_named_node_for_insertion(subject)? - } - NamedOrBlankNode::BlankNode(subject) => self + Subject::NamedNode(subject) => self.encode_named_node_for_insertion(subject)?, + Subject::BlankNode(subject) => self .storage .encode_blank_node(bnodes.entry(subject.clone()).or_default().as_ref())?, }, diff --git a/lib/src/storage/numeric_encoder.rs b/lib/src/storage/numeric_encoder.rs index 720e2ea0..94fe66a4 100644 --- a/lib/src/storage/numeric_encoder.rs +++ b/lib/src/storage/numeric_encoder.rs @@ -609,10 +609,10 @@ pub(crate) fn get_encoded_literal(literal: LiteralRef<'_>) -> EncodedTerm { } } -pub(crate) fn get_encoded_named_or_blank_node(term: NamedOrBlankNodeRef<'_>) -> EncodedTerm { +pub(crate) fn get_encoded_subject(term: SubjectRef<'_>) -> EncodedTerm { match term { - NamedOrBlankNodeRef::NamedNode(named_node) => get_encoded_named_node(named_node), - NamedOrBlankNodeRef::BlankNode(blank_node) => get_encoded_blank_node(blank_node), + SubjectRef::NamedNode(named_node) => get_encoded_named_node(named_node), + SubjectRef::BlankNode(blank_node) => get_encoded_blank_node(blank_node), } } @@ -634,7 +634,7 @@ pub(crate) fn get_encoded_graph_name(name: GraphNameRef<'_>) -> EncodedTerm { pub(crate) fn get_encoded_quad(quad: QuadRef<'_>) -> EncodedQuad { EncodedQuad { - subject: get_encoded_named_or_blank_node(quad.subject), + subject: get_encoded_subject(quad.subject), predicate: get_encoded_named_node(quad.predicate), object: get_encoded_term(quad.object), graph_name: get_encoded_graph_name(quad.graph_name), @@ -666,13 +666,10 @@ pub(crate) trait WriteEncoder: StrContainer { self.encode_rio_literal(literal.into()) } - fn encode_named_or_blank_node( - &self, - term: NamedOrBlankNodeRef<'_>, - ) -> Result { + fn encode_subject(&self, term: SubjectRef<'_>) -> Result { match term { - NamedOrBlankNodeRef::NamedNode(named_node) => self.encode_named_node(named_node), - NamedOrBlankNodeRef::BlankNode(blank_node) => self.encode_blank_node(blank_node), + SubjectRef::NamedNode(named_node) => self.encode_named_node(named_node), + SubjectRef::BlankNode(blank_node) => self.encode_blank_node(blank_node), } } @@ -694,7 +691,7 @@ pub(crate) trait WriteEncoder: StrContainer { fn encode_quad(&self, quad: QuadRef<'_>) -> Result { Ok(EncodedQuad { - subject: self.encode_named_or_blank_node(quad.subject)?, + subject: self.encode_subject(quad.subject)?, predicate: self.encode_named_node(quad.predicate)?, object: self.encode_term(quad.object)?, graph_name: self.encode_graph_name(quad.graph_name)?, @@ -707,7 +704,7 @@ pub(crate) trait WriteEncoder: StrContainer { graph_name: EncodedTerm, ) -> Result { Ok(EncodedQuad { - subject: self.encode_named_or_blank_node(triple.subject)?, + subject: self.encode_subject(triple.subject)?, predicate: self.encode_named_node(triple.predicate)?, object: self.encode_term(triple.object)?, graph_name, @@ -838,7 +835,7 @@ pub(crate) trait WriteEncoder: StrContainer { }) } - fn encode_rio_named_or_blank_node( + fn encode_rio_subject( &self, term: rio::NamedOrBlankNode<'_>, bnodes_map: &mut HashMap, @@ -869,11 +866,11 @@ pub(crate) trait WriteEncoder: StrContainer { bnodes_map: &mut HashMap, ) -> Result { Ok(EncodedQuad { - subject: self.encode_rio_named_or_blank_node(quad.subject, bnodes_map)?, + subject: self.encode_rio_subject(quad.subject, bnodes_map)?, predicate: self.encode_rio_named_node(quad.predicate)?, object: self.encode_rio_term(quad.object, bnodes_map)?, graph_name: match quad.graph_name { - Some(graph_name) => self.encode_rio_named_or_blank_node(graph_name, bnodes_map)?, + Some(graph_name) => self.encode_rio_subject(graph_name, bnodes_map)?, None => EncodedTerm::DefaultGraph, }, }) @@ -886,7 +883,7 @@ pub(crate) trait WriteEncoder: StrContainer { bnodes_map: &mut HashMap, ) -> Result { Ok(EncodedQuad { - subject: self.encode_rio_named_or_blank_node(triple.subject, bnodes_map)?, + subject: self.encode_rio_subject(triple.subject, bnodes_map)?, predicate: self.encode_rio_named_node(triple.predicate)?, object: self.encode_rio_term(triple.object, bnodes_map)?, graph_name, @@ -978,10 +975,7 @@ pub fn parse_day_time_duration_str(value: &str) -> Option { pub(crate) trait Decoder: StrLookup { fn decode_term(&self, encoded: &EncodedTerm) -> Result>; - fn decode_named_or_blank_node( - &self, - encoded: &EncodedTerm, - ) -> Result> { + fn decode_subject(&self, encoded: &EncodedTerm) -> Result> { match self.decode_term(encoded)? { Term::NamedNode(named_node) => Ok(named_node.into()), Term::BlankNode(blank_node) => Ok(blank_node.into()), @@ -1008,12 +1002,12 @@ pub(crate) trait Decoder: StrLookup { fn decode_quad(&self, encoded: &EncodedQuad) -> Result> { Ok(Quad::new( - self.decode_named_or_blank_node(&encoded.subject)?, + self.decode_subject(&encoded.subject)?, self.decode_named_node(&encoded.predicate)?, self.decode_term(&encoded.object)?, match &encoded.graph_name { EncodedTerm::DefaultGraph => None, - graph_name => Some(self.decode_named_or_blank_node(graph_name)?), + graph_name => Some(self.decode_subject(graph_name)?), }, )) } diff --git a/lib/src/store.rs b/lib/src/store.rs index 2ff7b6a3..124c1a0c 100644 --- a/lib/src/store.rs +++ b/lib/src/store.rs @@ -37,8 +37,8 @@ use crate::sparql::{ }; use crate::storage::io::{dump_dataset, dump_graph, load_dataset, load_graph}; use crate::storage::numeric_encoder::{ - get_encoded_graph_name, get_encoded_named_node, get_encoded_named_or_blank_node, - get_encoded_quad, get_encoded_term, Decoder, WriteEncoder, + get_encoded_graph_name, get_encoded_named_node, get_encoded_quad, get_encoded_subject, + get_encoded_term, Decoder, WriteEncoder, }; pub use crate::storage::ConflictableTransactionError; pub use crate::storage::TransactionError; @@ -164,14 +164,14 @@ impl Store { /// ``` pub fn quads_for_pattern( &self, - subject: Option>, + subject: Option>, predicate: Option>, object: Option>, graph_name: Option>, ) -> QuadIter { QuadIter { iter: self.storage.quads_for_pattern( - subject.map(get_encoded_named_or_blank_node).as_ref(), + subject.map(get_encoded_subject).as_ref(), predicate.map(get_encoded_named_node).as_ref(), object.map(get_encoded_term).as_ref(), graph_name.map(get_encoded_graph_name).as_ref(), @@ -441,13 +441,13 @@ impl Store { /// Usage example: /// ``` /// use oxigraph::store::Store; - /// use oxigraph::model::{NamedNode, QuadRef, NamedOrBlankNode}; + /// use oxigraph::model::{NamedNode, QuadRef, Subject}; /// /// let ex = NamedNode::new("http://example.com")?; /// let store = Store::new()?; /// store.insert(QuadRef::new(&ex, &ex, &ex, &ex))?; /// store.insert(QuadRef::new(&ex, &ex, &ex, None))?; - /// assert_eq!(vec![NamedOrBlankNode::from(ex)], store.named_graphs().collect::,_>>()?); + /// assert_eq!(vec![Subject::from(ex)], store.named_graphs().collect::,_>>()?); /// # Result::<_,Box>::Ok(()) /// ``` pub fn named_graphs(&self) -> GraphNameIter { @@ -472,9 +472,9 @@ impl Store { /// ``` pub fn contains_named_graph<'a>( &self, - graph_name: impl Into>, + graph_name: impl Into>, ) -> Result { - let graph_name = get_encoded_named_or_blank_node(graph_name.into()); + let graph_name = get_encoded_subject(graph_name.into()); self.storage.contains_named_graph(&graph_name) } @@ -495,9 +495,9 @@ impl Store { /// ``` pub fn insert_named_graph<'a>( &self, - graph_name: impl Into>, + graph_name: impl Into>, ) -> Result { - let graph_name = self.storage.encode_named_or_blank_node(graph_name.into())?; + let graph_name = self.storage.encode_subject(graph_name.into())?; self.storage.insert_named_graph(&graph_name) } @@ -549,9 +549,9 @@ impl Store { /// ``` pub fn remove_named_graph<'a>( &self, - graph_name: impl Into>, + graph_name: impl Into>, ) -> Result { - let graph_name = get_encoded_named_or_blank_node(graph_name.into()); + let graph_name = get_encoded_subject(graph_name.into()); self.storage.remove_named_graph(&graph_name) } @@ -714,9 +714,9 @@ impl Transaction<'_> { /// Returns `true` if the graph was not already in the store. pub fn insert_named_graph<'a>( &self, - graph_name: impl Into>, + graph_name: impl Into>, ) -> Result { - let graph_name = self.storage.encode_named_or_blank_node(graph_name.into())?; + let graph_name = self.storage.encode_subject(graph_name.into())?; self.storage.insert_named_graph(&graph_name) } } @@ -745,13 +745,13 @@ pub struct GraphNameIter { } impl Iterator for GraphNameIter { - type Item = Result; + type Item = Result; - fn next(&mut self) -> Option> { + fn next(&mut self) -> Option> { Some( - self.iter.next()?.and_then(|graph_name| { - Ok(self.store.storage.decode_named_or_blank_node(&graph_name)?) - }), + self.iter + .next()? + .and_then(|graph_name| Ok(self.store.storage.decode_subject(&graph_name)?)), ) } @@ -764,7 +764,7 @@ impl Iterator for GraphNameIter { fn store() -> Result<(), io::Error> { use crate::model::*; - let main_s = NamedOrBlankNode::from(BlankNode::default()); + let main_s = Subject::from(BlankNode::default()); let main_p = NamedNode::new("http://example.com").unwrap(); let main_o = Term::from(Literal::from(1)); let main_g = GraphName::from(BlankNode::default()); diff --git a/lib/tests/store.rs b/lib/tests/store.rs index 9f669449..675bc479 100644 --- a/lib/tests/store.rs +++ b/lib/tests/store.rs @@ -167,7 +167,7 @@ fn test_backward_compatibility() -> io::Result<()> { } assert!(store.contains_named_graph(graph_name)?); assert_eq!( - vec![NamedOrBlankNode::from(graph_name)], + vec![Subject::from(graph_name)], store.named_graphs().collect::>>()? ); }; diff --git a/python/src/model.rs b/python/src/model.rs index f30e67d0..02f33ae5 100644 --- a/python/src/model.rs +++ b/python/src/model.rs @@ -39,7 +39,7 @@ impl From for NamedNode { } } -impl From for NamedOrBlankNode { +impl From for Subject { fn from(node: PyNamedNode) -> Self { node.inner.into() } @@ -138,7 +138,7 @@ impl From for BlankNode { } } -impl From for NamedOrBlankNode { +impl From for Subject { fn from(node: PyBlankNode) -> Self { node.inner.into() } @@ -405,34 +405,34 @@ impl PyObjectProtocol for PyDefaultGraph { } #[derive(FromPyObject)] -pub enum PyNamedOrBlankNode { +pub enum PySubject { NamedNode(PyNamedNode), BlankNode(PyBlankNode), } -impl From for NamedOrBlankNode { - fn from(node: PyNamedOrBlankNode) -> Self { +impl From for Subject { + fn from(node: PySubject) -> Self { match node { - PyNamedOrBlankNode::NamedNode(node) => node.into(), - PyNamedOrBlankNode::BlankNode(node) => node.into(), + PySubject::NamedNode(node) => node.into(), + PySubject::BlankNode(node) => node.into(), } } } -impl From for PyNamedOrBlankNode { - fn from(node: NamedOrBlankNode) -> Self { +impl From for PySubject { + fn from(node: Subject) -> Self { match node { - NamedOrBlankNode::NamedNode(node) => PyNamedOrBlankNode::NamedNode(node.into()), - NamedOrBlankNode::BlankNode(node) => PyNamedOrBlankNode::BlankNode(node.into()), + Subject::NamedNode(node) => PySubject::NamedNode(node.into()), + Subject::BlankNode(node) => PySubject::BlankNode(node.into()), } } } -impl IntoPy for PyNamedOrBlankNode { +impl IntoPy for PySubject { fn into_py(self, py: Python<'_>) -> PyObject { match self { - PyNamedOrBlankNode::NamedNode(node) => node.into_py(py), - PyNamedOrBlankNode::BlankNode(node) => node.into_py(py), + PySubject::NamedNode(node) => node.into_py(py), + PySubject::BlankNode(node) => node.into_py(py), } } } @@ -519,7 +519,7 @@ impl<'a> From<&'a PyTriple> for TripleRef<'a> { #[pymethods] impl PyTriple { #[new] - fn new(subject: PyNamedOrBlankNode, predicate: PyNamedNode, object: PyTerm) -> Self { + fn new(subject: PySubject, predicate: PyNamedNode, object: PyTerm) -> Self { Triple::new(subject, predicate, object).into() } @@ -529,7 +529,7 @@ impl PyTriple { /// >>> Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')).subject /// #[getter] - fn subject(&self) -> PyNamedOrBlankNode { + fn subject(&self) -> PySubject { self.inner.subject.clone().into() } @@ -700,7 +700,7 @@ impl<'a> From<&'a PyQuad> for QuadRef<'a> { impl PyQuad { #[new] fn new( - subject: PyNamedOrBlankNode, + subject: PySubject, predicate: PyNamedNode, object: PyTerm, graph_name: Option, @@ -720,7 +720,7 @@ impl PyQuad { /// >>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).subject /// #[getter] - fn subject(&self) -> PyNamedOrBlankNode { + fn subject(&self) -> PySubject { self.inner.subject.clone().into() } @@ -804,7 +804,7 @@ impl PyMappingProtocol<'p> for PyQuad { let gil = Python::acquire_gil(); let py = gil.python(); match input { - 0 => Ok(PyNamedOrBlankNode::from(self.inner.subject.clone()).into_py(py)), + 0 => Ok(PySubject::from(self.inner.subject.clone()).into_py(py)), 1 => Ok(PyNamedNode::from(self.inner.predicate.clone()).into_py(py)), 2 => Ok(PyTerm::from(self.inner.object.clone()).into_py(py)), 3 => Ok(PyGraphName::from(self.inner.graph_name.clone()).into_py(py)), @@ -929,21 +929,21 @@ impl<'a> TryFrom<&'a PyAny> for PyNamedNodeRef<'a> { } } -pub enum PyNamedOrBlankNodeRef<'a> { +pub enum PySubjectRef<'a> { NamedNode(PyRef<'a, PyNamedNode>), BlankNode(PyRef<'a, PyBlankNode>), } -impl<'a> From<&'a PyNamedOrBlankNodeRef<'a>> for NamedOrBlankNodeRef<'a> { - fn from(value: &'a PyNamedOrBlankNodeRef<'a>) -> Self { +impl<'a> From<&'a PySubjectRef<'a>> for SubjectRef<'a> { + fn from(value: &'a PySubjectRef<'a>) -> Self { match value { - PyNamedOrBlankNodeRef::NamedNode(value) => value.inner.as_ref().into(), - PyNamedOrBlankNodeRef::BlankNode(value) => value.inner.as_ref().into(), + PySubjectRef::NamedNode(value) => value.inner.as_ref().into(), + PySubjectRef::BlankNode(value) => value.inner.as_ref().into(), } } } -impl<'a> TryFrom<&'a PyAny> for PyNamedOrBlankNodeRef<'a> { +impl<'a> TryFrom<&'a PyAny> for PySubjectRef<'a> { type Error = PyErr; fn try_from(value: &'a PyAny) -> PyResult { diff --git a/python/src/sparql.rs b/python/src/sparql.rs index b79fb756..e0173d83 100644 --- a/python/src/sparql.rs +++ b/python/src/sparql.rs @@ -50,7 +50,7 @@ pub fn parse_query( query.dataset_mut().set_available_named_graphs( named_graphs .iter()? - .map(|graph| Ok(graph?.extract::()?.into())) + .map(|graph| Ok(graph?.extract::()?.into())) .collect::>()?, ) } diff --git a/python/src/store.rs b/python/src/store.rs index 8ce27cad..4a8c9295 100644 --- a/python/src/store.rs +++ b/python/src/store.rs @@ -385,11 +385,11 @@ impl PyStore { PyGraphNameRef::DefaultGraph => Ok(()), PyGraphNameRef::NamedNode(graph_name) => self .inner - .insert_named_graph(&PyNamedOrBlankNodeRef::NamedNode(graph_name)) + .insert_named_graph(&PySubjectRef::NamedNode(graph_name)) .map(|_| ()), PyGraphNameRef::BlankNode(graph_name) => self .inner - .insert_named_graph(&PyNamedOrBlankNodeRef::BlankNode(graph_name)) + .insert_named_graph(&PySubjectRef::BlankNode(graph_name)) .map(|_| ()), } .map_err(map_io_err) @@ -414,11 +414,11 @@ impl PyStore { PyGraphNameRef::DefaultGraph => self.inner.clear_graph(GraphNameRef::DefaultGraph), PyGraphNameRef::NamedNode(graph_name) => self .inner - .remove_named_graph(&PyNamedOrBlankNodeRef::NamedNode(graph_name)) + .remove_named_graph(&PySubjectRef::NamedNode(graph_name)) .map(|_| ()), PyGraphNameRef::BlankNode(graph_name) => self .inner - .remove_named_graph(&PyNamedOrBlankNodeRef::BlankNode(graph_name)) + .remove_named_graph(&PySubjectRef::BlankNode(graph_name)) .map(|_| ()), } .map_err(map_io_err)?; @@ -487,7 +487,7 @@ impl PyIterProtocol for GraphNameIter { slf.into() } - fn __next__(mut slf: PyRefMut) -> PyResult> { + fn __next__(mut slf: PyRefMut) -> PyResult> { slf.inner .next() .map(|q| Ok(q.map_err(map_io_err)?.into())) @@ -501,7 +501,7 @@ pub fn extract_quads_pattern<'a>( object: &'a PyAny, graph_name: Option<&'a PyAny>, ) -> PyResult<( - Option>, + Option>, Option>, Option>, Option>, diff --git a/server/src/main.rs b/server/src/main.rs index 1e03256e..366ef6ab 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -21,7 +21,7 @@ use http_types::{ StatusCode, }; use oxigraph::io::{DatasetFormat, GraphFormat}; -use oxigraph::model::{GraphName, GraphNameRef, NamedNode, NamedOrBlankNode}; +use oxigraph::model::{GraphName, GraphNameRef, NamedNode, Subject}; use oxigraph::sparql::{Query, QueryResults, QueryResultsFormat, Update}; use oxigraph::store::Store; use oxiri::Iri; @@ -407,7 +407,7 @@ fn evaluate_sparql_query( let named_graph_uris = named_graph_uris .into_iter() .map(|e| Ok(NamedNode::new(e)?.into())) - .collect::>>() + .collect::>>() .map_err(bad_request)?; if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() { @@ -490,7 +490,7 @@ fn evaluate_sparql_update( let named_graph_uris = named_graph_uris .into_iter() .map(|e| Ok(NamedNode::new(e)?.into())) - .collect::>>() + .collect::>>() .map_err(bad_request)?; if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() { for using in update.using_datasets_mut() { diff --git a/spargebra/src/term.rs b/spargebra/src/term.rs index 56b57cfd..ca5992f5 100644 --- a/spargebra/src/term.rs +++ b/spargebra/src/term.rs @@ -123,29 +123,29 @@ impl fmt::Display for Literal { /// /// The default string formatter is returning an N-Triples, Turtle and SPARQL compatible representation. #[derive(Eq, PartialEq, Debug, Clone, Hash)] -pub enum NamedOrBlankNode { +pub enum Subject { NamedNode(NamedNode), BlankNode(BlankNode), } -impl fmt::Display for NamedOrBlankNode { +impl fmt::Display for Subject { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - NamedOrBlankNode::NamedNode(node) => node.fmt(f), - NamedOrBlankNode::BlankNode(node) => node.fmt(f), + Subject::NamedNode(node) => node.fmt(f), + Subject::BlankNode(node) => node.fmt(f), } } } -impl From for NamedOrBlankNode { +impl From for Subject { #[inline] fn from(node: NamedNode) -> Self { Self::NamedNode(node) } } -impl From for NamedOrBlankNode { +impl From for Subject { #[inline] fn from(node: BlankNode) -> Self { Self::BlankNode(node) @@ -196,12 +196,12 @@ impl From for Term { } } -impl From for Term { +impl From for Term { #[inline] - fn from(resource: NamedOrBlankNode) -> Self { + fn from(resource: Subject) -> Self { match resource { - NamedOrBlankNode::NamedNode(node) => Self::NamedNode(node), - NamedOrBlankNode::BlankNode(node) => Self::BlankNode(node), + Subject::NamedNode(node) => Self::NamedNode(node), + Subject::BlankNode(node) => Self::BlankNode(node), } } } @@ -285,7 +285,7 @@ impl From for GraphName { /// ``` #[derive(Eq, PartialEq, Debug, Clone, Hash)] pub struct Quad { - pub subject: NamedOrBlankNode, + pub subject: Subject, pub predicate: NamedNode, pub object: Term, pub graph_name: GraphName, diff --git a/testsuite/src/manifest.rs b/testsuite/src/manifest.rs index a50942f7..7fcf3c02 100644 --- a/testsuite/src/manifest.rs +++ b/testsuite/src/manifest.rs @@ -161,7 +161,7 @@ impl Iterator for TestManifest { TermRef::BlankNode(g) => Some(g.into()), _ => None, }) - .filter_map(|g: NamedOrBlankNodeRef<'_>| { + .filter_map(|g: SubjectRef<'_>| { if let ( Some(TermRef::NamedNode(endpoint)), Some(TermRef::NamedNode(data)), @@ -246,8 +246,7 @@ impl Iterator for TestManifest { None => { match self.manifests_to_do.pop() { Some(url) => { - let manifest = - NamedOrBlankNodeRef::from(NamedNodeRef::new(url.as_str()).unwrap()); + let manifest = SubjectRef::from(NamedNodeRef::new(url.as_str()).unwrap()); if let Err(error) = load_to_graph(&url, &mut self.graph) { return Some(Err(error)); } @@ -296,11 +295,11 @@ impl Iterator for TestManifest { struct RdfListIterator<'a> { graph: &'a Graph, - current_node: Option>, + current_node: Option>, } impl<'a> RdfListIterator<'a> { - fn iter(graph: &'a Graph, root: NamedOrBlankNodeRef<'a>) -> RdfListIterator<'a> { + fn iter(graph: &'a Graph, root: SubjectRef<'a>) -> RdfListIterator<'a> { RdfListIterator { graph, current_node: Some(root), diff --git a/testsuite/src/sparql_evaluator.rs b/testsuite/src/sparql_evaluator.rs index 5432990b..5d726367 100644 --- a/testsuite/src/sparql_evaluator.rs +++ b/testsuite/src/sparql_evaluator.rs @@ -104,7 +104,7 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> { } } for graph_name in query.dataset().available_named_graphs().unwrap_or(&[]) { - if let NamedOrBlankNode::NamedNode(graph_name) = graph_name { + if let Subject::NamedNode(graph_name) = graph_name { load_to_store(graph_name.as_str(), &store, graph_name.as_ref())?; } else { return Err(anyhow!( diff --git a/wikibase/src/main.rs b/wikibase/src/main.rs index 3f06019f..10e867ab 100644 --- a/wikibase/src/main.rs +++ b/wikibase/src/main.rs @@ -21,7 +21,7 @@ use http_types::{ StatusCode, }; use oxigraph::io::GraphFormat; -use oxigraph::model::{GraphName, NamedNode, NamedOrBlankNode}; +use oxigraph::model::{GraphName, NamedNode, Subject}; use oxigraph::sparql::{Query, QueryResults, QueryResultsFormat}; use oxigraph::store::Store; use std::str::FromStr; @@ -202,7 +202,7 @@ fn evaluate_sparql_query( let named_graph_uris = named_graph_uris .into_iter() .map(|e| Ok(NamedNode::new(e)?.into())) - .collect::>>() + .collect::>>() .map_err(bad_request)?; if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() {