Skip to main content

Rdf

Trait Rdf 

Source
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 subjects
  • IRI: Internationalized Resource Identifiers
  • Term: 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§

Source

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.

Source

type IRI: Iri + From<IriS> + TryFrom<Self::Term> + Matcher<Self::IRI> + Into<IriS>

The IRI type for this RDF implementation.

Source

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.

Source

type BNode: BlankNode + TryFrom<Self::Term>

The blank node type for this RDF implementation.

Source

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.

Source

type Triple: Triple<Self::Subject, Self::IRI, Self::Term>

The triple type representing RDF statements.

Source

type Err: Display

The error type for fallible operations.

Required Methods§

Source

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
Source

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
Source

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
Source

fn prefixmap(&self) -> Option<PrefixMap>

Returns the prefix map used by this RDF implementation.

Returns None if no prefix map is configured.

Source

fn resolve_prefix_local( &self, prefix: &str, local: &str, ) -> Result<IriS, PrefixMapError>

Resolves a prefix and local name to obtain the full IRI.

Combines a namespace prefix with a local name to produce the complete IRI

§Parameters
  • prefix - The namespace prefix
  • local - The local name
§Errors

Returns PrefixMapError if the prefix is not registered in the prefix map.

Provided Methods§

Source

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
Source

fn term_as_literal(term: &Self::Term) -> Result<Self::Literal, RDFError>

Converts a term to a literal.

§Parameters
  • term - The term to convert
§Errors

Returns RDFError::TermAsLiteral if the term is not a literal.

Source

fn term_as_sliteral(term: &Self::Term) -> Result<ConcreteLiteral, RDFError>

Attempts to convert a term into a concrete literal.

§Parameters
  • term - The term to convert
§Errors

Returns RDFError::TermAsLiteral if the term cannot be converted into a literal. Returns RDFError::LiteralAsSLiteral if the resulting literal cannot be converted into a concrete literal.

Source

fn term_as_subject(term: &Self::Term) -> Result<Self::Subject, RDFError>

Converts a term to a subject.

§Parameters
  • term - The term to convert
§Errors

Returns RDFError::TermAsSubject if the term cannot be used as a subject

Source

fn subject_as_term(subj: &Self::Subject) -> Self::Term

Converts a subject to a term.

§Parameters
  • subj - The subject to convert
Source

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
Source

fn iris_as_term(iri: &IriS) -> Self::Term

Converts an IriS to a term.

§Parameters
  • iri - The IriS to convert
Source

fn term_as_iri(term: &Self::Term) -> Result<Self::IRI, RDFError>

Converts a term to an IRI.

§Parameters
  • term - The term to convert
§Errors

Returns RDFError::TermAsIri if the term is not an IRI.

Source

fn iri_or_bnode_as_term(ib: &IriOrBlankNode) -> Self::Term

Converts an IRI or blank node to a term.

§Parameters
  • ib - The IRI or blank node to convert
Source

fn term_as_bnode(term: &Self::Term) -> Result<Self::BNode, RDFError>

Converts a term to a blank node.

§Parameters
  • term - The term to convert
§Errors

Returns RDFError::TermAsBNode if the term is not a blank node.

Source

fn term_as_iris(term: &Self::Term) -> Result<IriS, RDFError>

Converts a term to an IriS.

§Parameters
  • term - The term to convert
§Errors

Returns RDFError::TermAsIriS if the term is not an IRI.

Source

fn term_as_object(term: &Self::Term) -> Result<Object, RDFError>

Converts a term to an Object.

§Parameters
  • term - The term to convert
§Errors

Returns RDFError::TermAsObject if the conversion fails.

Source

fn object_as_term(object: &Object) -> Self::Term

Converts an Object to a term.

§Parameters
  • object - The object to convert
Source

fn subject_as_node(subject: &Self::Subject) -> Result<Object, RDFError>

Converts a subject to an Object.

§Parameters
  • subject - The subject to convert
§Errors

Returns RDFError if the subject cannot be converted to an object.

Source

fn term_as_lang(term: &Self::Term) -> Result<Lang, RDFError>

Extracts a language tag from a term.

§Parameters
  • term - The term to extract the language tag from
§Errors

Returns RDFError::TermAsLang if the term is not a language-tagged literal.

Source

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 compare
  • term2 - The second term to compare
§Errors

Returns RDFError::ComparisonError if the terms cannot be compared

Source

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 term
  • term2 - 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.

This implementation provides the fundamental RDF operations including type definitions, prefix resolution, and term qualification (converting full IRIs to prefixed names).