pub struct Dataset { /* private fields */ }
Expand description
An in-memory RDF dataset.
It can accommodate a fairly large number of quads (in the few millions).
It interns the strings and does not do any garbage collection yet:
if you insert and remove a lot of different terms, memory will grow without any reduction.
Usage example:
use oxrdf::*;
let mut dataset = Dataset::default();
// insertion
let ex = NamedNodeRef::new("http://example.com")?;
let quad = QuadRef::new(ex, ex, ex, ex);
dataset.insert(quad);
// simple filter
let results: Vec<_> = dataset.quads_for_subject(ex).collect();
assert_eq!(vec![quad], results);
// direct access to a dataset graph
let results: Vec<_> = dataset.graph(ex).iter().collect();
assert_eq!(vec![TripleRef::new(ex, ex, ex)], results);
Implementations§
Source§impl Dataset
impl Dataset
Sourcepub fn graph<'a, 'b>(
&'a self,
graph_name: impl Into<GraphNameRef<'b>>,
) -> GraphView<'a>
pub fn graph<'a, 'b>( &'a self, graph_name: impl Into<GraphNameRef<'b>>, ) -> GraphView<'a>
Provides a read-only view on an RDF graph contained in this dataset.
use oxrdf::*;
let mut dataset = Dataset::default();
let ex = NamedNodeRef::new("http://example.com")?;
dataset.insert(QuadRef::new(ex, ex, ex, ex));
let results: Vec<_> = dataset.graph(ex).iter().collect();
assert_eq!(vec![TripleRef::new(ex, ex, ex)], results);
Sourcepub fn graph_mut<'a, 'b>(
&'a mut self,
graph_name: impl Into<GraphNameRef<'b>>,
) -> GraphViewMut<'a>
pub fn graph_mut<'a, 'b>( &'a mut self, graph_name: impl Into<GraphNameRef<'b>>, ) -> GraphViewMut<'a>
Provides a read/write view on an RDF graph contained in this dataset.
use oxrdf::*;
let mut dataset = Dataset::default();
let ex = NamedNodeRef::new("http://example.com")?;
// We edit and query the dataset http://example.com graph
{
let mut graph = dataset.graph_mut(ex);
graph.insert(TripleRef::new(ex, ex, ex));
let results: Vec<_> = graph.iter().collect();
assert_eq!(vec![TripleRef::new(ex, ex, ex)], results);
}
// We have also changes the dataset itself
let results: Vec<_> = dataset.iter().collect();
assert_eq!(vec![QuadRef::new(ex, ex, ex, ex)], results);
pub fn quads_for_subject<'a, 'b>( &'a self, subject: impl Into<SubjectRef<'b>>, ) -> impl Iterator<Item = QuadRef<'a>> + 'a
pub fn quads_for_predicate<'a, 'b>( &'a self, predicate: impl Into<NamedNodeRef<'b>>, ) -> impl Iterator<Item = QuadRef<'a>> + 'a
pub fn quads_for_object<'a, 'b>( &'a self, object: impl Into<TermRef<'b>>, ) -> impl Iterator<Item = QuadRef<'a>> + 'a
pub fn quads_for_graph_name<'a, 'b>( &'a self, graph_name: impl Into<GraphNameRef<'b>>, ) -> impl Iterator<Item = QuadRef<'a>> + 'a
Sourcepub fn contains<'a>(&self, quad: impl Into<QuadRef<'a>>) -> bool
pub fn contains<'a>(&self, quad: impl Into<QuadRef<'a>>) -> bool
Checks if the dataset contains the given quad
Sourcepub fn remove<'a>(&mut self, quad: impl Into<QuadRef<'a>>) -> bool
pub fn remove<'a>(&mut self, quad: impl Into<QuadRef<'a>>) -> bool
Removes a concrete quad from the dataset.
Sourcepub fn canonicalize(&mut self, algorithm: CanonicalizationAlgorithm)
pub fn canonicalize(&mut self, algorithm: CanonicalizationAlgorithm)
Canonicalizes the dataset by renaming blank nodes.
Usage example (Dataset isomorphism):
use oxrdf::dataset::CanonicalizationAlgorithm;
use oxrdf::*;
let iri = NamedNodeRef::new("http://example.com")?;
let mut graph1 = Graph::new();
let bnode1 = BlankNode::default();
let g1 = BlankNode::default();
graph1.insert(QuadRef::new(iri, iri, &bnode1, &g1));
graph1.insert(QuadRef::new(&bnode1, iri, iri, &g1));
let mut graph2 = Graph::new();
let bnode2 = BlankNode::default();
let g2 = BlankNode::default();
graph2.insert(QuadRef::new(iri, iri, &bnode2, &g2));
graph2.insert(QuadRef::new(&bnode2, iri, iri, &g2));
assert_ne!(graph1, graph2);
graph1.canonicalize(CanonicalizationAlgorithm::Unstable);
graph2.canonicalize(CanonicalizationAlgorithm::Unstable);
assert_eq!(graph1, graph2);
Blank node ids depends on the current shape of the graph. Adding a new quad might change the ids of a lot of blank nodes.
Hence, this canonization might not be suitable for diffs.
This implementation worst-case complexity is in *O(b!)* with *b* the number of blank nodes in the input dataset.
Sourcepub fn canonicalize_blank_nodes(
&self,
algorithm: CanonicalizationAlgorithm,
) -> HashMap<BlankNodeRef<'_>, BlankNode>
pub fn canonicalize_blank_nodes( &self, algorithm: CanonicalizationAlgorithm, ) -> HashMap<BlankNodeRef<'_>, BlankNode>
Returns a map between the current dataset blank node and the canonicalized blank node to create a canonical dataset.
See also canonicalize
.
Trait Implementations§
Source§impl Extend<Quad> for Dataset
impl Extend<Quad> for Dataset
Source§fn extend<I: IntoIterator<Item = Quad>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Quad>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<'a, T: Into<QuadRef<'a>>> Extend<T> for Dataset
impl<'a, T: Into<QuadRef<'a>>> Extend<T> for Dataset
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl FromIterator<Quad> for Dataset
impl FromIterator<Quad> for Dataset
Source§impl<'a, T: Into<QuadRef<'a>>> FromIterator<T> for Dataset
impl<'a, T: Into<QuadRef<'a>>> FromIterator<T> for Dataset
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
Source§impl<'a> IntoIterator for &'a Dataset
impl<'a> IntoIterator for &'a Dataset
impl Eq for Dataset
Auto Trait Implementations§
impl Freeze for Dataset
impl RefUnwindSafe for Dataset
impl Send for Dataset
impl Sync for Dataset
impl Unpin for Dataset
impl UnwindSafe for Dataset
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more