pub struct InMemoryGraph { /* private fields */ }Expand description
An RDF graph stored entirely in memory.
The graph is backed by oxrdf::Graph and enriched with prefix handling,
base IRI support, blank node generation, and optional SPARQL querying via
an Oxigraph [Store].
Implementations§
Source§impl InMemoryGraph
impl InMemoryGraph
Sourcepub fn quads(&self) -> impl Iterator<Item = Quad> + '_
pub fn quads(&self) -> impl Iterator<Item = Quad> + '_
Returns an iterator over all triples as quads in the default graph.
Sourcepub fn merge_from_reader<R: Read>(
&mut self,
reader: &mut R,
source_name: &str,
format: &RDFFormat,
base: Option<&str>,
reader_mode: &ReaderMode,
) -> Result<(), InMemoryGraphError>
pub fn merge_from_reader<R: Read>( &mut self, reader: &mut R, source_name: &str, format: &RDFFormat, base: Option<&str>, reader_mode: &ReaderMode, ) -> Result<(), InMemoryGraphError>
Merges RDF data from a reader into the current graph.
The parsing behavior depends on RDFFormat and ReaderMode.
Prefixes and base IRI are merged when available.
§Parameters
reader- Input stream containing RDF datasource_name- Name used for error reportingformat- RDF serialization formatbase- Optional base IRI for resolving relative IRIsreader_mode- Controls error handling (strict or lax)
§Errors
Returns an error if parsing fails in strict mode or if I/O errors occur.
Sourcepub fn merge_prefixes(
&mut self,
prefixmap: PrefixMap,
) -> Result<(), InMemoryGraphError>
pub fn merge_prefixes( &mut self, prefixmap: PrefixMap, ) -> Result<(), InMemoryGraphError>
Sourcepub fn from_reader<R: Read>(
read: &mut R,
source_name: &str,
format: &RDFFormat,
base: Option<&str>,
reader_mode: &ReaderMode,
) -> Result<InMemoryGraph, InMemoryGraphError>
pub fn from_reader<R: Read>( read: &mut R, source_name: &str, format: &RDFFormat, base: Option<&str>, reader_mode: &ReaderMode, ) -> Result<InMemoryGraph, InMemoryGraphError>
Builds a new graph from a reader.
This is a convenience constructor that creates an empty graph and merges data from the reader.
§Parameters
read- Input stream containing RDF datasource_name- Name used for error reportingformat- RDF serialization formatbase- Optional base IRI for resolving relative IRIsreader_mode- Controls error handling (strict or lax)
§Errors
Returns an error if parsing fails.
Sourcepub fn resolve(&self, str: &str) -> Result<OxNamedNode, InMemoryGraphError>
pub fn resolve(&self, str: &str) -> Result<OxNamedNode, InMemoryGraphError>
Sourcepub fn show_blanknode(&self, bn: &OxBlankNode) -> String
pub fn show_blanknode(&self, bn: &OxBlankNode) -> String
Formats a blank node for display with color.
Returns a green-colored string representation.
§Parameters
bn- The blank node to format
Sourcepub fn show_literal(&self, lit: &OxLiteral) -> String
pub fn show_literal(&self, lit: &OxLiteral) -> String
Formats a literal for display with color.
Returns a red-colored string representation.
§Parameters
lit- The literal to format
Sourcepub fn from_str(
data: &str,
format: &RDFFormat,
base: Option<&str>,
reader_mode: &ReaderMode,
) -> Result<InMemoryGraph, InMemoryGraphError>
pub fn from_str( data: &str, format: &RDFFormat, base: Option<&str>, reader_mode: &ReaderMode, ) -> Result<InMemoryGraph, InMemoryGraphError>
Sourcepub fn add_triple_ref<'a, S, P, O>(
&mut self,
subj: S,
pred: P,
obj: O,
) -> Result<(), InMemoryGraphError>
pub fn add_triple_ref<'a, S, P, O>( &mut self, subj: S, pred: P, obj: O, ) -> Result<(), InMemoryGraphError>
Source§impl InMemoryGraph
impl InMemoryGraph
Sourcepub fn merge_from_path<P: AsRef<Path>>(
&mut self,
path: P,
format: &RDFFormat,
base: Option<&str>,
reader_mode: &ReaderMode,
) -> Result<(), InMemoryGraphError>
pub fn merge_from_path<P: AsRef<Path>>( &mut self, path: P, format: &RDFFormat, base: Option<&str>, reader_mode: &ReaderMode, ) -> Result<(), InMemoryGraphError>
Merges RDF data from a filesystem path.
Opens the file and delegates to merge_from_reader.
§Parameters
path- Path to the RDF fileformat- RDF serialization formatbase- Optional base IRI for resolving relative IRIsreader_mode- Controls error handling (strict or lax)
§Errors
Returns an error if the file cannot be opened or if parsing fails.
Sourcepub fn from_path<P: AsRef<Path>>(
path: P,
format: &RDFFormat,
base: Option<&str>,
reader_mode: &ReaderMode,
) -> Result<InMemoryGraph, InMemoryGraphError>
pub fn from_path<P: AsRef<Path>>( path: P, format: &RDFFormat, base: Option<&str>, reader_mode: &ReaderMode, ) -> Result<InMemoryGraph, InMemoryGraphError>
Builds a graph from a filesystem path.
Creates a new empty graph and merges data from the file.
§Parameters
path- Path to the RDF fileformat- RDF serialization formatbase- Optional base IRI for resolving relative IRIsreader_mode- Controls error handling (strict or lax)
§Errors
Returns an error if the file cannot be opened or if parsing fails.
Sourcepub fn parse_data(
data: &str,
format: &RDFFormat,
folder: &Path,
base: Option<&str>,
reader_mode: &ReaderMode,
) -> Result<InMemoryGraph, InMemoryGraphError>
pub fn parse_data( data: &str, format: &RDFFormat, folder: &Path, base: Option<&str>, reader_mode: &ReaderMode, ) -> Result<InMemoryGraph, InMemoryGraphError>
Parses data from a relative path within a folder.
Convenience method that joins the data file name with the folder path.
§Parameters
data- Relative file name within the folderformat- RDF serialization formatfolder- Base directory pathbase- Optional base IRI for resolving relative IRIsreader_mode- Controls error handling (strict or lax)
§Errors
Returns an error if the file cannot be opened or if parsing fails.
Trait Implementations§
Source§impl AsyncRDF for InMemoryGraph
impl AsyncRDF for InMemoryGraph
Source§fn get_predicates_subject<'life0, 'life1, 'async_trait>(
&'life0 self,
subject: &'life1 OxSubject,
) -> Pin<Box<dyn Future<Output = Result<HashSet<OxNamedNode>, InMemoryGraphError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_predicates_subject<'life0, 'life1, 'async_trait>(
&'life0 self,
subject: &'life1 OxSubject,
) -> Pin<Box<dyn Future<Output = Result<HashSet<OxNamedNode>, InMemoryGraphError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn get_objects_for_subject_predicate<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
subject: &'life1 OxSubject,
pred: &'life2 OxNamedNode,
) -> Pin<Box<dyn Future<Output = Result<HashSet<OxTerm>, InMemoryGraphError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_objects_for_subject_predicate<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
subject: &'life1 OxSubject,
pred: &'life2 OxNamedNode,
) -> Pin<Box<dyn Future<Output = Result<HashSet<OxTerm>, InMemoryGraphError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn get_subjects_for_object_predicate<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
object: &'life1 OxTerm,
pred: &'life2 OxNamedNode,
) -> Pin<Box<dyn Future<Output = Result<HashSet<OxSubject>, InMemoryGraphError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_subjects_for_object_predicate<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
object: &'life1 OxTerm,
pred: &'life2 OxNamedNode,
) -> Pin<Box<dyn Future<Output = Result<HashSet<OxSubject>, InMemoryGraphError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§type Subject = NamedOrBlankNode
type Subject = NamedOrBlankNode
Source§type Err = InMemoryGraphError
type Err = InMemoryGraphError
Source§impl BuildRDF for InMemoryGraph
Implementation of the BuildRDF trait for constructing and modifying RDF graphs.
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.
Source§fn add_base(&mut self, base: &Option<IriS>) -> Result<(), Self::Err>
fn add_base(&mut self, base: &Option<IriS>) -> Result<(), Self::Err>
Sets the base IRI for the graph.
The base IRI is used to resolve relative IRIs during parsing and serialization.
§Parameters
base- Optional base IRI to set
Source§fn add_bnode(&mut self) -> Result<Self::BNode, Self::Err>
fn add_bnode(&mut self) -> Result<Self::BNode, Self::Err>
Generates a new unique blank node.
Each call to this method increments an internal counter to ensure uniqueness.
§Errors
Returns an error if the blank node counter overflows (extremely unlikely).
Source§fn add_triple<S, P, O>(
&mut self,
subj: S,
pred: P,
obj: O,
) -> Result<(), Self::Err>
fn add_triple<S, P, O>( &mut self, subj: S, pred: P, obj: O, ) -> Result<(), Self::Err>
Adds a triple to the graph.
§Parameters
subj- The subject of the triplepred- The predicate of the tripleobj- The object of the triple
Source§fn remove_triple<S, P, O>(
&mut self,
subj: S,
pred: P,
obj: O,
) -> Result<(), Self::Err>
fn remove_triple<S, P, O>( &mut self, subj: S, pred: P, obj: O, ) -> Result<(), Self::Err>
Removes a triple from the graph.
§Parameters
subj- The subject of the triple to removepred- The predicate of the triple to removeobj- The object of the triple to remove
Source§fn add_type<S, T>(&mut self, node: S, type_: T) -> Result<(), Self::Err>
fn add_type<S, T>(&mut self, node: S, type_: T) -> Result<(), Self::Err>
Adds an rdf:type assertion to the graph.
This is a convenience method that adds a triple with rdf:type as the predicate.
§Parameters
node- The subject that has the typetype_- The type (class) of the subject
Source§fn serialize<W: Write>(
&self,
format: &RDFFormat,
write: &mut W,
) -> Result<(), Self::Err>
fn serialize<W: Write>( &self, format: &RDFFormat, write: &mut W, ) -> Result<(), Self::Err>
Serializes the graph to a writer in the specified RDF format.
All prefixes defined in the graph’s prefix map are included in the serialization.
§Parameters
format- The RDF serialization format to usewrite- The writer to serialize to
§Errors
Returns an error if serialization fails or if the writer encounters an I/O error.
Source§impl Clone for InMemoryGraph
impl Clone for InMemoryGraph
Source§fn clone(&self) -> InMemoryGraph
fn clone(&self) -> InMemoryGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for InMemoryGraph
impl Debug for InMemoryGraph
Source§impl Default for InMemoryGraph
impl Default for InMemoryGraph
Source§fn default() -> InMemoryGraph
fn default() -> InMemoryGraph
Source§impl FocusRDF for InMemoryGraph
Implementation of the FocusRDF trait for managing a focus term.
impl FocusRDF for InMemoryGraph
Implementation of the FocusRDF trait for managing a focus term.
The focus term is used to track a specific RDF term of interest during graph operations. This can be useful for navigation, querying, or maintaining context during traversals.
Source§fn get_focus(&self) -> Option<&Self::Term>
fn get_focus(&self) -> Option<&Self::Term>
Returns the current focus term, if one is set.
§Returns
Some(&Term)- If a focus term has been setNone- If no focus term is currently set
Source§fn get_focus_as_term(&self) -> Result<&Self::Term, RDFError>
fn get_focus_as_term(&self) -> Result<&Self::Term, RDFError>
Source§impl NeighsRDF for InMemoryGraph
Implementation of the NeighsRDF trait for navigating graph neighbors.
impl NeighsRDF for InMemoryGraph
Implementation of the NeighsRDF trait for navigating graph neighbors.
This implementation provides methods to iterate over triples in the graph, optionally filtered by subject, predicate, or object patterns.
Source§fn triples_matching<S, P, O>(
&self,
subject: &S,
predicate: &P,
object: &O,
) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
fn triples_matching<S, P, O>( &self, subject: &S, predicate: &P, object: &O, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
Returns an iterator over triples matching a pattern.
Uses the appropriate oxrdf index based on which positions are concrete vs wildcard, giving O(k) complexity instead of a full O(n) table scan.
§Parameters
subject- Pattern matcher for the subjectpredicate- Pattern matcher for the predicateobject- Pattern matcher for the object
§Returns
An iterator that yields triples matching all three patterns.
Source§fn contains<S, P, O>(
&self,
subject: &S,
predicate: &P,
object: &O,
) -> Result<bool, Self::Err>
fn contains<S, P, O>( &self, subject: &S, predicate: &P, object: &O, ) -> Result<bool, Self::Err>
Source§fn triples_with_subject(
&self,
subject: &Self::Subject,
) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
fn triples_with_subject( &self, subject: &Self::Subject, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
Source§fn triples_with_subject_predicate(
&self,
subject: &Self::Subject,
predicate: &Self::IRI,
) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
fn triples_with_subject_predicate( &self, subject: &Self::Subject, predicate: &Self::IRI, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
Source§fn triples_with_predicate(
&self,
predicate: &Self::IRI,
) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
fn triples_with_predicate( &self, predicate: &Self::IRI, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
Source§fn triples_with_predicate_object(
&self,
predicate: &Self::IRI,
object: &Self::Term,
) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
fn triples_with_predicate_object( &self, predicate: &Self::IRI, object: &Self::Term, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
Source§fn triples_with_object(
&self,
object: &Self::Term,
) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
fn triples_with_object( &self, object: &Self::Term, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
Source§fn incoming_arcs(
&self,
object: &Self::Term,
) -> Result<HashMap<<Self as Rdf>::IRI, HashSet<<Self as Rdf>::Subject>>, Self::Err>
fn incoming_arcs( &self, object: &Self::Term, ) -> Result<HashMap<<Self as Rdf>::IRI, HashSet<<Self as Rdf>::Subject>>, Self::Err>
Source§fn outgoing_arcs(
&self,
subject: &Self::Subject,
) -> Result<HashMap<<Self as Rdf>::IRI, HashSet<<Self as Rdf>::Term>>, Self::Err>
fn outgoing_arcs( &self, subject: &Self::Subject, ) -> Result<HashMap<<Self as Rdf>::IRI, HashSet<<Self as Rdf>::Term>>, Self::Err>
Source§fn outgoing_arcs_from_list(
&self,
subject: &Self::Subject,
preds: &[Self::IRI],
) -> Result<(HashMap<<Self as Rdf>::IRI, HashSet<<Self as Rdf>::Term>>, Vec<<Self as Rdf>::IRI>), Self::Err>
fn outgoing_arcs_from_list( &self, subject: &Self::Subject, preds: &[Self::IRI], ) -> Result<(HashMap<<Self as Rdf>::IRI, HashSet<<Self as Rdf>::Term>>, Vec<<Self as Rdf>::IRI>), Self::Err>
Source§fn shacl_instances_of<O>(
&self,
cls: &O,
) -> Result<impl Iterator<Item = Self::Subject>, Self::Err>
fn shacl_instances_of<O>( &self, cls: &O, ) -> Result<impl Iterator<Item = Self::Subject>, Self::Err>
Source§fn reifiers_of_triple(
&self,
triple: &Self::Triple,
) -> Result<impl Iterator<Item = Self::Subject>, Self::Err>
fn reifiers_of_triple( &self, triple: &Self::Triple, ) -> Result<impl Iterator<Item = Self::Subject>, Self::Err>
Source§fn object_for(
&self,
subject: &Self::Term,
predicate: &Self::IRI,
) -> Result<Option<Object>, RDFError>
fn object_for( &self, subject: &Self::Term, predicate: &Self::IRI, ) -> Result<Option<Object>, RDFError>
Source§fn objects_for_shacl_path(
&self,
subject: &Self::Term,
path: &SHACLPath,
) -> Result<HashSet<Self::Term>, RDFError>
fn objects_for_shacl_path( &self, subject: &Self::Term, path: &SHACLPath, ) -> Result<HashSet<Self::Term>, RDFError>
Source§impl Rdf for InMemoryGraph
Implementation of the core Rdf trait.
impl Rdf for InMemoryGraph
Implementation of the core Rdf trait.
This implementation provides the fundamental RDF operations including type definitions, prefix resolution, and term qualification (converting full IRIs to prefixed names).
Source§fn resolve_prefix_local(
&self,
prefix: &str,
local: &str,
) -> Result<IriS, PrefixMapError>
fn resolve_prefix_local( &self, prefix: &str, local: &str, ) -> Result<IriS, PrefixMapError>
Source§fn qualify_iri(&self, node: &Self::IRI) -> String
fn qualify_iri(&self, node: &Self::IRI) -> String
Converts a full IRI to a qualified (prefixed) name if possible.
If the IRI matches a known namespace prefix, it returns a shortened form (e.g., “foaf:Person”). Otherwise, it returns the full IRI.
§Parameters
node- The named node to qualify
§Returns
A string representation, either prefixed or full IRI.
Source§fn qualify_subject(&self, subj: &OxSubject) -> String
fn qualify_subject(&self, subj: &OxSubject) -> String
Source§fn qualify_term(&self, term: &OxTerm) -> String
fn qualify_term(&self, term: &OxTerm) -> String
Converts an RDF term (named node, blank node, or literal) to a qualified string.
Different term types are formatted differently:
- Named nodes: qualified using prefix map
- Blank nodes: formatted with green color
- Literals: formatted with red color
- RDF-star triples: not yet supported
§Parameters
term- The term to qualify
§Returns
A string representation of the term.
Source§fn prefixmap(&self) -> Option<PrefixMap>
fn prefixmap(&self) -> Option<PrefixMap>
Returns a reference to the graph’s prefix map.
§Returns
Some(&PrefixMap) containing all defined namespace prefixes.
Source§type Subject = NamedOrBlankNode
type Subject = NamedOrBlankNode
Source§type Err = InMemoryGraphError
type Err = InMemoryGraphError
Source§fn numeric_value(&self, term: &Self::Term) -> Option<Decimal>
fn numeric_value(&self, term: &Self::Term) -> Option<Decimal>
Source§fn term_as_literal(term: &Self::Term) -> Result<Self::Literal, RDFError>
fn term_as_literal(term: &Self::Term) -> Result<Self::Literal, RDFError>
Source§fn term_as_sliteral(term: &Self::Term) -> Result<ConcreteLiteral, RDFError>
fn term_as_sliteral(term: &Self::Term) -> Result<ConcreteLiteral, RDFError>
Source§fn term_as_subject(term: &Self::Term) -> Result<Self::Subject, RDFError>
fn term_as_subject(term: &Self::Term) -> Result<Self::Subject, RDFError>
Source§fn subject_as_term(subj: &Self::Subject) -> Self::Term
fn subject_as_term(subj: &Self::Subject) -> Self::Term
Source§fn triple_as_term(triple: &Self::Triple) -> Self::Term
fn triple_as_term(triple: &Self::Triple) -> Self::Term
Source§fn term_as_iri(term: &Self::Term) -> Result<Self::IRI, RDFError>
fn term_as_iri(term: &Self::Term) -> Result<Self::IRI, RDFError>
Source§fn iri_or_bnode_as_term(ib: &IriOrBlankNode) -> Self::Term
fn iri_or_bnode_as_term(ib: &IriOrBlankNode) -> Self::Term
Source§fn term_as_bnode(term: &Self::Term) -> Result<Self::BNode, RDFError>
fn term_as_bnode(term: &Self::Term) -> Result<Self::BNode, RDFError>
Source§fn term_as_iris(term: &Self::Term) -> Result<IriS, RDFError>
fn term_as_iris(term: &Self::Term) -> Result<IriS, RDFError>
IriS. Read moreSource§fn term_as_object(term: &Self::Term) -> Result<Object, RDFError>
fn term_as_object(term: &Self::Term) -> Result<Object, RDFError>
Object. Read moreSource§fn subject_as_node(subject: &Self::Subject) -> Result<Object, RDFError>
fn subject_as_node(subject: &Self::Subject) -> Result<Object, RDFError>
Object. Read more