Dataset

Trait Dataset 

Source
pub trait Dataset {
    type Quad<'x>: Quad
       where Self: 'x;
    type Error: Error + Send + Sync + 'static;

Show 17 methods // Required method fn quads(&self) -> impl Iterator<Item = DResult<Self, Self::Quad<'_>>> + '_; // Provided methods fn quads_matching<'s, S, P, O, G>( &'s self, sm: S, pm: P, om: O, gm: G, ) -> impl Iterator<Item = DResult<Self, Self::Quad<'_>>> + '_ 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, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_ { ... } fn predicates( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_ { ... } fn objects( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_ { ... } fn graph_names( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_ { ... } fn iris(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_ { ... } fn blank_nodes( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_ { ... } fn literals( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_ { ... } fn quoted_triples<'s>( &'s self, ) -> Box<dyn Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_> where DTerm<'s, Self>: Clone { ... } fn variables( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, 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§

Source

type Quad<'x>: Quad where Self: 'x

Determine the type of Quads that the methods of this dataset will yield.

Source

type Error: Error + Send + Sync + 'static

The error type that this dataset may raise.

Required Methods§

Source

fn quads(&self) -> impl Iterator<Item = DResult<Self, Self::Quad<'_>>> + '_

An iterator visiting all quads of this dataset in arbitrary order.

This iterator is fallible: its items are Results, 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§

Source

fn quads_matching<'s, S, P, O, G>( &'s self, sm: S, pm: P, om: O, gm: G, ) -> impl Iterator<Item = DResult<Self, Self::Quad<'_>>> + '_
where S: TermMatcher + 's, P: TermMatcher + 's, O: TermMatcher + 's, G: GraphNameMatcher + 's,

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 Terms, 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());
}
Source

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,

Return true if this dataset contains the given quad.

Source

fn subjects(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, 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.

Source

fn predicates( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, 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.

Source

fn objects(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, 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.

Source

fn graph_names( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, 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.

Source

fn iris(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, 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.

Source

fn blank_nodes( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, 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.

Source

fn literals(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, 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.

Source

fn quoted_triples<'s>( &'s self, ) -> Box<dyn Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_>
where DTerm<'s, Self>: Clone,

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.

Source

fn variables(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, 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.

Source

fn graph<T>(&self, graph_name: GraphName<T>) -> DatasetGraph<&Self, T>
where T: for<'x> Term<BorrowTerm<'x> = DTerm<'x, Self>> + 'static,

Borrows one of the graphs of this dataset

Source

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,

Borrows mutably one of the graphs of this dataset

Source

fn partial_union_graph<M>(&self, selector: M) -> PartialUnionGraph<&Self, M>

Borrows a graph that is the union of some of this dataset’s graphs

Source

fn union_graph(&self) -> UnionGraph<&Self>

Borrows a graph that is the union of all this dataset’s graphs (default and named)

Source

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

Source§

type Quad<'x> = <T as Dataset>::Quad<'x> where Self: 'x

Source§

type Error = <T as Dataset>::Error

Source§

fn quads(&self) -> impl Iterator<Item = DResult<Self, Self::Quad<'_>>> + '_

Source§

fn quads_matching<'s, S, P, O, G>( &'s self, sm: S, pm: P, om: O, gm: G, ) -> impl Iterator<Item = DResult<Self, Self::Quad<'s>>> + 's
where S: TermMatcher + 's, P: TermMatcher + 's, O: TermMatcher + 's, G: GraphNameMatcher + 's,

Source§

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,

Source§

fn subjects(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn predicates( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn objects(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn graph_names( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn iris(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn blank_nodes( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn literals(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn quoted_triples<'s>( &'s self, ) -> Box<dyn Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_>
where DTerm<'s, Self>: Clone,

Source§

fn variables(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

impl<'a, T: Dataset + ?Sized> Dataset for &'a mut T

Source§

type Quad<'x> = <T as Dataset>::Quad<'x> where Self: 'x

Source§

type Error = <T as Dataset>::Error

Source§

fn quads(&self) -> impl Iterator<Item = DResult<Self, Self::Quad<'_>>> + '_

Source§

fn quads_matching<'s, S, P, O, G>( &'s self, sm: S, pm: P, om: O, gm: G, ) -> impl Iterator<Item = DResult<Self, Self::Quad<'s>>> + 's
where S: TermMatcher + 's, P: TermMatcher + 's, O: TermMatcher + 's, G: GraphNameMatcher + 's,

Source§

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,

Source§

fn subjects(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn predicates( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn objects(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn graph_names( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn iris(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn blank_nodes( &self, ) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn literals(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

fn quoted_triples<'s>( &'s self, ) -> Box<dyn Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_>
where DTerm<'s, Self>: Clone,

Source§

fn variables(&self) -> impl Iterator<Item = DResult<Self, DTerm<'_, Self>>> + '_

Source§

impl<Q: Quad> Dataset for [Q]

Source§

type Error = Infallible

Source§

type Quad<'x> = ([<<Q as Quad>::Term as Term>::BorrowTerm<'x>; 3], Option<<<Q as Quad>::Term as Term>::BorrowTerm<'x>>) where Self: 'x

Source§

fn quads(&self) -> impl Iterator<Item = DResult<Self, Self::Quad<'_>>> + '_

Source§

impl<Q: Quad> Dataset for BTreeSet<Q>

NB: This is a straightforward and minimal implementation, not taking advantage of the order of terms to optimize Dataset::quads_matching nor other methods.

Source§

type Error = Infallible

Source§

type Quad<'x> = ([<<Q as Quad>::Term as Term>::BorrowTerm<'x>; 3], Option<<<Q as Quad>::Term as Term>::BorrowTerm<'x>>) where Self: 'x

Source§

fn quads(&self) -> impl Iterator<Item = DResult<Self, Self::Quad<'_>>> + '_

Source§

impl<Q: Quad> Dataset for Vec<Q>

Source§

type Error = Infallible

Source§

type Quad<'x> = ([<<Q as Quad>::Term as Term>::BorrowTerm<'x>; 3], Option<<<Q as Quad>::Term as Term>::BorrowTerm<'x>>) where Self: 'x

Source§

fn quads(&self) -> impl Iterator<Item = DResult<Self, Self::Quad<'_>>> + '_

Source§

impl<Q: Quad, S> Dataset for HashSet<Q, S>

Source§

type Error = Infallible

Source§

type Quad<'x> = ([<<Q as Quad>::Term as Term>::BorrowTerm<'x>; 3], Option<<<Q as Quad>::Term as Term>::BorrowTerm<'x>>) where Self: 'x

Source§

fn quads(&self) -> impl Iterator<Item = DResult<Self, Self::Quad<'_>>> + '_

Implementors§

Source§

impl<T> Dataset for GraphAsDataset<T>
where T: Graph,

Source§

type Quad<'x> = ([<<T as Graph>::Triple<'x> as Triple>::Term; 3], Option<<<T as Graph>::Triple<'x> as Triple>::Term>) where Self: 'x

Source§

type Error = <T as Graph>::Error