pub trait Expand<Iri> {
// Required methods
fn default_base_url(&self) -> Option<&Iri>;
async fn expand_full<'a, N, L, W>(
&'a self,
vocabulary: &'a mut N,
context: Context<Iri, <N as BlankIdVocabulary>::BlankId>,
base_url: Option<&'a <N as IriVocabulary>::Iri>,
loader: &'a mut L,
options: Options,
warnings_handler: W
) -> Result<ExpandedDocument<<N as IriVocabulary>::Iri, <N as BlankIdVocabulary>::BlankId>, Error<<L as Loader<<N as IriVocabulary>::Iri>>::Error>>
where N: VocabularyMut<Iri = Iri>,
Iri: Clone + Eq + Hash,
<N as BlankIdVocabulary>::BlankId: 'a + Clone + Eq + Hash,
L: Loader<Iri>,
W: 'a + WarningHandler<N>;
// Provided methods
async fn expand_with<'a, N, L>(
&'a self,
vocabulary: &'a mut N,
loader: &'a mut L
) -> Result<ExpandedDocument<Iri, <N as BlankIdVocabulary>::BlankId>, Error<<L as Loader<Iri>>::Error>>
where N: VocabularyMut<Iri = Iri>,
Iri: 'a + Clone + Eq + Hash,
<N as BlankIdVocabulary>::BlankId: 'a + Clone + Eq + Hash,
L: Loader<Iri> { ... }
async fn expand<'a, L>(
&'a self,
loader: &'a mut L
) -> Result<ExpandedDocument<Iri>, Error<<L as Loader<Iri>>::Error>>
where (): VocabularyMut<Iri = Iri>,
Iri: 'a + Clone + Eq + Hash,
L: Loader<Iri> { ... }
}
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::Value
representing
a JSON object and RemoteDocument
.
§Example
use iref::IriBuf;
use rdf_types::BlankIdBuf;
use static_iref::iri;
use json_ld::{syntax::Parse, RemoteDocument, Expand};
// Parse the input JSON(-LD) document.
let (json, _) = json_ld::syntax::Value::parse_str(
r##"
{
"@graph": [
{
"http://example.org/vocab#a": {
"@graph": [
{
"http://example.org/vocab#b": "Chapter One"
}
]
}
}
]
}
"##)
.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;
// The `expand` method returns an [`json_ld::ExpandedDocument`].
json
.expand(&mut loader)
.await
.unwrap();
Required Methods§
sourcefn default_base_url(&self) -> Option<&Iri>
fn default_base_url(&self) -> Option<&Iri>
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
.
sourceasync fn expand_full<'a, N, L, W>(
&'a self,
vocabulary: &'a mut N,
context: Context<Iri, <N as BlankIdVocabulary>::BlankId>,
base_url: Option<&'a <N as IriVocabulary>::Iri>,
loader: &'a mut L,
options: Options,
warnings_handler: W
) -> Result<ExpandedDocument<<N as IriVocabulary>::Iri, <N as BlankIdVocabulary>::BlankId>, Error<<L as Loader<<N as IriVocabulary>::Iri>>::Error>>where
N: VocabularyMut<Iri = Iri>,
Iri: Clone + Eq + Hash,
<N as BlankIdVocabulary>::BlankId: 'a + Clone + Eq + Hash,
L: Loader<Iri>,
W: 'a + WarningHandler<N>,
async fn expand_full<'a, N, L, W>(
&'a self,
vocabulary: &'a mut N,
context: Context<Iri, <N as BlankIdVocabulary>::BlankId>,
base_url: Option<&'a <N as IriVocabulary>::Iri>,
loader: &'a mut L,
options: Options,
warnings_handler: W
) -> Result<ExpandedDocument<<N as IriVocabulary>::Iri, <N as BlankIdVocabulary>::BlankId>, Error<<L as Loader<<N as IriVocabulary>::Iri>>::Error>>where
N: VocabularyMut<Iri = Iri>,
Iri: Clone + Eq + Hash,
<N as BlankIdVocabulary>::BlankId: 'a + Clone + Eq + Hash,
L: Loader<Iri>,
W: 'a + WarningHandler<N>,
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§
sourceasync fn expand_with<'a, N, L>(
&'a self,
vocabulary: &'a mut N,
loader: &'a mut L
) -> Result<ExpandedDocument<Iri, <N as BlankIdVocabulary>::BlankId>, Error<<L as Loader<Iri>>::Error>>where
N: VocabularyMut<Iri = Iri>,
Iri: 'a + Clone + Eq + Hash,
<N as BlankIdVocabulary>::BlankId: 'a + Clone + Eq + Hash,
L: Loader<Iri>,
async fn expand_with<'a, N, L>(
&'a self,
vocabulary: &'a mut N,
loader: &'a mut L
) -> Result<ExpandedDocument<Iri, <N as BlankIdVocabulary>::BlankId>, Error<<L as Loader<Iri>>::Error>>where
N: VocabularyMut<Iri = Iri>,
Iri: 'a + Clone + Eq + Hash,
<N as BlankIdVocabulary>::BlankId: 'a + Clone + Eq + Hash,
L: Loader<Iri>,
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
.
sourceasync fn expand<'a, L>(
&'a self,
loader: &'a mut L
) -> Result<ExpandedDocument<Iri>, Error<<L as Loader<Iri>>::Error>>
async fn expand<'a, L>( &'a self, loader: &'a mut L ) -> Result<ExpandedDocument<Iri>, Error<<L as Loader<Iri>>::Error>>
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
.
Object Safety§
Implementations on Foreign Types§
source§impl<Iri> Expand<Iri> for Value
impl<Iri> Expand<Iri> for Value
Value expansion without base URL.
fn default_base_url(&self) -> Option<&Iri>
async fn expand_full<'a, N, L, W>(
&'a self,
vocabulary: &'a mut N,
context: Context<Iri, <N as BlankIdVocabulary>::BlankId>,
base_url: Option<&'a Iri>,
loader: &'a mut L,
options: Options,
warnings_handler: W
) -> Result<ExpandedDocument<Iri, <N as BlankIdVocabulary>::BlankId>, Error<<L as Loader<Iri>>::Error>>where
N: VocabularyMut<Iri = Iri>,
Iri: 'a + Clone + Eq + Hash,
<N as BlankIdVocabulary>::BlankId: 'a + Clone + Eq + Hash,
L: Loader<Iri>,
W: 'a + WarningHandler<N>,
Implementors§
impl<Iri> Expand<Iri> for RemoteDocument<Iri>
Remote document expansion.
The default base URL given to the expansion algorithm is the URL of the remote document.