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§

source

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

Determine the type of Triples that the methods of this graph will yield.

source

type Error: Error + 'static

The error type that this graph may raise.

Required Methods§

source

fn triples(&self) -> GTripleSource<'_, Self>

An iterator visiting all triples of this graph 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 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§

source

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,

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 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 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());
}
source

fn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
where TS: Term, TP: Term, TO: Term,

Return true if this graph contains the given triple.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

fn quoted_triples<'s>(&'s self) -> GTermSource<'s, Self>
where GTerm<'s, Self>: Clone,

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.

source

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.

source

fn as_dataset(&self) -> GraphAsDataset<&Self>

Dataset adapter borrowing this graph

source

fn as_dataset_mut(&mut self) -> GraphAsDataset<&mut Self>

Dataset adapter borrowing this graph mutably

source

fn into_dataset(self) -> GraphAsDataset<Self>
where Self: Sized,

Dataset adapter taking ownership of this graph

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

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

source§

fn triples(&self) -> GTripleSource<'_, Self>

source§

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,

source§

fn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
where TS: Term, TP: Term, TO: Term,

source§

fn subjects(&self) -> GTermSource<'_, Self>

source§

fn predicates(&self) -> GTermSource<'_, Self>

source§

fn objects(&self) -> GTermSource<'_, Self>

source§

fn iris(&self) -> GTermSource<'_, Self>

source§

fn blank_nodes(&self) -> GTermSource<'_, Self>

source§

fn literals(&self) -> GTermSource<'_, Self>

source§

fn quoted_triples<'s>(&'s self) -> GTermSource<'s, Self>
where GTerm<'s, Self>: Clone,

source§

fn variables(&self) -> GTermSource<'_, Self>

source§

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

source§

fn triples(&self) -> GTripleSource<'_, Self>

source§

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,

source§

fn contains<TS, TP, TO>(&self, s: TS, p: TP, o: TO) -> GResult<Self, bool>
where TS: Term, TP: Term, TO: Term,

source§

fn subjects(&self) -> GTermSource<'_, Self>

source§

fn predicates(&self) -> GTermSource<'_, Self>

source§

fn objects(&self) -> GTermSource<'_, Self>

source§

fn iris(&self) -> GTermSource<'_, Self>

source§

fn blank_nodes(&self) -> GTermSource<'_, Self>

source§

fn literals(&self) -> GTermSource<'_, Self>

source§

fn quoted_triples<'s>(&'s self) -> GTermSource<'s, Self>
where GTerm<'s, Self>: Clone,

source§

fn variables(&self) -> GTermSource<'_, Self>

source§

impl<T: Triple> Graph for [T]

§

type Error = Infallible

§

type Triple<'x> = [<<T as Triple>::Term as Term>::BorrowTerm<'x>; 3] where Self: 'x

source§

fn triples(&self) -> GTripleSource<'_, Self>

source§

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.

§

type Error = Infallible

§

type Triple<'x> = [<<T as Triple>::Term as Term>::BorrowTerm<'x>; 3] where Self: 'x

source§

fn triples(&self) -> GTripleSource<'_, Self>

source§

impl<T: Triple> Graph for Vec<T>

§

type Error = Infallible

§

type Triple<'x> = [<<T as Triple>::Term as Term>::BorrowTerm<'x>; 3] where Self: 'x

source§

fn triples(&self) -> GTripleSource<'_, Self>

source§

impl<T: Triple, S> Graph for HashSet<T, S>

§

type Error = Infallible

§

type Triple<'x> = [<<T as Triple>::Term as Term>::BorrowTerm<'x>; 3] where Self: 'x

source§

fn triples(&self) -> GTripleSource<'_, Self>

Implementors§

source§

impl<D: Dataset, G: Term> Graph for DatasetGraph<D, G>

§

type Triple<'x> = [<<D as Dataset>::Quad<'x> as Quad>::Term; 3] where Self: 'x

§

type Error = <D as Dataset>::Error

source§

impl<D: Dataset, M: GraphNameMatcher + Copy> Graph for PartialUnionGraph<D, M>

§

type Triple<'x> = [<<D as Dataset>::Quad<'x> as Quad>::Term; 3] where Self: 'x

§

type Error = <D as Dataset>::Error

source§

impl<T: Dataset> Graph for UnionGraph<T>

§

type Triple<'x> = [<<T as Dataset>::Quad<'x> as Quad>::Term; 3] where Self: 'x

§

type Error = <T as Dataset>::Error