Skip to main content

NamedGraphManager

Struct NamedGraphManager 

Source
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

Source

pub fn new() -> Self

Create a new empty dataset manager

Source

pub fn with_capacity(named_graph_capacity: usize) -> Self

Create a dataset manager with an initial capacity hint for named graphs

Source

pub fn default_graph(&self) -> &Graph

Returns a shared reference to the default (unnamed) graph

Source

pub fn default_graph_mut(&mut self) -> &mut Graph

Returns an exclusive reference to the default (unnamed) graph

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn contains_named_graph(&self, name: &GraphName) -> bool

Returns true if a named graph with the given key exists

Source

pub fn list_named_graphs(&self) -> impl Iterator<Item = &GraphName>

Returns an iterator over the names of all named graphs (excluding default)

Source

pub fn graph_count(&self) -> usize

Returns the number of named graphs (excluding the default graph)

Source

pub fn total_graph_count(&self) -> usize

Returns the total number of graphs including the default graph

Source

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.

Source

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.

Source

pub fn contains_triple(&self, graph: &GraphName, triple: &Triple) -> bool

Returns true if the specified graph contains the given triple

Source

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.

Source

pub fn triple_count_in(&self, graph: &GraphName) -> usize

Returns the number of triples in the specified graph

Source

pub fn triple_count(&self) -> usize

Returns the total number of triples across all graphs (named + default)

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn insert_quad(&mut self, quad: Quad) -> Result<bool>

Insert a Quad (routing it to the appropriate named graph)

Source

pub fn iter_quads(&self) -> impl Iterator<Item = Quad> + '_

Returns an iterator over all quads in the dataset

Source

pub fn statistics(&self) -> GraphStatistics

Compute statistics for this dataset

Source

pub fn bulk_insert<I>(&mut self, graph: &GraphName, triples: I) -> usize
where I: IntoIterator<Item = Triple>,

Load all triples from an iterator into the given named graph

Returns the number of triples inserted (deduplicated).

Source

pub fn copy_graph( &mut self, source: &GraphName, destination: &GraphName, ) -> Result<usize>

Copy all triples from source graph into destination graph

Returns the number of triples copied (may be fewer if destination already contains some of them).

Source

pub fn move_graph( &mut self, source: &GraphName, destination: &GraphName, ) -> Result<usize>

Move all triples from source graph into destination graph

The source graph is emptied (but kept) after the operation. Returns the number of triples moved.

Trait Implementations§

Source§

impl Clone for NamedGraphManager

Source§

fn clone(&self) -> NamedGraphManager

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NamedGraphManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NamedGraphManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl GraphStore for NamedGraphManager

In-memory implementation of GraphStore backed by NamedGraphManager

Source§

fn add_triple(&mut self, graph: &GraphName, triple: Triple) -> Result<bool>

Add a triple to the given graph Read more
Source§

fn remove_triple(&mut self, graph: &GraphName, triple: &Triple) -> Result<bool>

Remove a triple from the given graph Read more
Source§

fn contains_triple(&self, graph: &GraphName, triple: &Triple) -> Result<bool>

Returns true if the graph contains the triple
Source§

fn triples_in_graph(&self, graph: &GraphName) -> Result<Vec<Triple>>

Returns an owned list of all triples in the graph
Source§

fn clear_graph(&mut self, graph: &GraphName) -> Result<usize>

Remove all triples from the graph (graph entry is kept) Read more
Source§

fn drop_graph(&mut self, graph: &GraphName) -> Result<bool>

Delete the graph and all its triples Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,