Trait sophia_api::dataset::Dataset
source · 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)
Object Safety§
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 [Q]
impl<Q: Quad> Dataset for [Q]
type Error = Infallible
type Quad<'x> = ([<<Q as Quad>::Term as Term>::BorrowTerm<'x>; 3], Option<<<Q as Quad>::Term as Term>::BorrowTerm<'x>>) where Self: 'x
fn quads(&self) -> DQuadSource<'_, 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.