fcapy.context.FormalContext¶
-
class
fcapy.context.FormalContext(data=None, object_names=None, attribute_names=None, **kwargs)¶ A class used to represent Formal Context object from FCA theory.
-
intention(objects)¶ Return maximal set of attributes which are shared by given
objects
-
extension(attributes)¶ Return maximal set of objects which share given
attributes
-
intention_i(object_indexes)¶ Offer the same logic as intention(…) but objects and attributes are defined by their indexes
-
extension_i(attribute_indexes)¶ Offer the same logic as extension(…) but objects and attributes are defined by their indexes
-
to_cxt(path=None)¶ Convert the FormalContext into cxt file format (save if
pathis given)
-
to_json(path=None)¶ Convert the FormalContext into json file format (save if
pathis given)
-
to_csv(path=None, \*\*kwargs)¶ Convert the FormalContext into csv file format (save if
pathis given)
-
to_pandas()¶ Convert the FormalContext into pandas.DataFrame object
Notes
Formal Context K = (G, M, I) - is a triplet of: 1. set of objects G (the property
object_namesin this class) 2. set of attributes M (the propertyattribute_namesin this class) 3. binary relation I between G and M (i.e. “gIm holds True” means “object g has attribute m”)(the property
datain this class)-
__init__(data=None, object_names=None, attribute_names=None, **kwargs)¶ - Parameters
data (`list of `list) – Two dimensional list of bool variables. “data[i][j] = True” represents that i-th object shares j-th attribute
object_names (`list of `str, optional) – Names of objects (rows) of the FormalContext
attribute_names (`list of `str, optional) – Names of attributes (columns) of the FormalContext
**kwargs –
description:`str with human readable description of the FormalContext (stored only in json file format)
Methods
__init__([data, object_names, attribute_names])- param data
Two dimensional list of bool variables.
extension(attributes)Return maximal set of objects which share given
attributesextension_i(attribute_indexes)Return indexes of maximal set of objects which share given
attribute_indexesintention(objects)Return maximal set of attributes which are shared by given
objectsintention_i(object_indexes)Return indexes of maximal set of attributes which are shared by given ``object_indexes`
print_data([max_n_objects, max_n_attributes])Get the FormalContext date in the string formatted as the table
to_csv([path])Convert the FormalContext into csv file format (save if
pathis given)to_cxt([path])Convert the FormalContext into cxt file format (save if
pathis given)to_json([path])Convert the FormalContext into json file format (save if
pathis given)Convert the FormalContext into pandas.DataFrame object
Attributes
Get of set the names of the attributes in the context
Get or set the data with relations between objects and attributes (`list of `list)
Get or set the human readable description of the context
Get the number of attributes in the context (i.e.
Get the number of objects in the context (i.e.
Get of set the names of the objects in the context
-
property
attribute_names¶ Get of set the names of the attributes in the context
-
property
data¶ Get or set the data with relations between objects and attributes (`list of `list)
- Parameters
value (`list of `list) – value[i][j] represents whether i-th object shares j-th attribute
- Raises
AssertionError – If
valueis not a list If ``value` of type list is given (should be `list of `list) If some lists ``value[i]` andvalue[j]have different length (should be the same for anyvalue[i]) If anyvalue[i][j]is not of type `bool
-
property
description¶ Get or set the human readable description of the context
JSON is the only file format to store this information. The description will be lost when saving context to .cxt or .csv
-
extension(attributes)¶ Return maximal set of objects which share given
attributes
-
extension_i(attribute_indexes)¶ Return indexes of maximal set of objects which share given
attribute_indexes
-
intention(objects)¶ Return maximal set of attributes which are shared by given
objects
-
intention_i(object_indexes)¶ Return indexes of maximal set of attributes which are shared by given ``object_indexes`
-
property
n_attributes¶ Get the number of attributes in the context (i.e. len(data[0])
-
property
n_objects¶ Get the number of objects in the context (i.e. len(data))
-
property
object_names¶ Get of set the names of the objects in the context
-
print_data(max_n_objects=20, max_n_attributes=10)¶ Get the FormalContext date in the string formatted as the table
- Parameters
max_n_objects (`int) – Maximal number of objects to print. If it is less then
n_objectsthen printmax_n_objects/2objects from the “top” and the “bottom” of the contextmax_n_attributes (`int) – Maximal number of attributes to print. If it is less then
n_attributesthen printmax_n_attributes/2attributes from the “left” and the “right” part of the context
- Returns
data_to_print – A string with the context data formatted as the table
- Return type
`str
-
to_csv(path=None, **kwargs)¶ Convert the FormalContext into csv file format (save if
pathis given)- Parameters
- Returns
context – If
pathis None, the string with .csv file data is returned. Ifpathis given - return None- Return type
`str
-
to_cxt(path=None)¶ Convert the FormalContext into cxt file format (save if
pathis given)
-
to_json(path=None)¶ Convert the FormalContext into json file format (save if
pathis given)
-
to_pandas()¶ Convert the FormalContext into pandas.DataFrame object
- Returns
df – The dataframe with boolean variables,
object_namesturned intodf.index,attribute_namesturned intodf.columns- Return type
pandas.DataFrame
-