[][src]Trait sophia::graph::MutableGraph

pub trait MutableGraph: Graph {
    type MutationError: 'static + Error;
    fn insert<TS, TP, TO>(
        &mut self,
        s: &TS,
        p: &TP,
        o: &TO
    ) -> Result<bool, Self::MutationError>
    where
        TO: TTerm + ?Sized,
        TP: TTerm + ?Sized,
        TS: TTerm + ?Sized
;
fn remove<TS, TP, TO>(
        &mut self,
        s: &TS,
        p: &TP,
        o: &TO
    ) -> Result<bool, Self::MutationError>
    where
        TO: TTerm + ?Sized,
        TP: TTerm + ?Sized,
        TS: TTerm + ?Sized
; fn insert_all<TS>(
        &mut self,
        src: TS
    ) -> Result<usize, StreamError<<TS as TripleSource>::Error, Self::MutationError>>
    where
        TS: TripleSource
, { ... }
fn remove_all<TS>(
        &mut self,
        src: TS
    ) -> Result<usize, StreamError<<TS as TripleSource>::Error, Self::MutationError>>
    where
        TS: TripleSource
, { ... }
fn remove_matching<S, P, O>(
        &'s mut self,
        ms: &S,
        mp: &P,
        mo: &O
    ) -> Result<usize, Self::MutationError>
    where
        O: TermMatcher + ?Sized,
        P: TermMatcher + ?Sized,
        S: TermMatcher + ?Sized,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
        Self::Error: Into<Self::MutationError>,
        Infallible: Into<Self::MutationError>
, { ... }
fn retain_matching<S, P, O>(
        &'s mut self,
        ms: &S,
        mp: &P,
        mo: &O
    ) -> Result<(), Self::MutationError>
    where
        O: TermMatcher + ?Sized,
        P: TermMatcher + ?Sized,
        S: TermMatcher + ?Sized,
        <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
        Self::Error: Into<Self::MutationError>,
        Infallible: Into<Self::MutationError>
, { ... } }

Generic trait for mutable RDF graphs.

NB: the semantics of this trait allows a graph to contain duplicate triples; see also SetGraph.

Associated Types

type MutationError: 'static + Error

The error type that this graph may raise during mutations.

Loading content...

Required methods

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

Insert the given triple in this graph.

Return value

The bool value returned in case of success is not significant unless this graph also implements SetGraph.

If it does, true is returned iff the insertion actually changed the graph. In other words, a return value of false means that the graph was not changed, because the triple was already present in this SetGraph.

Usage


let schema = Namespace::new("http://schema.org/").unwrap();
let s_name = schema.get("name").unwrap();

graph.insert(&s_name, &rdf::type_, &rdf::Property)?;
graph.insert(&s_name, &rdfs::range, &xsd::string)?;

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

Remove the given triple from this graph.

Return value

The bool value returned in case of success is not significant unless this graph also implements SetGraph.

If it does, true is returned iff the removal actually changed the graph. In other words, a return value of false means that the graph was not changed, because the triple was already absent from this SetGraph.

Loading content...

Provided methods

fn insert_all<TS>(
    &mut self,
    src: TS
) -> Result<usize, StreamError<<TS as TripleSource>::Error, Self::MutationError>> where
    TS: TripleSource

Insert into this graph all triples from the given source.

Blank node scope

The blank nodes contained in the triple source will be inserted as is. If they happen to have the same identifier as blank nodes already present, they will be considered equal. This might not be what you want, especially if the graph contains data from a file, and you are inserting data from a different file. In that case, you should first transform the triple source, in order to get fresh blank node identifiers.

Return value

The usize value returned in case of success is not significant unless this graph also implements SetGraph.

If it does, the number of triples that were actually inserted (i.e. that were not already present in this SetGraph) is returned.

fn remove_all<TS>(
    &mut self,
    src: TS
) -> Result<usize, StreamError<<TS as TripleSource>::Error, Self::MutationError>> where
    TS: TripleSource

Remove from this graph all triples from the given source.

Return value

The usize value returned in case of success is not significant unless this graph also implements SetGraph.

If it does, the number of triples that were actually removed (i.e. that were not already absent from this SetGraph) is returned.

fn remove_matching<S, P, O>(
    &'s mut self,
    ms: &S,
    mp: &P,
    mo: &O
) -> Result<usize, Self::MutationError> where
    O: TermMatcher + ?Sized,
    P: TermMatcher + ?Sized,
    S: TermMatcher + ?Sized,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
    Self::Error: Into<Self::MutationError>,
    Infallible: Into<Self::MutationError>, 

Remove all triples matching the given matchers.

Return value

The usize value returned in case of success is not significant unless this graph also implements SetGraph.

If it does, the number of triples that were actually removed (i.e. that were not already absent from this SetGraph) is returned.

Note to implementors

The default implementation is rather naive, and could be improved in specific implementations of the trait.

fn retain_matching<S, P, O>(
    &'s mut self,
    ms: &S,
    mp: &P,
    mo: &O
) -> Result<(), Self::MutationError> where
    O: TermMatcher + ?Sized,
    P: TermMatcher + ?Sized,
    S: TermMatcher + ?Sized,
    <<Self::Triple as TripleStreamingMode>::UnsafeTriple as UnsafeTriple>::Term: Clone,
    Self::Error: Into<Self::MutationError>,
    Infallible: Into<Self::MutationError>, 

Keep only the triples matching the given matchers.

Note to implementors

The default implementation is rather naive, and could be improved in specific implementations of the trait.

Loading content...

Implementations on Foreign Types

impl<T, BH> MutableGraph for HashSet<[T; 3], BH> where
    BH: BuildHasher,
    T: TTerm + CopyTerm + Eq + Hash
[src]

type MutationError = Infallible

impl<T> MutableGraph for Vec<[T; 3]> where
    T: TTerm + CopyTerm
[src]

type MutationError = Infallible

Loading content...

Implementors

impl<'_, D, E, T> MutableGraph for DatasetGraph<D, E, Option<&'_ T>> where
    D: MutableDataset,
    E: BorrowMut<D>,
    T: TTerm + ?Sized
[src]

type MutationError = <D as MutableDataset>::MutationError

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

type MutationError = Infallible

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

type MutationError = Infallible

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

type MutationError = Infallible

Loading content...