Concepts

The galactic.concepts module contains classes for exploring concept lattices.

  • Concept class is used to represent collections of objects that share a set of predicates;

  • ConceptLattice class is used to represent concept lattices;

  • ConceptClosure class is used to represent closure operators used in ConceptLattice instances.

Two classes allow to visualize concept lattices:

And two functions:

class Concept(closure: ConceptClosure, keys: Optional[Iterable[str]] = None)

The Concept class represents a formal concept.

__and__(other: Any) Concept

Return the join of this concept and the other.

Parameters:

other (Concept) – the other concept

Returns:

  • Concept – the join of this concept and the other

  • NotImplementedTypeNotImplemented if the other parameter is not a concept.

Raises:

ValueError – If the closure operators of the two concepts are not identical.

__eq__(other: Any) bool

Test if this concept is equal to the other.

Parameters:

other (Concept) – the other concept

Returns:

  • boolTrue if this concept is equal to the other.

  • NotImplementedTypeNotImplemented if the other parameter is not a concept.

__ge__(other: Any) bool

Test if this concept is greater than or equal to the other.

Parameters:

other (Concept) – the other concept

Returns:

  • boolTrue if this concept is greater than or equal to the other.

  • NotImplementedTypeNotImplemented if the other parameter is not a concept.

Raises:

ValueError – If the closure operators of the two concepts are not identical.

__gt__(other: Any) bool

Test if this concept is greater than the other.

Parameters:

other (Concept) – the other concept

Returns:

  • boolTrue if this concept is greater than the other.

  • NotImplementedTypeNotImplemented if the other parameter is not a concept.

Raises:

ValueError – If the closure operators of the two concepts are not identical.

__init__(closure: ConceptClosure, keys: Optional[Iterable[str]] = None)

Initialise a Concept instance.

Parameters:

closure (ConceptClosure) – The concept closure operator.

Keyword Arguments:

keys (Iterable[str], optional) – An iterable of identifiers.

__le__(other: Any) bool

Test if this concept is lesser than or equal to the other.

Parameters:

other (Concept) – the other concept

Returns:

  • boolTrue if this concept is lesser than or equal to the other.

  • NotImplementedTypeNotImplemented if the other parameter is not a concept.

Raises:

ValueError – If the closure operators of the two concepts are not identical.

__lt__(other: Any) bool

Test if this concept is lesser than the other.

Parameters:

other (Concept) – the other concept

Returns:

  • boolTrue if this concept is lesser than the other.

  • NotImplementedTypeNotImplemented if the other parameter is not a concept.

Raises:

ValueError – If the closure operators of the two concepts are not identical.

__ne__(other: Any) bool

Test if this concept is not equal to the other.

Parameters:

other (Concept) – the other concept

Returns:

True if this concept is not equal to the other.

Return type:

bool

__or__(other: Any) Concept

Return the join of this concept and the other.

Parameters:

other (Concept) – the other concept

Returns:

  • Concept – the join of this concept and the other

  • NotImplementedTypeNotImplemented if the other parameter is not a concept.

Raises:

ValueError – If the closure operators of the two concepts are not identical.

property closure: ConceptClosure

Get the closure operator.

Returns:

The closure operator.

Return type:

ConceptClosure

property descriptors: Mapping[Description, AbstractSet[Predicate]]

Get the descriptors.

Returns:

The descriptors.

Return type:

Mapping[Description, AbstractSet[Predicate]]

enlarge(keys: Iterable[str]) Concept

Enlarge the concept by adding objects.

Parameters:

keys (Iterable[Predicate]) – An iterable of identifiers.

Returns:

A new concept.

Return type:

Concept

equivalence(element: _T) Iterator[_T]

Compute equivalences of the element.

Parameters:

element (_T) – The element whose equivalences are requested

Returns:

An iterator over the equivalence elements of element

Return type:

Iterator[_T]

intersection(*args: Any) Meetable

Return the intersection of this element and the others.

Parameters:

*args (object) – the others elements

Returns:

the meet of this element and the others

Return type:

Meetable

Raises:

TypeError – if one of the other elements is not an instance of this element class.

predicates() Iterator[Predicate]

Get an iterator over the predicates.

Return type:

Iterator[Predicate]

restrict(predicates: Iterable[Predicate]) Concept

