pub trait Graph {
    type Triple: TripleStreamingMode;
    type Error: 'static + Error;
Show 20 methods fn triples(&self) -> GTripleSource<'_, Self>; fn triples_with_s<'s, TS>(&'s self, s: &'s TS) -> GTripleSource<'s, Self>
    where
        TS: TTerm + ?Sized
, { ... }
fn triples_with_p<'s, TP>(&'s self, p: &'s TP) -> GTripleSource<'s, Self>
    where
        TP: TTerm + ?Sized
, { ... }
fn triples_with_o<'s, TO>(&'s self, o: &'s TO) -> GTripleSource<'s, Self>
    where
        TO: TTerm + ?Sized
, { ... }
fn triples_with_sp<'s, TS, TP>(
        &'s self,
        s: &'s TS,
        p: &'s TP
    ) -> GTripleSource<'s, Self>
    where
        TS: TTerm + ?Sized,
        TP: TTerm + ?Sized
, { ... }
fn triples_with_so<'s, TS, TO>(
        &'s self,
        s: &'s TS,
        o: &'s TO
    ) -> GTripleSource<'s, Self>
    where
        TS: TTerm + ?Sized,
        TO: TTerm + ?Sized
, { ... }
fn triples_with_po<'s, TP, TO>(
        &'s self,
        p: &'s TP,
        o: &'s TO
    ) -> GTripleSource<'s, Self>
    where
        TP: TTerm + ?Sized,
        TO: TTerm + ?Sized
, { ... }
fn triples_with_spo<'s, TS, TP, TO>(
        &'s self,
        s: &'s TS,
        p: &'s TP,
        o: &'s TO
    ) -> GTripleSource<'s, Self>
    where
        TS: TTerm + ?Sized,
        TP: TTerm + ?Sized,
        TO: TTerm + ?Sized
, { ... }
fn contains<TS, TP, TO>(
        &self,
        s: &TS,
        p: &TP,
        o: &TO
    ) -> GResult<Self, bool>
    where
        TS: TTerm + ?Sized,
        TP: TTerm + ?Sized,
        TO: TTerm + ?Sized
, { ... }
fn triples_matching<'s, S, P, O>(
        &'s self,
        ms: &'s S,
        mp: &'s P,
        mo: &'s O
    ) -> GTripleSource<'s, Self>
    where
        S: TermMatcher + ?Sized,
        P: TermMatcher + ?Sized,
        O: TermMatcher + ?Sized
, { ... }
fn subjects(&self) -> GResultTermSet<Self>
    where
        GTerm<Self>: Clone + Eq + Hash
, { ... }
fn predicates(&self) -> GResultTermSet<Self>
    where
        GTerm<Self>: Clone + Eq + Hash
, { ... }
fn objects(&self) -> GResultTermSet<Self>
    where
        GTerm<Self>: Clone + Eq + Hash
, { ... }
fn iris(&self) -> GResultTermSet<Self>
    where
        GTerm<Self>: Clone + Eq + Hash
, { ... }
fn bnodes(&self) -> GResultTermSet<Self>
    where
        GTerm<Self>: Clone + Eq + Hash
, { ... }
fn literals(&self) -> GResultTermSet<Self>
    where
        GTerm<Self>: Clone + Eq + Hash
, { ... }
fn variables(&self) -> GResultTermSet<Self>
    where
        GTerm<Self>: Clone + Eq + Hash
, { ... }
fn as_dataset(&self) -> GraphAsDataset<Self, &Self> { ... }
fn as_dataset_mut(&mut self) -> GraphAsDataset<Self, &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.

Associated Types

Determine the type of Triples that the methods of this graph will yield (see streaming_mode)

The error type that this graph may raise.

Required methods

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

An iterator visiting all triples with the given subject.

See also triples.

An iterator visiting all triples with the given predicate.

See also triples.

An iterator visiting all triples with the given object.

See also triples.

An iterator visiting all triples with the given subject and predicate.

See also triples.

An iterator visiting all triples with the given subject and object.

See also triples.

An iterator visiting all triples with the given predicate and object.

See also triples.

An iterator visiting all triples with the given subject, predicate and object.

See also triples.

Return true if this graph contains the given triple.

An iterator visiting all triples matching the given subject, predicate and object.

See also triples.

Usage

Term references or arrays of term references are typically used as term matchers. The special ANY matcher can also be used to match anything.

use sophia_api::term::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());
}

Closures (accepting &dyn TTerm) can also be used, but notice that, for technical reasons, they must be enclosed in a 1-sized array.

use sophia_api::term::matcher::ANY;

for t in graph.triples_matching(
    &ANY,
    &rdfs::label,
    &[|t: &dyn TTerm| t.kind() == Literal && t.value().contains("needle")]
) {
    println!("{} was found", t?.s());
}

Build a Hashset of all the terms used as subject in this Graph.

Build a Hashset of all the terms used as predicate in this Graph.

Build a Hashset of all the terms used as object in this Graph.

Build a Hashset of all the IRIs used in this Graph.

Build a Hashset of all the BNodes used in this Graph.

Build a Hashset of all the Literals used in this Graph.

Build a Hashset of all the variables used in this Graph.

Dataset adapter borrowing this graph

Dataset adapter borrowing this graph mutably

Dataset adapter taking ownership of this graph

Implementations on Foreign Types

Implementors