Skip to content

dobraczka/eche

Folders and files

NameName
Last commit message
Last commit date

Latest commit

11a6d42 · Mar 22, 2024

History

35 Commits
Mar 11, 2024
Feb 16, 2024
Mar 21, 2024
Mar 21, 2024
Feb 14, 2024
Feb 14, 2024
Feb 14, 2024
Mar 22, 2024
Feb 16, 2024
Feb 14, 2024
Feb 14, 2024
Mar 7, 2024
Mar 22, 2024

Repository files navigation

eche logo

Actions Status Documentation Status Stable python versions Ruff

Usage

Eche provides a ClusterHelper class to conveniently handle entity clusters.

  from eche import ClusterHelper
  ch = ClusterHelper([{"a1", "b1"}, {"a2", "b2"}])
  print(ch.clusters)
  {0: {'a1', 'b1'}, 1: {'a2', 'b2'}}

Add an element to a cluster

  ch.add_to_cluster(0, "c1")
  print(ch.clusters)
  {0: {'a1', 'b1', 'c1'}, 1: {'a2', 'b2'}}

Add a new cluster

  ch.add({"e2", "f1", "c3"})
  print(ch.clusters)
  {0: {'a1', 'b1', 'c1'}, 1: {'a2', 'b2'}, 2: {'f1', 'e2', 'c3'}}

Remove an element from a cluster

  ch.remove("b1")
  print(ch.clusters)
  {0: {'a1', 'c1'}, 1: {'a2', 'b2'}, 2: {'f1', 'e2', 'c3'}}

The __contains__ function is smartly overloaded. You can check if an entity is in the ClusterHelper:

  "a1" in ch
  # True

If a cluster is present

  {"c1","a1"} in ch
  # True

And even if a link exists or not

  ("f1","e2") in ch
  # True
  ("a1","e2") in ch
  # False

To know the cluster id of an entity you can look it up with

  print(ch.elements["a1"])
  0

To get members of a cluster either use

  print(ch.members(0))
  {'a1', 'b1', 'c1'}

or simply

  print(ch[0])
  {'a1', 'b1', 'c1'}

More functions can be found in the Documentation.

Installation

Simply use pip for installation:

pip install eche