Skip to main content

Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

A graph is an unordered list of statements and may include duplicates. Note that this trait represents an immutable graph, a type should also implement the MutableGraph trait for mutation.

Implementations§

Source§

impl Graph

Source

pub fn named<N>(name: N) -> Self
where N: Into<GraphName>,

Source

pub fn unique() -> Self

Source

pub fn unique_named<N>(name: N) -> Self
where N: Into<GraphName>,

Source

pub fn with_mappings(self, mappings: IriPrefixMap) -> Self

Source

pub fn with_statements(self, statements: Vec<Statement>) -> Self

Source

pub fn is_empty(&self) -> bool

Returns true if there are no statements in this graph, else false.

Source

pub fn len(&self) -> usize

Return the number of statements in this graph.

Source

pub fn is_named(&self) -> bool

Returns true if this graph instance has a name.

Source

pub fn name(&self) -> Option<&GraphName>

Return the name of this graph.

Source

pub fn set_name(&mut self, name: GraphName)

Set the name of this graph.

Source

pub fn unset_name(&mut self)

Remove the name of this graph.

Source

pub fn contains_subject(&self, subject: &SubjectNode) -> bool

Returns true if this graph contains any statement with the provided subject, else false.

Source

pub fn contains(&self, statement: &Statement) -> bool

Returns true if this graph contains the provided statement, else false.

Source

pub fn contains_all( &self, subject: &SubjectNode, predicate: &Iri, object: &ObjectNode, ) -> bool

Returns true if this graph contains the any statement with the provided subject, predicate, and object, else false.

Source

pub fn matches( &self, subject: Option<&SubjectNode>, predicate: Option<&Iri>, object: Option<&ObjectNode>, ) -> HashSet<&Statement>

Returns true if this graph contains the any statement with the provided subject, predicate, and object, else false.

Source

pub fn statements(&self) -> impl Iterator<Item = &Statement>

Return an iterator over all the statements in the graph.

Source

pub fn subjects(&self) -> HashSet<&SubjectNode>

Return a set of all subjects in the graph, note that this is a set so that it removes duplicates.

Source

pub fn node_subjects(&self) -> HashSet<&SubjectNode>

Return a set of all subjects that are not blank nodes

Source

pub fn blank_node_subjects(&self) -> HashSet<&SubjectNode>

Return a set of all subjects that are blank nodes

Source

pub fn predicates(&self) -> HashSet<&Iri>

Return a set of all predicate in the graph, note that this is a set so that it removes duplicates.

Source

pub fn predicates_for(&self, subject: &SubjectNode) -> HashSet<&Iri>

Return a set of all predicate referenced by the provided subject in graph, note that this is a set so that it removes duplicates.

Source

pub fn objects(&self) -> HashSet<&ObjectNode>

Return a set of all objects in the graph, note that this is a set so that it removes duplicates.

Source

pub fn objects_for( &self, subject: &SubjectNode, predicate: &Iri, ) -> HashSet<&ObjectNode>

Return a set of all objects referenced by the provided subject and predicate in the graph, note that this is a set so that it removes duplicates.

Source

pub fn prefix_mappings(&self) -> &IriPrefixMap

Returns the set of prefix mappings held by the graph.

Source

pub fn set_prefix_mappings(&mut self, mappings: IriPrefixMap)

Set the prefix mappings held by the graph.

Source

pub fn insert(&mut self, statement: Statement)

Insert a new statement into the graph.

Source

pub fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = Statement>,

Source

pub fn merge(&mut self, other: &Self)

Merge another graph into this one. Note that the graphs are required to have the same implementation type based in the type qualifiers for StatementIter.

Source

pub fn dedup(&mut self) -> Vec<Statement>

Remove any duplicates within the graph, replacing any number of identical statements with just one. This will return a list of all statements removed.

This method does nothing if this graph has does not support the feature FEATURE_GRAPH_DUPLICATES and will therefore always return an empty list.

Source

pub fn remove(&mut self, statement: &Statement)

Remove any statement that matches the provided. If a graph has duplicates this method does not differentiate between them.

Source

pub fn remove_all_for(&mut self, subject: &SubjectNode) -> Vec<Statement>

Remove all statements from this graph that have the provided subject.

Source

pub fn clear(&mut self)

Remove all statements from this graph.

Source

pub fn skolemize(&self, base: &Iri) -> Result<Self, Error>

Return a new graph replacing all blank nodes with new, unique Iris. The base Iri is used to create identifiers, it’s path will be replaced entirely by a well-known format.

For example, given the following input graph with blank nodes:

<https://example.org/p/me> <https://example.org/v/name> _:B0f21 .
_:B0f21 <https://example.org/v/firstName> "My" .
_:B0f21 <https://example.org/v/lastName> "Name" .

the call to skolemize,

let base = Iri::from_str("https://example.com/me").unwrap();
graph.skolemize(&base)

results in a new graph containing replacement IRIs.

<https://example.org/p/me>
  <https://example.org/v/name>
  <https://example.com/.well-known/genid/62D22842-0D24-4911-AE7D-DF4DE06FD62F> .
<https://example.com/.well-known/genid/62D22842-0D24-4911-AE7D-DF4DE06FD62F>
  <https://example.org/v/firstName>
  "My" .
<https://example.com/.well-known/genid/62D22842-0D24-4911-AE7D-DF4DE06FD62F>
  <https://example.org/v/lastName>
  "Name" .
Source

pub fn simplify(&self) -> Result<Self, Error>

Return a new graph with certain features flattened to simplify the graph to a strict triple structure. For example:

  1. RDF* statements in subject and object nodes are reified into the graph.
  2. RDF collection objects in object nodes are reified into the graph.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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

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§

fn supports_feature(&self, feature: &Iri) -> bool

Return true if this instance, or factory, supports the feature identified by the Iri.
Source§

impl From<Graph> for DataSet

Source§

fn from(graphs: Graph) -> Self

Converts to this type from the input type.
Source§

impl From<Statement> for Graph

Source§

fn from(value: Statement) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Statement>> for Graph

Source§

fn from(value: Vec<Statement>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Graph> for DataSet

Source§

fn from_iter<T: IntoIterator<Item = Graph>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Statement> for Graph

Source§

fn from_iter<T: IntoIterator<Item = Statement>>(iter: T) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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, 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.