oxigraph::model

Struct Graph

Source
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

Source

pub fn new() -> Graph

Creates a new graph.

Source

pub fn iter(&self) -> Iter<'_>

Returns all the triples contained by the graph.

Source

pub fn triples_for_subject<'a, 'b>( &'a self, subject: impl Into<SubjectRef<'b>>, ) -> impl Iterator<Item = TripleRef<'a>> + 'a

Source

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

Source

pub fn object_for_subject_predicate<'a, 'b>( &'a self, subject: impl Into<SubjectRef<'b>>, predicate: impl Into<NamedNodeRef<'b>>, ) -> Option<TermRef<'a>>

Source

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

Source

pub fn triples_for_predicate<'a, 'b>( &'a self, predicate: impl Into<NamedNodeRef<'b>>, ) -> impl Iterator<Item = TripleRef<'a>> + 'a

Source

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

Source

pub fn subject_for_predicate_object<'a, 'b>( &'a self, predicate: impl Into<NamedNodeRef<'b>>, object: impl Into<TermRef<'b>>, ) -> Option<SubjectRef<'a>>

Source

pub fn triples_for_object<'a, 'b>( &'a self, object: impl Into<TermRef<'b>>, ) -> impl Iterator<Item = TripleRef<'a>> + 'a

Source

pub fn contains<'a>(&self, triple: impl Into<TripleRef<'a>>) -> bool

Checks if the graph contains the given triple.

Source

pub fn len(&self) -> usize

Returns the number of triples in this graph.

Source

pub fn is_empty(&self) -> bool

Checks if this graph contains a triple.

Source

pub fn insert<'a>(&mut self, triple: impl Into<TripleRef<'a>>) -> bool

Adds a triple to the graph.

Source

pub fn remove<'a>(&mut self, triple: impl Into<TripleRef<'a>>) -> bool

Removes a concrete triple from the graph.

Source

pub fn clear(&mut self)

Clears the graph.

Source

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 Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Graph

Source§

fn default() -> Graph

Returns the “default value” for a type. Read more
Source§

impl Display for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a, T> Extend<T> for Graph
where T: Into<TripleRef<'a>>,

Source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

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

Source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

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
where T: Into<TripleRef<'a>>,

Source§

fn from_iter<I>(iter: I) -> Graph
where I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
Source§

impl FromIterator<Triple> for Graph

Source§

fn from_iter<I>(iter: I) -> Graph
where I: IntoIterator<Item = Triple>,

Creates a value from an iterator. Read more
Source§

impl<'a> IntoIterator for &'a Graph

Source§

type Item = TripleRef<'a>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a Graph as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Graph

Source§

fn eq(&self, other: &Graph) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V