fca.api_models

Interface with the basic classes to be used in the entire fca module.

Module Contents

Classes

Context

The representation of a formal context

Lattice

Representation of a lattice with all the concepts and the hasse diagram

IncLattice

Incremenal Lattice that can receive objects on the fly.

class fca.api_models.Context(O, A, I, solver: fca.get_lattice.FCASolver = None)

Bases: fca.base_models.Context

The representation of a formal context

__init__(O, A, I, solver: fca.get_lattice.FCASolver = None)
Parameters:
  • O (List[str]) – list of object names

  • A (List[str]) – list of attribute names

  • I (List[List[int]]) incidence matrix (1 and 0 or True and False work) –

  • solver (FCASolver) – the solver that should know how to calculate concepts.

static from_csv(filename, format_name='one_line_per_attribute')
Parameters:
  • filename (str) – a string representing the path pointing to the file

  • format_name (str) – one_line_per_attribute | table

Returns:

A Context

get_concepts()
Returns:

A List[Concept]

get_lattice()
Returns:

A Lattice

get_association_rules(**kwargs)
Keyword Arguments:
  • min_support=0.5 (float) – a float between 0 and 1

  • min_confidence=1 (float) – a float between 0 and 1

Yields:
association rules with
  • Base Item

  • Appended Item

  • Support

  • Confidence

  • Lift

see (https://pypi.org/project/apyori/)

generate_association_rules(filename, **kwargs)
Keyword Arguments:
  • filename (str) – a str representing where to save the file. It must be csv

  • min_support=0.5 (float) – a float between 0 and 1

  • min_confidence=1 (float) – a float between 0 and 1

Yields:
association rules with
  • Base Item

  • Appended Item

  • Support

  • Confidence

  • Lift

see (https://pypi.org/project/apyori/)

graduate(relation, p, lattices)

Applies graduation. Extends the formal context with more attributes with the relation relation, using the p18n operator, against the lattices lattices (a list of lattice, lattice_idx)

to_csv(filename: str)
Args

filename (str): the name of the csv to be created

Creates a csv with name csv with one row g,m for each object g having an attribute m

class fca.api_models.Lattice(hasse, concepts, from_iteration=None)

Representation of a lattice with all the concepts and the hasse diagram

property bottom: fca.base_models.Concept
property top: fca.base_models.Concept
property inverted_hasse

The inverse of the hasse digraph

property concepts
__init__(hasse, concepts, from_iteration=None)
isomorph(other_lattice)

This method needs the two lattices to have the concepts ordered in the same way, othetwise it’ll fail - Complexity: O(|self.concepts|), omega(1)

get_concept(i)
plot(**kwargs)
Keyword Arguments:
  • show_plot (bool) – Whether to show the plot or not.

  • save_plot (str) – The path where to save the plot. If None, the plot wont be saved.

  • ax (Axes | List[Axes]) – to reuse axes from another plot.

  • fig (Figure) – the figure where to draw the plot.

  • print_latex (bool) – Whether to print the latex code of the plot in the standard output

  • destructed. (instance is) –

Returns:

(fig, ax, diameter)

graph_str_repr()

String representation of the graph

class fca.api_models.IncLattice(ctx_or_attributes: List[str] | Context | None = None)

Incremenal Lattice that can receive objects on the fly.

Its purpose is to be able to receive objects and update only the minimal parts of it each update takes O(|G|²|M||L|) where L is the Lattice we have so far, and G are the objects so far.

property concepts
property hasse
property bottom
property top
__init__(ctx_or_attributes: List[str] | Context | None = None)
Parameters:

ctx_or_attributes (List[str] | Context) – The list of attributes the Lattice will have or a Context.

Example

L1 = IncLattice()
L2 = IncLattice(['a', 'b', 'c'])
L3 = IncLattice(Context(['1', '2'], ['a', 'b', 'c'], [[1, 0, 0], [0, 1, 1]]))
static copy(l)
isomorph(other_lattice)

This method needs the two lattices to have the concepts ordered in the same way, othetwise it’ll fail - Complexity: O(|self.concepts|), omega(1)

merge_concepts(other)
add_intent(object_name: str, intent: List[int])
Parameters:
  • object_name (str) – the name of the object being added.

  • intent (List[int]) – The list of attribute indices the object has.

Example

L.add_intent('o1', [1, 3, 6])
delete_instance(object_name: str)
Parameters:

object_name (str) – the name of an object to be deleted.

Example

L.delete_instance('o1')
add_attribute(attr_name: str)
add_object(object_name: str)
add_pair(object_name: str, attr_name: str)
Parameters:
  • object_name (str) – the name of an object.

  • attr_name (str) – the name of an attribute corresponding to that object.

Example

L.add_pair('o1', 'a2')
get_concept(i: int) fca_algorithms_cpp.ConceptCpp
Parameters:

i (int) – index of the concept to be returned

Returns:

ConceptCpp in i-th position

plot(**kwargs)
Keyword Arguments:
  • show_plot (bool) – Whether to show the plot or not.

  • save_plot (str) – The path where to save the plot. If None, the plot wont be saved.

  • ax (Axes | List[Axes]) – to reuse axes from another plot.

  • fig (Figure) – the figure where to draw the plot.

  • print_latex (bool) – Whether to print the latex code of the plot in the standard output

  • destructed. (instance is) –

Returns:

(fig, ax, diameter)