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
impl Graph
pub fn named<N>(name: N) -> Self
pub fn unique() -> Self
pub fn unique_named<N>(name: N) -> Self
pub fn with_mappings(self, mappings: PrefixMapping) -> Self
pub fn with_statements(self, statements: Vec<Statement>) -> Self
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if there are no statements in this graph, else false
.
Sourcepub fn unset_name(&mut self)
pub fn unset_name(&mut self)
Remove the name of this graph.
Sourcepub fn contains_subject(&self, subject: &SubjectNode) -> bool
pub fn contains_subject(&self, subject: &SubjectNode) -> bool
Returns true
if this graph contains any statement with the provided subject, else false
.
Sourcepub fn contains(&self, statement: &Statement) -> bool
pub fn contains(&self, statement: &Statement) -> bool
Returns true
if this graph contains the provided statement, else false
.
Sourcepub fn contains_all(
&self,
subject: &SubjectNode,
predicate: &Iri,
object: &ObjectNode,
) -> bool
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
.
Sourcepub fn matches(
&self,
subject: Option<&SubjectNode>,
predicate: Option<&Iri>,
object: Option<&ObjectNode>,
) -> HashSet<&Statement>
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
.
Sourcepub fn statements(&self) -> impl Iterator<Item = &Statement>
pub fn statements(&self) -> impl Iterator<Item = &Statement>
Return an iterator over all the statements in the graph.
Sourcepub fn subjects(&self) -> HashSet<&SubjectNode>
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.
Sourcepub fn node_subjects(&self) -> HashSet<&SubjectNode>
pub fn node_subjects(&self) -> HashSet<&SubjectNode>
Return a set of all subjects that are not blank nodes
Sourcepub fn blank_node_subjects(&self) -> HashSet<&SubjectNode>
pub fn blank_node_subjects(&self) -> HashSet<&SubjectNode>
Return a set of all subjects that are blank nodes
Sourcepub fn predicates(&self) -> HashSet<&Iri>
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.
Sourcepub fn predicates_for(&self, subject: &SubjectNode) -> HashSet<&Iri>
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.
Sourcepub fn objects(&self) -> HashSet<&ObjectNode>
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.
Sourcepub fn objects_for(
&self,
subject: &SubjectNode,
predicate: &Iri,
) -> HashSet<&ObjectNode>
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.
Sourcepub fn prefix_mappings(&self) -> &PrefixMapping
pub fn prefix_mappings(&self) -> &PrefixMapping
Returns the set of prefix mappings held by the graph.
Sourcepub fn set_prefix_mappings(&mut self, mappings: PrefixMapping)
pub fn set_prefix_mappings(&mut self, mappings: PrefixMapping)
Set the prefix mappings held by the graph.
Sourcepub fn merge(&mut self, other: &Self)
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
.
Sourcepub fn dedup(&mut self) -> Vec<Statement>
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.
Sourcepub fn remove(&mut self, statement: &Statement)
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.
Sourcepub fn remove_all_for(&mut self, subject: &SubjectNode) -> Vec<Statement>
pub fn remove_all_for(&mut self, subject: &SubjectNode) -> Vec<Statement>
Remove all statements from this graph that have the provided subject.
Sourcepub fn skolemize(self, base: &Iri) -> Result<Self, Error>
pub fn skolemize(self, base: &Iri) -> Result<Self, Error>
Replace all blank nodes with new, unique Iris. This creates a new graph and leaves the initial graph unchanged. 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" .