hermes.model.types.ld_list
==========================

.. py:module:: hermes.model.types.ld_list


Classes
-------

.. autoapisummary::

   hermes.model.types.ld_list.ld_list


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

.. py:class:: ld_list(data: hermes.model.types.ld_container.EXPANDED_JSON_LD_VALUE, *, parent: Optional[Union[hermes.model.types.ld_dict.ld_dict, 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 list ("@set", "@list" or "@graph").
   See also :class:`ld_container`.

   .. attribute:: container_type

      The type of JSON-LD container the list is representing. ("@set", "@list", "graph")

      :type: str

   .. attribute:: item_list

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

      :type: EXPANDED_JSON_LD_VALUE


   .. py:method:: __getitem__(index: Union[int, slice]) -> Union[hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_dict.ld_dict, ld_list, list[Union[hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_dict.ld_dict, ld_list]]]

      Get the item(s) at position index in their native python version.

      :param index: The positon(s) from which the item(s) is/ are taken.
      :type index: int | slice

      :returns:     The item(s) at index in the native python version.
      :rtype: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list | list[BASIC_TYPE | TIME_TYPE | ld_dict | ld_list]



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

      Set the item(s) at position index to the given value(s).

      All given values are expanded. If any are assimilated by self all items that would be added by this are added.

      :param index: The positon(s) at which the item(s) is/ are set.
      :type index: int | slice
      :param value: The new value(s).
      :type value: JSON_LD_VALUE | BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :rtype: None

      :raises TypeError: If a slice is not assigned an iterable.



   .. py:method:: __delitem__(index: Union[int, slice]) -> None

      Delete the item(s) at position index.

      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 index: The positon(s) at which the item(s) is/ are deleted.
      :type index: int | slice

      :rtype: None



   .. py:method:: __len__() -> int

      Returns the number of items in this ld_list.

      :returns: The length of self.
      :rtype: int



   .. py:method:: __iter__() -> collections.abc.Generator[Union[hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_dict.ld_dict, ld_list], None, None]

      Returns an iterator over the native python version of the values contained in self.

      :returns: The Iterator over self's values.
      :rtype: Generator[BASIC_TYPE | TIME_TYPE | ld_dict | ld_list, None, None]



   .. py:method:: __contains__(value: hermes.model.types.ld_container.JSON_LD_VALUE) -> bool

      Returns whether or not value is contained in self.

      Note that it is not directly checked if value is in self.item_list:
      First value is expanded then it is checked if value is in self.item_list.
      If however value is assimilated by self it is checked if all values are contained in self.item_list.

      Also note that the checks whether the expanded value is in self.item_list is based on ld_list.__eq__.
      That means that this value is 'contained' in self.item_list if any object in self.item_list
      has the same @id like it or it xor the object in the item_list has an id an all other values are the same.

      :param value: The object being checked whether or not it is in self.
      :type value: JSON_LD_VALUE

      :returns: Whether or not value is being considered to be contained in self.
      :rtype: bool



   .. py:method:: __eq__(other: Union[ld_list, list[Union[hermes.model.types.ld_container.JSON_LD_VALUE, hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_dict.ld_dict, ld_list]], 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, hermes.model.types.ld_dict.ld_dict, ld_list]]]) -> bool

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

      If other is not an ld_list, it is converted first.
      For each index it is checked if the ids of the items at index in self and other match if both have one,
      if only one has or neither have an id all other values are compared.

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

      If self or other is considered unordered the comparison is more difficult. All items in self are compared
      with all items in other. On the resulting graph given by the realtion == the Hopcroft-Karp algoritm is used
      to determine if there exists a bijection reordering self so that the ordered comparison of self with other
      returns true.

      :param other: The list/ container/
                    ld_list self is compared to.
      :type other: ld_list | list[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:: _bfs_step(verticies1: set[collections.abc.Hashable], edges: dict[collections.abc.Hashable, tuple[collections.abc.Hashable]], matches: dict[collections.abc.Hashable, collections.abc.Hashable], distances: dict[collections.abc.Hashable, Union[int, float]]) -> bool
      :classmethod:


      Completes the BFS step of Hopcroft-Karp. I.e.:

      Finds the shortest path from all unmatched verticies in verticies1 to any unmatched vertex in any value in edges
      where the connecting paths are alternating between matches and its complement.

      It also marks each vertex in verticies1 with how few verticies from verticies1 have to be passed
      to reach the vertex from an unmatched one in verticies1. This is stored in distances.

      :param verticies1: The set of verticies in the left partition of the bipartite graph.
      :type verticies1: set[Hashable]
      :param edges: The edges in the bipartite graph. (As the edges are bidirectional
                    they are expected to be given in this format: Dictionary with keys being the vertices in the left
                    partition and values being tuples of verticies in the right partition.)
      :type edges: dict[Hashable, tuple[Hashable]]
      :param matches: The current matching of verticies in the left partition with the ones in
                      the right partition.
      :type matches: dict[Hashable, Hashable]
      :param distances: The reference to the dictionary mapping verticies of the left
                        partition to the minimal number of verticies in the left partition that will be passed on a path from an
                        unmatched vertex of the left partition to the vertex that is the key.
      :type distances: dict[Hashable, Union[int, float]]

      :returns:     Wheter or not a alternating path from an unmatched vertex in the left partition to an unmatched vertex
                    in the right partition exists.
      :rtype: bool



   .. py:method:: _dfs_step(ver: collections.abc.Hashable, edges: dict[collections.abc.Hashable, tuple[collections.abc.Hashable]], matches: dict[collections.abc.Hashable, collections.abc.Hashable], distances: dict[collections.abc.Hashable, Union[int, float]]) -> bool
      :classmethod:


      Completes the DFS step of Hopcroft-Karp. I.e.:

      Adds all edges on every path with the minimal path length to matches if they would be in the symmetric
      difference of matches and the set of edges on the union of the paths.

      :param ver: The set of verticies in the left partition of the bipartite graph.
      :type ver: Hashable
      :param edges: The edges in the bipartite graph. (As the edges are bidirectional
                    they are expected to be given in this format: Dictionary with keys being the vertices in the left
                    partition and values being tuples of verticies in the right partition.)
      :type edges: dict[Hashable, tuple[Hashable]]
      :param matches: The current matching of verticies in the left partition with the ones in
                      the right partition.
      :type matches: dict[Hashable, Hashable]
      :param distances: The reference to the dictionary mapping verticies of the left
                        partition to the minimal number of verticies in the left partition that will be passed on a path from an
                        unmatched vertex of the left partition to the vertex that is the key. The values will be replaced with
                        float("inf") to mark already visited vertices.
      :type distances: dict[Hashable, Union[int, float]]

      :returns:     Wheter or not a path from the unmatched vertex ver in the left partition to an unmatched vertex
                    in the right partition could still exist.
      :rtype: bool



   .. py:method:: _hopcroft_karp(verticies1: set[collections.abc.Hashable], verticies2: set[collections.abc.Hashable], edges: dict[collections.abc.Hashable, tuple[collections.abc.Hashable]]) -> int
      :classmethod:


      Implementation of Hopcroft-Karp. I.e.:

      Finds how maximal number of edges with the property that no two edges share an endpoint (and startpoint)
      in the given bipartite graph.

      Note that verticies1 and verticies2 have to be disjoint.

      :param verticies1: The set of verticies in the left partition of the bipartite graph.
      :type verticies1: set[Hashable]
      :param verticies2: The set of verticies in the right partition of the bipartite graph.
      :type verticies2: set[Hashable]
      :param edges: The edges in the bipartite graph. (As the edges are bidirectional
                    they are expected to be given in this format: Dictionary with keys being the vertices in the left
                    partition and values being tuples of verticies in the right partition.)
      :type edges: dict[Hashable, tuple[Hashable]]

      :returns: The number of edges.
      :rtype: int



   .. py:method:: __ne__(other: Union[ld_list, list[Union[hermes.model.types.ld_container.JSON_LD_VALUE, hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_dict.ld_dict, 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_list.__eq__` for more details on the comparison.)

      :param other: The list/ container/
                    ld_list self is compared to.
      :type other: ld_list | list[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:: append(value: Union[hermes.model.types.ld_container.JSON_LD_VALUE, hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_dict.ld_dict, ld_list]) -> None

      Append the item to the given ld_list self.

      The given value is expanded. If it is assimilated by self all items that would be added by this are added.

      :param value: The new value.
      :type value: JSON_LD_VALUE | BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :rtype: None



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

      Append the items in value to the given ld_list self.

      The given values are expanded. If any are assimilated by self all items that would be added by this are added.

      :param value: The new values.
      :type value: list[JSON_LD_VALUE | BASIC_TYPE | TIME_TYPE | ld_dcit | ld_list]

      :rtype: None



   .. py:method:: to_native_python() -> list[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: list[BASIC_TYPE | TIME_TYPE | NATIVE_LD_CONTAINER]



   .. py:method:: compact(context: Optional[Union[list[Union[hermes.model.types.ld_container.JSON_LD_CONTEXT_DICT, str]], hermes.model.types.ld_container.JSON_LD_CONTEXT_DICT, str]] = None) -> hermes.model.types.ld_container.COMPACTED_JSON_LD_VALUE

      Returns the compacted version of the given ld_list using its context only if none was supplied.
      The returned object is of the form `{"@context": the_context, container_type: compacted_content}`.

      :param context: The context to use for the compaction. If None the context of self is used.
      :type context: list[JSON_LD_CONTEXT_DICT | str] | JSON_LD_CONTEXT_DICT | str | None

      :returns: The compacted version of selfs JSON-LD representation.
      :rtype: COMPACTED_JSON_LD_VALUE



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


      Returns wheter the given value is considered to be possible of representing an ld_list.

      I.e. if ld_value is of the form [{container_type: [...]}] where container_type is '@set', '@list' or '@graph'.

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

      :returns: Wheter or not ld_value could represent an ld_list.
      :rtype: bool



   .. py:method:: is_container(value: Any) -> bool
      :classmethod:


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

      I.e. if ld_value is of the form {container_type: [...]} where container_type is '@set', '@list' or '@graph'.

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

      :returns: Wheter or not ld_value could represent a json-ld container.
      :rtype: bool



   .. py:method:: from_list(value: list[Union[hermes.model.types.ld_container.JSON_LD_VALUE, hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE]], *, parent: Optional[Union[hermes.model.types.ld_dict.ld_dict, 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, container_type: str = '@set') -> Self
      :classmethod:


      Creates a ld_list from the given list with the given parent, key, context and container_type.

      Note that only container_type '@set' is valid for key '@type'.

      Further more note that if parent would assimilate the values in value no new ld_list is created
      and the given values are appended to parent instead and parent is returned.

      :param value: The list of values the ld_list should be created from.
      :type value: list[JSON_LD_VALUE | BASIC_TYPE | TIME_TYPE]
      :param parent: The parent container of the new ld_list. If value is assimilated by
                     parent druing JSON-LD expansion parent is extended by value and parent is returned.
      :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 list
                      (it will also inherit the context of parent). Note that this context won't be added to parent if value
                      is assimilated by parent and parent is returned.
      :type context: str | JSON_LD_CONTEXT_DICT | list[str | JSON_LD_CONTEXT_DICT] | None
      :param container_type: The container type of the new list valid are '@set', '@list' and '@graph'.
                             If value is assimilated by parent and parent is returned the given container_type won't affect
                             the container type of parent. Also note that only '@set' is valid if key is '@type'.
      :type container_type: str

      :returns: The new ld_list build from value or if value is assimilated by parent, parent extended by value.
      :rtype: ld_list

      :raises ValueError: If key is '@type' and container_type is not '@set'.



   .. py:method:: get_item_list_from_container(ld_value: dict[str, list[Any]]) -> list[Any]
      :classmethod:


      Returns the item list from a container, the given ld_value, (i.e. {container_type: item_list}).
      Only '@set', '@list' and '@graph' are valid container types.

      :param ld_value: The container whose item list is to be returned.
      :type ld_value: dict[str, list[Any]]

      :returns: The list the container holds.
      :rtype: list[Any]

      :raises ValueError: If the item_container is not a dict.
      :raises ValueError: If the container_type is not exactly one of '@set', '@list' and '@graph'.
      :raises ValueError: If the item_list is no list.



