pub struct NamedGraphManager { /* private fields */ }Expand description
High-level manager for named RDF graphs within a single dataset
Provides a Jena-compatible API for creating, querying, and managing
named graphs. Each graph is identified by a GraphName key.
§Example
use oxirs_core::named_graph::NamedGraphManager;
use oxirs_core::model::{GraphName, NamedNode, Literal, Triple};
let mut mgr = NamedGraphManager::new();
let graph_iri = NamedNode::new("http://example.org/graph1").expect("valid IRI");
let key = GraphName::NamedNode(graph_iri.clone());
// Create a named graph (auto-created on first insert)
mgr.add_named_graph(key.clone());
// Insert a triple into that graph
let subj = NamedNode::new("http://example.org/s").expect("valid IRI");
let pred = NamedNode::new("http://example.org/p").expect("valid IRI");
let obj = Literal::new("hello");
let triple = Triple::new(subj, pred, obj);
mgr.insert_triple(&key, triple).expect("operation should succeed");
assert_eq!(mgr.triple_count_in(&key), 1);Implementations§
Source§impl NamedGraphManager
impl NamedGraphManager
Sourcepub fn with_capacity(named_graph_capacity: usize) -> Self
pub fn with_capacity(named_graph_capacity: usize) -> Self
Create a dataset manager with an initial capacity hint for named graphs
Sourcepub fn default_graph(&self) -> &Graph
pub fn default_graph(&self) -> &Graph
Returns a shared reference to the default (unnamed) graph
Sourcepub fn default_graph_mut(&mut self) -> &mut Graph
pub fn default_graph_mut(&mut self) -> &mut Graph
Returns an exclusive reference to the default (unnamed) graph
Sourcepub fn add_named_graph(&mut self, name: GraphName) -> bool
pub fn add_named_graph(&mut self, name: GraphName) -> bool
Create (or ensure the existence of) a named graph
Returns true if the graph was newly created, false if it already existed.
Has no effect on the default graph key.
Sourcepub fn remove_named_graph(&mut self, name: &GraphName) -> Option<Graph>
pub fn remove_named_graph(&mut self, name: &GraphName) -> Option<Graph>
Remove a named graph from the dataset
Returns the removed Graph if it existed, None otherwise.
Calling this with the default graph key clears the default graph and
returns the old contents.
Sourcepub fn get_named_graph(&self, name: &GraphName) -> Option<&Graph>
pub fn get_named_graph(&self, name: &GraphName) -> Option<&Graph>
Returns a shared reference to the named graph with the given key
Returns None if no such graph exists. Use the default-graph key to
access the default graph.
Sourcepub fn get_or_create_named_graph_mut(&mut self, name: &GraphName) -> &mut Graph
pub fn get_or_create_named_graph_mut(&mut self, name: &GraphName) -> &mut Graph
Returns an exclusive reference to the named graph with the given key, creating an empty graph entry if it does not exist yet.
Sourcepub fn get_named_graph_mut(&mut self, name: &GraphName) -> Option<&mut Graph>
pub fn get_named_graph_mut(&mut self, name: &GraphName) -> Option<&mut Graph>
Returns an exclusive reference to an existing named graph
Returns None if the graph does not exist (unlike
get_or_create_named_graph_mut).
Sourcepub fn contains_named_graph(&self, name: &GraphName) -> bool
pub fn contains_named_graph(&self, name: &GraphName) -> bool
Returns true if a named graph with the given key exists
Sourcepub fn list_named_graphs(&self) -> impl Iterator<Item = &GraphName>
pub fn list_named_graphs(&self) -> impl Iterator<Item = &GraphName>
Returns an iterator over the names of all named graphs (excluding default)
Sourcepub fn graph_count(&self) -> usize
pub fn graph_count(&self) -> usize
Returns the number of named graphs (excluding the default graph)
Sourcepub fn total_graph_count(&self) -> usize
pub fn total_graph_count(&self) -> usize
Returns the total number of graphs including the default graph
Sourcepub fn insert_triple(
&mut self,
graph: &GraphName,
triple: Triple,
) -> Result<bool>
pub fn insert_triple( &mut self, graph: &GraphName, triple: Triple, ) -> Result<bool>
Insert a triple into the specified graph
If the graph does not exist it is created automatically.
Returns true if the triple was newly inserted.
Sourcepub fn remove_triple(
&mut self,
graph: &GraphName,
triple: &Triple,
) -> Result<bool>
pub fn remove_triple( &mut self, graph: &GraphName, triple: &Triple, ) -> Result<bool>
Remove a triple from the specified graph
Returns true if the triple was present and removed.
Returns an error if the graph does not exist.
Sourcepub fn contains_triple(&self, graph: &GraphName, triple: &Triple) -> bool
pub fn contains_triple(&self, graph: &GraphName, triple: &Triple) -> bool
Returns true if the specified graph contains the given triple
Sourcepub fn triples_in_graph(&self, graph: &GraphName) -> Vec<Triple>
pub fn triples_in_graph(&self, graph: &GraphName) -> Vec<Triple>
Returns an owned Vec of all triples in the specified graph
Returns an empty vector if the graph does not exist.
Sourcepub fn triple_count_in(&self, graph: &GraphName) -> usize
pub fn triple_count_in(&self, graph: &GraphName) -> usize
Returns the number of triples in the specified graph
Sourcepub fn triple_count(&self) -> usize
pub fn triple_count(&self) -> usize
Returns the total number of triples across all graphs (named + default)
Sourcepub fn clear_graph(&mut self, graph: &GraphName) -> Result<usize>
pub fn clear_graph(&mut self, graph: &GraphName) -> Result<usize>
Remove all triples from the specified graph (graph itself remains)
Returns the number of triples removed.
Sourcepub fn drop_graph(&mut self, graph: &GraphName) -> bool
pub fn drop_graph(&mut self, graph: &GraphName) -> bool
Remove all triples from the specified graph and delete the graph entry
Returns true if the graph existed. For the default graph this clears
its contents but does not destroy the graph slot.
Sourcepub fn union_graph(&self) -> Graph
pub fn union_graph(&self) -> Graph
Build the union graph: all triples from all named graphs merged together
The returned Graph is a fresh copy; modifications do not affect
the original graphs.
Sourcepub fn union_of_named_graphs(&self) -> Graph
pub fn union_of_named_graphs(&self) -> Graph
Merge all named graphs (but NOT the default graph) into a union graph
Useful when implementing the SPARQL UNION DEFAULT GRAPH feature.
Sourcepub fn insert_quad(&mut self, quad: Quad) -> Result<bool>
pub fn insert_quad(&mut self, quad: Quad) -> Result<bool>
Insert a Quad (routing it to the appropriate named graph)
Sourcepub fn iter_quads(&self) -> impl Iterator<Item = Quad> + '_
pub fn iter_quads(&self) -> impl Iterator<Item = Quad> + '_
Returns an iterator over all quads in the dataset
Sourcepub fn statistics(&self) -> GraphStatistics
pub fn statistics(&self) -> GraphStatistics
Compute statistics for this dataset
Sourcepub fn bulk_insert<I>(&mut self, graph: &GraphName, triples: I) -> usizewhere
I: IntoIterator<Item = Triple>,
pub fn bulk_insert<I>(&mut self, graph: &GraphName, triples: I) -> usizewhere
I: IntoIterator<Item = Triple>,
Load all triples from an iterator into the given named graph
Returns the number of triples inserted (deduplicated).
Trait Implementations§
Source§impl Clone for NamedGraphManager
impl Clone for NamedGraphManager
Source§fn clone(&self) -> NamedGraphManager
fn clone(&self) -> NamedGraphManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NamedGraphManager
impl Debug for NamedGraphManager
Source§impl Default for NamedGraphManager
impl Default for NamedGraphManager
Source§impl GraphStore for NamedGraphManager
In-memory implementation of GraphStore backed by NamedGraphManager
impl GraphStore for NamedGraphManager
In-memory implementation of GraphStore backed by NamedGraphManager
Source§fn add_triple(&mut self, graph: &GraphName, triple: Triple) -> Result<bool>
fn add_triple(&mut self, graph: &GraphName, triple: Triple) -> Result<bool>
Source§fn remove_triple(&mut self, graph: &GraphName, triple: &Triple) -> Result<bool>
fn remove_triple(&mut self, graph: &GraphName, triple: &Triple) -> Result<bool>
Source§fn contains_triple(&self, graph: &GraphName, triple: &Triple) -> Result<bool>
fn contains_triple(&self, graph: &GraphName, triple: &Triple) -> Result<bool>
true if the graph contains the tripleSource§fn triples_in_graph(&self, graph: &GraphName) -> Result<Vec<Triple>>
fn triples_in_graph(&self, graph: &GraphName) -> Result<Vec<Triple>>
Auto Trait Implementations§
impl Freeze for NamedGraphManager
impl RefUnwindSafe for NamedGraphManager
impl Send for NamedGraphManager
impl Sync for NamedGraphManager
impl Unpin for NamedGraphManager
impl UnsafeUnpin for NamedGraphManager
impl UnwindSafe for NamedGraphManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more