hermes.model.types.ld_dict
==========================

.. py:module:: hermes.model.types.ld_dict


Classes
-------

.. autoapisummary::

   hermes.model.types.ld_dict.ld_dict


Module Contents
---------------

.. py:class:: ld_dict(data: list[dict[str, hermes.model.types.ld_container.EXPANDED_JSON_LD_VALUE]], *, parent: Optional[Union[ld_dict, hermes.model.types.ld_list.ld_list]] = None, key: Optional[str] = None, index: Optional[int] = None, context: Optional[list[Union[str, hermes.model.types.ld_container.JSON_LD_CONTEXT_DICT]]] = None)

   Bases: :py:obj:`hermes.model.types.ld_container.ld_container`


   An JSON-LD container resembling a dict.
   See also :class:`ld_container`

   .. attribute:: data_dict

      The dict of items (in expanded JSON-LD form)
      that are contained in this ld_dict.

      :type: dict[str, EXPANDED_JSON_LD_VALUE]

   .. attribute:: _NO_DEFAULT

      (class attribute) A type used as a placeholder to represent "no default".

      :type: type[str]


   .. py:method:: __getitem__(key: str) -> hermes.model.types.ld_list.ld_list

      Get the item with the given key in as a ld_list.

      If self contains no key, value pair with the given key, then an empty list is added as its value and returned.

      :param key: The key (compacted or expanded) to the item.
      :type key: str

      :returns: The ld_list item at the key.
      :rtype: ld_list



   .. py:method:: __setitem__(key: str, value: Union[hermes.model.types.ld_container.JSON_LD_VALUE, hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, ld_dict, hermes.model.types.ld_list.ld_list]) -> None

      Set the item at the given key to the given value or delete it if value is None.
      The given value is expanded.

      :param key: The key at which the item is set.
      :type key: str
      :param value: The new value.
      :type value: JSON_LD_VALUE | BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :rtype: None



   .. py:method:: __delitem__(key: str) -> None

      Delete the key, value pair with the given value pair.

      Note that if a deleted object is represented by an ld_container druing this process it will still exist
      and not be modified afterwards.

      :param key: The key (expanded or compacted) of the key, value pair that is deleted.
      :type key: str

      :rtype: None



   .. py:method:: __contains__(key: str) -> bool

      Returns whether or not self contains a key, value pair with the given key.

      :param key: The key for which it is checked if a key, value pair is contained in self.
      :type key: str

      :returns: Whether or not self contains a key, value pair with the given key.
      :rtype: bool



   .. py:method:: __eq__(other: Union[ld_dict, dict[str, Union[hermes.model.types.ld_container.JSON_LD_VALUE, hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, ld_dict, hermes.model.types.ld_list.ld_list]]]) -> bool

      Returns wheter or not self is considered to be equal to other.

      If other is not an ld_dict, it is converted first.

      If an id check is possible return its result otherwise:

      For each key, value pair its value is compared to the value with the same key in other.

      Note that due to those circumstances equality is not transitve
      meaning if a == b and b == c it is not guaranteed that a == c.

      :param other: The dict/ ld_dict self is compared to.
      :type other: ld_dict | dict[str, JSON_LD_VALUE | BASIC_TYPE | TIME_TYPE | ld_dict | ld_list]

      :returns:

                Whether or not self and other are considered equal.
                    If other is of the wrong type return the NotImplemented singleton instead.
      :rtype: bool



   .. py:method:: __ne__(other: Union[ld_dict, dict[str, Union[hermes.model.types.ld_container.JSON_LD_VALUE, hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, ld_dict, hermes.model.types.ld_list.ld_list]]]) -> bool

      Returns whether or not self and other not considered to be equal.

      (Returns not self.__eq__(other) if the return type is bool.
      See :meth:`ld_dict.__eq__` for more details on the comparison.)

      :param other: The dict/ ld_dict self is compared to.
      :type other: ld_dict | dict[str, JSON_LD_VALUE | BASIC_TYPE | TIME_TYPE | ld_dict | ld_list]

      :returns:     Whether or not self and other are not considered equal. If other is of the wrong type return the
                    NotImplemented singleton instead.
      :rtype: bool



   .. py:method:: __bool__() -> bool

      Returns the truth value self would have if it was a normal dict.

      I.e. returns true if no key, value pair is in self.

      :returns: The truth value of self.
      :rtype: bool



   .. py:method:: setdefault(key: str, default: Union[hermes.model.types.ld_container.JSON_LD_VALUE, hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, ld_dict, hermes.model.types.ld_list.ld_list]) -> hermes.model.types.ld_list.ld_list

      Get the value for the given key if self has a value for the key. Otherwise set the value for key to default and
      then return the value at key in self.

      :param key: The key at which the value is returned.
      :type key: str
      :param default: The value that is set at key in self
                      if there is no value for key in self.
      :type default: JSON_LD_VALUE | BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :returns: The value at key in self (if no value at key in self, it is set to default first).
      :rtype: ld_list



   .. py:method:: emplace(key: str) -> None

      Emplace the value at key in self (it is set to an empty list) if there is no value yet.

      :param key: The key at which the value in self is emplaced.
      :type key: str

      :rtype: None



   .. py:method:: get(key: str, default: Any = _NO_DEFAULT) -> Union[hermes.model.types.ld_list.ld_list, Any]

      Get the item with the given key in as a ld_list using the build in get.

      If a KeyError is raised, return the default or reraise it if no default is given.

      :param key: The key (compacted or expanded) to the item.
      :type key: str

      :returns: The ld_list item at the key.
      :rtype: ld_list

      :raises KeyError: If :meth:`__getitem__(key)` raised a KeyError and default isn't set.



   .. py:method:: update(other: Union[ld_dict, dict[str, Union[hermes.model.types.ld_container.JSON_LD_VALUE, hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, ld_dict, hermes.model.types.ld_list.ld_list]]]) -> None

      Set the items at the given keys to the given values or delete it if value is None by using build in set.

      :param other: The key, value pairs giving the new values and their keys.
      :type other: ld_dict | dict[str, JSON_LD_VALUE | BASIC_TYPE | TIME_TYPE | ld_dict | ld_list]

      :rtype: None



   .. py:method:: keys() -> collections.abc.KeysView[str]

      Return the keys of the key, value pairs of self.

      :returns: The keys of the values in self.
      :rtype: KeysView[str]



   .. py:method:: compact_keys() -> collections.abc.Iterator[str]

      Return an iterator of the compacted keys of the key, value pairs of self.

      :returns: An iterator over the compacted keys in self.
      :rtype: Iterator[str]



   .. py:method:: items() -> collections.abc.Generator[tuple[str, hermes.model.types.ld_list.ld_list], None, None]

      Return an generator of tuples of keys and their values in self.

      :returns: A Generator over all key, value pairs in self.
      :rtype: Generator[tuple[str, ld_list], None, None]



   .. py:property:: ref
      :type: dict[Literal['@id'], str]


      ...})

      :returns: The minimal JSON_LD object referencing self.
      :rtype: dict[Literal["@id"], str]

      :raises KeyError: If self has no value for "@id".

      :type: Return the dict used to reference this object by its id. (Its form is {"@id"


   .. py:method:: to_native_python() -> dict[str, Union[hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_container.NATIVE_LD_CONTAINER]]

      Return a native python version of this object where all ld_container are replaced by lists and dicts.

      :returns: The native python version of self.
      :rtype: dict[str, BASIC_TYPE | TIME_TYPE | NATIVE_LD_CONTAINER]



   .. py:method:: from_dict(value: dict[str, hermes.model.types.ld_container.NATIVE_LD_CONTAINER], *, parent: Optional[Union[ld_dict, hermes.model.types.ld_list.ld_list]] = None, key: Optional[str] = None, context: Optional[Union[str, hermes.model.types.ld_container.JSON_LD_CONTEXT_DICT, list[Union[str, hermes.model.types.ld_container.JSON_LD_CONTEXT_DICT]]]] = None, ld_type: Optional[Union[str, list[str]]] = None) -> ld_dict
      :classmethod:


      Creates a ld_dict from the given dict with the given parent, key, context and ld_type.

      Uses the expansion of the JSON-LD Processor and not the one of ld_container.

      :param value: The dict of values the ld_dict should be created from.
      :type value: dict[str, NATIVE_LD_CONTAINER]
      :param parent: The parent container of the new ld_list.
      :type parent: ld_dict | ld_list | None
      :param key: The key into the inner most parent container representing a dict of the new ld_list.
      :type key: str | None
      :param context: The context for the new dict (it will also inherit the context of parent).
      :type context: str | JSON_LD_CONTEXT_DICT | list[str | JSON_LD_CONTEXT_DICT] | None
      :param ld_type: Additional value(s) for the new dict.
      :type ld_type: str | list[str] | None

      :returns: The new ld_dict build from value.
      :rtype: ld_dict



   .. py:method:: is_ld_dict(ld_value: Any) -> bool
      :classmethod:


      Returns wheter the given value is considered to be possible of representing an expanded json-ld dict.

      I.e. if ld_value is a list containing a dict containing none of the keys "@set", "@graph", "@list" and "@value"
      and not only the key "@id".

      :param ld_value: The value that is checked.
      :type ld_value: Any

      :returns: Wheter or not ld_value could represent an expanded json-ld dict.
      :rtype: bool



   .. py:method:: is_json_dict(ld_value: Any) -> bool
      :classmethod:


      Returns wheter the given value is considered to be possible of representing an expanded json-ld dict.

      I.e. if ld_value is a dict containing none of the keys "@set", "@graph", "@list" and "@value"
      and not only the key "@id".

      :param ld_value: The value that is checked.
      :type ld_value: Any

      :returns: Wheter or not ld_value could represent an expanded json-ld dict.
      :rtype: bool



