Skip to main content

NeighsRDF

Trait NeighsRDF 

Source
pub trait NeighsRDF: Rdf {
Show 17 methods // Required methods fn triples(&self) -> 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> where S: Matcher<Self::Subject>, P: Matcher<Self::IRI>, O: Matcher<Self::Term>; // Provided methods fn contains<S, P, O>( &self, subject: &S, predicate: &P, object: &O, ) -> Result<bool, Self::Err> where S: Matcher<Self::Subject>, P: Matcher<Self::IRI>, O: Matcher<Self::Term> { ... } fn triples_with_subject( &self, subject: &Self::Subject, ) -> 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> { ... } fn triples_with_predicate( &self, predicate: &Self::IRI, ) -> 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> { ... } fn triples_with_object( &self, object: &Self::Term, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err> { ... } fn incoming_arcs( &self, object: &Self::Term, ) -> Result<HashMap<<Self as Rdf>::IRI, HashSet<<Self as Rdf>::Subject>>, Self::Err> { ... } fn outgoing_arcs( &self, subject: &Self::Subject, ) -> Result<HashMap<<Self as Rdf>::IRI, HashSet<<Self as Rdf>::Term>>, 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> { ... } fn shacl_instances_of<O>( &self, cls: &O, ) -> Result<impl Iterator<Item = Self::Subject>, Self::Err> where O: Matcher<Self::Term> { ... } fn reifiers_of_triple( &self, triple: &Self::Triple, ) -> Result<impl Iterator<Item = Self::Subject>, Self::Err> { ... } fn object_for( &self, subject: &Self::Term, predicate: &Self::IRI, ) -> Result<Option<Object>, RDFError> { ... } fn objects_for_shacl_path( &self, subject: &Self::Term, path: &SHACLPath, ) -> Result<HashSet<Self::Term>, RDFError> { ... } fn objects_for( &self, subject: &Self::Term, predicate: &Self::IRI, ) -> Result<HashSet<Self::Term>, RDFError> { ... } fn subjects_for( &self, predicate: &Self::IRI, object: &Self::Term, ) -> Result<HashSet<Self::Term>, RDFError> { ... }
}
Expand description

Trait for navigating RDF graphs and querying triples.

This trait extends Rdf with methods for retrieving triples based on subject-predicate-object patterns, exploring node neighborhoods, and following SHACL property paths. All query methods support flexible matching using the Matcher trait, allowing exact matches or wildcards.

§Graph Navigation

The trait provides two primary navigation models:

  • Triple queries: Retrieve triples matching specific patterns
  • Arc-based navigation: Explore incoming and outgoing relationships

Required Methods§

Source

fn triples(&self) -> Result<impl Iterator<Item = Self::Triple>, Self::Err>

Returns an iterator over all triples in the RDF graph.

This method provides access to the complete set of triples. For large graphs, implementations should return a lazy iterator that retrieves triples incrementally rather than loading everything into memory.

Source