Restrict the concept by adding predicates.

Parameters:

predicates (Iterable[Predicate]) – An iterable of predicates.

Returns:

A new concept.

Return type:

Concept

subsumption(element: _T) Iterator[_T]

Compute subsumed elements of the element.

Parameters:

element (_T) – The element whose subsumed elements are requested

Returns:

An iterator over the subsumed elements of element

Return type:

Iterator[_T]

property support: float

Get the closed set support.

Returns:

The closed set support.

Return type:

float

supsumption(element: _T) Iterator[_T]

Compute supsumed elements of the element.

Notes

supsumption is a neologism to designate the inverse relation of subsumption.

Parameters:

element (_T) – The element whose supsumed elements are requested

Returns:

An iterator over the supsumed elements of element

Return type:

Iterator[_T]

union(*args: Any) Joinable

Return the union of this element and the others.

Parameters:

*args (object) – the others elements

Returns:

the join of this element and the others

Return type:

Joinable

Raises:

TypeError – if one of the other elements is not an instance of this element class.

class ConceptClosure(population: Population, descriptions: Iterable[Description])

The ConceptClosure class.

It allows to compute concepts using a closure operator.

__call__(keys: Optional[Iterable[str]] = None) Concept

Initialise a concept using an iterable of identifiers.

Keyword Arguments:

keys (Iterable[str], optional) – An iterable of identifiers.

Returns:

A new concept equal to the closure of the keys.

Return type:

Concept

__init__(population: Population, descriptions: Iterable[Description])

Initialise a ConceptClosure instance.

Parameters:
property descriptions: Sequence[Description]

Get the descriptions.

Returns:

The descriptions.

Return type:

Sequence[Description]

property population: Population

Get the population.

Returns:

The population of individuals.

Return type:

Population

property universe: FiniteUniverse[str]

Get the underlying universe.

Returns:

The underlying universe.

Return type:

FiniteUniverse[str]

class ConceptLattice(population: Population, descriptions: Iterable[Description])

The ConceptLattice class represents concept lattices.

__contains__(item: Any) bool

Get the membership of an element.

Parameters:

item – The element whose membership is requested.

Returns:

True if the item belongs to the partially ordered set.

Return type:

bool

__copy__() Lattice[_E]

Get a copy of the lattice.

The operation is in \(O(j+m)\).

Returns:

The copy of this lattice.

Return type:

Lattice[_E]

__init__(population: Population, descriptions: Iterable[Description]) None

Initialise a ConceptLattice instance.

Parameters:
__iter__() Iterator[Link[_P, _P]]

Get an iterator over the elements.

Returns:

An iterator over the elements

Return type:

Iterator[Link[_P, _P]]

property atoms: AbstractSet[_E]

Get the atoms of this lattice.

Returns:

The atoms

Return type:

AbstractSet[_E]

property bottom: AbstractSet[_E]

Get the bottom elements.

The collection contains only one element, the minimum element.

Returns:

The bottom elements.

Return type:

AbstractSet[_E]

property closure: ConceptClosure

Get the underlying closure operator.

Returns:

The closure operator.

Return type:

ConceptClosure

property co_atoms: AbstractSet[_E]

Get the co-atoms of this lattice.

Returns:

The co-atoms.

Return type:

AbstractSet[_E]

property co_domain: AbstractSet[_E]

Get the co-domain of this lattice.

Returns:

The co-domain of this lattice.

Return type:

AbstractSet[_E]

property cover: AbstractReversibleCoveringRelation[_E]

Get the covering relation of this lattice.

Returns:

The covering relation.

Return type:

AbstractReversibleCoveringRelation[_E]

property descriptions: Sequence[Description]

Get the underlying descriptions.

Returns:

The descriptions. It’s a proxy to self.closure.descriptions.

Return type:

Sequence[Description]

property domain: AbstractSet[_E]

Get the domain of this lattice.

Returns:

The domain of this lattice.

Return type:

AbstractSet[_E]

extend(iterable: Iterable[_E]) None

In-place enlarge the lattice with an iterable of elements.

Parameters:

iterable (Iterable[_E]) – An iterable of elements

filter(element: _E) AbstractLattice[_E]

Get a filter of a lattice.

Parameters:

element (_E) – The lower limit

Returns:

