# rdflib.plugins.shared.jsonld package

## Submodules

## rdflib.plugins.shared.jsonld.context module

Implementation of the JSON-LD Context structure. See:

> http://json-ld.org/

class rdflib.plugins.shared.jsonld.context.Context(source=None, base=None, version=1.1)

  Bases: `object`

  Parameters:

    - source (`Union`[`List`[`Union`[`Dict`[`str`, `Any`], `str`, `None`]], `Dict`[`str`, `Any`], `str`, `None`])

    - base (`Optional`[`str`])

    - version (`Optional`[`float`])

  __dict__ = mappingproxy({'__module__': 'rdflib.plugins.shared.jsonld.context', '__init__': <function Context.__init__>, 'base': <property object>, 'subcontext': <function Context.subcontext>, '_subcontext': <function Context._subcontext>, '_clear': <function Context._clear>, 'get_context_for_term': <function Context.get_context_for_term>, 'get_context_for_type': <function Context.get_context_for_type>, 'get_id': <function Context.get_id>, 'get_type': <function Context.get_type>, 'get_language': <function Context.get_language>, 'get_value': <function Context.get_value>, 'get_graph': <function Context.get_graph>, 'get_list': <function Context.get_list>, 'get_set': <function Context.get_set>, 'get_rev': <function Context.get_rev>, '_get': <function Context._get>, 'get_key': <function Context.get_key>, 'get_keys': <function Context.get_keys>, 'lang_key': <property object>, 'id_key': <property object>, 'type_key': <property object>, 'value_key': <property object>, 'list_key': <property object>, 'rev_key': <property object>, 'graph_key': <property object>, 'add_term': <function Context.add_term>, 'find_term': <function Context.find_term>, 'resolve': <function Context.resolve>, 'resolve_iri': <function Context.resolve_iri>, 'isblank': <function Context.isblank>, 'expand': <function Context.expand>, 'shrink_iri': <function Context.shrink_iri>, 'to_symbol': <function Context.to_symbol>, 'load': <function Context.load>, '_accept_term': <function Context._accept_term>, '_prep_sources': <function Context._prep_sources>, '_fetch_context': <function Context._fetch_context>, '_read_source': <function Context._read_source>, '_read_term': <function Context._read_term>, '_rec_expand': <function Context._rec_expand>, '_prep_expand': <function Context._prep_expand>, '_get_source_id': <function Context._get_source_id>, '_term_dict': <function Context._term_dict>, 'to_dict': <function Context.to_dict>, '__dict__': <attribute '__dict__' of 'Context' objects>, '__weakref__': <attribute '__weakref__' of 'Context' objects>, '__doc__': None, '__annotations__': {'version': 'float', 'vocab': 'Optional[str]', '_base': 'Optional[str]', 'terms': 'Dict[str, Any]', '_alias': 'Dict[str, List[str]]', '_lookup': 'Dict[Tuple[str, Any, Union[Defined, str], bool], Term]', '_prefixes': 'Dict[str, Any]', 'parent': 'Optional[Context]', '_context_cache': 'Dict[str, Any]'}})
  __init__(source=None, base=None, version=1.1)
    Parameters:

      - source (`Union`[`List`[`Union`[`Dict`[`str`, `Any`], `str`, `None`]], `Dict`[`str`, `Any`], `str`, `None`])

      - base (`Optional`[`str`])

      - version (`Optional`[`float`])

  __module__ = 'rdflib.plugins.shared.jsonld.context'
  __weakref__

    list of weak references to the object

  add_term(name, idref, coercion=UNDEF, container=UNDEF, index=None, language=UNDEF, reverse=False, context=UNDEF, prefix=None, protected=False)
    Parameters:

      - name (`str`)

      - idref (`str`)

      - coercion (`Union`[`Defined`, `str`])

      - container (`Union`[`Collection`[`Any`], `str`, `Defined`])

      - index (`Union`[`str`, `Defined`, `None`])

      - language (`Union`[`str`, `Defined`, `None`])

      - reverse (`bool`)

      - context (`Any`)

      - prefix (`Optional`[`bool`])

      - protected (`bool`)

  property base: str | None
  expand(term_curie_or_iri, use_vocab=True)
    Parameters:

      - term_curie_or_iri (`Any`)

      - use_vocab (`bool`)

    Return type:

      `Optional`[`str`]

  find_term(idref, coercion=None, container=UNDEF, language=None, reverse=False)
    Parameters:

      - idref (`str`)

      - coercion (`Union`[`str`, `Defined`, `None`])

      - container (`Union`[`Defined`, `str`])

      - language (`Optional`[`str`])

      - reverse (`bool`)

  get_context_for_term(term)
    Parameters:

      term (`Optional`[`Term`])

    Return type:

      `Context`

  get_context_for_type(node)
    Parameters:

      node (`Any`)

    Return type:

      `Optional`[`Context`]

  get_graph(obj)
    Parameters:

      obj (`Dict`[`str`, `Any`])

    Return type:

      `Any`

  get_id(obj)
    Parameters:

      obj (`Dict`[`str`, `Any`])

    Return type:

      `Any`

  get_key(key)
    Parameters:

      key (`str`)

    Return type:

      `str`

  get_keys(key)
    Parameters:

      key (`str`)

    Return type:

      `Generator`[`str`, `None`, `None`]

  get_language(obj)
    Parameters:

      obj (`Dict`[`str`, `Any`])

    Return type:

      `Any`

  get_list(obj)
    Parameters:

      obj (`Dict`[`str`, `Any`])

    Return type:

      `Any`

  get_rev(obj)
    Parameters:

      obj (`Dict`[`str`, `Any`])

    Return type:

      `Any`

  get_set(obj)
    Parameters:

      obj (`Dict`[`str`, `Any`])

    Return type:

      `Any`

  get_type(obj)
    Parameters:

      obj (`Dict`[`str`, `Any`])

    Return type:

      `Any`

  get_value(obj)
    Parameters:

      obj (`Dict`[`str`, `Any`])

    Return type:

      `Any`

  property graph_key
  property id_key
  isblank(ref)
    Parameters:

      ref (`str`)

    Return type:

      `bool`

  property lang_key
  property list_key
  load(source, base=None, referenced_contexts=None)
    Parameters:

      - source (`Union`[`List`[`Union`[`Dict`[`str`, `Any`], `str`, `None`]], `Dict`[`str`, `Any`], `str`, `None`])

      - base (`Optional`[`str`])

      - referenced_contexts (`Set`[`Any`])

  resolve(curie_or_iri)
    Parameters:

      curie_or_iri (`str`)

    Return type:

      `str`

  resolve_iri(iri)
    Parameters:

      iri (`str`)

    Return type:

      `str`

  property rev_key
  shrink_iri(iri)
    Parameters:

      iri (`str`)

    Return type:

      `str`

  subcontext(source, propagate=True)
    Parameters:

      - source (`Any`)

      - propagate (`bool`)

    Return type:

      `Context`

  to_dict()

    Returns a dictionary representation of the context that can be serialized to JSON.

    Return type:

      `Dict`[`str`, `Any`]

    Returns:

      a dictionary representation of the context.

  to_symbol(iri)
    Parameters:

      iri (`str`)

    Return type:

      `Optional`[`str`]

  property type_key
  property value_key