fn triples_matching<S, P, O>( &self, subject: &S, predicate: &P, object: &O, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>
where S: Matcher<Self::Subject>, P: Matcher<Self::IRI>, O: Matcher<Self::Term>,

Returns an iterator over triples matching the given pattern.

This is the core query method that all other triple queries delegate to. Each parameter accepts a Matcher, allowing exact values or wildcards via Any.

§Implementation Note

This function must retrieve triples from the graph, but should not load all triples into memory for large graphs. For SPARQL-based implementations, translate the pattern into a SPARQL query that retrieves only matching triples incrementally.

§Arguments
  • subject - Matcher for the subject position
  • predicate - Matcher for the predicate position
  • object - Matcher for the object position

Provided Methods§

Source

fn contains<S, P, O>( &self, subject: &S, predicate: &P, object: &O, ) -> Result<bool, Self::Err>
where S: Matcher<Self::Subject>, P: Matcher<Self::IRI>, O: Matcher<Self::Term>,

Checks whether the graph contains at least one triple matching the pattern.

§Arguments
  • subject - Matcher for the subject (use Any for wildcard)
  • predicate - Matcher for the predicate (use Any for wildcard)
  • object - Matcher for the object (use Any for wildcard)
Source

fn triples_with_subject( &self, subject: &Self::Subject, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>

Returns all triples with the specified subject.

Equivalent to triples_matching(subject, Any, Any).

§Arguments
  • subject - The subject to match
Source

fn triples_with_subject_predicate( &self, subject: &Self::Subject, predicate: &Self::IRI, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>

Returns all triples with the specified subject and predicate.

Equivalent to triples_matching(subject, predicate, Any).

§Arguments
  • subject - The subject to match
  • predicate - The predicate to match
Source

fn triples_with_predicate( &self, predicate: &Self::IRI, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>

Returns all triples with the specified predicate.

Equivalent to triples_matching(Any, predicate, Any).

§Arguments
  • predicate - The predicate to match
Source

fn triples_with_predicate_object( &self, predicate: &Self::IRI, object: &Self::Term, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>

Returns all triples with the specified predicate and object.

Equivalent to triples_matching(Any, predicate, object).

§Arguments
  • predicate - The predicate to match
  • object - The object to match
Source

fn triples_with_object( &self, object: &Self::Term, ) -> Result<impl Iterator<Item = Self::Triple> + '_, Self::Err>

Returns all triples with the specified object.

Equivalent to triples_matching(Any, Any, object).

§Arguments
  • object - The object to match
Source

fn incoming_arcs( &self, object: &Self::Term, ) -> Result<HashMap<<Self as Rdf>::IRI, HashSet<<Self as Rdf>::Subject>>, Self::Err>

Returns all incoming arcs (predicates and subjects) pointing to an object.

This method performs reverse navigation, finding all subjects that have relationships pointing to the specified object, grouped by predicate.

§Arguments
  • object - The object term to find incoming relationships for
Source

fn outgoing_arcs( &self, subject: &Self::Subject, ) -> Result<HashMap<<Self as Rdf>::IRI, HashSet<<Self as Rdf>::Term>>, Self::Err>

Returns all outgoing arcs (predicates and objects) from a subject.

This method performs forward navigation, finding all predicates and their associated objects for the specified subject.

§Arguments
  • subject - The subject to find outgoing relationships for
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>

Returns filtered outgoing arcs and remainder predicates.

This method retrieves outgoing arcs from a subject, but only includes predicates that appear in the provided allowlist. Predicates not in the list are collected separately in the remainder vector.

§Arguments
  • subject - The subject to query
  • preds - A slice of predicates to include in the filtered results
Source

fn shacl_instances_of<O>( &self, cls: &O, ) -> Result<impl Iterator<Item = Self::Subject>, Self::Err>
where O: Matcher<Self::Term>,

Returns all subjects that are instances of the specified class.

This method queries for subjects that have rdf:type relationships pointing to the given class term.

§Arguments
  • cls - Matcher for the class (object position of rdf:type triples)
Source

fn reifiers_of_triple( &self, triple: &Self::Triple, ) -> Result<impl Iterator<Item = Self::Subject>, Self::Err>

Returns all subjects that reify the specified triple.

This method finds RDF reification statements where subjects use rdf:reifies to reference the given triple. This supports RDF-star reification patterns.

§Arguments
  • triple - The triple to find reifiers for
Source

fn object_for( &self, subject: &Self::Term, predicate: &Self::IRI, ) -> Result<Option<Object>, RDFError>

Returns the first object for the given subject-predicate pair.

This is a convenience method that returns at most one object. If multiple objects exist, only the first encountered is returned.

§Arguments
  • subject - The subject to query
  • predicate - The predicate to match
Source

fn objects_for_shacl_path( &self, subject: &Self::Term, path: &SHACLPath, ) -> Result<HashSet<Self::Term>, RDFError>

Returns all objects reachable by following a SHACL property path.

SHACL property paths extend simple predicate-based navigation with complex path expressions including sequences, alternatives, inverses, and quantifiers.

§Path Types
  • Predicate: Direct predicate navigation (ex:name)
  • Alternative: Union of multiple paths (ex:father | ex:mother)
  • Sequence: Composed paths (ex:parent / ex:name)
  • Inverse: Reverse navigation (^ex:author)
  • ZeroOrMore: Transitive closure (ex:subClassOf*)
  • OneOrMore: Non-empty transitive closure (ex:subClassOf+)
  • ZeroOrOne: Optional path (ex:nickname?)
§Arguments
  • subject - The starting term for path navigation
  • path - The SHACL property path to follow
Source

fn objects_for( &self, subject: &Self::Term, predicate: &Self::IRI, ) -> Result<HashSet<Self::Term>, RDFError>

Returns all objects for the given subject-predicate pair.

This method retrieves the object position of all triples matching the specified subject and predicate.

§Arguments
  • subject - The subject term to query
  • predicate - The predicate IRI to match
§Errors

Returns RDFError::ErrorObjectsFor if the query fails or if the subject term cannot be converted to a valid subject.

Source

fn subjects_for( &self, predicate: &Self::IRI, object: &Self::Term, ) -> Result<HashSet<Self::Term>, RDFError>

Returns all subjects for the given predicate-object pair.

This method performs reverse lookup, finding subjects that have the specified predicate pointing to the given object.

§Arguments
  • predicate - The predicate IRI to match
  • object - The object term to query
§Errors

Returns RDFError::ErrorSubjectsFor if the query 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 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.