Skip to main content

FocusRDF

Trait FocusRDF 

Source
pub trait FocusRDF: NeighsRDF
where Self: 'static,
{ // Required methods fn set_focus(&mut self, focus: &Self::Term); fn get_focus(&self) -> Option<&Self::Term>; // Provided methods fn get_focus_as_term(&self) -> Result<&Self::Term, RDFError> { ... } fn get_focus_as_subject(&self) -> Result<Self::Subject, RDFError> { ... } fn get_path_for( &mut self, subject: &Self::Term, predicate: &Self::IRI, ) -> Result<Option<SHACLPath>, RDFError> { ... } }
Expand description

A trait for RDF graphs that maintain a focus node for context-aware parsing.

FocusRDF extends NeighsRDF by adding the concept of a “focus node” - a current point of reference within the RDF graph. This focus node serves as the starting point for parsing operations, allowing parsers to navigate the graph structure from a specific node without repeatedly specifying it.

The focus node pattern is commonly used in RDF validation (like SHACL) and graph traversal scenarios where operations are performed relative to a particular node.

Required Methods§

Source

fn set_focus(&mut self, focus: &Self::Term)

Sets the current focus node.

§Arguments
  • focus - The RDF term to set as the new focus node
Source

fn get_focus(&self) -> Option<&Self::Term>

Retrieves the current focus node if one is set.

§Returns

A reference to Some(term) if a focus is set, or None otherwise

Provided Methods§

Source

fn get_focus_as_term(&self) -> Result<&Self::Term, RDFError>

Retrieves the current focus node as a term, failing if no focus is set.

This is a convenience method that unwraps the focus option and returns an error if no focus node is currently set. Useful when a focus is required for an operation to proceed.

§Returns
  • Ok(&term) - A reference to the current focus node
  • Err(RDFError::NoFocusNodeError) - If no focus is currently set
Source

fn get_focus_as_subject(&self) -> Result<Self::Subject, RDFError>

Retrieves the current focus node as a subject, failing if not set or not a valid subject.

§Returns
  • Ok(subject) - The current focus as a subject node
  • Err(RDFError::NoFocusNodeError) - If no focus is currently set
  • Err(RDFError::ExpectedSubjectError) - If the focus is a literal or cannot be converted to a subject
Source

fn get_path_for( &mut self, subject: &Self::Term, predicate: &Self::IRI, ) -> Result<Option<SHACLPath>, RDFError>

Parses and retrieves a SHACL path from a subject-predicate pair.

§Arguments
  • subject - The subject node to query
  • predicate - The predicate whose object should be parsed as a SHACL path
§Returns
  • Ok(Some(path)) - If an object exists and was successfully parsed as a SHACL path
  • Ok(None) - If no object exists or parsing failed
  • Err(e) - If querying the graph for objects fails

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