The lower bounded lattice.

Return type:

AbstractLattice[_E]

Raises:

ValueError – If the element does not belong to the poset.

property global_entropy: float

Compute the global entropy of the Moore family.

\[H(L)=\sum_{A\in L}p(A)I(A)=n-\frac{\sum_{A\in L}\kappa(( A,B))\log_2(\kappa(A))}{2^n}\]

Notes

See Information .

Returns:

The global entropy.

Return type:

float

Examples

>>> from galactic.algebras.closure import MooreFamily
>>> from galactic.examples.closure import NumericalClosure, NumericalClosed
>>> elements = {0, 1, 2, 3, 4, 5}
>>> closure = NumericalClosure(elements)
>>> family = MooreFamily[NumericalClosed, int](closure)
>>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])])
>>> round(family.global_entropy, 3)
1.311
property global_information: float

Compute the global information of the Moore family.

It is equal to the global entropy multiplied by the number of element defined by the closure operator.

\[I(L)=n H(L)\]
Returns:

The global information.

Return type:

float

Examples

>>> from galactic.algebras.closure import MooreFamily
>>> from galactic.examples.closure import NumericalClosure, NumericalClosed
>>> elements = {0, 1, 2, 3, 4, 5}
>>> closure = NumericalClosure(elements)
>>> family = MooreFamily[NumericalClosed, int](closure)
>>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])])
>>> round(family.global_information, 3)
7.868
property global_logarithmic_stability: float

Compute the global normalized logarithmic stability of the Moore family.

\[\lambda(L)=\sum_{A\in L}p(A)\lambda(A)\]
Returns:

The global normalized logarithmic stability.

Return type:

float

Examples

>>> from galactic.algebras.closure import MooreFamily
>>> from galactic.examples.closure import NumericalClosure, NumericalClosed
>>> elements = {0, 1, 2, 3, 4, 5}
>>> closure = NumericalClosure(elements)
>>> family = MooreFamily[NumericalClosed, int](closure)
>>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])])
>>> round(family.global_logarithmic_stability, 3)
0.335
property global_stability: float

Compute the global stability of the Moore family.

\[\sigma(L)=\sum_{A\in L}p(A)\sigma(A) =\sum_{A\in L}\frac{\kappa(A)^2}{2^{|A|+n}}\]
Returns:

The global stability.

Return type:

float

Examples

>>> from galactic.algebras.closure import MooreFamily
>>> from galactic.examples.closure import NumericalClosure, NumericalClosed
>>> elements = {0, 1, 2, 3, 4, 5}
>>> closure = NumericalClosure(elements)
>>> family = MooreFamily[NumericalClosed, int](closure)
>>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])])
>>> round(family.global_stability, 3)
0.703
greatest_join_irreducible(element: _E) AbstractSet[_E]

Get the greatest join irreducible smaller than an element.

Parameters:

element (_E) – The element whose greatest join irreducible are requested

Returns:

The greatest join irreducible smaller than the element.

Return type:

AbstractSet[_E]

Raises:

ValueError – If the element does not belong to the lattice.

ideal(element: _E) AbstractLattice[_E]

Get an ideal of a lattice.

Parameters:

element (_E) – The upper limit

Returns:

The upper bounded lattice.

Return type:

AbstractLattice[_E]

Raises:

ValueError – If the element does not belong to the poset.

information() Iterator[Measure[_E, float]]

Get an iterator on elements (\(A\), \(I(A)\)).

\(I(A)\) is the information of \(A\).

\[I(A)=-\log_2(p(A)\]
Returns:

An iterator on elements and their information.

Return type:

Iterator[Measure[_E, float]]

Notes

See Information .

Examples

>>> from galactic.algebras.closure import MooreFamily
>>> from galactic.examples.closure import NumericalClosure, NumericalClosed
>>> elements = {0, 1, 2, 3, 4, 5}
>>> closure = NumericalClosure(elements)
>>> family = MooreFamily[NumericalClosed, int](closure)
>>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])])
>>> for element, information in family.information():
...     print(list(element), information)
[2, 3] 4.0
[2, 3, 4] 4.0
[1, 2, 3] 4.0
[1, 2, 3, 4] 4.0
[0, 1, 2, 3, 4, 5] 0.4150374992788439
isdisjoint(other)

