Package: concepts
Concepts is a simple Python implementation ofFormal Concept Analysis(FCA).FCA provides a mathematical model for describing a set ofobjects(e.g. King
Arthur, Sir Robin, and the holy grail) with a set ofproperties(e.g. human,
knight, king, and mysterious) which each of the objects either has or not. A
table calledformal contextdefines which objects have a given property and
vice versa which properties a given object has.LinksGitHub:https://github.com/xflr6/conceptsPyPI:https://pypi.org/project/concepts/Documentation:https://concepts.readthedocs.ioChangelog:https://concepts.readthedocs.io/en/latest/changelog.htmlIssue Tracker:https://github.com/xflr6/concepts/issuesDownload:https://pypi.org/project/concepts/#filesInstallationThis package runs under Python 2.7 and 3.5+, usepipto install:$pipinstallconceptsThis will also install thebitsetsandgraphvizpackages from PyPI as
required dependencies.Rendering lattice graphs depends on theGraphviz software. Make sure itsdotexecutable is on your systems’ path.QuickstartCreate aformal contextdefining which object has which property, e.g. from
a simple ASCII-art style cross-table withobjectrows andpropertycolumns
(alternatively load a CXT or CSV file):>>>fromconceptsimportContext>>>c=Context.fromstring('''
...            |human|knight|king |mysterious|
... King Arthur|  X  |  X   |  X  |          |
... Sir Robin  |  X  |  X   |     |          |
... holy grail |     |      |     |     X    |
... ''')>>>c# doctest: +ELLIPSIS<Contextobjectmapping3objectsto4properties[dae7402a]at0x...>Querycommon propertiesof objects orcommon objectsof properties
(derivation):>>>c.intension(['King Arthur','Sir Robin'])('human','knight')>>>c.extension(['knight','mysterious'])()Get the closest matchingobjects-properties pairof objects or properties
(formal concepts):>>>c['Sir Robin','holy grail'](('King Arthur','Sir Robin','holy grail'),())>>>c['king',](('King Arthur',),('human','knight','king'))Iterate over theconcept latticeof all objects-properties pairs:>>>forextent,intentinc.lattice:...print('%r%r'%(extent,intent))()('human','knight','king','mysterious')('King Arthur',)('human','knight','king')('holy grail',)('mysterious',)('King Arthur','Sir Robin')('human','knight')('King Arthur','Sir Robin','holy grail')()Make a Graphviz visualization of the lattice (use.graphviz(view=True)to
directly render it and display the resulting PDF):>>>c.lattice.graphviz()# doctest: +ELLIPSIS<graphviz.dot.Digraphobjectat0x...>Further readinghttps://en.wikipedia.org/wiki/Formal_concept_analysishttp://www.upriss.org.uk/fca/The generation of the concept lattice is based on the algorithm from C. Lindig.Fast Concept Analysis. In Gerhard Stumme, editors, Working with Conceptual
Structures - Contributions to ICCS 2000, Shaker Verlag, Aachen, Germany, 2000.The included exampleCXTfiles are taken from Uta Priss’FCA homepageSee alsoThe implementation is based on these Python packages:bitsets– Ordered subsets over a predefined domaingraphviz– Simple Python interface for GraphvizThe following package is build on top of concepts:features– Feature set algebra for linguisticsIf you want to apply FCA to bigger data sets, you might want to considerother
implementationsbased onmore sophisticated algorithmslikeIn-CloseorFcbo.LicenseConcepts is distributed under theMIT license.