pub trait Dataset {
type Quad<'x>: Quad
where Self: 'x;
type Error: Error + 'static;
Show 17 methods
// Required method
fn quads(&self) -> DQuadSource<'_, Self>;
// Provided methods
fn quads_matching<'s, S, P, O, G>(
&'s self,
sm: S,
pm: P,
om: O,
gm: G,
) -> DQuadSource<'s, Self>
where S: TermMatcher + 's,
P: TermMatcher + 's,
O: TermMatcher + 's,
G: GraphNameMatcher + 's { ... }
fn contains<TS, TP, TO, TG>(
&self,
s: TS,
p: TP,
o: TO,
g: GraphName<TG>,
) -> DResult<Self, bool>
where TS: Term,
TP: Term,
TO: Term,
TG: Term { ... }
fn subjects(&self) -> DTermSource<'_, Self> { ... }
fn predicates(&self) -> DTermSource<'_, Self> { ... }
fn objects(&self) -> DTermSource<'_, Self> { ... }
fn graph_names(&self) -> DTermSource<'_, Self> { ... }
fn iris(&self) -> DTermSource<'_, Self> { ... }
fn blank_nodes(&self) -> DTermSource<'_, Self> { ... }
fn literals(&self) -> DTermSource<'_, Self> { ... }
fn quoted_triples<'s>(&'s self) -> DTermSource<'s, Self>
where DTerm<'s, Self>: Clone { ... }
fn variables(&self) -> DTermSource<'_, Self> { ... }
fn graph<T>(&self, graph_name: GraphName<T>) -> DatasetGraph<&Self, T>
where T: for<'x> Term<BorrowTerm<'x> = DTerm<'x, Self>> + 'static { ... }
fn graph_mut<T>(
&mut self,
graph_name: GraphName<T>,
) -> DatasetGraph<&mut Self, T>
where T: for<'x> Term<BorrowTerm<'x> = DTerm<'x, Self>> + 'static { ... }
fn partial_union_graph<M>(&self, selector: M) -> PartialUnionGraph<&Self, M>
where M: GraphNameMatcher + Copy { ... }
fn union_graph(&self) -> UnionGraph<&Self> { ... }
fn into_union_graph(self) -> UnionGraph<Self>
where Self: Sized { ... }
}
Expand description
Generic trait for RDF datasets.
For convenience, this trait is implemented by standard collections of quads.
NB: the semantics of this trait allows a dataset to contain duplicate quads;
see also SetDataset
.
Required Associated Types§
Required Methods§
Sourcefn quads(&self) -> DQuadSource<'_, Self>
fn quads(&self) -> DQuadSource<'_, Self>
An iterator visiting all quads of this dataset 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 q in dataset.quads() {
let q = q?; // rethrow error if any
// do something with q
}
Another way is to use the specific methods provided by QuadSource
,
for example:
dataset.quads().for_each_quad(|q| {
// do something with q
})?; // rethrow error if any
Provided Methods§
Sourcefn quads_matching<'s, S, P, O, G>(
&'s self,
sm: S,
pm: P,
om: O,
gm: G,
) -> DQuadSource<'s, Self>
fn quads_matching<'s, S, P, O, G>( &'s self, sm: S, pm: P, om: O, gm: G, ) -> DQuadSource<'s, Self>
An iterator visiting all quads matching the given subject, predicate and object.
See crate::term::matcher
See also quads
.
§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 q in dataset.quads_matching(Any, [&rdf::type_], [city, country], Any) {
println!("{:?} was found", q?.s());
}
Here is another example using a closure as a TermMatcher
.
use sophia_api::term::matcher::Any;
for q in dataset.quads_matching(
Any,
[&rdfs::label],
|t: SimpleTerm| t.lexical_form().map(|v| v.contains("needle")).unwrap_or(false),
Any,
) {
println!("{:?} was found", q?.s());
}
Sourcefn contains<TS, TP, TO, TG>(
&self,
s: TS,
p: TP,
o: TO,
g: GraphName<TG>,
) -> DResult<Self, bool>
fn contains<TS, TP, TO, TG>( &self, s: TS, p: TP, o: TO, g: GraphName<TG>, ) -> DResult<Self, bool>
Return true
if this dataset contains the given quad.
Sourcefn subjects(&self) -> DTermSource<'_, Self>
fn subjects(&self) -> DTermSource<'_, Self>
Build a fallible iterator of all the terms used as subject in this Dataset.
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) -> DTermSource<'_, Self>
fn predicates(&self) -> DTermSource<'_, Self>
Build a fallible iterator of all the terms used as predicate in this Dataset.
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) -> DTermSource<'_, Self>
fn objects(&self) -> DTermSource<'_, Self>
Build a fallible iterator of all the terms used as object in this Dataset.
NB: implementations SHOULD avoid yielding the same term multiple times, but MAY do so. Users MUST therefore be prepared to deal with duplicates.
Sourcefn graph_names(&self) -> DTermSource<'_, Self>
fn graph_names(&self) -> DTermSource<'_, Self>
Build a fallible iterator of all the terms used as graph name in this Dataset.
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) -> DTermSource<'_, Self>
fn iris(&self) -> DTermSource<'_, Self>
Build a fallible iterator of all the IRIs used in this Dataset (including those used inside quoted quads, 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) -> DTermSource<'_, Self>
fn blank_nodes(&self) -> DTermSource<'_, Self>
Build a fallible iterator of all the blank nodes used in this Dataset (including those used inside quoted quads, 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) -> DTermSource<'_, Self>
fn literals(&self) -> DTermSource<'_, Self>
Build a fallible iterator of all the literals used in this Dataset (including those used inside quoted quads, 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) -> DTermSource<'s, Self>
fn quoted_triples<'s>(&'s self) -> DTermSource<'s, Self>
Build a fallible iterator of all the quoted triples used in this Dataset (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) -> DTermSource<'_, Self>
fn variables(&self) -> DTermSource<'_, Self>
Build a fallible iterator of all the variables used in this Dataset (including those used inside quoted quads, 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 graph<T>(&self, graph_name: GraphName<T>) -> DatasetGraph<&Self, T>
fn graph<T>(&self, graph_name: GraphName<T>) -> DatasetGraph<&Self, T>
Borrows one of the graphs of this dataset
Sourcefn graph_mut<T>(
&mut self,
graph_name: GraphName<T>,
) -> DatasetGraph<&mut Self, T>
fn graph_mut<T>( &mut self, graph_name: GraphName<T>, ) -> DatasetGraph<&mut Self, T>
Borrows mutably one of the graphs of this dataset
Sourcefn partial_union_graph<M>(&self, selector: M) -> PartialUnionGraph<&Self, M>where
M: GraphNameMatcher + Copy,
fn partial_union_graph<M>(&self, selector: M) -> PartialUnionGraph<&Self, M>where
M: GraphNameMatcher + Copy,
Borrows a graph that is the union of some of this dataset’s graphs
Sourcefn union_graph(&self) -> UnionGraph<&Self>
fn union_graph(&self) -> UnionGraph<&Self>
Borrows a graph that is the union of all this dataset’s graphs (default and named)
Sourcefn into_union_graph(self) -> UnionGraph<Self>where
Self: Sized,
fn into_union_graph(self) -> UnionGraph<Self>where
Self: Sized,
Convert into a graph that is the union of all this dataset’s graphs (default and named)
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: Dataset + ?Sized> Dataset for &'a T
impl<'a, T: Dataset + ?Sized> Dataset for &'a T
type Quad<'x> = <T as Dataset>::Quad<'x> where Self: 'x
type Error = <T as Dataset>::Error
fn quads(&self) -> DQuadSource<'_, Self>
fn quads_matching<'s, S, P, O, G>( &'s self, sm: S, pm: P, om: O, gm: G, ) -> DQuadSource<'s, Self>
fn contains<TS, TP, TO, TG>( &self, s: TS, p: TP, o: TO, g: GraphName<TG>, ) -> DResult<Self, bool>
fn subjects(&self) -> DTermSource<'_, Self>
fn predicates(&self) -> DTermSource<'_, Self>
fn objects(&self) -> DTermSource<'_, Self>
fn graph_names(&self) -> DTermSource<'_, Self>
fn iris(&self) -> DTermSource<'_, Self>
fn blank_nodes(&self) -> DTermSource<'_, Self>
fn literals(&self) -> DTermSource<'_, Self>
fn quoted_triples<'s>(&'s self) -> DTermSource<'s, Self>
fn variables(&self) -> DTermSource<'_, Self>
Source§impl<'a, T: Dataset + ?Sized> Dataset for &'a mut T
impl<'a, T: Dataset + ?Sized> Dataset for &'a mut T
type Quad<'x> = <T as Dataset>::Quad<'x> where Self: 'x
type Error = <T as Dataset>::Error
fn quads(&self) -> DQuadSource<'_, Self>
fn quads_matching<'s, S, P, O, G>( &'s self, sm: S, pm: P, om: O, gm: G, ) -> DQuadSource<'s, Self>
fn contains<TS, TP, TO, TG>( &self, s: TS, p: TP, o: TO, g: GraphName<TG>, ) -> DResult<Self, bool>
fn subjects(&self) -> DTermSource<'_, Self>
fn predicates(&self) -> DTermSource<'_, Self>
fn objects(&self) -> DTermSource<'_, Self>
fn graph_names(&self) -> DTermSource<'_, Self>
fn iris(&self) -> DTermSource<'_, Self>
fn blank_nodes(&self) -> DTermSource<'_, Self>
fn literals(&self) -> DTermSource<'_, Self>
fn quoted_triples<'s>(&'s self) -> DTermSource<'s, Self>
fn variables(&self) -> DTermSource<'_, Self>
Source§impl<Q: Quad> Dataset for BTreeSet<Q>
impl<Q: Quad> Dataset for BTreeSet<Q>
NB: This is a straighforward and minimal implementation,
not taking advantage of the order of terms to optimize Dataset::quads_matching
nor other methods.