Return True if two sets have a null intersection.

property join_irreducible: AbstractSet[_E]

Get the join irreducible elements.

Returns:

The join irreducible elements

Return type:

AbstractSet[_E]

logarithmic_stabilities() Iterator[Measure[_E, float]]

Get an iterator on (\(A\), \(\lambda(A)\)).

\(\lambda(A)\) is the normalized logarithmic stabilities of \(A\) (the normalized logarithmic stability is always between 0 and 1).

  • if \(\kappa(A)\) is equal to \(2^{|A|}\), the normalized logarithmic stability is equal to 1.

  • if \(\kappa(A)\) is equal to \(1\), the normalized logarithmic stability is equal to 0

  • the special case \(A=\emptyset\) (\(2^{|A|}=\kappa(A)=1\)) gives \(\lambda(\emptyset)=1\) by convention.

\[\begin{split}\begin{eqnarray} \lambda(A) &=&\frac{-\log_2\left(1-\sigma(A)+\frac{1}{2^{|A|}}\right)}{|A|}\\ &=&\frac{-\log_2\left(\frac{2^{|A|}-\kappa(A)+1}{2^{|A|}}\right)}{|A|}\\ &=&\frac{|A|-\log_2\left(2^{|A|}-\kappa(A)+1\right)}{|A|}\\ &=&1-\frac{\log_2\left(2^{|A|}-\kappa(A)+1\right)}{|A|}\\ \lambda(\emptyset) &=&1\\ \end{eqnarray}\end{split}\]

See also

parts()

Notes

Originally, the logarithmic stability was defined using

\[\begin{split}\begin{eqnarray} -\log_2\left(1-\sigma(A)\right) &=&-\log_2\left(1-\frac{\kappa(A)}{2^{|A|}}\right)\\ &=&|A|-\log_2\left(2^{|A|}-\kappa(A)\right)\\ \end{eqnarray}\end{split}\]

but this formulae can give an infinity value and it is not normalized between elements.

Returns:

An iterator on elements and their normalized logarithmic stability.

Return type:

Iterator[Measure[_E, float]]

Examples

>>> from galactic.algebras.closure import MooreFamily
>>> from galactic.examples.closure import NumericalClosure, NumericalClosed
>>> elements = {0, 1, 2, 3, 4, 5}
>>> closure = NumericalClosure(elements)
>>> family = MooreFamily[NumericalClosed, int](closure)
>>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])])
>>> for element, stability in family.logarithmic_stabilities():
...     print(list(element), round(stability, 3))
[2, 3] 1.0
[2, 3, 4] 0.226
[1, 2, 3] 0.226
[1, 2, 3, 4] 0.075
[0, 1, 2, 3, 4, 5] 0.319
lower_limit(limit: _E, strict: bool = Ellipsis) AbstractSet[_E]

Get the elements greater than a limit.

Parameters:
  • limit (_E) – The lower limit

  • strict (bool) – Is the comparison strict?

Returns:

The selected elements.

Return type:

AbstractSet[_E]

property maximum: _E

Get the maximum element of this lattice.

Returns:

the maximum element

Return type:

_E

property meet_irreducible: AbstractSet[_E]

Get the meet irreducible elements.

Returns:

The meet irreducible elements

Return type:

AbstractSet[_E]

property minimum: _E

Get the minimum element of this lattice.

Returns:

The minimum element

Return type:

_E

parts() Iterator[Measure[_E, int]]

Get an iterator on (\(A\), \(\kappa(A)\)).

\(\kappa(A)\) is the number of parts of \(A\) whose closure \(\phi\) equal to \(A\).

\[\kappa(A)= \left|\left\{ \tilde A\subseteq A: \phi\left(\tilde A\right)=A \right\}\right|\]
Returns:

An iterator on elements and the number of parts \(\tilde A\subseteq A\subseteq X\) whose closure is equal to the element.

Return type:

Iterator[Measure[_E, int]]

Examples

>>> from galactic.algebras.closure import MooreFamily
>>> from galactic.examples.closure import NumericalClosure, NumericalClosed
>>> elements = {0, 1, 2, 3, 4, 5}
>>> closure = NumericalClosure(elements)
>>> family = MooreFamily[NumericalClosed, int](closure)
>>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])])
>>> for element, count in family.parts():
...     print(list(element), count)
[2, 3] 4
[2, 3, 4] 4
[1, 2, 3] 4
[1, 2, 3, 4] 4
[0, 1, 2, 3, 4, 5] 48
property population: Population

