pub trait Graph {
type Triple<'x>: Triple
where Self: 'x;
type Error: Error + 'static;
Show 14 methods
// Required method
fn triples(&self) -> GTripleSource<'_, Self>;
// Provided methods
fn triples_matching<'s, S, P, O>(
&'s self,
sm: S,
pm: P,
om: O,
) -> GTripleSource<'s, Self>
where S: TermMatcher + 's,
P: TermMatcher + 's,
O: TermMatcher + 's { ... }
fn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
where TS: Term,
TP: Term,
TO: Term { ... }
fn subjects(&self) -> GTermSource<'_, Self> { ... }
fn predicates(&self) -> GTermSource<'_, Self> { ... }
fn objects(&self) -> GTermSource<'_, Self> { ... }
fn iris(&self) -> GTermSource<'_, Self> { ... }
fn blank_nodes(&self) -> GTermSource<'_, Self> { ... }
fn literals(&self) -> GTermSource<'_, Self> { ... }
fn quoted_triples<'s>(&'s self) -> GTermSource<'s, Self>
where GTerm<'s, Self>: Clone { ... }
fn variables(&self) -> GTermSource<'_, Self> { ... }
fn as_dataset(&self) -> GraphAsDataset<&Self> { ... }
fn as_dataset_mut(&mut self) -> GraphAsDataset<&mut Self> { ... }
fn into_dataset(self) -> GraphAsDataset<Self>
where Self: Sized { ... }
}
Expand description
Generic trait for RDF graphs.
For convenience, this trait is implemented by standard collections of triples.
NB: the semantics of this trait allows a graph to contain duplicate triples;
see also SetGraph
.
Required Associated Types§
Required Methods§
Sourcefn triples(&self) -> GTripleSource<'_, Self>
fn triples(&self) -> GTripleSource<'_, Self>
An iterator visiting all triples of this graph in arbitrary order.
This iterator is fallible:
its items are Result
s,
an error may occur at any time during the iteration.
§Examples
The result of this method is an iterator,
so it can be used in a for
loop:
for t in graph.triples() {
let t = t?; // rethrow error if any
// do something with t
}
Another way is to use the specific methods provided by TripleSource
,
for example:
graph.triples().for_each_triple(|t| {
// do something with t
})?; // rethrow error if any
Provided Methods§
Sourcefn triples_matching<'s, S, P, O>(
&'s self,
sm: S,
pm: P,
om: O,
) -> GTripleSource<'s, Self>
fn triples_matching<'s, S, P, O>( &'s self, sm: S, pm: P, om: O, ) -> GTripleSource<'s, Self>
An iterator visiting all triples matching the given subject, predicate and object.
See crate::term::matcher
.
See also triples
.
§Usage
Typical implementations of TermMatcher
include arrays/slices of Term
s,
closure accepting a SimpleTerm
, or the special matcher Any
.
let s = Namespace::new("http://schema.org/")?;
let city = s.get("City")?;
let country = s.get("Country")?;
for t in graph.triples_matching(Any, [&rdf::type_], [city, country]) {
println!("{:?} was found", t?.s());
}
Here is another example using a closure as a TermMatcher
.
for t in graph.triples_matching(
Any,
[&rdfs::label],
|t: SimpleTerm| t.lexical_form().map(|v| v.contains("needle")).unwrap_or(false),
) {
println!("{:?} was found", t?.s());
}
Sourcefn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
fn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
Return true
if this graph contains the given triple.
Sourcefn subjects(&self) -> GTermSource<'_, Self>
fn subjects(&self) -> GTermSource<'_, Self>
Build a fallible iterator of all the terms used as subject in this Graph.
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn predicates(&self) -> GTermSource<'_, Self>
fn predicates(&self) -> GTermSource<'_, Self>
Build a fallible iterator of all the terms used as predicate in this Graph.
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn objects(&self) -> GTermSource<'_, Self>
fn objects(&self) -> GTermSource<'_, Self>
Build a fallible iterator of all the terms used as object in this Graph.
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn iris(&self) -> GTermSource<'_, Self>
fn iris(&self) -> GTermSource<'_, Self>
Build a fallible iterator of all the IRIs used in this Graph (including those used inside quoted triples, if any).
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn blank_nodes(&self) -> GTermSource<'_, Self>
fn blank_nodes(&self) -> GTermSource<'_, Self>
Build a fallible iterator of all the blank nodes used in this Graph (including those used inside quoted triples, if any).
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn literals(&self) -> GTermSource<'_, Self>
fn literals(&self) -> GTermSource<'_, Self>
Build a fallible iterator of all the literals used in this Graph (including those used inside quoted triples, if any).
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn quoted_triples<'s>(&'s self) -> GTermSource<'s, Self>
fn quoted_triples<'s>(&'s self) -> GTermSource<'s, Self>
Build a fallible iterator of all the quoted triples used in this Graph (including those used inside quoted triples, if any).
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn variables(&self) -> GTermSource<'_, Self>
fn variables(&self) -> GTermSource<'_, Self>
Build a fallible iterator of all the variables used in this Graph (including those used inside quoted triples, if any).
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn as_dataset(&self) -> GraphAsDataset<&Self>
fn as_dataset(&self) -> GraphAsDataset<&Self>
Dataset
adapter borrowing this graph
Sourcefn as_dataset_mut(&mut self) -> GraphAsDataset<&mut Self>
fn as_dataset_mut(&mut self) -> GraphAsDataset<&mut Self>
Dataset
adapter borrowing this graph mutably
Sourcefn into_dataset(self) -> GraphAsDataset<Self>where
Self: Sized,
fn into_dataset(self) -> GraphAsDataset<Self>where
Self: Sized,
Dataset
adapter taking ownership of this graph
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<'a, T: Graph + ?Sized> Graph for &'a T
impl<'a, T: Graph + ?Sized> Graph for &'a T
type Triple<'x> = <T as Graph>::Triple<'x> where Self: 'x
type Error = <T as Graph>::Error
fn triples(&self) -> GTripleSource<'_, Self>
fn triples_matching<'s, S, P, O>( &'s self, sm: S, pm: P, om: O, ) -> GTripleSource<'s, Self>
fn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
fn subjects(&self) -> GTermSource<'_, Self>
fn predicates(&self) -> GTermSource<'_, Self>
fn objects(&self) -> GTermSource<'_, Self>
fn iris(&self) -> GTermSource<'_, Self>
fn blank_nodes(&self) -> GTermSource<'_, Self>
fn literals(&self) -> GTermSource<'_, Self>
fn quoted_triples<'s>(&'s self) -> GTermSource<'s, Self>
fn variables(&self) -> GTermSource<'_, Self>
Source§impl<'a, T: Graph + ?Sized> Graph for &'a mut T
impl<'a, T: Graph + ?Sized> Graph for &'a mut T
type Triple<'x> = <T as Graph>::Triple<'x> where Self: 'x
type Error = <T as Graph>::Error
fn triples(&self) -> GTripleSource<'_, Self>
fn triples_matching<'s, S, P, O>( &'s self, sm: S, pm: P, om: O, ) -> GTripleSource<'s, Self>
fn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
fn subjects(&self) -> GTermSource<'_, Self>
fn predicates(&self) -> GTermSource<'_, Self>
fn objects(&self) -> GTermSource<'_, Self>
fn iris(&self) -> GTermSource<'_, Self>
fn blank_nodes(&self) -> GTermSource<'_, Self>
fn literals(&self) -> GTermSource<'_, Self>
fn quoted_triples<'s>(&'s self) -> GTermSource<'s, Self>
fn variables(&self) -> GTermSource<'_, Self>
Source§impl<T: Triple> Graph for BTreeSet<T>
impl<T: Triple> Graph for BTreeSet<T>
NB: This is a straighforward and minimal implementation,
not taking advantage of the order of terms to optimize Graph::triples_matching
nor other methods.