pub trait Expand<T, B, M> {
fn default_base_url(&self) -> Option<&T>;
fn expand_full<'a, N, C, L>(
&'a self,
vocabulary: &'a mut N,
context: Context<T, B, C, M>,
base_url: Option<&'a T>,
loader: &'a mut L,
options: Options,
warnings_handler: impl Send + WarningHandler<B, N, M> + 'a
) -> Pin<Box<dyn Future<Output = Result<Meta<ExpandedDocument<T, B, M>, M>, Meta<Error<M, <L as ContextLoader<T, M>>::ContextError>, M>>> + Send + 'a, Global>>
where
L: Loader<T, M> + ContextLoader<T, M> + Send + Sync,
N: Send + Sync + VocabularyMut<Iri = T, BlankId = B>,
T: Clone + Eq + Hash + Send + Sync,
B: 'a + Clone + Eq + Hash + Send + Sync,
M: Clone + Send + Sync,
C: 'a + ProcessMeta<T, B, M> + From<Value<M>>,
<L as Loader<T, M>>::Output: Into<Value<M>>,
<L as ContextLoader<T, M>>::Context: Into<C>,
<L as ContextLoader<T, M>>::ContextError: Send;
fn expand_with<'a, L>(
&'a self,
vocabulary: &'a mut impl Send + Sync + VocabularyMut<Iri = T, BlankId = B>,
loader: &'a mut L
) -> Pin<Box<dyn Future<Output = Result<Meta<ExpandedDocument<T, B, M>, M>, Meta<Error<M, <L as ContextLoader<T, M>>::ContextError>, M>>> + Send + 'a, Global>>
where
L: Loader<T, M> + ContextLoader<T, M> + Send + Sync,
T: 'a + Clone + Eq + Hash + Send + Sync,
B: 'a + Clone + Eq + Hash + Send + Sync,
M: 'a + Clone + Send + Sync,
<L as Loader<T, M>>::Output: Into<Value<M>>,
<L as ContextLoader<T, M>>::Context: ProcessMeta<T, B, M> + From<Value<M>>,
<L as ContextLoader<T, M>>::ContextError: Send,
{ ... }
fn expand<'a, L>(
&'a self,
loader: &'a mut L
) -> Pin<Box<dyn Future<Output = Result<Meta<ExpandedDocument<T, B, M>, M>, Meta<Error<M, <L as ContextLoader<T, M>>::ContextError>, M>>> + Send + 'a, Global>>
where
L: Loader<T, M> + ContextLoader<T, M> + Send + Sync,
T: 'a + Clone + Eq + Hash + Send + Sync,
B: 'a + Clone + Eq + Hash + Send + Sync,
M: 'a + Clone + Send + Sync,
<L as Loader<T, M>>::Output: Into<Value<M>>,
<L as ContextLoader<T, M>>::Context: ProcessMeta<T, B, M> + From<Value<M>>,
<L as ContextLoader<T, M>>::ContextError: Send,
(): VocabularyMut<Iri = T, BlankId = B>,
{ ... }
}
Expand description
Document expansion.
This trait provides the functions necessary to expand
a JSON-LD document into an ExpandedDocument
.
It is implemented by json_syntax::MetaValue
representing
a JSON object (ith its metadata) and RemoteDocument
.
Example
use iref::IriBuf;
use rdf_types::BlankIdBuf;
use static_iref::iri;
use locspan::{Meta, Span};
use json_ld::{syntax::Parse, RemoteDocument, Expand};
// Parse the input JSON(-LD) document.
// Each fragment of the parsed value will be annotated (the metadata) with its
// [`Span`] in the input text.
let json = json_ld::syntax::Value::parse_str(
r##"
{
"@graph": [
{
"http://example.org/vocab#a": {
"@graph": [
{
"http://example.org/vocab#b": "Chapter One"
}
]
}
}
]
}
"##,
|span| span, // the metadata only consists of the `span`.
)
.unwrap();
// Prepare a dummy document loader using [`json_ld::NoLoader`],
// since we won't need to load any remote document while expanding this one.
let mut loader: json_ld::NoLoader<IriBuf, Span, json_ld::syntax::Value<Span>> =
json_ld::NoLoader::new();
// The `expand` method returns an [`json_ld::ExpandedDocument`] (with the metadata).
let _: Meta<json_ld::ExpandedDocument<IriBuf, BlankIdBuf, _>, _> =
json
.expand(&mut loader)
.await
.unwrap();
Required Methods§
sourcefn default_base_url(&self) -> Option<&T>
fn default_base_url(&self) -> Option<&T>
Returns the default base URL passed to the expansion algorithm
and used to initialize the default empty context when calling
Expand::expand
or Expand::expand_with
.
sourcefn expand_full<'a, N, C, L>(
&'a self,
vocabulary: &'a mut N,
context: Context<T, B, C, M>,
base_url: Option<&'a T>,
loader: &'a mut L,
options: Options,
warnings_handler: impl Send + WarningHandler<B, N, M> + 'a
) -> Pin<Box<dyn Future<Output = Result<Meta<ExpandedDocument<T, B, M>, M>, Meta<Error<M, <L as ContextLoader<T, M>>::ContextError>, M>>> + Send + 'a, Global>>where
L: Loader<T, M> + ContextLoader<T, M> + Send + Sync,
N: Send + Sync + VocabularyMut<Iri = T, BlankId = B>,
T: Clone + Eq + Hash + Send + Sync,
B: 'a + Clone + Eq + Hash + Send + Sync,
M: Clone + Send + Sync,
C: 'a + ProcessMeta<T, B, M> + From<Value<M>>,
<L as Loader<T, M>>::Output: Into<Value<M>>,
<L as ContextLoader<T, M>>::Context: Into<C>,
<L as ContextLoader<T, M>>::ContextError: Send,
fn expand_full<'a, N, C, L>(
&'a self,
vocabulary: &'a mut N,
context: Context<T, B, C, M>,
base_url: Option<&'a T>,
loader: &'a mut L,
options: Options,
warnings_handler: impl Send + WarningHandler<B, N, M> + 'a
) -> Pin<Box<dyn Future<Output = Result<Meta<ExpandedDocument<T, B, M>, M>, Meta<Error<M, <L as ContextLoader<T, M>>::ContextError>, M>>> + Send + 'a, Global>>where
L: Loader<T, M> + ContextLoader<T, M> + Send + Sync,
N: Send + Sync + VocabularyMut<Iri = T, BlankId = B>,
T: Clone + Eq + Hash + Send + Sync,
B: 'a + Clone + Eq + Hash + Send + Sync,
M: Clone + Send + Sync,
C: 'a + ProcessMeta<T, B, M> + From<Value<M>>,
<L as Loader<T, M>>::Output: Into<Value<M>>,
<L as ContextLoader<T, M>>::Context: Into<C>,
<L as ContextLoader<T, M>>::ContextError: Send,
Expand the document with full options.
The vocabulary
is used to interpret identifiers.
The context
is used as initial context.
The base_url
is the initial base URL used to resolve relative IRI references.
The given loader
is used to load remote documents (such as contexts)
imported by the input and required during expansion.
The options
are used to tweak the expansion algorithm.
The warning_handler
is called each time a warning is emitted during expansion.
Provided Methods§
sourcefn expand_with<'a, L>(
&'a self,
vocabulary: &'a mut impl Send + Sync + VocabularyMut<Iri = T, BlankId = B>,
loader: &'a mut L
) -> Pin<Box<dyn Future<Output = Result<Meta<ExpandedDocument<T, B, M>, M>, Meta<Error<M, <L as ContextLoader<T, M>>::ContextError>, M>>> + Send + 'a, Global>>where
L: Loader<T, M> + ContextLoader<T, M> + Send + Sync,
T: 'a + Clone + Eq + Hash + Send + Sync,
B: 'a + Clone + Eq + Hash + Send + Sync,
M: 'a + Clone + Send + Sync,
<L as Loader<T, M>>::Output: Into<Value<M>>,
<L as ContextLoader<T, M>>::Context: ProcessMeta<T, B, M> + From<Value<M>>,
<L as ContextLoader<T, M>>::ContextError: Send,
fn expand_with<'a, L>(
&'a self,
vocabulary: &'a mut impl Send + Sync + VocabularyMut<Iri = T, BlankId = B>,
loader: &'a mut L
) -> Pin<Box<dyn Future<Output = Result<Meta<ExpandedDocument<T, B, M>, M>, Meta<Error<M, <L as ContextLoader<T, M>>::ContextError>, M>>> + Send + 'a, Global>>where
L: Loader<T, M> + ContextLoader<T, M> + Send + Sync,
T: 'a + Clone + Eq + Hash + Send + Sync,
B: 'a + Clone + Eq + Hash + Send + Sync,
M: 'a + Clone + Send + Sync,
<L as Loader<T, M>>::Output: Into<Value<M>>,
<L as ContextLoader<T, M>>::Context: ProcessMeta<T, B, M> + From<Value<M>>,
<L as ContextLoader<T, M>>::ContextError: Send,
Expand the input JSON-LD document with the given vocabulary
to interpret identifiers.
The given loader
is used to load remote documents (such as contexts)
imported by the input and required during expansion.
The expansion algorithm is called with an empty initial context with
a base URL given by Expand::default_base_url
.
sourcefn expand<'a, L>(
&'a self,
loader: &'a mut L
) -> Pin<Box<dyn Future<Output = Result<Meta<ExpandedDocument<T, B, M>, M>, Meta<Error<M, <L as ContextLoader<T, M>>::ContextError>, M>>> + Send + 'a, Global>>where
L: Loader<T, M> + ContextLoader<T, M> + Send + Sync,
T: 'a + Clone + Eq + Hash + Send + Sync,
B: 'a + Clone + Eq + Hash + Send + Sync,
M: 'a + Clone + Send + Sync,
<L as Loader<T, M>>::Output: Into<Value<M>>,
<L as ContextLoader<T, M>>::Context: ProcessMeta<T, B, M> + From<Value<M>>,
<L as ContextLoader<T, M>>::ContextError: Send,
(): VocabularyMut<Iri = T, BlankId = B>,
fn expand<'a, L>(
&'a self,
loader: &'a mut L
) -> Pin<Box<dyn Future<Output = Result<Meta<ExpandedDocument<T, B, M>, M>, Meta<Error<M, <L as ContextLoader<T, M>>::ContextError>, M>>> + Send + 'a, Global>>where
L: Loader<T, M> + ContextLoader<T, M> + Send + Sync,
T: 'a + Clone + Eq + Hash + Send + Sync,
B: 'a + Clone + Eq + Hash + Send + Sync,
M: 'a + Clone + Send + Sync,
<L as Loader<T, M>>::Output: Into<Value<M>>,
<L as ContextLoader<T, M>>::Context: ProcessMeta<T, B, M> + From<Value<M>>,
<L as ContextLoader<T, M>>::ContextError: Send,
(): VocabularyMut<Iri = T, BlankId = B>,
Expand the input JSON-LD document.
The given loader
is used to load remote documents (such as contexts)
imported by the input and required during expansion.
The expansion algorithm is called with an empty initial context with
a base URL given by Expand::default_base_url
.
Implementations on Foreign Types§
source§impl<T, B, M> Expand<T, B, M> for Meta<Value<M>, M>
impl<T, B, M> Expand<T, B, M> for Meta<Value<M>, M>
Value expansion without base URL.
fn default_base_url(&self) -> Option<&T>
fn expand_full<'a, N, C, L>(
&'a self,
vocabulary: &'a mut N,
context: Context<T, B, C, M>,
base_url: Option<&'a T>,
loader: &'a mut L,
options: Options,
warnings_handler: impl Send + WarningHandler<B, N, M> + 'a
) -> Pin<Box<dyn Future<Output = Result<Meta<ExpandedDocument<T, B, M>, M>, Meta<Error<M, <L as ContextLoader<T, M>>::ContextError>, M>>> + Send + 'a, Global>>where
L: Loader<T, M> + ContextLoader<T, M> + Send + Sync,
N: Send + Sync + VocabularyMut<Iri = T, BlankId = B>,
T: Clone + Eq + Hash + Send + Sync,
B: 'a + Clone + Eq + Hash + Send + Sync,
M: 'a + Clone + Send + Sync,
C: 'a + ProcessMeta<T, B, M> + From<Value<M>>,
<L as Loader<T, M>>::Output: Into<Value<M>>,
<L as ContextLoader<T, M>>::Context: Into<C>,
<L as ContextLoader<T, M>>::ContextError: Send,
Implementors§
impl<T, B, M> Expand<T, B, M> for RemoteDocument<T, M, Value<M>>
Remote document expansion.
The default base URL given to the expansion algorithm is the URL of the remote document.