[−][src]Enum sophia::term::Term
Generic type for RDF terms.
See module documentation for more detail.
Variants
Iri(IriData<T>)
BNode(BNodeId<T>)
Literal(T, LiteralKind<T>)
Variable(T)
Methods
impl<T> Term<T> where
T: TermData,
[src]
T: TermData,
pub fn value(&self) -> String
[src]
Return a copy of this term's underlying text.
NB: for literals, the value only conveys the literal value, not the datatype or the language tag.error
See also n3
.
pub fn n3(&self) -> String
[src]
Return the N3 serialization of this term.
impl<T> Term<T> where
T: TermData,
[src]
T: TermData,
pub fn new_iri<U>(iri: U) -> Result<Term<T>> where
T: From<U>,
[src]
T: From<U>,
Return a new IRI term from the given text.
May fail if txt
is not a valid IRI.
pub fn new_iri2<U, V>(ns: U, suffix: V) -> Result<Term<T>> where
T: From<U> + From<V>,
[src]
T: From<U> + From<V>,
Return a new IRI term from the two given parts (prefix and suffix).
May fail if the concatenation of ns
and suffix
does not produce a valid IRI.
pub fn new_bnode<U>(id: U) -> Result<Term<T>> where
T: From<U>,
[src]
T: From<U>,
Return a new blank node term with the given bnode ID.
Currently, this may never fail; however it returns a result for homogeneity with other constructor methods, and because future versions may be more picky regarding bnode IDs.
pub fn new_literal_lang<U, V>(txt: U, lang: V) -> Result<Term<T>> where
T: From<U> + From<V>,
[src]
T: From<U> + From<V>,
Return a new literal term with the given value and language tag.
May fail if the language tag is not valid.
pub fn new_literal_dt<U>(txt: U, dt: Term<T>) -> Result<Term<T>> where
T: From<U>,
[src]
T: From<U>,
Return a new literal term with the given value and datatype.
May fail if dt
is not a valid datatype.
pub fn new_variable<U>(name: U) -> Result<Term<T>> where
T: From<U>,
[src]
T: From<U>,
Return a new variable term with the given name.
May fail if name
is not a valid variable name.
pub fn from_with<'a, U, F>(other: &'a Term<U>, factory: F) -> Term<T> where
U: TermData,
F: FnMut(&'a str) -> T,
[src]
U: TermData,
F: FnMut(&'a str) -> T,
Copy another term with the given factory.
pub fn normalized_with<U, F>(
other: &Term<U>,
factory: F,
norm: Normalization
) -> Term<T> where
U: TermData,
F: FnMut(&str) -> T,
[src]
other: &Term<U>,
factory: F,
norm: Normalization
) -> Term<T> where
U: TermData,
F: FnMut(&str) -> T,
Copy another term with the given factory, applying the given normalization policy.
pub unsafe fn new_iri_unchecked<U>(iri: U, abs: Option<bool>) -> Term<T> where
T: From<U>,
[src]
T: From<U>,
Return a new IRI term,
assuming that iri
is a valid IRI,
and that abs
correctly indicates whether it is absolute or relative.
pub unsafe fn new_iri2_unchecked<U, V>(
ns: U,
suffix: V,
abs: Option<bool>
) -> Term<T> where
T: From<U> + From<V>,
[src]
ns: U,
suffix: V,
abs: Option<bool>
) -> Term<T> where
T: From<U> + From<V>,
Return a new IRI term,
assuming that ns
and suffix
concatenate to a valid IRI,
and that abs
correctly indicates whether it is absolute or relative.
pub unsafe fn new_bnode_unchecked<U>(id: U) -> Term<T> where
T: From<U>,
[src]
T: From<U>,
Return a new blank node term,
assuming that id
is a valid bnode ID.
pub unsafe fn new_literal_lang_unchecked<U, V>(txt: U, lang: V) -> Term<T> where
T: From<U> + From<V>,
[src]
T: From<U> + From<V>,
Return a literal term,
assuming that lang
is a valid language tag.
pub unsafe fn new_literal_dt_unchecked<U>(txt: U, dt: Term<T>) -> Term<T> where
T: From<U> + Debug,
[src]
T: From<U> + Debug,
pub fn join<U>(&self, t: &Term<U>) -> Term<U> where
U: TermData + From<String>,
[src]
U: TermData + From<String>,
If t
is or contains a relative IRI, replace it with an absolute one,
using this term as the base.
Otherwise, returns t
unchanged.
This affects IRI terms, but also Literal terms with a datatype.
Example
use sophia::term::*; let i1 = BoxTerm::new_iri("http://example.org/foo/bar").unwrap(); let i2 = BoxTerm::new_iri("../baz").unwrap(); let i3 = i1.join(&i2); assert_eq!(&i3.value(), "http://example.org/baz");
Panics
Panics if this Term is not an IRI or is not absolute (see is_absolute
).
Performance
If you need to join multiple terms to the same base,
you should use batch_join
instead,
as it factorizes the pre-processing required for joining IRIs.
pub fn batch_join<F, U>(&self, task: F) where
F: FnOnce(&dyn Fn(&Term<U>) -> Term<U>),
U: TermData + From<String>,
[src]
F: FnOnce(&dyn Fn(&Term<U>) -> Term<U>),
U: TermData + From<String>,
Takes a closure with a join
parameter,
where join
is a function comparable to the join
method.
Useful for joining multiple terms with this IRI.
Example
use sophia::term::*; let i1 = BoxTerm::new_iri("http://example.org/foo/bar").unwrap(); let mut terms = vec![ BoxTerm::new_iri("../baz").unwrap(), BoxTerm::new_iri("#baz").unwrap(), BoxTerm::new_iri("http://another.example.org").unwrap(), ]; i1.batch_join(|join| { for t in &mut terms { *t = join(t); } });
Panics
Panics if this Term is not an IRI or is not absolute (see is_absolute
).
pub fn is_absolute(&self) -> bool
[src]
Return whether this term is absolue.
- An IRI is absolute iff it is an absolute IRI.
- A typed literal is absolute iff its datatype is absolute.
- Any other term is always absolute.
Trait Implementations
impl<U> TermMatcher for Term<U> where
U: TermData,
[src]
U: TermData,
type TermData = U
fn constant(&self) -> Option<&Term<Self::TermData>>
[src]
fn matches<T>(&self, t: &Term<T>) -> bool where
T: TermData,
[src]
T: TermData,
impl<U> GraphNameMatcher for Term<U> where
U: TermData,
[src]
U: TermData,
type TermData = U
fn constant(&self) -> Option<Option<&Term<Self::TermData>>>
[src]
fn matches<T>(&self, g: Option<&Term<T>>) -> bool where
T: TermData,
[src]
T: TermData,
impl<T: Clone> Clone for Term<T> where
T: TermData,
[src]
T: TermData,
fn clone(&self) -> Term<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'a, T, U> From<&'a Term<U>> for Term<T> where
T: TermData + From<&'a str>,
U: TermData,
[src]
T: TermData + From<&'a str>,
U: TermData,
impl<T, U> PartialEq<Term<U>> for IriData<T> where
T: AsRef<str>,
U: TermData,
[src]
T: AsRef<str>,
U: TermData,
fn eq(&self, other: &Term<U>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<T, U> PartialEq<Term<U>> for Term<T> where
T: TermData,
U: TermData,
[src]
T: TermData,
U: TermData,
fn eq(&self, other: &Term<U>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<T, U> PartialEq<IriData<U>> for Term<T> where
T: TermData,
U: TermData,
[src]
T: TermData,
U: TermData,
fn eq(&self, other: &IriData<U>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<T: Copy> Copy for Term<T> where
T: TermData,
[src]
T: TermData,
impl<T: Eq> Eq for Term<T> where
T: TermData,
[src]
T: TermData,
impl<T: Debug> Debug for Term<T> where
T: TermData,
[src]
T: TermData,
impl<T: Hash> Hash for Term<T> where
T: TermData,
[src]
T: TermData,
Auto Trait Implementations
impl<T> Sync for Term<T> where
T: Sync,
T: Sync,
impl<T> Send for Term<T> where
T: Send,
T: Send,
impl<T> Unpin for Term<T> where
T: Unpin,
T: Unpin,
impl<T> RefUnwindSafe for Term<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> UnwindSafe for Term<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<F> TermMatcher for F where
F: Fn(&Term<&str>) -> bool,
[src]
F: Fn(&Term<&str>) -> bool,
type TermData = &'static str
fn constant(&Self) -> Option<&Term<<F as TermMatcher>::TermData>>
[src]
fn matches<T>(&Self, &Term<T>) -> bool where
T: TermData,
[src]
T: TermData,
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,