Skip to main content

BuildRDF

Trait BuildRDF 

Source
pub trait BuildRDF: NeighsRDF {
    // Required methods
    fn empty() -> Self;
    fn add_base(&mut self, base: &Option<IriS>) -> Result<(), Self::Err>;
    fn add_prefix(&mut self, alias: &str, iri: &IriS) -> Result<(), Self::Err>;
    fn add_prefix_map(&mut self, prefix_map: PrefixMap) -> Result<(), Self::Err>;
    fn add_triple<S, P, O>(
        &mut self,
        subj: S,
        pred: P,
        obj: O,
    ) -> Result<(), Self::Err>
       where S: Into<Self::Subject>,
             P: Into<Self::IRI>,
             O: Into<Self::Term>;
    fn remove_triple<S, P, O>(
        &mut self,
        subj: S,
        pred: P,
        obj: O,
    ) -> Result<(), Self::Err>
       where S: Into<Self::Subject>,
             P: Into<Self::IRI>,
             O: Into<Self::Term>;
    fn add_type<S, T>(&mut self, node: S, type_: T) -> Result<(), Self::Err>
       where S: Into<Self::Subject>,
             T: Into<Self::Term>;
    fn add_bnode(&mut self) -> Result<Self::BNode, Self::Err>;
    fn serialize<W: Write>(
        &self,
        format: &RDFFormat,
        writer: &mut W,
    ) -> Result<(), Self::Err>;
}
Expand description

Trait for building and modifying RDF graphs.

This trait provides methods for constructing RDF graphs by adding triples, managing namespace prefixes, creating blank nodes, and serializing the graph to various RDF formats. It extends NeighsRDF with mutation capabilities.

Required Methods§

Source

fn empty() -> Self

Creates a new empty RDF graph.

Returns a graph with no triples, no prefix declarations, and no base IRI. This is the starting point for building RDF data.

Source

fn add_base(&mut self, base: &Option<IriS>) -> Result<(), Self::Err>

Sets the base IRI for resolving relative IRI references.

§Arguments
  • base - Optional base IRI for resolving relative references
Source

fn add_prefix(&mut self, alias: &str, iri: &IriS) -> Result<(), Self::Err>

Adds a namespace prefix declaration to the graph.

§Arguments
  • alias - The prefix alias (e.g., “foaf”, “ex”, “rdf”)
  • iri - The full namespace IRI this prefix represents
Source

fn add_prefix_map(&mut self, prefix_map: PrefixMap) -> Result<(), Self::Err>

Adds multiple prefix declarations from a prefix map.

§Arguments
  • prefix_map - A map of prefix aliases to namespace IRIs
Source

fn add_triple<S, P, O>( &mut self, subj: S, pred: P, obj: O, ) -> Result<(), Self::Err>
where S: Into<Self::Subject>, P: Into<Self::IRI>, O: Into<Self::Term>,

Adds an RDF triple to the graph.

§Type Parameters
  • S - Type convertible to the subject representation
  • P - Type convertible to the predicate (IRI) representation
  • O - Type convertible to the object (term) representation
§Arguments
  • subj - The subject of the triple (IRI or blank node)
  • pred - The predicate of the triple (must be an IRI)
  • obj - The object of the triple (IRI, blank node, or literal)
Source

fn remove_triple<S, P, O>( &mut self, subj: S, pred: P, obj: O, ) -> Result<(), Self::Err>
where S: Into<Self::Subject>, P: Into<Self::IRI>, O: Into<Self::Term>,

Removes an RDF triple from the graph.

§Type Parameters
  • S - Type convertible to the subject representation
  • P - Type convertible to the predicate (IRI) representation
  • O - Type convertible to the object (term) representation
§Arguments
  • subj - The subject of the triple to remove
  • pred - The predicate of the triple to remove
  • obj - The object of the triple to remove
Source

fn add_type<S, T>(&mut self, node: S, type_: T) -> Result<(), Self::Err>
where S: Into<Self::Subject>, T: Into<Self::Term>,

Adds an rdf:type declaration to the graph.

§Type Parameters
  • S - Type convertible to the subject representation
  • T - Type convertible to the term representation (typically an IRI)
§Arguments
  • node - The resource being typed (subject)
  • type_ - The type/class of the resource (typically an IRI)
Source

fn add_bnode(&mut self) -> Result<Self::BNode, Self::Err>

Adds an Blank node to the RDF graph and get the node identifier

Source

fn serialize<W: Write>( &self, format: &RDFFormat, writer: &mut W, ) -> Result<(), Self::Err>

Serializes the graph to an RDF format.

§Arguments
  • format - The RDF serialization format to use
  • writer - The destination for serialized output

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.

Implementors§

Source§

impl BuildRDF for InMemoryGraph

Implementation of the BuildRDF trait for constructing and modifying RDF graphs.

This implementation provides methods to build RDF graphs programmatically by adding prefixes, base IRIs, blank nodes, triples, and types. It also supports serialization to various RDF formats.