Get the underlying population.

Returns:

The population. It’s a proxy to self.closure.population.

Return type:

Population

predecessors(element: _E) AbstractSet[_E]

Get the predecessors of an element.

Parameters:

element (_E) – The element whose predecessors are requested

Returns:

The predecessors.

Return type:

AbstractSet[_E]

Raises:

ValueError – If the element does not belong to the poset.

probabilities() Iterator[Measure[_E, float]]

Get an iterator on (\(A\), \(p(A)\)).

\(p(A)\) is the probability of \(A\).

\[p(A)=\frac{\kappa(A)}{2^n}\]

See also

parts()

Returns:

An iterator on elements and their probability.

Return type:

Iterator[Measure[_E, float]]

Examples

>>> from galactic.algebras.closure import MooreFamily
>>> from galactic.examples.closure import NumericalClosure, NumericalClosed
>>> elements = {0, 1, 2, 3, 4, 5}
>>> closure = NumericalClosure(elements)
>>> family = MooreFamily[NumericalClosed, int](closure)
>>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])])
>>> for element, probability in family.probabilities():
...     print(list(element), probability)
[2, 3] 0.0625
[2, 3, 4] 0.0625
[1, 2, 3] 0.0625
[1, 2, 3, 4] 0.0625
[0, 1, 2, 3, 4, 5] 0.75
property reduced_context: AbstractBinaryRelation[_E, _E]

Get the reduced context from this lattice.

Returns:

The reduced context.

Return type:

AbstractBinaryRelation[_E, _E]

property sinks: AbstractSet[_E]

Get the sink elements.

The collection contains only one element, the maximum element.

Returns:

The sink elements.

Return type:

AbstractSet[_E]

smallest_meet_irreducible(element: _E) AbstractSet[_E]

Get the smallest meet irreducible greater than an element.

Parameters:

element (_E) – The element whose greatest join irreducible are requested

Returns:

The smallest meet irreducible smaller than the element.

Return type:

AbstractSet[_E]

Raises:

ValueError – If the element does not belong to the lattice.

property sources: AbstractSet[_E]

Get the source elements.

The collection contains only one element, the minimum element.

Returns:

The source elements.

Return type:

AbstractSet[_E]

stabilities() Iterator[Measure[_E, float]]

Get an iterator on (\(A\), \(\sigma(A)\)).

\(\sigma(A)\) is the stability of \(A\).

\[\sigma(A)=\frac{\kappa(A)}{2^{|A|}}\]

See also

parts()

Returns:

An iterator on elements and their stability.

Return type:

Iterator[Measure[_E, float]]

Examples

>>> from galactic.algebras.closure import MooreFamily
>>> from galactic.examples.closure import NumericalClosure, NumericalClosed
>>> elements = {0, 1, 2, 3, 4, 5}
>>> closure = NumericalClosure(elements)
>>> family = MooreFamily[NumericalClosed, int](closure)
>>> family.extend([closure([1, 2, 3]), closure([2, 3, 4])])
>>> for element, stability in family.stabilities():
...     print(list(element), round(stability, 3))
[2, 3] 1.0
[2, 3, 4] 0.5
[1, 2, 3] 0.5
[1, 2, 3, 4] 0.25
[0, 1, 2, 3, 4, 5] 0.75
successors(element: _E) AbstractSet[_E]

Get the successors of an element.

Parameters:

element (_E) – The element whose successors are requested

Returns:

The successors.

Return type:

AbstractSet[_E]

Raises:

ValueError – If the element does not belong to the poset.

property top: AbstractSet[_E]

Get the top elements.

The collection contains only one element, the maximum element.

Returns:

The top elements.

Return type:

AbstractSet[_E]

property universes: Tuple[AbstractSet[_E], AbstractSet[_E]]

Get the universes of this lattice.

Returns:

The universes.

Return type:

Tuple[AbstractSet[_E], AbstractSet[_E]]

upper_limit(limit: _E, strict: bool = False) AbstractSet[_E]

Get the elements lesser than a limit.

