[][src]Enum sophia::term::Term

pub enum Term<T> where
    T: TermData
{ Iri(IriData<T>), BNode(BNodeId<T>), Literal(T, LiteralKind<T>), Variable(T), }

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]

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]

pub fn new_iri<U>(iri: U) -> Result<Term<T>> where
    T: From<U>, 
[src]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

Return a typed literal term.

Panics

Panics if dt is not an IRI.

pub fn join<U>(&self, t: &Term<U>) -> Term<U> where
    U: TermData + From<String>, 
[src]

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]

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]

type TermData = U

impl<U> GraphNameMatcher for Term<U> where
    U: TermData
[src]

type TermData = U

impl<T: Clone> Clone for Term<T> where
    T: TermData
[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]

impl<T, U> PartialEq<Term<U>> for IriData<T> where
    T: AsRef<str>,
    U: TermData
[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl<T, U> PartialEq<Term<U>> for Term<T> where
    T: TermData,
    U: TermData
[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl<T, U> PartialEq<IriData<U>> for Term<T> where
    T: TermData,
    U: TermData
[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl<T: Copy> Copy for Term<T> where
    T: TermData
[src]

impl<T: Eq> Eq for Term<T> where
    T: TermData
[src]

impl<T: Debug> Debug for Term<T> where
    T: TermData
[src]

impl<T: Hash> Hash for Term<T> where
    T: TermData
[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

Auto Trait Implementations

impl<T> Sync for Term<T> where
    T: Sync

impl<T> Send for Term<T> where
    T: Send

impl<T> Unpin for Term<T> where
    T: Unpin

impl<T> RefUnwindSafe for Term<T> where
    T: RefUnwindSafe

impl<T> UnwindSafe for Term<T> where
    T: UnwindSafe

Blanket Implementations

impl<F> TermMatcher for F where
    F: Fn(&Term<&str>) -> bool
[src]

type TermData = &'static str

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]