[][src]Trait sophia::graph::Graph

pub trait Graph {
    type Triple: TripleStreamingMode;
    type Error: 'static + Error;
    fn triples(
        &self
    ) -> Box<dyn Iterator<Item = Result<StreamedTriple<'_, Self::Triple>, Self::Error>>>; fn triples_with_s<TS>(
        &'s self,
        s: &'s TS
    ) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's>
    where
        TS: TTerm + ?Sized
, { ... }
fn triples_with_p<TP>(
        &'s self,
        p: &'s TP
    ) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's>
    where
        TP: TTerm + ?Sized
, { ... }
fn triples_with_o<TO>(
        &'s self,
        o: &'s TO
    ) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's>
    where
        TO: TTerm + ?Sized
, { ... }
fn triples_with_sp<TS, TP>(
        &'s self,
        s: &'s TS,
        p: &'s TP
    ) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's>
    where
        TP: TTerm + ?Sized,
        TS: TTerm + ?Sized
, { ... }
fn triples_with_so<TS, TO>(
        &'s self,
        s: &'s TS,
        o: &'s TO
    ) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's>
    where
        TO: TTerm + ?Sized,
        TS: TTerm + ?Sized
, { ... }
fn triples_with_po<TP, TO>(
        &'s self,
        p: &'s TP,
        o: &'s TO
    ) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's>
    where
        TO: TTerm + ?Sized,
        TP: TTerm + ?Sized
, { ... }
fn triples_with_spo<TS, TP, TO>(
        &'s self,
        s: &'s TS,
        p: &'s TP,
        o: &'s TO
    ) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's>
    where
        TO: TTerm + ?Sized,
        TP: TTerm + ?Sized,
        TS: TTerm + ?Sized
, { ... }
fn contains<TS, TP, TO>(
        &self,
        s: &TS,
        p: &TP,
        o: &TO
    ) -> Result<bool, Self::Error>
    where
        TO: TTerm + ?Sized,
        TP: TTerm + ?Sized,
        TS: TTerm + ?Sized
, { ... }
fn triples_matching<S, P, O>(
        &'s self,
        ms: &'s S,
        mp: &'s P,
        mo: &'s O
    ) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's>
    where
        O: TermMatcher + ?Sized,
        P: TermMatcher + ?Sized,
        S: TermMatcher + ?Sized
, { ... }
fn subjects(
        &self
    ) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error>
    where
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash
, { ... }
fn predicates(
        &self
    ) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error>
    where
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash
, { ... }
fn objects(
        &self
    ) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error>
    where
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash
, { ... }
fn iris(
        &self
    ) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error>
    where
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash
, { ... }
fn bnodes(
        &self
    ) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error>
    where
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash
, { ... }
fn literals(
        &self
    ) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error>
    where
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash
, { ... }
fn variables(
        &self
    ) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error>
    where
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash
, { ... }
fn as_dataset(&self) -> GraphAsDataset<Self, &Self> { ... }
fn as_dataset_mut(&mut self) -> GraphAsDataset<Self, &mut Self> { ... }
fn into_dataset(self) -> GraphAsDataset<Self, Self> { ... } }

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

type Triple: TripleStreamingMode

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

type Error: 'static + Error

The error type that this graph may raise.

Loading content...

Required methods

fn triples(
    &self
) -> Box<dyn Iterator<Item = Result<StreamedTriple<'_, Self::Triple>, Self::Error>>>

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
Loading content...

Provided methods

fn triples_with_s<TS>(
    &'s self,
    s: &'s TS
) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's> where
    TS: TTerm + ?Sized

An iterator visiting all triples with the given subject.

See also triples.

fn triples_with_p<TP>(
    &'s self,
    p: &'s TP
) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's> where
    TP: TTerm + ?Sized

An iterator visiting all triples with the given predicate.

See also triples.

fn triples_with_o<TO>(
    &'s self,
    o: &'s TO
) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's> where
    TO: TTerm + ?Sized

An iterator visiting all triples with the given object.

See also triples.

