Trait sophia_api::graph::Graph
source · 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
Object Safety§
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 [T]
impl<T: Triple> Graph for [T]
type Error = Infallible
type Triple<'x> = [<<T as Triple>::Term as Term>::BorrowTerm<'x>; 3] where Self: 'x
fn triples(&self) -> GTripleSource<'_, 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.