class rdflib.plugins.shared.jsonld.context.Defined

  Bases: `int`

  __dict__ = mappingproxy({'__module__': 'rdflib.plugins.shared.jsonld.context', '__dict__': <attribute '__dict__' of 'Defined' objects>, '__doc__': None, '__annotations__': {}})
  __module__ = 'rdflib.plugins.shared.jsonld.context'

class rdflib.plugins.shared.jsonld.context.Term(id, name, type, container, index, language, reverse, context, prefix, protected)

  Bases: `tuple`

  __getnewargs__()

    Return self as a plain tuple. Used by copy and pickle.

  __match_args__ = ('id', 'name', 'type', 'container', 'index', 'language', 'reverse', 'context', 'prefix', 'protected')
  __module__ = 'rdflib.plugins.shared.jsonld.context'
  static __new__(_cls, id, name, type=0, container=0, index=0, language=0, reverse=False, context=0, prefix=False, protected=False)

    Create new instance of Term(id, name, type, container, index, language, reverse, context, prefix, protected)

  __repr__()

    Return a nicely formatted representation string

  __slots__ = ()
  container

    Alias for field number 3

  context

    Alias for field number 7

  id

    Alias for field number 0

  index

    Alias for field number 4

  language

    Alias for field number 5

  name

    Alias for field number 1

  prefix

    Alias for field number 8

  protected

    Alias for field number 9

  reverse

    Alias for field number 6

  type

    Alias for field number 2

## rdflib.plugins.shared.jsonld.errors module

exception rdflib.plugins.shared.jsonld.errors.JSONLDException

  Bases: `ValueError`

  __module__ = 'rdflib.plugins.shared.jsonld.errors'
  __weakref__

    list of weak references to the object

## rdflib.plugins.shared.jsonld.keys module

## rdflib.plugins.shared.jsonld.util module

rdflib.plugins.shared.jsonld.util.context_from_urlinputsource(source)

  Please note that JSON-LD documents served with the application/ld+json media type MUST have all context information, including references to external contexts, within the body of the document. Contexts linked via a http://www.w3.org/ns/json-ld#context HTTP Link Header MUST be ignored for such documents.

  Parameters:

    source (`URLInputSource`)

  Return type:

    `Optional`[`str`]

rdflib.plugins.shared.jsonld.util.norm_url(base, url)

      >>> norm_url('http://example.org/', '/one')
      'http://example.org/one'
      >>> norm_url('http://example.org/', '/one#')
      'http://example.org/one#'
      >>> norm_url('http://example.org/one', 'two')
      'http://example.org/two'
      >>> norm_url('http://example.org/one/', 'two')
      'http://example.org/one/two'
      >>> norm_url('http://example.org/', 'http://example.net/one')
      'http://example.net/one'
      >>> norm_url('http://example.org/', 'http://example.org//one')
      'http://example.org//one'

  Parameters:

    - base (`str`)

    - url (`str`)

  Return type:

    `str`

rdflib.plugins.shared.jsonld.util.source_to_json(source, fragment_id=None, extract_all_scripts=False)

  Extract JSON from a source document.

  The source document can be JSON or HTML with embedded JSON script elements (type attribute = “application/ld+json”). To process as HTML `source.content_type` must be set to “text/html” or “application/xhtml+xml”.

  Parameters:

    - source (`Union`[`IO`[`bytes`], `TextIO`, `InputSource`, `str`, `bytes`, `PurePath`, `None`]) – the input source document (JSON or HTML)

    - fragment_id (`Optional`[`str`]) – if source is an HTML document then extract only the script element with matching id attribute, defaults to None

    - extract_all_scripts (`Optional`[`bool`]) – if source is an HTML document then extract all script elements (unless fragment_id is provided), defaults to False (extract only the first script element)

  Return type:

    `Tuple`[`Union`[`Dict`, `List`[`Dict`]], `Any`]

  Returns:

    Tuple with the extracted JSON document and value of the HTML base element

rdflib.plugins.shared.jsonld.util.split_iri(iri)
  Parameters:

    iri (`str`)

  Return type:

    `Tuple`[`str`, `Optional`[`str`]]

## Module contents