Parameters:
  • limit (_E) – The upper limit

  • strict (bool) – Is the comparison strict?

Returns:

The selected elements.

Return type:

AbstractSet[_E]

class ConceptRenderer(fill_color: str = '#ffffff', current_color: str = '#ad7fa8', anonymous_color: str = '#d3d3d3', generator_color: str = '#fcaf3e', pseudo_color: str = '#729fcf', prototype_color: str = '#8ae234', show_predicates: bool = False, show_individuals: bool = False, compact: bool = True, join_irreducible: bool = False, meet_irreducible: bool = False, width: int = 40)

The ConceptRenderer class renders graphviz node and edge attributes.

It is used for rendering Concept instances.

__init__(fill_color: str = '#ffffff', current_color: str = '#ad7fa8', anonymous_color: str = '#d3d3d3', generator_color: str = '#fcaf3e', pseudo_color: str = '#729fcf', prototype_color: str = '#8ae234', show_predicates: bool = False, show_individuals: bool = False, compact: bool = True, join_irreducible: bool = False, meet_irreducible: bool = False, width: int = 40)

Initialise a ConceptRenderer instance.

Keyword Arguments:
  • fill_color (str) – The fill color.

  • anonymous_color (str) – The anonymous color.

  • generator_color (str) – The generator color.

  • pseudo_color (str) – The pseudo-generator color.

  • prototype_color (str) – The prototype color.

  • show_predicates (bool) – Display predicates.

  • show_individuals (bool) – Display individuals.

  • compact (bool) – Compact mode.

  • join_irreducible (bool) – Display elements as join irreducible.

  • meet_irreducible (bool) – Display elements as meet irreducible.

  • width (int) – The node width.

property anonymous_color: str

Get the anonymous color.

Returns:

The anonymous color.

Return type:

str

attributes(element: Concept, index: Optional[int] = None, current: bool = False, successors: Optional[AbstractSet[Concept]] = None, predecessors: Optional[AbstractSet[Concept]] = None) Dict[str, str]

Produce a dictionary of graphviz attributes for a node.

Parameters:

element (Concept) – The concept to render.

Keyword Arguments:
Returns:

A dictionary of graphviz attributes.

Return type:

Dict[str, str]

property compact: bool

Get the compact mode.

Returns:

True

If the display is in compact mode.

Return type:

bool

property current_color: str

Get the current color.

Returns:

The current color.

Return type:

str

property fill_color: str

Get the fill color.

Returns:

The fill color.

Return type:

str

property generator_color: str

Get the generator color.

Returns:

The generator color.

Return type:

str

property join_irreducible: bool

Get the join irreducible mode.

Returns:

True

If the display is in join irreducible mode.

Return type:

bool

property meet_irreducible: bool

Get the meet irreducible mode.

Returns:

True

If the display is in meet irreducible mode.

Return type:

bool

property prototype_color: str

Get the prototype color.

Returns:

The prototype color.

Return type:

str

property pseudo_color: str

Get the pseudo color.

Returns:

The pseudo color.

Return type:

str

render(element: Concept, index: int) str

Render a concept for a cell element.

Parameters:
  • element (Concept) – The concept to render.

  • index (int) – The element index.

Returns:

The markdown representation of a Concept.

Return type:

str

property show_individuals: bool

Get the show individuals mode.

Returns:

True

If the display is in show individuals mode.

Return type:

bool

property show_predicates: bool

Get the show predicates mode.

Returns:

True

If the display is in show predicates mode.

Return type:

bool

property width: int

Get the width.

Returns:

The current width.

Return type:

int

class HierarchicalRenderer(compression: Optional[float] = None)

The HierarchicalRenderer class renders edge attributes.

__init__(compression: Optional[float] = None) None

Initialize a HierarchicalRenderer class.

Keyword Arguments:

compression (float, optional) – The compression rate.

attributes(source: Concept, destination: Concept, successors: Optional[AbstractSet[Concept]] = None, predecessors: Optional[AbstractSet[Concept]] = None) Dict[str, str]

Return a dictionary of graphviz attributes for an edge.

Parameters:
  • source (_E) – The edge source

  • destination (_F) – The edge destination

Keyword Arguments:
  • successors (AbstractSet[_F], optional) – The successors of source (including current destination).

  • predecessors (AbstractSet[_E], optional) – The predecessors of destination (including current source).

