sophia_api::graph

Trait 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

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: Graph + ?Sized> Graph for &'a T

Source§

type Triple<'x> = <T as Graph>::Triple<'x> where Self: 'x

Source§

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

Source§

type Triple<'x> = <T as Graph>::Triple<'x> where Self: 'x

Source§

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]

Source§

type Error = Infallible

Source§

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.

Source§

type Error = Infallible

Source§

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>

Source§

type Error = Infallible

Source§

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>

Source§

type Error = Infallible

Source§

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>

Source§

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

Source§

type Error = <D as Dataset>::Error

Source§

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

Source§

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

Source§

type Error = <D as Dataset>::Error

Source§

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

Source§

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

Source§

type Error = <T as Dataset>::Error