srdf/
srdf_builder.rs

1use std::io::Write;
2
3use iri_s::IriS;
4use prefixmap::PrefixMap;
5
6use crate::{Query, RDFFormat};
7
8/// Types that implement this trait can build RDF data
9pub trait SRDFBuilder: Query {
10    /// Returns an empty RDF graph
11    fn empty() -> Self;
12
13    /// Adds an optional IRI as base
14    fn add_base(&mut self, base: &Option<IriS>) -> Result<(), Self::Err>;
15
16    /// Adds a prefix declaration to the current RDF graph
17    fn add_prefix(&mut self, alias: &str, iri: &IriS) -> Result<(), Self::Err>;
18
19    /// Adds a prefix map declaration to the current RDF graph
20    fn add_prefix_map(&mut self, prefix_map: PrefixMap) -> Result<(), Self::Err>;
21
22    /// Adds an RDF triple to the current RDF graph
23    fn add_triple<S, P, O>(&mut self, subj: S, pred: P, obj: O) -> Result<(), Self::Err>
24    where
25        S: Into<Self::Subject>,
26        P: Into<Self::IRI>,
27        O: Into<Self::Term>;
28
29    /// Removes an RDF triple to the current RDF graph
30    fn remove_triple<S, P, O>(&mut self, subj: S, pred: P, obj: O) -> Result<(), Self::Err>
31    where
32        S: Into<Self::Subject>,
33        P: Into<Self::IRI>,
34        O: Into<Self::Term>;
35
36    /// Adds an `rdf:type` declaration to the current RDF graph
37    fn add_type<S, T>(&mut self, node: S, type_: T) -> Result<(), Self::Err>
38    where
39        S: Into<Self::Subject>,
40        T: Into<Self::Term>;
41
42    /// Adds an Blank node to the RDF graph and get the node identifier
43    fn add_bnode(&mut self) -> Result<Self::BNode, Self::Err>;
44
45    /// Serialize the current graph to a Write implementation
46    fn serialize<W: Write>(&self, format: &RDFFormat, writer: &mut W) -> Result<(), Self::Err>;
47}