Skip to main content

rudof_rdf/rdf_core/term/
term.rs

1use std::{
2    fmt::{Debug, Display},
3    hash::Hash,
4};
5
6/// Represents any RDF term that can appear in an RDF graph.
7///
8/// In RDF, terms are the fundamental building blocks of triples. A term can be
9/// an IRI (Internationalized Resource Identifier), a blank node, a literal value,
10/// or (in RDF-star) a quoted triple.
11pub trait Term: Debug + Clone + Display + PartialEq + Eq + Hash {
12    /// Returns the kind of RDF term this represents.
13    ///
14    /// This method allows distinguishing between different types of RDF terms
15    /// at runtime.
16    fn kind(&self) -> TermKind;
17
18    /// Returns `true` if this term is an IRI.
19    fn is_iri(&self) -> bool {
20        self.kind() == TermKind::Iri
21    }
22
23    /// Returns `true` if this term is a blank node.
24    fn is_blank_node(&self) -> bool {
25        self.kind() == TermKind::BlankNode
26    }
27
28    /// Returns `true` if this term is a literal.
29    fn is_literal(&self) -> bool {
30        self.kind() == TermKind::Literal
31    }
32
33    /// Returns `true` if this term is a quoted triple (RDF-star).
34    fn is_triple(&self) -> bool {
35        self.kind() == TermKind::Triple
36    }
37
38    /// Returns the lexical representation of this term as a string.
39    fn lexical_form(&self) -> String;
40}
41
42/// Represents the kind of RDF term.
43#[derive(PartialEq)]
44pub enum TermKind {
45    Iri,
46    BlankNode,
47    Literal,
48    Triple,
49}