Trait json_ld::Expand

source ·
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§

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.

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§

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.

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§

Value expansion without base URL.

Implementors§

Remote document expansion.

The default base URL given to the expansion algorithm is the URL of the remote document.