Concepts

The galactic.concepts module contains several classes for exploring lattices using context:

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

  • Descriptors class is used to represent descriptors of a concept;

  • Individuals is used to represent the individuals that belong to a concept;

class galactic.concepts.Descriptors(values: Optional[Mapping[galactic.descriptions.main.Description, Iterable[galactic.descriptions.main.Predicate]]] = None)

Bases: collections.abc.Mapping

The Descriptors class is used to represent each description by a collection of predicates.

__init__(values: Optional[Mapping[galactic.descriptions.main.Description, Iterable[galactic.descriptions.main.Predicate]]] = None)

Initialise a Descriptors instance.

Keyword Arguments

values (Mapping) – A mapping from descriptions to an iterable of predicates.

Raises

TypeError – If the values argument is not an instance of Mapping.

__call__(individual: Any)bool

Call each predicate on the individual.

Returns

True if the individual verify all predicates.

Return type

bool

predicates() → Iterator[galactic.descriptions.main.Predicate]

Get an iterator over the predicates.

Returns

Return type

Iterator[Predicate]

class galactic.concepts.Individuals(concept: galactic.concepts.main.Concept)

Bases: collections.abc.Mapping

The Individuals class is used to represent the individuals hold by a concept.

__init__(concept: galactic.concepts.main.Concept)

Initialise an Individuals instance.

Parameters

concept (Concept) – The underlying concept.

Raises

TypeError – If the concept argument is not an instance of Concept.

class galactic.concepts.Concept(population: Optional[galactic.population.main.Population] = None, descriptions: Optional[Iterable[galactic.descriptions.main.Description]] = None)

Bases: galactic.algebras.lattice.lattices.Element

The Concept class is used to represent a collection of individuals that verify an Iterable of Predicate instances.

__init__(population: Optional[galactic.population.main.Population] = None, descriptions: Optional[Iterable[galactic.descriptions.main.Description]] = None)

Initialise a Concept instance.

Keyword Arguments
  • population (Population) – The context population

  • descriptions (Iterable[Description]) – An iterable of Description instances.

Raises
  • TypeError – If the population is not an instance of Population.

  • TypeError – If the descriptions is not an instance of Iterable

optimize() → galactic.concepts.main.Concept

The optimize() method optimize a concept by only keeping a set of necessary predicates.

Returns

self for chaining

Return type

Concept

compare(other: galactic.concepts.main.Concept, keys: Optional[Collection[Any]] = None) → Any

Compare the concept to the other using a collection of individuals.

Returns

  • int

    • Concept.EQUAL (0b00) if the concepts are equal.

    • Concept.INF (0b01) if the concept is lesser than the other

    • Concept.SUP (0b10) if the concept is greater than the other

    • Concept.INCOMPARABLE (0b11) if the concept is not comparable to the other

  • NotImplementedType – If the comparison is not implemented

__eq__(other: Any)bool

Test if this element is equal to the other.

Parameters

other (Concept) – the other element

Returns

  • boolTrue if this element is equal to the other.

  • NotImplementedType – If the comparison is not implemented

__lt__(other: Any)bool

Test if this element is lesser than the other.

Parameters

other (Concept) – the other element

Returns

  • boolTrue if this element is lesser than the other.

  • NotImplementedType – If the comparison is not implemented

__le__(other: Any)bool

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

Parameters

other (Concept) – the other element

Returns

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

  • NotImplementedType – If the comparison is not implemented

__gt__(other: Any)bool

Test if this element is greater than the other.

Parameters

other (Concept) – the other element

Returns

  • boolTrue if this element is greater than the other.

  • NotImplementedType – If the comparison is not implemented

__ge__(other: Any)bool

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

Parameters

other (Concept) – the other element

Returns

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

  • NotImplementedType – If the comparison is not implemented

is_comparable(other: Any) → Any

Test if this element is comparable to the other.

Parameters

other (Concept) – the other element

Returns

  • boolTrue if this element is either:

    • lesser than or equal to the other;

    • greater than or equal to the other.

    False otherwise.

  • NotImplementedType – If the comparison is not implemented

__and__(other: Any) → galactic.concepts.main.Concept

Return the meet of this element and the other.

Parameters

other (Concept) – the other element

Returns

  • Concept – the meet of this element and the other

  • NotImplementedTypeNotImplemented if the other concept is either not a concept or either not constructed with the same population.

__or__(other: Any) → galactic.concepts.main.Concept

Return the join of this element and the other.

Parameters

other (Concept) – the other element

Returns

  • Concept – the join of this element and the other

  • NotImplementedTypeNotImplemented if the other concept is either not a concept or either not constructed with the same population.

predicates() → Iterator[galactic.descriptions.main.Predicate]

Get the predicates.

Returns

The predicates.

Return type

Iterator[Predicate]

selectors() → Iterator[galactic.descriptions.main.Predicate]

Get the selectors.

Returns

The selectors.

Return type

Iterator[Predicate]

descriptors() → galactic.concepts.main.Descriptors

Get the descriptors.

Returns

The descriptors.

Return type

Descriptors

individuals() → galactic.concepts.main.Individuals

Get the individuals.

Returns

The individuals.

Return type

Individuals

population() → galactic.population.main.Population

Get the population.

Returns

The population.

Return type

Population

property support

Get the concept support.

Returns

The concept support.

Return type

float

class galactic.concepts.ConceptRenderer(fill_color: str = '#ffffff', 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_mode: bool = True, width: int = 40)

Bases: galactic.algebras.poset.collections.GraphvizRenderer, galactic.algebras.context.main.ContextRenderer

The ConceptRenderer class renders graphviz node and edge attributes for Concept instances.

header(concept: galactic.concepts.main.Concept, context: galactic.algebras.context.main.Context)str

Render an attribute into the header.

Parameters
  • attribute (Any) – The attribute to render

  • context (Context) – The underlying context

Returns

The string representation of the attribute into the header.

Return type

str

row(concept: galactic.concepts.main.Concept, _context: galactic.algebras.context.main.Context)str

Render an object into the header.

Parameters
  • obj (Any) – The object to render

  • context (Context) – The underlying context

Returns

The string representation of the object into a row.

Return type

str

initialize()None

Initialize the renderer.

node_attributes(node: galactic.concepts.main.Concept, poset: galactic.algebras.poset.collections.PartiallyOrderedSet) → Dict[str, str]

Returns a dictionnary of graphviz attributes for a node.

Parameters
Returns

A dictionnary of graphviz attributes

Return type

Dict[str, str]