fn triples_with_sp<TS, TP>(
    &'s self,
    s: &'s TS,
    p: &'s TP
) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's> where
    TP: TTerm + ?Sized,
    TS: TTerm + ?Sized

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

See also triples.

fn triples_with_so<TS, TO>(
    &'s self,
    s: &'s TS,
    o: &'s TO
) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's> where
    TO: TTerm + ?Sized,
    TS: TTerm + ?Sized

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

See also triples.

fn triples_with_po<TP, TO>(
    &'s self,
    p: &'s TP,
    o: &'s TO
) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's> where
    TO: TTerm + ?Sized,
    TP: TTerm + ?Sized

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

See also triples.

fn triples_with_spo<TS, TP, TO>(
    &'s self,
    s: &'s TS,
    p: &'s TP,
    o: &'s TO
) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's> where
    TO: TTerm + ?Sized,
    TP: TTerm + ?Sized,
    TS: TTerm + ?Sized

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

See also triples.

fn contains<TS, TP, TO>(
    &self,
    s: &TS,
    p: &TP,
    o: &TO
) -> Result<bool, Self::Error> where
    TO: TTerm + ?Sized,
    TP: TTerm + ?Sized,
    TS: TTerm + ?Sized

Return true if this graph contains the given triple.

fn triples_matching<S, P, O>(
    &'s self,
    ms: &'s S,
    mp: &'s P,
    mo: &'s O
) -> Box<dyn Iterator<Item = Result<StreamedTriple<'s, Self::Triple>, Self::Error>> + 's> where
    O: TermMatcher + ?Sized,
    P: TermMatcher + ?Sized,
    S: TermMatcher + ?Sized

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

fn subjects(
    &self
) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error> where
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash

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

fn predicates(
    &self
) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error> where
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash

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

fn objects(
    &self
) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error> where
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash

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

fn iris(
    &self
) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error> where
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash

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

fn bnodes(
    &self
) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error> where
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash

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

fn literals(
    &self
) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error> where
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash

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

fn variables(
    &self
) -> Result<HashSet<<<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term, RandomState>, Self::Error> where
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Eq,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Hash

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

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

Dataset adapter borrowing this graph

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

Dataset adapter borrowing this graph mutably

fn into_dataset(self) -> GraphAsDataset<Self, Self>

Dataset adapter taking ownership of this graph

Loading content...

Implementations on Foreign Types

impl<T> Graph for Vec<T> where
    T: Triple
[src]

type Triple = ByRef<T>

type Error = Infallible

impl<T> Graph for [T] where
    T: Triple
[src]

type Triple = ByRef<T>

type Error = Infallible

impl<T, BH> Graph for HashSet<T, BH> where
    BH: BuildHasher,
    T: Eq + Hash + Triple
[src]

type Triple = ByRef<T>

type Error = Infallible

Loading content...

Implementors

impl<D, E, M> Graph for DatasetGraph<D, E, M> where
    D: Dataset + ?Sized,
    E: Borrow<D>,
    M: GraphNameMatcher
[src]

type Triple = FromQuad<<D as Dataset>::Quad>

type Error = <D as Dataset>::Error

impl<I> Graph for HashGraph<I> where
    I: TermIndexMap,
    I::Index: Hash,
    <I::Factory as TermFactory>::TermData: 'static, 
[src]

type Triple = ByTermRefs<Term<Self::TermData>>

type Error = Infallible

impl<T> Graph for OpsWrapper<T> where
    T: IndexedGraph + Graph<Triple = ByTermRefs<Term<<T as IndexedGraph>::TermData>>>, 
[src]

type Triple = <Self::Wrapped as Graph>::Triple

type Error = <Self::Wrapped as Graph>::Error

impl<T> Graph for SpoWrapper<T> where
    T: IndexedGraph + Graph<Triple = ByTermRefs<Term<<T as IndexedGraph>::TermData>>>, 
[src]

type Triple = <Self::Wrapped as Graph>::Triple

type Error = <Self::Wrapped as Graph>::Error

Loading content...