Returns:

A dictionary of graphviz attributes

Return type:

Dict[str, str]

property compression: Optional[float]

Get the compression rate.

Returns:

The compression rate.

Return type:

bool

class ConceptLatticeRenderer(*args, **kwds)

The ConceptLatticeRenderer class renders graph attributes.

add_destination(element: _F, index: Optional[int] = None, current: bool = False, successors: Optional[AbstractSet[_E]] = None, predecessors: Optional[AbstractSet[_E]] = None) None

Add a destination to the graph.

Parameters:

element (_F) – The destination to add.

Keyword Arguments:
  • index (int, optional) – The destination index.

  • current (bool) – is element the current element?

  • successors (AbstractSet[_E], optional) – The successors of the destination.

  • predecessors (AbstractSet[_E], optional) – The predecessors of the destination.

add_edge(source: _E, destination: _F, successors: Optional[AbstractSet[_F]] = None, predecessors: Optional[AbstractSet[_E]] = None) None

Add an edge to the graph.

Parameters:
  • source (_E) – The edge source

  • destination (_F) – The edge destination

Keyword Arguments:
  • successors (AbstractSet[_F], optional) – The successors of source (including current destination).

  • predecessors (AbstractSet[_E], optional) – The predecessors of destination (including current source).

add_source(element: _E, index: Optional[int] = None, current: bool = False, successors: Optional[AbstractSet[_F]] = None, predecessors: Optional[AbstractSet[_F]] = None) None

Add a source to the graph.

Parameters:

element (_E) – The source to add.

Keyword Arguments:
  • index (int, optional) – The source index.

  • current (bool) – is element the current element?

  • successors (AbstractSet[_F], optional) – The successors of the source.

  • predecessors (AbstractSet[_F], optional) – The predecessors of the source.

attributes() Dict[str, str]

Return a dictionary of graphviz attributes for a Hasse diagram.

Returns:

A dictionary of graphviz attributes

Return type:

Dict[str, str]

class ConceptTable(lattice: ConceptLattice, all_individuals: bool = False, all_predicates: bool = False, concept_width: int = 1, individual_width: int = 1, predicate_width: int = 1)

The Table class is used to represent lattice in jupyter notebooks.

__init__(lattice: ConceptLattice, all_individuals: bool = False, all_predicates: bool = False, concept_width: int = 1, individual_width: int = 1, predicate_width: int = 1)

Initialise a Table class.

Parameters:

lattice (ConceptLattice) – The lattice whose table representation is requested

Keyword Arguments:
  • all_individuals (bool) – A boolean flag for displaying all individuals for each concept

  • all_predicates (bool) – A boolean flag for displaying all predicates for each concept

  • concept_width (int) – The concept width

  • individual_width (int) – The individual width.

  • predicate_width (int) – The predicate width.

By default only new predicates and new individuals are displayed. The values of the given widths are compared with each other to allocate relative column sizes.

property all_individuals: bool

Get the all individuals flag.

Returns:

The all individuals flag.

Return type:

bool

property all_predicates: bool

Get the all predicates flag.

Returns:

The all predicates flag.

Return type:

bool

property concept_width: int

Get the concept width.

Returns:

The concept width.

Return type:

int

property individual_width: int

Get the individual width.

Returns:

The individual width.

Return type:

int

property lattice: ConceptLattice

Get the underlying lattice.

Returns:

The concept lattice.

Return type:

ConceptLattice

property predicate_width: int

Get the predicate width.

Returns:

The predicate width.

Return type:

int

new_predicates(concept: Concept, successors: AbstractSet[Concept]) Iterator[Predicate]

Get the new predicates given by the concept.

Parameters:
  • concept (Concept) – The concept whose new predicates are requested.

  • successors (AbstractSet[Concept]) – The successors of the concept.

Returns:

An iterator over the new predicates.

Return type:

Iterator[Predicate]

new_individuals(concept: Concept, predecessors: AbstractSet[Concept]) Iterator[str]

Get the new individuals given by the concept.

Parameters:
  • concept (Concept) – The concept whose new individuals are requested.

  • predecessors (AbstractSet[Concept]) – The predecessors of the concept.

Returns:

An iterator over the individual keys.

Return type:

Iterator[str]