pub trait Rdf: Sized {
type Subject: Subject + From<Self::IRI> + From<Self::BNode> + From<IriS> + From<IriOrBlankNode> + TryFrom<Self::Term> + TryInto<IriOrBlankNode> + TryFrom<Object> + Matcher<Self::Subject>;
type IRI: Iri + From<IriS> + TryFrom<Self::Term> + Matcher<Self::IRI> + Into<IriS>;
type Term: Term + From<Self::Subject> + From<Self::IRI> + From<Self::BNode> + From<Self::Literal> + From<Self::Triple> + From<IriS> + From<Object> + TryInto<Object> + Matcher<Self::Term> + PartialEq;
type BNode: BlankNode + TryFrom<Self::Term>;
type Literal: Literal + From<bool> + From<String> + From<i128> + From<f64> + TryFrom<Self::Term> + From<ConcreteLiteral> + TryInto<ConcreteLiteral>;
type Triple: Triple<Self::Subject, Self::IRI, Self::Term>;
type Err: Display;
Show 22 methods
// Required methods
fn qualify_iri(&self, iri: &Self::IRI) -> String;
fn qualify_subject(&self, subj: &Self::Subject) -> String;
fn qualify_term(&self, term: &Self::Term) -> String;
fn prefixmap(&self) -> Option<PrefixMap>;
fn resolve_prefix_local(
&self,
prefix: &str,
local: &str,
) -> Result<IriS, PrefixMapError>;
// Provided methods
fn numeric_value(&self, term: &Self::Term) -> Option<Decimal> { ... }
fn term_as_literal(term: &Self::Term) -> Result<Self::Literal, RDFError> { ... }
fn term_as_sliteral(term: &Self::Term) -> Result<ConcreteLiteral, RDFError> { ... }
fn term_as_subject(term: &Self::Term) -> Result<Self::Subject, RDFError> { ... }
fn subject_as_term(subj: &Self::Subject) -> Self::Term { ... }
fn triple_as_term(triple: &Self::Triple) -> Self::Term { ... }
fn iris_as_term(iri: &IriS) -> Self::Term { ... }
fn term_as_iri(term: &Self::Term) -> Result<Self::IRI, RDFError> { ... }
fn iri_or_bnode_as_term(ib: &IriOrBlankNode) -> Self::Term { ... }
fn term_as_bnode(term: &Self::Term) -> Result<Self::BNode, RDFError> { ... }
fn term_as_iris(term: &Self::Term) -> Result<IriS, RDFError> { ... }
fn term_as_object(term: &Self::Term) -> Result<Object, RDFError> { ... }
fn object_as_term(object: &Object) -> Self::Term { ... }
fn subject_as_node(subject: &Self::Subject) -> Result<Object, RDFError> { ... }
fn term_as_lang(term: &Self::Term) -> Result<Lang, RDFError> { ... }
fn compare(
&self,
term1: &Self::Term,
term2: &Self::Term,
) -> Result<Ordering, RDFError> { ... }
fn equals(&self, term1: &Self::Term, term2: &Self::Term) -> bool { ... }
}Expand description
A trait representing an RDF graph implementation with its associated types and operations.
This trait defines the core interface for working with RDF data structures, including subjects, predicates, objects, literals, and triples. It provides type-safe conversions between different RDF components and utility methods for common RDF operations.
§Associated Types
Implementors must define concrete types for all RDF components:
Subject: Resources that can appear as triple subjectsIRI: Internationalized Resource IdentifiersTerm: Any RDF term (IRIs, literals, blank nodes, or triples)BNode: Blank nodes (anonymous resources)Literal: Literal values (strings, numbers, dates, etc.)Triple: RDF statements (subject-predicate-object)Err: Error type for operations that can fail
Required Associated Types§
Sourcetype Subject: Subject + From<Self::IRI> + From<Self::BNode> + From<IriS> + From<IriOrBlankNode> + TryFrom<Self::Term> + TryInto<IriOrBlankNode> + TryFrom<Object> + Matcher<Self::Subject>
type Subject: Subject + From<Self::IRI> + From<Self::BNode> + From<IriS> + From<IriOrBlankNode> + TryFrom<Self::Term> + TryInto<IriOrBlankNode> + TryFrom<Object> + Matcher<Self::Subject>
The subject type for this RDF implementation.
Sourcetype IRI: Iri + From<IriS> + TryFrom<Self::Term> + Matcher<Self::IRI> + Into<IriS>
type IRI: Iri + From<IriS> + TryFrom<Self::Term> + Matcher<Self::IRI> + Into<IriS>
The IRI type for this RDF implementation.
Sourcetype Term: Term + From<Self::Subject> + From<Self::IRI> + From<Self::BNode> + From<Self::Literal> + From<Self::Triple> + From<IriS> + From<Object> + TryInto<Object> + Matcher<Self::Term> + PartialEq
type Term: Term + From<Self::Subject> + From<Self::IRI> + From<Self::BNode> + From<Self::Literal> + From<Self::Triple> + From<IriS> + From<Object> + TryInto<Object> + Matcher<Self::Term> + PartialEq
The term type representing any RDF component.
Sourcetype Literal: Literal + From<bool> + From<String> + From<i128> + From<f64> + TryFrom<Self::Term> + From<ConcreteLiteral> + TryInto<ConcreteLiteral>
type Literal: Literal + From<bool> + From<String> + From<i128> + From<f64> + TryFrom<Self::Term> + From<ConcreteLiteral> + TryInto<ConcreteLiteral>
The literal type for representing data values.
Required Methods§
Sourcefn qualify_iri(&self, iri: &Self::IRI) -> String
fn qualify_iri(&self, iri: &Self::IRI) -> String
Returns the prefixed name corresponding to an IRI.
Converts a full IRI to its shortened form using registered namespace prefixes.
§Parameters
iri- The IRI to qualify
Sourcefn qualify_subject(&self, subj: &Self::Subject) -> String
fn qualify_subject(&self, subj: &Self::Subject) -> String
Returns the prefixed representation of a subject.
Converts a subject to its qualified string form, applying prefix mappings if the subject is an IRI.
§Parameters
subj- The subject to qualify
Sourcefn qualify_term(&self, term: &Self::Term) -> String
fn qualify_term(&self, term: &Self::Term) -> String
Returns the prefixed representation of a term.
Converts a term to its qualified string form, applying prefix mappings where applicable.
§Parameters
term- The term to qualify
Sourcefn prefixmap(&self) -> Option<PrefixMap>
fn prefixmap(&self) -> Option<PrefixMap>
Returns the prefix map used by this RDF implementation.
Returns None if no prefix map is configured.
Sourcefn resolve_prefix_local(
&self,
prefix: &str,
local: &str,
) -> Result<IriS, PrefixMapError>
fn resolve_prefix_local( &self, prefix: &str, local: &str, ) -> Result<IriS, PrefixMapError>
Provided Methods§
Sourcefn numeric_value(&self, term: &Self::Term) -> Option<Decimal>
fn numeric_value(&self, term: &Self::Term) -> Option<Decimal>
Extracts the numeric value from a term, if it represents a number.
Attempts to convert the term to a literal and extract its numeric value
as a Decimal. Returns None if the term is not a numeric literal.
§Parameters
term- The term to extract the numeric value from
Sourcefn term_as_sliteral(term: &Self::Term) -> Result<ConcreteLiteral, RDFError>
fn term_as_sliteral(term: &Self::Term) -> Result<ConcreteLiteral, RDFError>
Sourcefn subject_as_term(subj: &Self::Subject) -> Self::Term
fn subject_as_term(subj: &Self::Subject) -> Self::Term
Sourcefn triple_as_term(triple: &Self::Triple) -> Self::Term
fn triple_as_term(triple: &Self::Triple) -> Self::Term
Converts a triple to a term (RDF-star support).
In RDF-star, triples can be used as terms in other triples.
§Parameters
triple- The triple to convert
Sourcefn iris_as_term(iri: &IriS) -> Self::Term
fn iris_as_term(iri: &IriS) -> Self::Term
Sourcefn iri_or_bnode_as_term(ib: &IriOrBlankNode) -> Self::Term
fn iri_or_bnode_as_term(ib: &IriOrBlankNode) -> Self::Term
Sourcefn object_as_term(object: &Object) -> Self::Term
fn object_as_term(object: &Object) -> Self::Term
Sourcefn compare(
&self,
term1: &Self::Term,
term2: &Self::Term,
) -> Result<Ordering, RDFError>
fn compare( &self, term1: &Self::Term, term2: &Self::Term, ) -> Result<Ordering, RDFError>
Compares two terms according to SPARQL ordering semantics.
The comparison follows the SPARQL 1.1 specification for operator mapping: https://www.w3.org/TR/sparql11-query/#OperatorMapping
§Parameters
term1- The first term to compareterm2- The second term to compare
§Errors
Returns RDFError::ComparisonError if the terms cannot be compared
Sourcefn equals(&self, term1: &Self::Term, term2: &Self::Term) -> bool
fn equals(&self, term1: &Self::Term, term2: &Self::Term) -> bool
Checks if two terms are equal according to SPARQL semantics.
The equality follows the SPARQL 1.1 specification for operator mapping: https://www.w3.org/TR/sparql11-query/#OperatorMapping
§Parameters
term1- The first termterm2- The second term
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 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).