Renames NamedOrBlankNode to Subject

Preparatory work for RDF-star addition
pull/171/head
Tpt 4 years ago
parent bc27a298fa
commit 8004fc28c0
  1. 6
      lib/src/io/read.rs
  2. 175
      lib/src/model/dataset.rs
  3. 18
      lib/src/model/graph.rs
  4. 22
      lib/src/model/interning.rs
  5. 3
      lib/src/model/mod.rs
  6. 18
      lib/src/model/sophia.rs
  7. 132
      lib/src/model/triple.rs
  8. 5
      lib/src/sophia.rs
  9. 6
      lib/src/sparql/algebra.rs
  10. 6
      lib/src/sparql/dataset.rs
  11. 2
      lib/src/sparql/eval.rs
  12. 10
      lib/src/sparql/update.rs
  13. 38
      lib/src/storage/numeric_encoder.rs
  14. 40
      lib/src/store.rs
  15. 2
      lib/tests/store.rs
  16. 50
      python/src/model.rs
  17. 2
      python/src/sparql.rs
  18. 12
      python/src/store.rs
  19. 6
      server/src/main.rs
  20. 22
      spargebra/src/term.rs
  21. 9
      testsuite/src/manifest.rs
  22. 2
      testsuite/src/sparql_evaluator.rs
  23. 4
      wikibase/src/main.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 { match node {
rio::NamedOrBlankNode::NamedNode(node) => self.named_node(node).into(), rio::NamedOrBlankNode::NamedNode(node) => self.named_node(node).into(),
rio::NamedOrBlankNode::BlankNode(node) => self.blank_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 { fn triple(&mut self, triple: &rio::Triple<'a>) -> Triple {
Triple { Triple {
subject: self.named_or_blank_node(triple.subject), subject: self.subject(triple.subject),
predicate: self.named_node(triple.predicate), predicate: self.named_node(triple.predicate),
object: self.term(triple.object), object: self.term(triple.object),
} }
@ -363,7 +363,7 @@ impl<'a> RioMapper {
fn quad(&mut self, quad: &rio::Quad<'a>) -> Quad { fn quad(&mut self, quad: &rio::Quad<'a>) -> Quad {
Quad { Quad {
subject: self.named_or_blank_node(quad.subject), subject: self.subject(quad.subject),
predicate: self.named_node(quad.predicate), predicate: self.named_node(quad.predicate),
object: self.term(quad.object), object: self.term(quad.object),
graph_name: self.graph_name(quad.graph_name), graph_name: self.graph_name(quad.graph_name),

@ -27,7 +27,7 @@ use crate::io::{
DatasetFormat, DatasetParser, DatasetSerializer, GraphFormat, GraphParser, GraphSerializer, DatasetFormat, DatasetParser, DatasetSerializer, GraphFormat, GraphParser, GraphSerializer,
}; };
use crate::model::interning::*; use crate::model::interning::*;
use crate::model::NamedOrBlankNodeRef; use crate::model::SubjectRef;
use crate::model::*; use crate::model::*;
use lasso::Rodeo; use lasso::Rodeo;
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;
@ -69,7 +69,7 @@ pub struct Dataset {
interner: Rodeo, interner: Rodeo,
gspo: BTreeSet<( gspo: BTreeSet<(
InternedGraphName, InternedGraphName,
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
)>, )>,
@ -77,16 +77,16 @@ pub struct Dataset {
InternedGraphName, InternedGraphName,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedNamedOrBlankNode, InternedSubject,
)>, )>,
gosp: BTreeSet<( gosp: BTreeSet<(
InternedGraphName, InternedGraphName,
InternedTerm, InternedTerm,
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
)>, )>,
spog: BTreeSet<( spog: BTreeSet<(
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, InternedGraphName,
@ -94,12 +94,12 @@ pub struct Dataset {
posg: BTreeSet<( posg: BTreeSet<(
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedNamedOrBlankNode, InternedSubject,
InternedGraphName, InternedGraphName,
)>, )>,
ospg: BTreeSet<( ospg: BTreeSet<(
InternedTerm, InternedTerm,
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedGraphName, InternedGraphName,
)>, )>,
@ -177,21 +177,21 @@ impl Dataset {
pub fn quads_for_subject<'a, 'b>( pub fn quads_for_subject<'a, 'b>(
&'a self, &'a self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
) -> impl Iterator<Item = QuadRef<'a>> + 'a { ) -> impl Iterator<Item = QuadRef<'a>> + 'a {
let subject = self let subject = self
.encoded_named_or_blank_node(subject) .encoded_subject(subject)
.unwrap_or_else(InternedNamedOrBlankNode::impossible); .unwrap_or_else(InternedSubject::impossible);
self.interned_quads_for_subject(subject) self.interned_quads_for_subject(subject)
.map(move |q| self.decode_spog(q)) .map(move |q| self.decode_spog(q))
} }
fn interned_quads_for_subject( fn interned_quads_for_subject(
&self, &self,
subject: InternedNamedOrBlankNode, subject: InternedSubject,
) -> impl Iterator< ) -> impl Iterator<
Item = ( Item = (
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, InternedGraphName,
@ -231,7 +231,7 @@ impl Dataset {
predicate: InternedNamedNode, predicate: InternedNamedNode,
) -> impl Iterator< ) -> impl Iterator<
Item = ( Item = (
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, InternedGraphName,
@ -242,13 +242,13 @@ impl Dataset {
&( &(
predicate, predicate,
InternedTerm::first(), InternedTerm::first(),
InternedNamedOrBlankNode::first(), InternedSubject::first(),
InternedGraphName::first(), InternedGraphName::first(),
) )
..&( ..&(
predicate.next(), predicate.next(),
InternedTerm::first(), InternedTerm::first(),
InternedNamedOrBlankNode::first(), InternedSubject::first(),
InternedGraphName::first(), InternedGraphName::first(),
), ),
) )
@ -273,7 +273,7 @@ impl Dataset {
object: InternedTerm, object: InternedTerm,
) -> impl Iterator< ) -> impl Iterator<
Item = ( Item = (
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, InternedGraphName,
@ -283,13 +283,13 @@ impl Dataset {
.range( .range(
&( &(
object, object,
InternedNamedOrBlankNode::first(), InternedSubject::first(),
InternedNamedNode::first(), InternedNamedNode::first(),
InternedGraphName::first(), InternedGraphName::first(),
) )
..&( ..&(
object.next(), object.next(),
InternedNamedOrBlankNode::first(), InternedSubject::first(),
InternedNamedNode::first(), InternedNamedNode::first(),
InternedGraphName::first(), InternedGraphName::first(),
), ),
@ -303,7 +303,7 @@ impl Dataset {
graph_name: InternedGraphName, graph_name: InternedGraphName,
) -> impl Iterator< ) -> impl Iterator<
Item = ( Item = (
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, InternedGraphName,
@ -313,13 +313,13 @@ impl Dataset {
.range( .range(
&( &(
graph_name, graph_name,
InternedNamedOrBlankNode::first(), InternedSubject::first(),
InternedNamedNode::first(), InternedNamedNode::first(),
InternedTerm::first(), InternedTerm::first(),
) )
..&( ..&(
graph_name.next(), graph_name.next(),
InternedNamedOrBlankNode::first(), InternedSubject::first(),
InternedNamedNode::first(), InternedNamedNode::first(),
InternedTerm::first(), InternedTerm::first(),
), ),
@ -356,7 +356,7 @@ impl Dataset {
fn insert_encoded( fn insert_encoded(
&mut self, &mut self,
quad: ( quad: (
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, InternedGraphName,
@ -383,7 +383,7 @@ impl Dataset {
fn remove_encoded( fn remove_encoded(
&mut self, &mut self,
quad: ( quad: (
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, InternedGraphName,
@ -483,13 +483,13 @@ impl Dataset {
&mut self, &mut self,
quad: QuadRef<'_>, quad: QuadRef<'_>,
) -> ( ) -> (
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, 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), InternedNamedNode::encoded_into(quad.predicate, &mut self.interner),
InternedTerm::encoded_into(quad.object, &mut self.interner), InternedTerm::encoded_into(quad.object, &mut self.interner),
InternedGraphName::encoded_into(quad.graph_name, &mut self.interner), InternedGraphName::encoded_into(quad.graph_name, &mut self.interner),
@ -500,13 +500,13 @@ impl Dataset {
&self, &self,
quad: QuadRef<'_>, quad: QuadRef<'_>,
) -> Option<( ) -> Option<(
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, InternedGraphName,
)> { )> {
Some(( Some((
self.encoded_named_or_blank_node(quad.subject)?, self.encoded_subject(quad.subject)?,
self.encoded_named_node(quad.predicate)?, self.encoded_named_node(quad.predicate)?,
self.encoded_term(quad.object)?, self.encoded_term(quad.object)?,
self.encoded_graph_name(quad.graph_name)?, self.encoded_graph_name(quad.graph_name)?,
@ -520,11 +520,11 @@ impl Dataset {
InternedNamedNode::encoded_from(node.into(), &self.interner) InternedNamedNode::encoded_from(node.into(), &self.interner)
} }
pub(super) fn encoded_named_or_blank_node<'a>( pub(super) fn encoded_subject<'a>(
&self, &self,
node: impl Into<NamedOrBlankNodeRef<'a>>, node: impl Into<SubjectRef<'a>>,
) -> Option<InternedNamedOrBlankNode> { ) -> Option<InternedSubject> {
InternedNamedOrBlankNode::encoded_from(node.into(), &self.interner) InternedSubject::encoded_from(node.into(), &self.interner)
} }
pub(super) fn encoded_term<'a>(&self, term: impl Into<TermRef<'a>>) -> Option<InternedTerm> { pub(super) fn encoded_term<'a>(&self, term: impl Into<TermRef<'a>>) -> Option<InternedTerm> {
@ -541,7 +541,7 @@ impl Dataset {
fn decode_spog( fn decode_spog(
&self, &self,
quad: ( quad: (
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, InternedGraphName,
@ -597,7 +597,7 @@ impl Dataset {
fn blank_nodes(&self) -> HashSet<InternedBlankNode> { fn blank_nodes(&self) -> HashSet<InternedBlankNode> {
let mut bnodes = HashSet::new(); let mut bnodes = HashSet::new();
for (g, s, _, o) in &self.gspo { for (g, s, _, o) in &self.gspo {
if let InternedNamedOrBlankNode::BlankNode(bnode) = s { if let InternedSubject::BlankNode(bnode) = s {
bnodes.insert(*bnode); bnodes.insert(*bnode);
} }
if let InternedTerm::BlankNode(bnode) = o { if let InternedTerm::BlankNode(bnode) = o {
@ -625,7 +625,7 @@ impl Dataset {
let mut new_hashes = HashMap::new(); let mut new_hashes = HashMap::new();
for (bnode, old_hash) in &hashes { for (bnode, old_hash) in &hashes {
for (_, p, o, g) in for (_, p, o, g) in
self.interned_quads_for_subject(InternedNamedOrBlankNode::BlankNode(*bnode)) self.interned_quads_for_subject(InternedSubject::BlankNode(*bnode))
{ {
to_hash.push(( to_hash.push((
self.hash_named_node(p), self.hash_named_node(p),
@ -637,7 +637,7 @@ impl Dataset {
for (s, p, _, g) in self.interned_quads_for_object(InternedTerm::BlankNode(*bnode)) for (s, p, _, g) in self.interned_quads_for_object(InternedTerm::BlankNode(*bnode))
{ {
to_hash.push(( to_hash.push((
self.hash_named_or_blank_node(s, &hashes), self.hash_subject(s, &hashes),
self.hash_named_node(p), self.hash_named_node(p),
self.hash_graph_name(g, &hashes), self.hash_graph_name(g, &hashes),
1, 1,
@ -647,7 +647,7 @@ impl Dataset {
self.interned_quads_for_graph_name(InternedGraphName::BlankNode(*bnode)) self.interned_quads_for_graph_name(InternedGraphName::BlankNode(*bnode))
{ {
to_hash.push(( to_hash.push((
self.hash_named_or_blank_node(s, &hashes), self.hash_subject(s, &hashes),
self.hash_named_node(p), self.hash_named_node(p),
self.hash_term(o, &hashes), self.hash_term(o, &hashes),
2, 2,
@ -674,12 +674,12 @@ impl Dataset {
self.hash_tuple(node.decode_from(&self.interner)) self.hash_tuple(node.decode_from(&self.interner))
} }
fn hash_named_or_blank_node( fn hash_subject(
&self, &self,
node: InternedNamedOrBlankNode, node: InternedSubject,
bnodes_hash: &HashMap<InternedBlankNode, u64>, bnodes_hash: &HashMap<InternedBlankNode, u64>,
) -> u64 { ) -> u64 {
if let InternedNamedOrBlankNode::BlankNode(bnode) = node { if let InternedSubject::BlankNode(bnode) = node {
*bnodes_hash.get(&bnode).unwrap() *bnodes_hash.get(&bnode).unwrap()
} else { } else {
self.hash_tuple(node.decode_from(&self.interner)) self.hash_tuple(node.decode_from(&self.interner))
@ -717,7 +717,7 @@ impl Dataset {
hash: &HashMap<InternedBlankNode, u64>, hash: &HashMap<InternedBlankNode, u64>,
partition: &[(u64, Vec<InternedBlankNode>)], partition: &[(u64, Vec<InternedBlankNode>)],
) -> Vec<( ) -> Vec<(
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, InternedGraphName,
@ -755,7 +755,7 @@ impl Dataset {
&mut self, &mut self,
hashes: &HashMap<InternedBlankNode, u64>, hashes: &HashMap<InternedBlankNode, u64>,
) -> Vec<( ) -> Vec<(
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, InternedGraphName,
@ -765,8 +765,8 @@ impl Dataset {
.into_iter() .into_iter()
.map(|(s, p, o, g)| { .map(|(s, p, o, g)| {
( (
if let InternedNamedOrBlankNode::BlankNode(bnode) = s { if let InternedSubject::BlankNode(bnode) = s {
InternedNamedOrBlankNode::BlankNode(self.map_bnode(bnode, hashes)) InternedSubject::BlankNode(self.map_bnode(bnode, hashes))
} else { } else {
s s
}, },
@ -894,13 +894,13 @@ impl<'a> GraphView<'a> {
let iter = self.dataset.gspo.range( let iter = self.dataset.gspo.range(
&( &(
self.graph_name, self.graph_name,
InternedNamedOrBlankNode::first(), InternedSubject::first(),
InternedNamedNode::first(), InternedNamedNode::first(),
InternedTerm::first(), InternedTerm::first(),
) )
..&( ..&(
self.graph_name.next(), self.graph_name.next(),
InternedNamedOrBlankNode::first(), InternedSubject::first(),
InternedNamedNode::first(), InternedNamedNode::first(),
InternedTerm::first(), InternedTerm::first(),
), ),
@ -913,16 +913,16 @@ impl<'a> GraphView<'a> {
pub fn triples_for_subject<'b>( pub fn triples_for_subject<'b>(
self, self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
) -> impl Iterator<Item = TripleRef<'a>> + 'a { ) -> impl Iterator<Item = TripleRef<'a>> + '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( pub(super) fn triples_for_interned_subject(
self, self,
subject: Option<InternedNamedOrBlankNode>, subject: Option<InternedSubject>,
) -> impl Iterator<Item = TripleRef<'a>> + 'a { ) -> impl Iterator<Item = TripleRef<'a>> + 'a {
let subject = subject.unwrap_or_else(InternedNamedOrBlankNode::impossible); let subject = subject.unwrap_or_else(InternedSubject::impossible);
self.dataset self.dataset
.gspo .gspo
.range( .range(
@ -944,21 +944,21 @@ impl<'a> GraphView<'a> {
pub fn objects_for_subject_predicate<'b>( pub fn objects_for_subject_predicate<'b>(
self, self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
predicate: impl Into<NamedNodeRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>,
) -> impl Iterator<Item = TermRef<'a>> + 'a { ) -> impl Iterator<Item = TermRef<'a>> + 'a {
self.objects_for_interned_subject_predicate( 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), self.dataset.encoded_named_node(predicate),
) )
} }
pub fn objects_for_interned_subject_predicate( pub fn objects_for_interned_subject_predicate(
self, self,
subject: Option<InternedNamedOrBlankNode>, subject: Option<InternedSubject>,
predicate: Option<InternedNamedNode>, predicate: Option<InternedNamedNode>,
) -> impl Iterator<Item = TermRef<'a>> + 'a { ) -> impl Iterator<Item = TermRef<'a>> + '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); let predicate = predicate.unwrap_or_else(InternedNamedNode::impossible);
self.dataset self.dataset
.gspo .gspo
@ -976,7 +976,7 @@ impl<'a> GraphView<'a> {
pub fn object_for_subject_predicate<'b>( pub fn object_for_subject_predicate<'b>(
self, self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
predicate: impl Into<NamedNodeRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>,
) -> Option<TermRef<'a>> { ) -> Option<TermRef<'a>> {
self.objects_for_subject_predicate(subject, predicate) self.objects_for_subject_predicate(subject, predicate)
@ -985,21 +985,21 @@ impl<'a> GraphView<'a> {
pub fn predicates_for_subject_object<'b>( pub fn predicates_for_subject_object<'b>(
self, self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
object: impl Into<TermRef<'b>>, object: impl Into<TermRef<'b>>,
) -> impl Iterator<Item = NamedNodeRef<'a>> + 'a { ) -> impl Iterator<Item = NamedNodeRef<'a>> + 'a {
self.predicates_for_interned_subject_object( self.predicates_for_interned_subject_object(
self.dataset.encoded_named_or_blank_node(subject), self.dataset.encoded_subject(subject),
self.dataset.encoded_term(object), self.dataset.encoded_term(object),
) )
} }
pub(super) fn predicates_for_interned_subject_object( pub(super) fn predicates_for_interned_subject_object(
self, self,
subject: Option<InternedNamedOrBlankNode>, subject: Option<InternedSubject>,
object: Option<InternedTerm>, object: Option<InternedTerm>,
) -> impl Iterator<Item = NamedNodeRef<'a>> + 'a { ) -> impl Iterator<Item = NamedNodeRef<'a>> + '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); let object = object.unwrap_or_else(InternedTerm::impossible);
self.dataset self.dataset
.gosp .gosp
@ -1034,13 +1034,13 @@ impl<'a> GraphView<'a> {
self.graph_name, self.graph_name,
predicate, predicate,
InternedTerm::first(), InternedTerm::first(),
InternedNamedOrBlankNode::first(), InternedSubject::first(),
) )
..&( ..&(
self.graph_name, self.graph_name,
predicate.next(), predicate.next(),
InternedTerm::first(), InternedTerm::first(),
InternedNamedOrBlankNode::first(), InternedSubject::first(),
), ),
) )
.map(move |q| self.decode_gpos(*q)) .map(move |q| self.decode_gpos(*q))
@ -1050,7 +1050,7 @@ impl<'a> GraphView<'a> {
self, self,
predicate: impl Into<NamedNodeRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>,
object: impl Into<TermRef<'b>>, object: impl Into<TermRef<'b>>,
) -> impl Iterator<Item = NamedOrBlankNodeRef<'a>> + 'a { ) -> impl Iterator<Item = SubjectRef<'a>> + 'a {
self.subjects_for_interned_predicate_object( self.subjects_for_interned_predicate_object(
self.dataset.encoded_named_node(predicate), self.dataset.encoded_named_node(predicate),
self.dataset.encoded_term(object), self.dataset.encoded_term(object),
@ -1061,23 +1061,18 @@ impl<'a> GraphView<'a> {
self, self,
predicate: Option<InternedNamedNode>, predicate: Option<InternedNamedNode>,
object: Option<InternedTerm>, object: Option<InternedTerm>,
) -> impl Iterator<Item = NamedOrBlankNodeRef<'a>> + 'a { ) -> impl Iterator<Item = SubjectRef<'a>> + 'a {
let predicate = predicate.unwrap_or_else(InternedNamedNode::impossible); let predicate = predicate.unwrap_or_else(InternedNamedNode::impossible);
let object = object.unwrap_or_else(InternedTerm::impossible); let object = object.unwrap_or_else(InternedTerm::impossible);
self.dataset self.dataset
.gpos .gpos
.range( .range(
&( &(self.graph_name, predicate, object, InternedSubject::first())
self.graph_name,
predicate,
object,
InternedNamedOrBlankNode::first(),
)
..&( ..&(
self.graph_name, self.graph_name,
predicate, predicate,
object.next(), object.next(),
InternedNamedOrBlankNode::first(), InternedSubject::first(),
), ),
) )
.map(move |q| q.3.decode_from(&self.dataset.interner)) .map(move |q| q.3.decode_from(&self.dataset.interner))
@ -1087,7 +1082,7 @@ impl<'a> GraphView<'a> {
self, self,
predicate: impl Into<NamedNodeRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>,
object: impl Into<TermRef<'b>>, object: impl Into<TermRef<'b>>,
) -> Option<NamedOrBlankNodeRef<'a>> { ) -> Option<SubjectRef<'a>> {
self.subjects_for_predicate_object(predicate, object).next() self.subjects_for_predicate_object(predicate, object).next()
} }
@ -1109,13 +1104,13 @@ impl<'a> GraphView<'a> {
&( &(
self.graph_name, self.graph_name,
object, object,
InternedNamedOrBlankNode::first(), InternedSubject::first(),
InternedNamedNode::first(), InternedNamedNode::first(),
) )
..&( ..&(
self.graph_name, self.graph_name,
object.next(), object.next(),
InternedNamedOrBlankNode::first(), InternedSubject::first(),
InternedNamedNode::first(), InternedNamedNode::first(),
), ),
) )
@ -1169,9 +1164,9 @@ impl<'a> GraphView<'a> {
fn encoded_triple( fn encoded_triple(
&self, &self,
triple: TripleRef<'_>, triple: TripleRef<'_>,
) -> Option<(InternedNamedOrBlankNode, InternedNamedNode, InternedTerm)> { ) -> Option<(InternedSubject, InternedNamedNode, InternedTerm)> {
Some(( 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_named_node(triple.predicate)?,
self.dataset.encoded_term(triple.object)?, self.dataset.encoded_term(triple.object)?,
)) ))
@ -1181,7 +1176,7 @@ impl<'a> GraphView<'a> {
self, self,
quad: ( quad: (
InternedGraphName, InternedGraphName,
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
), ),
@ -1199,7 +1194,7 @@ impl<'a> GraphView<'a> {
InternedGraphName, InternedGraphName,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedNamedOrBlankNode, InternedSubject,
), ),
) -> TripleRef<'a> { ) -> TripleRef<'a> {
self.decode_gspo((quad.0, quad.3, quad.1, quad.2)) self.decode_gspo((quad.0, quad.3, quad.1, quad.2))
@ -1210,7 +1205,7 @@ impl<'a> GraphView<'a> {
quad: ( quad: (
InternedGraphName, InternedGraphName,
InternedTerm, InternedTerm,
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
), ),
) -> TripleRef<'a> { ) -> TripleRef<'a> {
@ -1344,9 +1339,9 @@ impl<'a> GraphViewMut<'a> {
fn encode_triple( fn encode_triple(
&mut self, &mut self,
triple: TripleRef<'_>, 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), InternedNamedNode::encoded_into(triple.predicate, &mut self.dataset.interner),
InternedTerm::encoded_into(triple.object, &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>( pub fn triples_for_subject<'b>(
&'a self, &'a self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
) -> impl Iterator<Item = TripleRef<'a>> + 'a { ) -> impl Iterator<Item = TripleRef<'a>> + 'a {
self.read() 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>( pub fn objects_for_subject_predicate<'b>(
&'a self, &'a self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
predicate: impl Into<NamedNodeRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>,
) -> impl Iterator<Item = TermRef<'a>> + 'a { ) -> impl Iterator<Item = TermRef<'a>> + 'a {
self.read().objects_for_interned_subject_predicate( 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), self.dataset.encoded_named_node(predicate),
) )
} }
pub fn object_for_subject_predicate<'b>( pub fn object_for_subject_predicate<'b>(
&'a self, &'a self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
predicate: impl Into<NamedNodeRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>,
) -> Option<TermRef<'a>> { ) -> Option<TermRef<'a>> {
self.read().object_for_subject_predicate(subject, predicate) self.read().object_for_subject_predicate(subject, predicate)
@ -1386,11 +1381,11 @@ impl<'a> GraphViewMut<'a> {
pub fn predicates_for_subject_object<'b>( pub fn predicates_for_subject_object<'b>(
&'a self, &'a self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
object: impl Into<TermRef<'b>>, object: impl Into<TermRef<'b>>,
) -> impl Iterator<Item = NamedNodeRef<'a>> + 'a { ) -> impl Iterator<Item = NamedNodeRef<'a>> + 'a {
self.read().predicates_for_interned_subject_object( 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), self.dataset.encoded_term(object),
) )
} }
@ -1407,7 +1402,7 @@ impl<'a> GraphViewMut<'a> {
&'a self, &'a self,
predicate: impl Into<NamedNodeRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>,
object: impl Into<TermRef<'b>>, object: impl Into<TermRef<'b>>,
) -> impl Iterator<Item = NamedOrBlankNodeRef<'a>> + 'a { ) -> impl Iterator<Item = SubjectRef<'a>> + 'a {
self.read().subjects_for_interned_predicate_object( self.read().subjects_for_interned_predicate_object(
self.dataset.encoded_named_node(predicate), self.dataset.encoded_named_node(predicate),
self.dataset.encoded_term(object), self.dataset.encoded_term(object),
@ -1418,7 +1413,7 @@ impl<'a> GraphViewMut<'a> {
&'a self, &'a self,
predicate: impl Into<NamedNodeRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>,
object: impl Into<TermRef<'b>>, object: impl Into<TermRef<'b>>,
) -> Option<NamedOrBlankNodeRef<'a>> { ) -> Option<SubjectRef<'a>> {
self.read().subject_for_predicate_object(predicate, object) self.read().subject_for_predicate_object(predicate, object)
} }
@ -1509,7 +1504,7 @@ pub struct Iter<'a> {
inner: std::collections::btree_set::Iter< inner: std::collections::btree_set::Iter<
'a, 'a,
( (
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
InternedGraphName, InternedGraphName,
@ -1532,7 +1527,7 @@ pub struct GraphViewIter<'a> {
'a, 'a,
( (
InternedGraphName, InternedGraphName,
InternedNamedOrBlankNode, InternedSubject,
InternedNamedNode, InternedNamedNode,
InternedTerm, InternedTerm,
), ),

@ -76,26 +76,26 @@ impl Graph {
pub fn triples_for_subject<'a, 'b>( pub fn triples_for_subject<'a, 'b>(
&'a self, &'a self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
) -> impl Iterator<Item = TripleRef<'a>> + 'a { ) -> impl Iterator<Item = TripleRef<'a>> + 'a {
self.graph() 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>( pub fn objects_for_subject_predicate<'a, 'b>(
&'a self, &'a self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
predicate: impl Into<NamedNodeRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>,
) -> impl Iterator<Item = TermRef<'a>> + 'a { ) -> impl Iterator<Item = TermRef<'a>> + 'a {
self.graph().objects_for_interned_subject_predicate( 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), self.dataset.encoded_named_node(predicate),
) )
} }
pub fn object_for_subject_predicate<'a, 'b>( pub fn object_for_subject_predicate<'a, 'b>(
&'a self, &'a self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
predicate: impl Into<NamedNodeRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>,
) -> Option<TermRef<'a>> { ) -> Option<TermRef<'a>> {
self.graph() self.graph()
@ -105,11 +105,11 @@ impl Graph {
pub fn predicates_for_subject_object<'a, 'b>( pub fn predicates_for_subject_object<'a, 'b>(
&'a self, &'a self,
subject: impl Into<NamedOrBlankNodeRef<'b>>, subject: impl Into<SubjectRef<'b>>,
object: impl Into<TermRef<'b>>, object: impl Into<TermRef<'b>>,
) -> impl Iterator<Item = NamedNodeRef<'a>> + 'a { ) -> impl Iterator<Item = NamedNodeRef<'a>> + 'a {
self.graph().predicates_for_interned_subject_object( 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), self.dataset.encoded_term(object),
) )
} }
@ -126,7 +126,7 @@ impl Graph {
&'a self, &'a self,
predicate: impl Into<NamedNodeRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>,
object: impl Into<TermRef<'b>>, object: impl Into<TermRef<'b>>,
) -> impl Iterator<Item = NamedOrBlankNodeRef<'a>> + 'a { ) -> impl Iterator<Item = SubjectRef<'a>> + 'a {
self.graph().subjects_for_interned_predicate_object( self.graph().subjects_for_interned_predicate_object(
self.dataset.encoded_named_node(predicate), self.dataset.encoded_named_node(predicate),
self.dataset.encoded_term(object), self.dataset.encoded_term(object),
@ -137,7 +137,7 @@ impl Graph {
&'a self, &'a self,
predicate: impl Into<NamedNodeRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>,
object: impl Into<TermRef<'b>>, object: impl Into<TermRef<'b>>,
) -> Option<NamedOrBlankNodeRef<'a>> { ) -> Option<SubjectRef<'a>> {
self.graph().subject_for_predicate_object(predicate, object) self.graph().subject_for_predicate_object(predicate, object)
} }

@ -166,38 +166,38 @@ impl InternedLiteral {
} }
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Copy, Hash)] #[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Copy, Hash)]
pub enum InternedNamedOrBlankNode { pub enum InternedSubject {
NamedNode(InternedNamedNode), NamedNode(InternedNamedNode),
BlankNode(InternedBlankNode), BlankNode(InternedBlankNode),
} }
impl InternedNamedOrBlankNode { impl InternedSubject {
pub fn encoded_into(node: NamedOrBlankNodeRef<'_>, interner: &mut Rodeo) -> Self { pub fn encoded_into(node: SubjectRef<'_>, interner: &mut Rodeo) -> Self {
match node { match node {
NamedOrBlankNodeRef::NamedNode(node) => { SubjectRef::NamedNode(node) => {
Self::NamedNode(InternedNamedNode::encoded_into(node, interner)) Self::NamedNode(InternedNamedNode::encoded_into(node, interner))
} }
NamedOrBlankNodeRef::BlankNode(node) => { SubjectRef::BlankNode(node) => {
Self::BlankNode(InternedBlankNode::encoded_into(node, interner)) Self::BlankNode(InternedBlankNode::encoded_into(node, interner))
} }
} }
} }
pub fn encoded_from(node: NamedOrBlankNodeRef<'_>, interner: &Rodeo) -> Option<Self> { pub fn encoded_from(node: SubjectRef<'_>, interner: &Rodeo) -> Option<Self> {
Some(match node { Some(match node {
NamedOrBlankNodeRef::NamedNode(node) => { SubjectRef::NamedNode(node) => {
Self::NamedNode(InternedNamedNode::encoded_from(node, interner)?) Self::NamedNode(InternedNamedNode::encoded_from(node, interner)?)
} }
NamedOrBlankNodeRef::BlankNode(node) => { SubjectRef::BlankNode(node) => {
Self::BlankNode(InternedBlankNode::encoded_from(node, interner)?) 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 { match self {
Self::NamedNode(node) => NamedOrBlankNodeRef::NamedNode(node.decode_from(interner)), Self::NamedNode(node) => SubjectRef::NamedNode(node.decode_from(interner)),
Self::BlankNode(node) => NamedOrBlankNodeRef::BlankNode(node.decode_from(interner)), Self::BlankNode(node) => SubjectRef::BlankNode(node.decode_from(interner)),
} }
} }

@ -22,8 +22,7 @@ pub use self::literal::{Literal, LiteralRef};
pub use self::named_node::{NamedNode, NamedNodeRef}; pub use self::named_node::{NamedNode, NamedNodeRef};
pub use self::parser::TermParseError; pub use self::parser::TermParseError;
pub use self::triple::{ pub use self::triple::{
GraphName, GraphNameRef, NamedOrBlankNode, NamedOrBlankNodeRef, Quad, QuadRef, Term, TermRef, GraphName, GraphNameRef, Quad, QuadRef, Subject, SubjectRef, Term, TermRef, Triple, TripleRef,
Triple, TripleRef,
}; };
pub use oxilangtag::LanguageTagParseError; pub use oxilangtag::LanguageTagParseError;
pub use oxiri::IriParseError; pub use oxiri::IriParseError;

@ -189,9 +189,9 @@ impl<'a> From<GraphNameRef<'a>> for Option<TermRef<'a>> {
} }
} }
impl TTerm for NamedOrBlankNode { impl TTerm for Subject {
fn kind(&self) -> TermKind { fn kind(&self) -> TermKind {
use NamedOrBlankNode::*; use Subject::*;
match self { match self {
NamedNode(_) => TermKind::Iri, NamedNode(_) => TermKind::Iri,
BlankNode(_) => TermKind::BlankNode, BlankNode(_) => TermKind::BlankNode,
@ -199,7 +199,7 @@ impl TTerm for NamedOrBlankNode {
} }
fn value_raw(&self) -> RawValue<'_> { fn value_raw(&self) -> RawValue<'_> {
use NamedOrBlankNode::*; use Subject::*;
match self { match self {
NamedNode(n) => n.value_raw(), NamedNode(n) => n.value_raw(),
BlankNode(n) => n.value_raw(), BlankNode(n) => n.value_raw(),
@ -207,7 +207,7 @@ impl TTerm for NamedOrBlankNode {
} }
fn as_dyn(&self) -> &dyn TTerm { fn as_dyn(&self) -> &dyn TTerm {
use NamedOrBlankNode::*; use Subject::*;
match self { match self {
NamedNode(n) => n.as_dyn(), NamedNode(n) => n.as_dyn(),
BlankNode(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; type Error = SophiaToOxigraphConversionError;
fn try_copy<T>(other: &T) -> Result<Self, Self::Error> fn try_copy<T>(other: &T) -> Result<Self, Self::Error>
@ -230,9 +230,9 @@ impl TryCopyTerm for NamedOrBlankNode {
} }
} }
impl<'a> TTerm for NamedOrBlankNodeRef<'a> { impl<'a> TTerm for SubjectRef<'a> {
fn kind(&self) -> TermKind { fn kind(&self) -> TermKind {
use NamedOrBlankNodeRef::*; use SubjectRef::*;
match self { match self {
NamedNode(_) => TermKind::Iri, NamedNode(_) => TermKind::Iri,
BlankNode(_) => TermKind::BlankNode, BlankNode(_) => TermKind::BlankNode,
@ -240,7 +240,7 @@ impl<'a> TTerm for NamedOrBlankNodeRef<'a> {
} }
fn value_raw(&self) -> RawValue<'_> { fn value_raw(&self) -> RawValue<'_> {
use NamedOrBlankNodeRef::*; use SubjectRef::*;
match self { match self {
NamedNode(n) => n.value_raw(), NamedNode(n) => n.value_raw(),
BlankNode(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 { fn as_dyn(&self) -> &dyn TTerm {
use NamedOrBlankNodeRef::*; use SubjectRef::*;
match self { match self {
NamedNode(n) => n.as_dyn(), NamedNode(n) => n.as_dyn(),
BlankNode(n) => n.as_dyn(), BlankNode(n) => n.as_dyn(),

@ -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). /// 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)] #[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub enum NamedOrBlankNode { pub enum Subject {
NamedNode(NamedNode), NamedNode(NamedNode),
BlankNode(BlankNode), BlankNode(BlankNode),
} }
impl NamedOrBlankNode { impl Subject {
#[inline] #[inline]
pub fn is_named_node(&self) -> bool { pub fn is_named_node(&self) -> bool {
self.as_ref().is_named_node() self.as_ref().is_named_node()
@ -24,43 +24,43 @@ impl NamedOrBlankNode {
} }
#[inline] #[inline]
pub fn as_ref(&self) -> NamedOrBlankNodeRef<'_> { pub fn as_ref(&self) -> SubjectRef<'_> {
match self { match self {
Self::NamedNode(node) => NamedOrBlankNodeRef::NamedNode(node.as_ref()), Self::NamedNode(node) => SubjectRef::NamedNode(node.as_ref()),
Self::BlankNode(node) => NamedOrBlankNodeRef::BlankNode(node.as_ref()), Self::BlankNode(node) => SubjectRef::BlankNode(node.as_ref()),
} }
} }
} }
impl fmt::Display for NamedOrBlankNode { impl fmt::Display for Subject {
#[inline] #[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.as_ref().fmt(f) self.as_ref().fmt(f)
} }
} }
impl From<NamedNode> for NamedOrBlankNode { impl From<NamedNode> for Subject {
#[inline] #[inline]
fn from(node: NamedNode) -> Self { fn from(node: NamedNode) -> Self {
Self::NamedNode(node) Self::NamedNode(node)
} }
} }
impl From<NamedNodeRef<'_>> for NamedOrBlankNode { impl From<NamedNodeRef<'_>> for Subject {
#[inline] #[inline]
fn from(node: NamedNodeRef<'_>) -> Self { fn from(node: NamedNodeRef<'_>) -> Self {
node.into_owned().into() node.into_owned().into()
} }
} }
impl From<BlankNode> for NamedOrBlankNode { impl From<BlankNode> for Subject {
#[inline] #[inline]
fn from(node: BlankNode) -> Self { fn from(node: BlankNode) -> Self {
Self::BlankNode(node) Self::BlankNode(node)
} }
} }
impl From<BlankNodeRef<'_>> for NamedOrBlankNode { impl From<BlankNodeRef<'_>> for Subject {
#[inline] #[inline]
fn from(node: BlankNodeRef<'_>) -> Self { fn from(node: BlankNodeRef<'_>) -> Self {
node.into_owned().into() node.into_owned().into()
@ -69,12 +69,12 @@ impl From<BlankNodeRef<'_>> 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). /// 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)] #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
pub enum NamedOrBlankNodeRef<'a> { pub enum SubjectRef<'a> {
NamedNode(NamedNodeRef<'a>), NamedNode(NamedNodeRef<'a>),
BlankNode(BlankNodeRef<'a>), BlankNode(BlankNodeRef<'a>),
} }
impl<'a> NamedOrBlankNodeRef<'a> { impl<'a> SubjectRef<'a> {
#[inline] #[inline]
pub fn is_named_node(&self) -> bool { pub fn is_named_node(&self) -> bool {
match self { match self {
@ -92,15 +92,15 @@ impl<'a> NamedOrBlankNodeRef<'a> {
} }
#[inline] #[inline]
pub fn into_owned(self) -> NamedOrBlankNode { pub fn into_owned(self) -> Subject {
match self { match self {
Self::NamedNode(node) => NamedOrBlankNode::NamedNode(node.into_owned()), Self::NamedNode(node) => Subject::NamedNode(node.into_owned()),
Self::BlankNode(node) => NamedOrBlankNode::BlankNode(node.into_owned()), Self::BlankNode(node) => Subject::BlankNode(node.into_owned()),
} }
} }
} }
impl fmt::Display for NamedOrBlankNodeRef<'_> { impl fmt::Display for SubjectRef<'_> {
#[inline] #[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
@ -110,54 +110,54 @@ impl fmt::Display for NamedOrBlankNodeRef<'_> {
} }
} }
impl<'a> From<NamedNodeRef<'a>> for NamedOrBlankNodeRef<'a> { impl<'a> From<NamedNodeRef<'a>> for SubjectRef<'a> {
#[inline] #[inline]
fn from(node: NamedNodeRef<'a>) -> Self { fn from(node: NamedNodeRef<'a>) -> Self {
Self::NamedNode(node) Self::NamedNode(node)
} }
} }
impl<'a> From<&'a NamedNode> for NamedOrBlankNodeRef<'a> { impl<'a> From<&'a NamedNode> for SubjectRef<'a> {
#[inline] #[inline]
fn from(node: &'a NamedNode) -> Self { fn from(node: &'a NamedNode) -> Self {
node.as_ref().into() node.as_ref().into()
} }
} }
impl<'a> From<BlankNodeRef<'a>> for NamedOrBlankNodeRef<'a> { impl<'a> From<BlankNodeRef<'a>> for SubjectRef<'a> {
#[inline] #[inline]
fn from(node: BlankNodeRef<'a>) -> Self { fn from(node: BlankNodeRef<'a>) -> Self {
Self::BlankNode(node) Self::BlankNode(node)
} }
} }
impl<'a> From<&'a BlankNode> for NamedOrBlankNodeRef<'a> { impl<'a> From<&'a BlankNode> for SubjectRef<'a> {
#[inline] #[inline]
fn from(node: &'a BlankNode) -> Self { fn from(node: &'a BlankNode) -> Self {
node.as_ref().into() node.as_ref().into()
} }
} }
impl<'a> From<&'a NamedOrBlankNode> for NamedOrBlankNodeRef<'a> { impl<'a> From<&'a Subject> for SubjectRef<'a> {
#[inline] #[inline]
fn from(node: &'a NamedOrBlankNode) -> Self { fn from(node: &'a Subject) -> Self {
node.as_ref() node.as_ref()
} }
} }
impl<'a> From<NamedOrBlankNodeRef<'a>> for NamedOrBlankNode { impl<'a> From<SubjectRef<'a>> for Subject {
#[inline] #[inline]
fn from(node: NamedOrBlankNodeRef<'a>) -> Self { fn from(node: SubjectRef<'a>) -> Self {
node.into_owned() node.into_owned()
} }
} }
impl<'a> From<NamedOrBlankNodeRef<'a>> for rio::NamedOrBlankNode<'a> { impl<'a> From<SubjectRef<'a>> for rio::NamedOrBlankNode<'a> {
#[inline] #[inline]
fn from(node: NamedOrBlankNodeRef<'a>) -> Self { fn from(node: SubjectRef<'a>) -> Self {
match node { match node {
NamedOrBlankNodeRef::NamedNode(node) => rio::NamedNode::from(node).into(), SubjectRef::NamedNode(node) => rio::NamedNode::from(node).into(),
NamedOrBlankNodeRef::BlankNode(node) => rio::BlankNode::from(node).into(), SubjectRef::BlankNode(node) => rio::BlankNode::from(node).into(),
} }
} }
} }
@ -246,19 +246,19 @@ impl From<LiteralRef<'_>> for Term {
} }
} }
impl From<NamedOrBlankNode> for Term { impl From<Subject> for Term {
#[inline] #[inline]
fn from(node: NamedOrBlankNode) -> Self { fn from(node: Subject) -> Self {
match node { match node {
NamedOrBlankNode::NamedNode(node) => node.into(), Subject::NamedNode(node) => node.into(),
NamedOrBlankNode::BlankNode(node) => node.into(), Subject::BlankNode(node) => node.into(),
} }
} }
} }
impl From<NamedOrBlankNodeRef<'_>> for Term { impl From<SubjectRef<'_>> for Term {
#[inline] #[inline]
fn from(node: NamedOrBlankNodeRef<'_>) -> Self { fn from(node: SubjectRef<'_>) -> Self {
node.into_owned().into() node.into_owned().into()
} }
} }
@ -351,19 +351,19 @@ impl<'a> From<&'a Literal> for TermRef<'a> {
} }
} }
impl<'a> From<NamedOrBlankNodeRef<'a>> for TermRef<'a> { impl<'a> From<SubjectRef<'a>> for TermRef<'a> {
#[inline] #[inline]
fn from(node: NamedOrBlankNodeRef<'a>) -> Self { fn from(node: SubjectRef<'a>) -> Self {
match node { match node {
NamedOrBlankNodeRef::NamedNode(node) => node.into(), SubjectRef::NamedNode(node) => node.into(),
NamedOrBlankNodeRef::BlankNode(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] #[inline]
fn from(node: &'a NamedOrBlankNode) -> Self { fn from(node: &'a Subject) -> Self {
node.as_ref().into() node.as_ref().into()
} }
} }
@ -397,7 +397,7 @@ impl<'a> From<TermRef<'a>> for rio::Term<'a> {
#[derive(Eq, PartialEq, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct Triple { pub struct Triple {
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this 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 /// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
pub predicate: NamedNode, pub predicate: NamedNode,
@ -410,7 +410,7 @@ impl Triple {
/// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) /// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple)
#[inline] #[inline]
pub fn new( pub fn new(
subject: impl Into<NamedOrBlankNode>, subject: impl Into<Subject>,
predicate: impl Into<NamedNode>, predicate: impl Into<NamedNode>,
object: impl Into<Term>, object: impl Into<Term>,
) -> Self { ) -> Self {
@ -453,7 +453,7 @@ impl fmt::Display for Triple {
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
pub struct TripleRef<'a> { pub struct TripleRef<'a> {
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple /// 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 /// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
pub predicate: NamedNodeRef<'a>, 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) /// Builds an RDF [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple)
#[inline] #[inline]
pub fn new( pub fn new(
subject: impl Into<NamedOrBlankNodeRef<'a>>, subject: impl Into<SubjectRef<'a>>,
predicate: impl Into<NamedNodeRef<'a>>, predicate: impl Into<NamedNodeRef<'a>>,
object: impl Into<TermRef<'a>>, object: impl Into<TermRef<'a>>,
) -> Self { ) -> Self {
@ -600,26 +600,26 @@ impl From<BlankNodeRef<'_>> for GraphName {
} }
} }
impl From<NamedOrBlankNode> for GraphName { impl From<Subject> for GraphName {
#[inline] #[inline]
fn from(node: NamedOrBlankNode) -> Self { fn from(node: Subject) -> Self {
match node { match node {
NamedOrBlankNode::NamedNode(node) => node.into(), Subject::NamedNode(node) => node.into(),
NamedOrBlankNode::BlankNode(node) => node.into(), Subject::BlankNode(node) => node.into(),
} }
} }
} }
impl From<NamedOrBlankNodeRef<'_>> for GraphName { impl From<SubjectRef<'_>> for GraphName {
#[inline] #[inline]
fn from(node: NamedOrBlankNodeRef<'_>) -> Self { fn from(node: SubjectRef<'_>) -> Self {
node.into_owned().into() node.into_owned().into()
} }
} }
impl From<Option<NamedOrBlankNode>> for GraphName { impl From<Option<Subject>> for GraphName {
#[inline] #[inline]
fn from(name: Option<NamedOrBlankNode>) -> Self { fn from(name: Option<Subject>) -> Self {
if let Some(node) = name { if let Some(node) = name {
node.into() node.into()
} else { } else {
@ -628,7 +628,7 @@ impl From<Option<NamedOrBlankNode>> for GraphName {
} }
} }
impl From<GraphName> for Option<NamedOrBlankNode> { impl From<GraphName> for Option<Subject> {
#[inline] #[inline]
fn from(name: GraphName) -> Self { fn from(name: GraphName) -> Self {
match name { match name {
@ -713,19 +713,19 @@ impl<'a> From<&'a BlankNode> for GraphNameRef<'a> {
} }
} }
impl<'a> From<NamedOrBlankNodeRef<'a>> for GraphNameRef<'a> { impl<'a> From<SubjectRef<'a>> for GraphNameRef<'a> {
#[inline] #[inline]
fn from(node: NamedOrBlankNodeRef<'a>) -> Self { fn from(node: SubjectRef<'a>) -> Self {
match node { match node {
NamedOrBlankNodeRef::NamedNode(node) => node.into(), SubjectRef::NamedNode(node) => node.into(),
NamedOrBlankNodeRef::BlankNode(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] #[inline]
fn from(node: &'a NamedOrBlankNode) -> Self { fn from(node: &'a Subject) -> Self {
node.as_ref().into() node.as_ref().into()
} }
} }
@ -744,9 +744,9 @@ impl<'a> From<GraphNameRef<'a>> for GraphName {
} }
} }
impl<'a> From<Option<NamedOrBlankNodeRef<'a>>> for GraphNameRef<'a> { impl<'a> From<Option<SubjectRef<'a>>> for GraphNameRef<'a> {
#[inline] #[inline]
fn from(name: Option<NamedOrBlankNodeRef<'a>>) -> Self { fn from(name: Option<SubjectRef<'a>>) -> Self {
if let Some(node) = name { if let Some(node) = name {
node.into() node.into()
} else { } else {
@ -755,7 +755,7 @@ impl<'a> From<Option<NamedOrBlankNodeRef<'a>>> for GraphNameRef<'a> {
} }
} }
impl<'a> From<GraphNameRef<'a>> for Option<NamedOrBlankNodeRef<'a>> { impl<'a> From<GraphNameRef<'a>> for Option<SubjectRef<'a>> {
#[inline] #[inline]
fn from(name: GraphNameRef<'a>) -> Self { fn from(name: GraphNameRef<'a>) -> Self {
match name { match name {
@ -781,7 +781,7 @@ impl<'a> From<GraphNameRef<'a>> for Option<rio::NamedOrBlankNode<'a>> {
#[derive(Eq, PartialEq, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct Quad { pub struct Quad {
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this 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 /// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
pub predicate: NamedNode, 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) /// 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] #[inline]
pub fn new( pub fn new(
subject: impl Into<NamedOrBlankNode>, subject: impl Into<Subject>,
predicate: impl Into<NamedNode>, predicate: impl Into<NamedNode>,
object: impl Into<Term>, object: impl Into<Term>,
graph_name: impl Into<GraphName>, graph_name: impl Into<GraphName>,
@ -843,7 +843,7 @@ impl From<Quad> for Triple {
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
pub struct QuadRef<'a> { pub struct QuadRef<'a> {
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple /// 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 /// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
pub predicate: NamedNodeRef<'a>, 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) /// 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] #[inline]
pub fn new( pub fn new(
subject: impl Into<NamedOrBlankNodeRef<'a>>, subject: impl Into<SubjectRef<'a>>,
predicate: impl Into<NamedNodeRef<'a>>, predicate: impl Into<NamedNodeRef<'a>>,
object: impl Into<TermRef<'a>>, object: impl Into<TermRef<'a>>,
graph_name: impl Into<GraphNameRef<'a>>, graph_name: impl Into<GraphNameRef<'a>>,

@ -1,8 +1,7 @@
//! This crate provides implementation of [Sophia](https://docs.rs/sophia/) traits for the `store` module. //! This crate provides implementation of [Sophia](https://docs.rs/sophia/) traits for the `store` module.
use crate::model::{ use crate::model::{
BlankNodeRef, GraphNameRef, LiteralRef, NamedNodeRef, NamedOrBlankNodeRef, Quad, QuadRef, Term, BlankNodeRef, GraphNameRef, LiteralRef, NamedNodeRef, Quad, QuadRef, SubjectRef, Term, TermRef,
TermRef,
}; };
use crate::sparql::{EvaluationError, QueryResults}; use crate::sparql::{EvaluationError, QueryResults};
use crate::store::Store; 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<NamedOrBlankNodeRef<'a>> fn convert_subject<'a, T>(term: &'a T, buffer: &'a mut String) -> Option<SubjectRef<'a>>
where where
T: TTerm + ?Sized + 'a, T: TTerm + ?Sized + 'a,
{ {

@ -171,7 +171,7 @@ impl<'a> TryFrom<&'a String> for Update {
#[derive(Eq, PartialEq, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct QueryDataset { pub struct QueryDataset {
default: Option<Vec<GraphName>>, default: Option<Vec<GraphName>>,
named: Option<Vec<NamedOrBlankNode>>, named: Option<Vec<Subject>>,
} }
impl QueryDataset { 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 /// 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() self.named.as_deref()
} }
@ -272,7 +272,7 @@ impl QueryDataset {
/// ///
/// # Result::Ok::<_, Box<dyn std::error::Error>>(()) /// # Result::Ok::<_, Box<dyn std::error::Error>>(())
/// ``` /// ```
pub fn set_available_named_graphs(&mut self, named_graphs: Vec<NamedOrBlankNode>) { pub fn set_available_named_graphs(&mut self, named_graphs: Vec<Subject>) {
self.named = Some(named_graphs); self.named = Some(named_graphs);
} }
} }

@ -1,8 +1,8 @@
use crate::sparql::algebra::QueryDataset; use crate::sparql::algebra::QueryDataset;
use crate::sparql::EvaluationError; use crate::sparql::EvaluationError;
use crate::storage::numeric_encoder::{ use crate::storage::numeric_encoder::{
get_encoded_graph_name, get_encoded_named_or_blank_node, EncodedQuad, EncodedTerm, get_encoded_graph_name, get_encoded_subject, EncodedQuad, EncodedTerm, StrContainer, StrHash,
StrContainer, StrHash, StrLookup, StrLookup,
}; };
use crate::storage::Storage; use crate::storage::Storage;
use std::cell::RefCell; use std::cell::RefCell;
@ -28,7 +28,7 @@ impl DatasetView {
named: dataset.available_named_graphs().map(|graphs| { named: dataset.available_named_graphs().map(|graphs| {
graphs graphs
.iter() .iter()
.map(|g| get_encoded_named_or_blank_node(g.as_ref())) .map(|g| get_encoded_subject(g.as_ref()))
.collect::<Vec<_>>() .collect::<Vec<_>>()
}), }),
}; };

@ -2668,7 +2668,7 @@ fn decode_triple<D: Decoder>(
object: &EncodedTerm, object: &EncodedTerm,
) -> Result<Triple, EvaluationError> { ) -> Result<Triple, EvaluationError> {
Ok(Triple::new( Ok(Triple::new(
decoder.decode_named_or_blank_node(subject)?, decoder.decode_subject(subject)?,
decoder.decode_named_node(predicate)?, decoder.decode_named_node(predicate)?,
decoder.decode_term(object)?, decoder.decode_term(object)?,
)) ))

@ -19,8 +19,8 @@ use oxiri::Iri;
use spargebra::algebra::{GraphPattern, GraphTarget}; use spargebra::algebra::{GraphPattern, GraphTarget};
use spargebra::term::{ use spargebra::term::{
BlankNode, GraphName, GraphNamePattern, GroundQuad, GroundQuadPattern, GroundTerm, BlankNode, GraphName, GraphNamePattern, GroundQuad, GroundQuadPattern, GroundTerm,
GroundTermPattern, Literal, NamedNode, NamedNodePattern, NamedOrBlankNode, Quad, QuadPattern, GroundTermPattern, Literal, NamedNode, NamedNodePattern, Quad, QuadPattern, Subject, Term,
Term, TermPattern, Variable, TermPattern, Variable,
}; };
use spargebra::GraphUpdateOperation; use spargebra::GraphUpdateOperation;
use std::collections::HashMap; use std::collections::HashMap;
@ -301,10 +301,8 @@ impl<'a> SimpleUpdateEvaluator<'a> {
) -> Result<Option<EncodedQuad>, EvaluationError> { ) -> Result<Option<EncodedQuad>, EvaluationError> {
Ok(Some(EncodedQuad { Ok(Some(EncodedQuad {
subject: match &quad.subject { subject: match &quad.subject {
NamedOrBlankNode::NamedNode(subject) => { Subject::NamedNode(subject) => self.encode_named_node_for_insertion(subject)?,
self.encode_named_node_for_insertion(subject)? Subject::BlankNode(subject) => self
}
NamedOrBlankNode::BlankNode(subject) => self
.storage .storage
.encode_blank_node(bnodes.entry(subject.clone()).or_default().as_ref())?, .encode_blank_node(bnodes.entry(subject.clone()).or_default().as_ref())?,
}, },

@ -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 { match term {
NamedOrBlankNodeRef::NamedNode(named_node) => get_encoded_named_node(named_node), SubjectRef::NamedNode(named_node) => get_encoded_named_node(named_node),
NamedOrBlankNodeRef::BlankNode(blank_node) => get_encoded_blank_node(blank_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 { pub(crate) fn get_encoded_quad(quad: QuadRef<'_>) -> EncodedQuad {
EncodedQuad { EncodedQuad {
subject: get_encoded_named_or_blank_node(quad.subject), subject: get_encoded_subject(quad.subject),
predicate: get_encoded_named_node(quad.predicate), predicate: get_encoded_named_node(quad.predicate),
object: get_encoded_term(quad.object), object: get_encoded_term(quad.object),
graph_name: get_encoded_graph_name(quad.graph_name), graph_name: get_encoded_graph_name(quad.graph_name),
@ -666,13 +666,10 @@ pub(crate) trait WriteEncoder: StrContainer {
self.encode_rio_literal(literal.into()) self.encode_rio_literal(literal.into())
} }
fn encode_named_or_blank_node( fn encode_subject(&self, term: SubjectRef<'_>) -> Result<EncodedTerm, Self::Error> {
&self,
term: NamedOrBlankNodeRef<'_>,
) -> Result<EncodedTerm, Self::Error> {
match term { match term {
NamedOrBlankNodeRef::NamedNode(named_node) => self.encode_named_node(named_node), SubjectRef::NamedNode(named_node) => self.encode_named_node(named_node),
NamedOrBlankNodeRef::BlankNode(blank_node) => self.encode_blank_node(blank_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<EncodedQuad, Self::Error> { fn encode_quad(&self, quad: QuadRef<'_>) -> Result<EncodedQuad, Self::Error> {
Ok(EncodedQuad { Ok(EncodedQuad {
subject: self.encode_named_or_blank_node(quad.subject)?, subject: self.encode_subject(quad.subject)?,
predicate: self.encode_named_node(quad.predicate)?, predicate: self.encode_named_node(quad.predicate)?,
object: self.encode_term(quad.object)?, object: self.encode_term(quad.object)?,
graph_name: self.encode_graph_name(quad.graph_name)?, graph_name: self.encode_graph_name(quad.graph_name)?,
@ -707,7 +704,7 @@ pub(crate) trait WriteEncoder: StrContainer {
graph_name: EncodedTerm, graph_name: EncodedTerm,
) -> Result<EncodedQuad, Self::Error> { ) -> Result<EncodedQuad, Self::Error> {
Ok(EncodedQuad { Ok(EncodedQuad {
subject: self.encode_named_or_blank_node(triple.subject)?, subject: self.encode_subject(triple.subject)?,
predicate: self.encode_named_node(triple.predicate)?, predicate: self.encode_named_node(triple.predicate)?,
object: self.encode_term(triple.object)?, object: self.encode_term(triple.object)?,
graph_name, graph_name,
@ -838,7 +835,7 @@ pub(crate) trait WriteEncoder: StrContainer {
}) })
} }
fn encode_rio_named_or_blank_node( fn encode_rio_subject(
&self, &self,
term: rio::NamedOrBlankNode<'_>, term: rio::NamedOrBlankNode<'_>,
bnodes_map: &mut HashMap<String, u128>, bnodes_map: &mut HashMap<String, u128>,
@ -869,11 +866,11 @@ pub(crate) trait WriteEncoder: StrContainer {
bnodes_map: &mut HashMap<String, u128>, bnodes_map: &mut HashMap<String, u128>,
) -> Result<EncodedQuad, Self::Error> { ) -> Result<EncodedQuad, Self::Error> {
Ok(EncodedQuad { 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)?, predicate: self.encode_rio_named_node(quad.predicate)?,
object: self.encode_rio_term(quad.object, bnodes_map)?, object: self.encode_rio_term(quad.object, bnodes_map)?,
graph_name: match quad.graph_name { 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, None => EncodedTerm::DefaultGraph,
}, },
}) })
@ -886,7 +883,7 @@ pub(crate) trait WriteEncoder: StrContainer {
bnodes_map: &mut HashMap<String, u128>, bnodes_map: &mut HashMap<String, u128>,
) -> Result<EncodedQuad, Self::Error> { ) -> Result<EncodedQuad, Self::Error> {
Ok(EncodedQuad { 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)?, predicate: self.encode_rio_named_node(triple.predicate)?,
object: self.encode_rio_term(triple.object, bnodes_map)?, object: self.encode_rio_term(triple.object, bnodes_map)?,
graph_name, graph_name,
@ -978,10 +975,7 @@ pub fn parse_day_time_duration_str(value: &str) -> Option<EncodedTerm> {
pub(crate) trait Decoder: StrLookup { pub(crate) trait Decoder: StrLookup {
fn decode_term(&self, encoded: &EncodedTerm) -> Result<Term, DecoderError<Self::Error>>; fn decode_term(&self, encoded: &EncodedTerm) -> Result<Term, DecoderError<Self::Error>>;
fn decode_named_or_blank_node( fn decode_subject(&self, encoded: &EncodedTerm) -> Result<Subject, DecoderError<Self::Error>> {
&self,
encoded: &EncodedTerm,
) -> Result<NamedOrBlankNode, DecoderError<Self::Error>> {
match self.decode_term(encoded)? { match self.decode_term(encoded)? {
Term::NamedNode(named_node) => Ok(named_node.into()), Term::NamedNode(named_node) => Ok(named_node.into()),
Term::BlankNode(blank_node) => Ok(blank_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<Quad, DecoderError<Self::Error>> { fn decode_quad(&self, encoded: &EncodedQuad) -> Result<Quad, DecoderError<Self::Error>> {
Ok(Quad::new( Ok(Quad::new(
self.decode_named_or_blank_node(&encoded.subject)?, self.decode_subject(&encoded.subject)?,
self.decode_named_node(&encoded.predicate)?, self.decode_named_node(&encoded.predicate)?,
self.decode_term(&encoded.object)?, self.decode_term(&encoded.object)?,
match &encoded.graph_name { match &encoded.graph_name {
EncodedTerm::DefaultGraph => None, EncodedTerm::DefaultGraph => None,
graph_name => Some(self.decode_named_or_blank_node(graph_name)?), graph_name => Some(self.decode_subject(graph_name)?),
}, },
)) ))
} }

@ -37,8 +37,8 @@ use crate::sparql::{
}; };
use crate::storage::io::{dump_dataset, dump_graph, load_dataset, load_graph}; use crate::storage::io::{dump_dataset, dump_graph, load_dataset, load_graph};
use crate::storage::numeric_encoder::{ use crate::storage::numeric_encoder::{
get_encoded_graph_name, get_encoded_named_node, get_encoded_named_or_blank_node, get_encoded_graph_name, get_encoded_named_node, get_encoded_quad, get_encoded_subject,
get_encoded_quad, get_encoded_term, Decoder, WriteEncoder, get_encoded_term, Decoder, WriteEncoder,
}; };
pub use crate::storage::ConflictableTransactionError; pub use crate::storage::ConflictableTransactionError;
pub use crate::storage::TransactionError; pub use crate::storage::TransactionError;
@ -164,14 +164,14 @@ impl Store {
/// ``` /// ```
pub fn quads_for_pattern( pub fn quads_for_pattern(
&self, &self,
subject: Option<NamedOrBlankNodeRef<'_>>, subject: Option<SubjectRef<'_>>,
predicate: Option<NamedNodeRef<'_>>, predicate: Option<NamedNodeRef<'_>>,
object: Option<TermRef<'_>>, object: Option<TermRef<'_>>,
graph_name: Option<GraphNameRef<'_>>, graph_name: Option<GraphNameRef<'_>>,
) -> QuadIter { ) -> QuadIter {
QuadIter { QuadIter {
iter: self.storage.quads_for_pattern( 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(), predicate.map(get_encoded_named_node).as_ref(),
object.map(get_encoded_term).as_ref(), object.map(get_encoded_term).as_ref(),
graph_name.map(get_encoded_graph_name).as_ref(), graph_name.map(get_encoded_graph_name).as_ref(),
@ -441,13 +441,13 @@ impl Store {
/// Usage example: /// Usage example:
/// ``` /// ```
/// use oxigraph::store::Store; /// use oxigraph::store::Store;
/// use oxigraph::model::{NamedNode, QuadRef, NamedOrBlankNode}; /// use oxigraph::model::{NamedNode, QuadRef, Subject};
/// ///
/// let ex = NamedNode::new("http://example.com")?; /// let ex = NamedNode::new("http://example.com")?;
/// let store = Store::new()?; /// let store = Store::new()?;
/// store.insert(QuadRef::new(&ex, &ex, &ex, &ex))?; /// store.insert(QuadRef::new(&ex, &ex, &ex, &ex))?;
/// store.insert(QuadRef::new(&ex, &ex, &ex, None))?; /// store.insert(QuadRef::new(&ex, &ex, &ex, None))?;
/// assert_eq!(vec![NamedOrBlankNode::from(ex)], store.named_graphs().collect::<Result<Vec<_>,_>>()?); /// assert_eq!(vec![Subject::from(ex)], store.named_graphs().collect::<Result<Vec<_>,_>>()?);
/// # Result::<_,Box<dyn std::error::Error>>::Ok(()) /// # Result::<_,Box<dyn std::error::Error>>::Ok(())
/// ``` /// ```
pub fn named_graphs(&self) -> GraphNameIter { pub fn named_graphs(&self) -> GraphNameIter {
@ -472,9 +472,9 @@ impl Store {
/// ``` /// ```
pub fn contains_named_graph<'a>( pub fn contains_named_graph<'a>(
&self, &self,
graph_name: impl Into<NamedOrBlankNodeRef<'a>>, graph_name: impl Into<SubjectRef<'a>>,
) -> Result<bool, io::Error> { ) -> Result<bool, io::Error> {
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) self.storage.contains_named_graph(&graph_name)
} }
@ -495,9 +495,9 @@ impl Store {
/// ``` /// ```
pub fn insert_named_graph<'a>( pub fn insert_named_graph<'a>(
&self, &self,
graph_name: impl Into<NamedOrBlankNodeRef<'a>>, graph_name: impl Into<SubjectRef<'a>>,
) -> Result<bool, io::Error> { ) -> Result<bool, io::Error> {
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) self.storage.insert_named_graph(&graph_name)
} }
@ -549,9 +549,9 @@ impl Store {
/// ``` /// ```
pub fn remove_named_graph<'a>( pub fn remove_named_graph<'a>(
&self, &self,
graph_name: impl Into<NamedOrBlankNodeRef<'a>>, graph_name: impl Into<SubjectRef<'a>>,
) -> Result<bool, io::Error> { ) -> Result<bool, io::Error> {
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) self.storage.remove_named_graph(&graph_name)
} }
@ -714,9 +714,9 @@ impl Transaction<'_> {
/// Returns `true` if the graph was not already in the store. /// Returns `true` if the graph was not already in the store.
pub fn insert_named_graph<'a>( pub fn insert_named_graph<'a>(
&self, &self,
graph_name: impl Into<NamedOrBlankNodeRef<'a>>, graph_name: impl Into<SubjectRef<'a>>,
) -> Result<bool, UnabortableTransactionError> { ) -> Result<bool, UnabortableTransactionError> {
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) self.storage.insert_named_graph(&graph_name)
} }
} }
@ -745,13 +745,13 @@ pub struct GraphNameIter {
} }
impl Iterator for GraphNameIter { impl Iterator for GraphNameIter {
type Item = Result<NamedOrBlankNode, io::Error>; type Item = Result<Subject, io::Error>;
fn next(&mut self) -> Option<Result<NamedOrBlankNode, io::Error>> { fn next(&mut self) -> Option<Result<Subject, io::Error>> {
Some( Some(
self.iter.next()?.and_then(|graph_name| { self.iter
Ok(self.store.storage.decode_named_or_blank_node(&graph_name)?) .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> { fn store() -> Result<(), io::Error> {
use crate::model::*; 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_p = NamedNode::new("http://example.com").unwrap();
let main_o = Term::from(Literal::from(1)); let main_o = Term::from(Literal::from(1));
let main_g = GraphName::from(BlankNode::default()); let main_g = GraphName::from(BlankNode::default());

@ -167,7 +167,7 @@ fn test_backward_compatibility() -> io::Result<()> {
} }
assert!(store.contains_named_graph(graph_name)?); assert!(store.contains_named_graph(graph_name)?);
assert_eq!( assert_eq!(
vec![NamedOrBlankNode::from(graph_name)], vec![Subject::from(graph_name)],
store.named_graphs().collect::<io::Result<Vec<_>>>()? store.named_graphs().collect::<io::Result<Vec<_>>>()?
); );
}; };

@ -39,7 +39,7 @@ impl From<PyNamedNode> for NamedNode {
} }
} }
impl From<PyNamedNode> for NamedOrBlankNode { impl From<PyNamedNode> for Subject {
fn from(node: PyNamedNode) -> Self { fn from(node: PyNamedNode) -> Self {
node.inner.into() node.inner.into()
} }
@ -138,7 +138,7 @@ impl From<PyBlankNode> for BlankNode {
} }
} }
impl From<PyBlankNode> for NamedOrBlankNode { impl From<PyBlankNode> for Subject {
fn from(node: PyBlankNode) -> Self { fn from(node: PyBlankNode) -> Self {
node.inner.into() node.inner.into()
} }
@ -405,34 +405,34 @@ impl PyObjectProtocol for PyDefaultGraph {
} }
#[derive(FromPyObject)] #[derive(FromPyObject)]
pub enum PyNamedOrBlankNode { pub enum PySubject {
NamedNode(PyNamedNode), NamedNode(PyNamedNode),
BlankNode(PyBlankNode), BlankNode(PyBlankNode),
} }
impl From<PyNamedOrBlankNode> for NamedOrBlankNode { impl From<PySubject> for Subject {
fn from(node: PyNamedOrBlankNode) -> Self { fn from(node: PySubject) -> Self {
match node { match node {
PyNamedOrBlankNode::NamedNode(node) => node.into(), PySubject::NamedNode(node) => node.into(),
PyNamedOrBlankNode::BlankNode(node) => node.into(), PySubject::BlankNode(node) => node.into(),
} }
} }
} }
impl From<NamedOrBlankNode> for PyNamedOrBlankNode { impl From<Subject> for PySubject {
fn from(node: NamedOrBlankNode) -> Self { fn from(node: Subject) -> Self {
match node { match node {
NamedOrBlankNode::NamedNode(node) => PyNamedOrBlankNode::NamedNode(node.into()), Subject::NamedNode(node) => PySubject::NamedNode(node.into()),
NamedOrBlankNode::BlankNode(node) => PyNamedOrBlankNode::BlankNode(node.into()), Subject::BlankNode(node) => PySubject::BlankNode(node.into()),
} }
} }
} }
impl IntoPy<PyObject> for PyNamedOrBlankNode { impl IntoPy<PyObject> for PySubject {
fn into_py(self, py: Python<'_>) -> PyObject { fn into_py(self, py: Python<'_>) -> PyObject {
match self { match self {
PyNamedOrBlankNode::NamedNode(node) => node.into_py(py), PySubject::NamedNode(node) => node.into_py(py),
PyNamedOrBlankNode::BlankNode(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] #[pymethods]
impl PyTriple { impl PyTriple {
#[new] #[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() 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 /// >>> Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')).subject
/// <NamedNode value=http://example.com> /// <NamedNode value=http://example.com>
#[getter] #[getter]
fn subject(&self) -> PyNamedOrBlankNode { fn subject(&self) -> PySubject {
self.inner.subject.clone().into() self.inner.subject.clone().into()
} }
@ -700,7 +700,7 @@ impl<'a> From<&'a PyQuad> for QuadRef<'a> {
impl PyQuad { impl PyQuad {
#[new] #[new]
fn new( fn new(
subject: PyNamedOrBlankNode, subject: PySubject,
predicate: PyNamedNode, predicate: PyNamedNode,
object: PyTerm, object: PyTerm,
graph_name: Option<PyGraphName>, graph_name: Option<PyGraphName>,
@ -720,7 +720,7 @@ impl PyQuad {
/// >>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).subject /// >>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).subject
/// <NamedNode value=http://example.com> /// <NamedNode value=http://example.com>
#[getter] #[getter]
fn subject(&self) -> PyNamedOrBlankNode { fn subject(&self) -> PySubject {
self.inner.subject.clone().into() self.inner.subject.clone().into()
} }
@ -804,7 +804,7 @@ impl PyMappingProtocol<'p> for PyQuad {
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();
let py = gil.python(); let py = gil.python();
match input { 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)), 1 => Ok(PyNamedNode::from(self.inner.predicate.clone()).into_py(py)),
2 => Ok(PyTerm::from(self.inner.object.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)), 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>), NamedNode(PyRef<'a, PyNamedNode>),
BlankNode(PyRef<'a, PyBlankNode>), BlankNode(PyRef<'a, PyBlankNode>),
} }
impl<'a> From<&'a PyNamedOrBlankNodeRef<'a>> for NamedOrBlankNodeRef<'a> { impl<'a> From<&'a PySubjectRef<'a>> for SubjectRef<'a> {
fn from(value: &'a PyNamedOrBlankNodeRef<'a>) -> Self { fn from(value: &'a PySubjectRef<'a>) -> Self {
match value { match value {
PyNamedOrBlankNodeRef::NamedNode(value) => value.inner.as_ref().into(), PySubjectRef::NamedNode(value) => value.inner.as_ref().into(),
PyNamedOrBlankNodeRef::BlankNode(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; type Error = PyErr;
fn try_from(value: &'a PyAny) -> PyResult<Self> { fn try_from(value: &'a PyAny) -> PyResult<Self> {

@ -50,7 +50,7 @@ pub fn parse_query(
query.dataset_mut().set_available_named_graphs( query.dataset_mut().set_available_named_graphs(
named_graphs named_graphs
.iter()? .iter()?
.map(|graph| Ok(graph?.extract::<PyNamedOrBlankNode>()?.into())) .map(|graph| Ok(graph?.extract::<PySubject>()?.into()))
.collect::<PyResult<_>>()?, .collect::<PyResult<_>>()?,
) )
} }

@ -385,11 +385,11 @@ impl PyStore {
PyGraphNameRef::DefaultGraph => Ok(()), PyGraphNameRef::DefaultGraph => Ok(()),
PyGraphNameRef::NamedNode(graph_name) => self PyGraphNameRef::NamedNode(graph_name) => self
.inner .inner
.insert_named_graph(&PyNamedOrBlankNodeRef::NamedNode(graph_name)) .insert_named_graph(&PySubjectRef::NamedNode(graph_name))
.map(|_| ()), .map(|_| ()),
PyGraphNameRef::BlankNode(graph_name) => self PyGraphNameRef::BlankNode(graph_name) => self
.inner .inner
.insert_named_graph(&PyNamedOrBlankNodeRef::BlankNode(graph_name)) .insert_named_graph(&PySubjectRef::BlankNode(graph_name))
.map(|_| ()), .map(|_| ()),
} }
.map_err(map_io_err) .map_err(map_io_err)
@ -414,11 +414,11 @@ impl PyStore {
PyGraphNameRef::DefaultGraph => self.inner.clear_graph(GraphNameRef::DefaultGraph), PyGraphNameRef::DefaultGraph => self.inner.clear_graph(GraphNameRef::DefaultGraph),
PyGraphNameRef::NamedNode(graph_name) => self PyGraphNameRef::NamedNode(graph_name) => self
.inner .inner
.remove_named_graph(&PyNamedOrBlankNodeRef::NamedNode(graph_name)) .remove_named_graph(&PySubjectRef::NamedNode(graph_name))
.map(|_| ()), .map(|_| ()),
PyGraphNameRef::BlankNode(graph_name) => self PyGraphNameRef::BlankNode(graph_name) => self
.inner .inner
.remove_named_graph(&PyNamedOrBlankNodeRef::BlankNode(graph_name)) .remove_named_graph(&PySubjectRef::BlankNode(graph_name))
.map(|_| ()), .map(|_| ()),
} }
.map_err(map_io_err)?; .map_err(map_io_err)?;
@ -487,7 +487,7 @@ impl PyIterProtocol for GraphNameIter {
slf.into() slf.into()
} }
fn __next__(mut slf: PyRefMut<Self>) -> PyResult<Option<PyNamedOrBlankNode>> { fn __next__(mut slf: PyRefMut<Self>) -> PyResult<Option<PySubject>> {
slf.inner slf.inner
.next() .next()
.map(|q| Ok(q.map_err(map_io_err)?.into())) .map(|q| Ok(q.map_err(map_io_err)?.into()))
@ -501,7 +501,7 @@ pub fn extract_quads_pattern<'a>(
object: &'a PyAny, object: &'a PyAny,
graph_name: Option<&'a PyAny>, graph_name: Option<&'a PyAny>,
) -> PyResult<( ) -> PyResult<(
Option<PyNamedOrBlankNodeRef<'a>>, Option<PySubjectRef<'a>>,
Option<PyNamedNodeRef<'a>>, Option<PyNamedNodeRef<'a>>,
Option<PyTermRef<'a>>, Option<PyTermRef<'a>>,
Option<PyGraphNameRef<'a>>, Option<PyGraphNameRef<'a>>,

@ -21,7 +21,7 @@ use http_types::{
StatusCode, StatusCode,
}; };
use oxigraph::io::{DatasetFormat, GraphFormat}; 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::sparql::{Query, QueryResults, QueryResultsFormat, Update};
use oxigraph::store::Store; use oxigraph::store::Store;
use oxiri::Iri; use oxiri::Iri;
@ -407,7 +407,7 @@ fn evaluate_sparql_query(
let named_graph_uris = named_graph_uris let named_graph_uris = named_graph_uris
.into_iter() .into_iter()
.map(|e| Ok(NamedNode::new(e)?.into())) .map(|e| Ok(NamedNode::new(e)?.into()))
.collect::<Result<Vec<NamedOrBlankNode>>>() .collect::<Result<Vec<Subject>>>()
.map_err(bad_request)?; .map_err(bad_request)?;
if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() { 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 let named_graph_uris = named_graph_uris
.into_iter() .into_iter()
.map(|e| Ok(NamedNode::new(e)?.into())) .map(|e| Ok(NamedNode::new(e)?.into()))
.collect::<Result<Vec<NamedOrBlankNode>>>() .collect::<Result<Vec<Subject>>>()
.map_err(bad_request)?; .map_err(bad_request)?;
if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() { if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() {
for using in update.using_datasets_mut() { for using in update.using_datasets_mut() {

@ -123,29 +123,29 @@ impl fmt::Display for Literal {
/// ///
/// The default string formatter is returning an N-Triples, Turtle and SPARQL compatible representation. /// The default string formatter is returning an N-Triples, Turtle and SPARQL compatible representation.
#[derive(Eq, PartialEq, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub enum NamedOrBlankNode { pub enum Subject {
NamedNode(NamedNode), NamedNode(NamedNode),
BlankNode(BlankNode), BlankNode(BlankNode),
} }
impl fmt::Display for NamedOrBlankNode { impl fmt::Display for Subject {
#[inline] #[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
NamedOrBlankNode::NamedNode(node) => node.fmt(f), Subject::NamedNode(node) => node.fmt(f),
NamedOrBlankNode::BlankNode(node) => node.fmt(f), Subject::BlankNode(node) => node.fmt(f),
} }
} }
} }
impl From<NamedNode> for NamedOrBlankNode { impl From<NamedNode> for Subject {
#[inline] #[inline]
fn from(node: NamedNode) -> Self { fn from(node: NamedNode) -> Self {
Self::NamedNode(node) Self::NamedNode(node)
} }
} }
impl From<BlankNode> for NamedOrBlankNode { impl From<BlankNode> for Subject {
#[inline] #[inline]
fn from(node: BlankNode) -> Self { fn from(node: BlankNode) -> Self {
Self::BlankNode(node) Self::BlankNode(node)
@ -196,12 +196,12 @@ impl From<Literal> for Term {
} }
} }
impl From<NamedOrBlankNode> for Term { impl From<Subject> for Term {
#[inline] #[inline]
fn from(resource: NamedOrBlankNode) -> Self { fn from(resource: Subject) -> Self {
match resource { match resource {
NamedOrBlankNode::NamedNode(node) => Self::NamedNode(node), Subject::NamedNode(node) => Self::NamedNode(node),
NamedOrBlankNode::BlankNode(node) => Self::BlankNode(node), Subject::BlankNode(node) => Self::BlankNode(node),
} }
} }
} }
@ -285,7 +285,7 @@ impl From<NamedNode> for GraphName {
/// ``` /// ```
#[derive(Eq, PartialEq, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct Quad { pub struct Quad {
pub subject: NamedOrBlankNode, pub subject: Subject,
pub predicate: NamedNode, pub predicate: NamedNode,
pub object: Term, pub object: Term,
pub graph_name: GraphName, pub graph_name: GraphName,

@ -161,7 +161,7 @@ impl Iterator for TestManifest {
TermRef::BlankNode(g) => Some(g.into()), TermRef::BlankNode(g) => Some(g.into()),
_ => None, _ => None,
}) })
.filter_map(|g: NamedOrBlankNodeRef<'_>| { .filter_map(|g: SubjectRef<'_>| {
if let ( if let (
Some(TermRef::NamedNode(endpoint)), Some(TermRef::NamedNode(endpoint)),
Some(TermRef::NamedNode(data)), Some(TermRef::NamedNode(data)),
@ -246,8 +246,7 @@ impl Iterator for TestManifest {
None => { None => {
match self.manifests_to_do.pop() { match self.manifests_to_do.pop() {
Some(url) => { Some(url) => {
let manifest = let manifest = SubjectRef::from(NamedNodeRef::new(url.as_str()).unwrap());
NamedOrBlankNodeRef::from(NamedNodeRef::new(url.as_str()).unwrap());
if let Err(error) = load_to_graph(&url, &mut self.graph) { if let Err(error) = load_to_graph(&url, &mut self.graph) {
return Some(Err(error)); return Some(Err(error));
} }
@ -296,11 +295,11 @@ impl Iterator for TestManifest {
struct RdfListIterator<'a> { struct RdfListIterator<'a> {
graph: &'a Graph, graph: &'a Graph,
current_node: Option<NamedOrBlankNodeRef<'a>>, current_node: Option<SubjectRef<'a>>,
} }
impl<'a> RdfListIterator<'a> { 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 { RdfListIterator {
graph, graph,
current_node: Some(root), current_node: Some(root),

@ -104,7 +104,7 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> {
} }
} }
for graph_name in query.dataset().available_named_graphs().unwrap_or(&[]) { 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())?; load_to_store(graph_name.as_str(), &store, graph_name.as_ref())?;
} else { } else {
return Err(anyhow!( return Err(anyhow!(

@ -21,7 +21,7 @@ use http_types::{
StatusCode, StatusCode,
}; };
use oxigraph::io::GraphFormat; use oxigraph::io::GraphFormat;
use oxigraph::model::{GraphName, NamedNode, NamedOrBlankNode}; use oxigraph::model::{GraphName, NamedNode, Subject};
use oxigraph::sparql::{Query, QueryResults, QueryResultsFormat}; use oxigraph::sparql::{Query, QueryResults, QueryResultsFormat};
use oxigraph::store::Store; use oxigraph::store::Store;
use std::str::FromStr; use std::str::FromStr;
@ -202,7 +202,7 @@ fn evaluate_sparql_query(
let named_graph_uris = named_graph_uris let named_graph_uris = named_graph_uris
.into_iter() .into_iter()
.map(|e| Ok(NamedNode::new(e)?.into())) .map(|e| Ok(NamedNode::new(e)?.into()))
.collect::<Result<Vec<NamedOrBlankNode>>>() .collect::<Result<Vec<Subject>>>()
.map_err(bad_request)?; .map_err(bad_request)?;
if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() { if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() {

Loading…
Cancel
Save