pub struct Graph { /* private fields */ }
Expand description
An in-memory RDF graph.
It can accommodate a fairly large number of triples (in the few millions).
It interns the string 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 graph = Graph::default();
// insertion
let ex = NamedNodeRef::new("http://example.com")?;
let triple = TripleRef::new(ex, ex, ex);
graph.insert(triple);
// simple filter
let results: Vec<_> = graph.triples_for_subject(ex).collect();
assert_eq!(vec![triple], results);
Implementations§
Source§impl Graph
impl Graph
pub fn triples_for_subject<'a, 'b>( &'a self, subject: impl Into<SubjectRef<'b>>, ) -> impl Iterator<Item = TripleRef<'a>> + 'a
pub fn objects_for_subject_predicate<'a, 'b>( &'a self, subject: impl Into<SubjectRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>, ) -> impl Iterator<Item = TermRef<'a>> + 'a
pub fn object_for_subject_predicate<'a, 'b>( &'a self, subject: impl Into<SubjectRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>, ) -> Option<TermRef<'a>>
pub fn predicates_for_subject_object<'a, 'b>( &'a self, subject: impl Into<SubjectRef<'b>>, object: impl Into<TermRef<'b>>, ) -> impl Iterator<Item = NamedNodeRef<'a>> + 'a
pub fn triples_for_predicate<'a, 'b>( &'a self, predicate: impl Into<NamedNodeRef<'b>>, ) -> impl Iterator<Item = TripleRef<'a>> + 'a
pub fn subjects_for_predicate_object<'a, 'b>( &'a self, predicate: impl Into<NamedNodeRef<'b>>, object: impl Into<TermRef<'b>>, ) -> impl Iterator<Item = SubjectRef<'a>> + 'a
pub fn subject_for_predicate_object<'a, 'b>( &'a self, predicate: impl Into<NamedNodeRef<'b>>, object: impl Into<TermRef<'b>>, ) -> Option<SubjectRef<'a>>
pub fn triples_for_object<'a, 'b>( &'a self, object: impl Into<TermRef<'b>>, ) -> impl Iterator<Item = TripleRef<'a>> + 'a
Sourcepub fn contains<'a>(&self, triple: impl Into<TripleRef<'a>>) -> bool
pub fn contains<'a>(&self, triple: impl Into<TripleRef<'a>>) -> bool
Checks if the graph contains the given triple.
Sourcepub fn insert<'a>(&mut self, triple: impl Into<TripleRef<'a>>) -> bool
pub fn insert<'a>(&mut self, triple: impl Into<TripleRef<'a>>) -> bool
Adds a triple to the graph.
Sourcepub fn remove<'a>(&mut self, triple: impl Into<TripleRef<'a>>) -> bool
pub fn remove<'a>(&mut self, triple: impl Into<TripleRef<'a>>) -> bool
Removes a concrete triple from the graph.
Sourcepub fn canonicalize(&mut self, algorithm: CanonicalizationAlgorithm)
pub fn canonicalize(&mut self, algorithm: CanonicalizationAlgorithm)
Canonicalizes the dataset by renaming blank nodes.
Usage example (Graph isomorphism):
use oxrdf::graph::CanonicalizationAlgorithm;
use oxrdf::*;
let iri = NamedNodeRef::new("http://example.com")?;
let mut graph1 = Graph::new();
let bnode1 = BlankNode::default();
graph1.insert(TripleRef::new(iri, iri, &bnode1));
graph1.insert(TripleRef::new(&bnode1, iri, iri));
let mut graph2 = Graph::new();
let bnode2 = BlankNode::default();
graph2.insert(TripleRef::new(iri, iri, &bnode2));
graph2.insert(TripleRef::new(&bnode2, iri, iri));
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.
Trait Implementations§
Source§impl<'a, T> Extend<T> for Graph
impl<'a, T> Extend<T> for Graph
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
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 Extend<Triple> for Graph
impl Extend<Triple> for Graph
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Triple>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Triple>,
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> FromIterator<T> for Graph
impl<'a, T> FromIterator<T> for Graph
Source§impl FromIterator<Triple> for Graph
impl FromIterator<Triple> for Graph
Source§impl<'a> IntoIterator for &'a Graph
impl<'a> IntoIterator for &'a Graph
impl Eq for Graph
Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnwindSafe for Graph
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