API Reference

Context

concepts.load_cxt(filename, encoding=None)

Load and return formal context from CXT file.

Parameters:
  • filename – Path to the CXT file to load the context from.
  • encoding – Encoding of the file (‘utf-8’, ‘latin1’, ‘ascii’, ...).

Example

>>> load_cxt('examples/digits.cxt')  
<Context object mapping 10 objects to 7 properties at 0x...>
concepts.load_csv(filename, dialect='excel', encoding='utf-8')

Load and return formal context from CSV file.

Parameters:
  • filename – Path to the CSV file to load the context from.
  • dialect – Syntax variant of the CSV file (‘excel’, ‘excel-tab’).
  • encoding – Encoding of the file (‘utf-8’, ‘latin1’, ‘ascii’, ...).

Example

>>> load_csv('examples/vowels.csv')  
<Context object mapping 12 objects to 8 properties at 0x...>
concepts.make_context(source, frmat='table')

Return a new context from source string in the given format.

Parameters:
  • source – Formal context table as plain-text string.
  • frmat – Format of the context string (‘table’, ‘cxt’, ‘csv’).

Example

>>> make_context('''
...      |male|female|adult|child|
... man  |  X |      |  X  |     |
... woman|    |   X  |  X  |     |
... boy  |  X |      |     |  X  |
... girl |    |   X  |     |  X  |
... ''')  
<Context object mapping 4 objects to 4 properties at 0x...>
class concepts.Context(objects, properties, bools)

Formal context defining a relation between objects and properties.

Example

>>> Context(['man', 'woman'], ['male', 'female'], [(True, False), (False, True)])  
<Context object mapping 2 objects to 2 properties at 0x...>
__getitem__(items, raw=False)

Return (extension, intension) pair by shared objects or properties.

bools

Row-wise boolean relation matrix between objects and properties.

definition()

Return (objects, properties, bools) triple as mutable object.

extension(properties, raw=False)

Return all objects sharing the given properties.

classmethod fromfile(filename, frmat='cxt', encoding=None, **kwargs)

Return a new context from file source in given format.

classmethod fromstring(source, frmat='table', **kwargs)

Return a new context from string source in given format.

intension(objects, raw=False)

Return all properties shared by the given objects.

lattice

The concept lattice of the formal context.

neighbors(objects, raw=False)

Return the upper neighbors of the concept having all given objects.

objects

(Names of the) objects described by the context.

properties

(Names of the) properties that describe the objects.

relations(include_unary=False)

Return the logical relations between the context properties.

tofile(filename, frmat='cxt', encoding='utf-8', **kwargs)

Save the context serialized to file in the given format.

tostring(frmat='table', **kwargs)

Return the context serialized in the given string-based format.

Definition

class concepts.Definition(objects=(), properties=(), bools=())

Mutable triple of (objects, properties, bools) for creating a context.

Example

>>> Definition(['man', 'woman'], ['male', 'female'], [(True, False), (False, True)])
<Definition(['man', 'woman'], ['male', 'female'], [(True, False), (False, True)])>
add_object(obj, properties=())

Add an object to the definition and add properties as related.

add_property(prop, objects=())

Add a property to the definition and add objects as related.

fromfile(filename, frmat='cxt', encoding=None, **kwargs)

Return a new definiton from file source in given format.

intersection(other, ignore_conflicts=False)

Return a new definition from the intersection of the definitions.

intersection_update(other, ignore_conflicts=False)

Update the definition with the intersection of ther other.

inverted()

Return a new definition flipping all booleans.

move_object(obj, index)

Reorder the definition such that object is at index.

move_property(prop, index)

Reorder the definition such that property is at index.

remove_object(obj)

Remove an object from the definition.

remove_property(prop)

Remove a property from the definition.

rename_object(old, new)

Replace the name of an object by a new one.

rename_property(old, new)

Replace the name of a property by a new one.

set_object(obj, properties)

Add an object to the definition and set its properties.

set_property(prop, objects)

Add a property to the definition and set its objects.

take(objects=None, properties=None, reorder=False)

Return a subset with given objects/properties as new definition.

transposed()

Return a new definition swapping objects and properties.

union(other, ignore_conflicts=False)

Return a new definition from the union of the definitions.

union_update(other, ignore_conflicts=False)

Update the definition with the union of ther other.

Lattice

class concepts.lattices.Lattice(context, infimum=())

Formal concept lattice as directed acyclic graph of concepts.

__call__(properties)

Return concept having all given properties as intension.

__getitem__(key)

Return concept by index, intension, or extension.

atoms

Minimal non-infimum concepts.

downset_union(concepts)

Yield all concepts that imply any of the given ones.

graphviz(filename=None, directory=None, render=False, view=False, **kwargs)

Return graphviz source for visualizing the lattice graph.

join(concepts)

Return the nearest concept that subsumes all given concepts.

meet(concepts)

Return the nearest concept that implies all given concepts.

upset_generalization(concepts)

Yield all concepts that subsume only the given ones.

upset_union(concepts)

Yield all concepts that subsume any of the given ones.

Concept

class concepts.lattices.Concept(lattice, extent, intent, upper, lower)

Formal concept as pair of extent and intent.

__iter__()

Pair of extent and intent.

attributes()

Shortlex ordered properties generating the concept.

complement_of(other)

Infimum meet and supremum join.

downset()

Implying concepts.

extent

Objects subsumed by the concept.

implies(other)

Implication.

incompatible_with(other)

Infimum meet.

intent

Properties implied by the concept.

join(other)

Least upper bound, supremum, or, generalization.

meet(other)

Greatest lower bound, infimum, and, unification.

minimal()

Shortlex minimal properties generating the concept.

orthogonal_to(other)

Non-infimum meet, incomparable, and non-supremum join.

properly_implies(other)

Proper implication.

properly_subsumes(other)

Proper subsumption.

subcontrary_with(other)

Non-infimum meet and supremum join.

subsumes(other)

Subsumption.

upset()

Subsuming concepts.