[−][src]Struct sophia_term::literal::Literal
An RDF literal.
Each literals has a lexical value, i.e. a text, and a datatype.
Language tagged literals
Language-tagged literals have the type rdf:langString
and an additional
language-tag.
The tags conform to BCP47.
Datatypes
Datatypes in RDF have a lexical scope and a value scope. Transformation between them is done by the lexical-to-value mapping of a datatype. If the text of a typed literal is not in the value space of its datatype, literal is called ill-typed or malformed. However, RDF specification explicitly requires implementations to accept those literals. In the end such malformed literals lead to logical inconsistency in a graph.
Implementations
impl<TD> Literal<TD> where
TD: TermData,
[src]
TD: TermData,
pub fn new_lang<U, V>(txt: U, tag: V) -> Result<Self> where
V: AsRef<str>,
TD: From<U> + From<V>,
[src]
V: AsRef<str>,
TD: From<U> + From<V>,
Return a new language-tagged literal.
Error
If tag
is not a valid language-tag according to
BCP47 an error is raised.
pub fn new_dt<U, V>(txt: U, dt: Iri<V>) -> Self where
TD: From<U> + From<V>,
V: TermData,
[src]
TD: From<U> + From<V>,
V: TermData,
Return a new literal with an arbitrary datatype.
Neither is checked if dt
refers to a known datatype nor if txt
is
ill-type and not in the lexical space of dt
. This is intended as the
RDF specification
requires implementations to accept ill-typed literals.
pub fn new_lang_unchecked<U, V>(txt: U, tag: V) -> Self where
V: AsRef<str>,
TD: From<U> + From<V>,
[src]
V: AsRef<str>,
TD: From<U> + From<V>,
Return a new language-tagged literal.
Pre-condition
tag
must be a valid language-tag according to
BCP47.
In debug mode this is asserted.
pub fn as_ref(&self) -> Literal<&TD>
[src]
Borrow the inner contents of the literal.
pub fn as_ref_str(&self) -> Literal<&str>
[src]
Borrow the inner contents of the literal as &str
.
pub fn map<F, TD2>(self, f: F) -> Literal<TD2> where
F: FnMut(TD) -> TD2,
TD2: TermData,
[src]
F: FnMut(TD) -> TD2,
TD2: TermData,
Create a new literal by applying f
to the TermData
of self
.
pub fn map_into<TD2>(self) -> Literal<TD2> where
TD: Into<TD2>,
TD2: TermData,
[src]
TD: Into<TD2>,
TD2: TermData,
Maps the literal using the Into
trait.
pub fn clone_map<'a, U, F>(&'a self, factory: F) -> Literal<U> where
U: TermData,
F: FnMut(&'a str) -> U,
[src]
U: TermData,
F: FnMut(&'a str) -> U,
Clone self while transforming the inner TermData
with the given
factory.
This is done in one step in contrast to calling clone().map(factory)
.
pub fn clone_into<'src, U>(&'src self) -> Literal<U> where
U: TermData + From<&'src str>,
[src]
U: TermData + From<&'src str>,
Apply clone_map()
using the Into
trait.
pub fn normalized(&self, policy: Normalization) -> Literal<MownStr<'_>>
[src]
Return a literal equivalent to this one,
with its datatype (if any)
is internally represented with all its data in ns
, and an empty suffix
.
Performances
The returned literal will borrow data from this one as much as possible, but strings may be allocated in case a concatenation is required.
pub fn write_fmt<W>(&self, w: &mut W) -> Result where
W: Write,
[src]
W: Write,
Writes the literal to the fmt::Write
using the NTriples syntax.
pub fn write_io<W>(&self, w: &mut W) -> Result<()> where
W: Write,
[src]
W: Write,
Writes the literal to the io::Write
using the NTriples syntax.
pub fn txt(&self) -> &TD
[src]
Returns the literal's lexical value.
pub fn dt(&self) -> Iri<&str>
[src]
Return an IRI borrowing the literals datatype.
Note: A language-tagged literal has always the type rdf:langString
.
pub fn lang(&self) -> Option<&TD>
[src]
Return the language-tag of the literal if it has one.
pub fn eq_txt<U>(&self, other: Literal<U>) -> bool where
U: TermData,
[src]
U: TermData,
Check if both literals have the same lexical value.
Trait Implementations
impl<TD: Clone + TermData> Clone for Literal<TD>
[src]
impl<TD: Copy + TermData> Copy for Literal<TD>
[src]
impl<TD: Debug + TermData> Debug for Literal<TD>
[src]
impl<TD> Display for Literal<TD> where
TD: TermData,
[src]
TD: TermData,
impl<T: TermData> Eq for Literal<T>
[src]
impl<TD> From<Literal<TD>> for Term<TD> where
TD: TermData,
[src]
TD: TermData,
impl<'a, T: ?Sized> From<NativeLiteral<T, &'a str>> for Literal<&'a str> where
T: DataType,
[src]
T: DataType,
impl<T: ?Sized, TD> From<NativeLiteral<T, Box<str>>> for Literal<TD> where
T: DataType,
TD: TermData + From<Box<str>> + From<&'static str>,
[src]
T: DataType,
TD: TermData + From<Box<str>> + From<&'static str>,
fn from(other: NativeLiteral<T>) -> Literal<TD>
[src]
impl<TD> Hash for Literal<TD> where
TD: TermData,
[src]
TD: TermData,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<TD: TermData> Ord for Literal<TD>
[src]
fn cmp(&self, other: &Literal<TD>) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<TD, TE: ?Sized> PartialEq<TE> for Literal<TD> where
TD: TermData,
TE: TTerm,
[src]
TD: TermData,
TE: TTerm,
impl<TD, TE: ?Sized> PartialOrd<TE> for Literal<TD> where
TD: TermData,
TE: TTerm,
[src]
TD: TermData,
TE: TTerm,
fn partial_cmp(&self, other: &TE) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'b, TD> Resolve<&'a Literal<TD>, Literal<MownStr<'a>>> for IriParsed<'b> where
TD: TermData,
[src]
TD: TermData,
fn resolve(&self, other: &'a Literal<TD>) -> Literal<MownStr<'a>>
[src]
Resolve the data type's IRI if it is relative.
Note that this only affects datatyped literals; language-tagged literals are absolute by construction.
Performance
May allocate an intermediate IRI if other.dt()
is suffixed.
impl<TD: TermData> TTerm for Literal<TD>
[src]
fn kind(&self) -> TermKind
[src]
fn value_raw(&self) -> RawValue<'_>
[src]
fn datatype(&self) -> Option<SimpleIri<'_>>
[src]
fn language(&self) -> Option<&str>
[src]
fn as_dyn(&self) -> &dyn TTerm
[src]
fn value(&self) -> MownStr<'_>
[src]
fn is_absolute(&self) -> bool
[src]
impl<TD> TryCopyTerm for Literal<TD> where
TD: TermData + for<'x> From<&'x str>,
[src]
TD: TermData + for<'x> From<&'x str>,
type Error = TermError
The error type produced when failing to copy a given term
fn try_copy<T: ?Sized>(term: &T) -> Result<Self, Self::Error> where
T: TTerm,
[src]
T: TTerm,
impl<'a, T, U> TryFrom<&'a Term<U>> for Literal<T> where
T: TermData + From<&'a str>,
U: TermData,
[src]
T: TermData + From<&'a str>,
U: TermData,
type Error = TermError
The type returned in the event of a conversion error.
fn try_from(term: &'a Term<U>) -> Result<Self, Self::Error>
[src]
impl<TD> TryFrom<Term<TD>> for Literal<TD> where
TD: TermData,
[src]
TD: TermData,
Auto Trait Implementations
impl<TD> RefUnwindSafe for Literal<TD> where
TD: RefUnwindSafe,
TD: RefUnwindSafe,
impl<TD> Send for Literal<TD> where
TD: Send,
TD: Send,
impl<TD> Sync for Literal<TD> where
TD: Sync,
TD: Sync,
impl<TD> Unpin for Literal<TD> where
TD: Unpin,
TD: Unpin,
impl<TD> UnwindSafe for Literal<TD> where
TD: UnwindSafe,
TD: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> ConvertibleTerm for T where
T: TTerm + ?Sized,
[src]
T: TTerm + ?Sized,
fn try_converted<U>(&Self) -> Result<U, TermError> where
U: TryConvertTerm,
<U as FromStr>::Err: Error,
<U as FromStr>::Err: 'static,
[src]
U: TryConvertTerm,
<U as FromStr>::Err: Error,
<U as FromStr>::Err: 'static,
impl<T> CopiableTerm for T where
T: TTerm + ?Sized,
[src]
T: TTerm + ?Sized,
fn copied<U>(&self) -> U where
U: CopyTerm,
[src]
U: CopyTerm,
fn try_copied<U>(&self) -> Result<U, <U as TryCopyTerm>::Error> where
U: TryCopyTerm,
[src]
U: TryCopyTerm,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<U> TermMatcher for U where
U: TTerm + ?Sized,
[src]
U: TTerm + ?Sized,
type Term = U
Type of TTerm
used internally by this matcher.
fn constant(&self) -> Option<&U>
[src]
fn matches<T>(&self, t: &T) -> bool where
T: TTerm + ?Sized,
[src]
T: TTerm + ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,