Skip to main content

Little helper for handling entity clusters

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eche-0.1.0.tar.gz (10.0 kB view hashes)

Uploaded Source

Built Distribution

eche-0.1.0-py3-none-any.whl (8.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page