galactic.algebras.concept.examples.animals.core

galactic.algebras.concept.examples.animals.core#

galactic.algebras.concept.examples.animals.core module

Defines a sample formal context representing various animals and their attributes.

Variables

  • ANIMAL_DATA — a dictionary containing a sample table

  • ANIMAL_ATTRS — a list of attribute names

Examples

>>> from pprint import pprint
>>> from galactic.algebras.concept.examples.animals.core import (
...     ANIMAL_DATA,
...     ANIMAL_ATTRS,
... )
>>> pprint(ANIMAL_DATA)
{'Cat': ['small', 'fourlegs', 'hair', 'hunt', 'run'],
 'Cow': ['big', 'fourlegs', 'hair', 'hooves'],
 'Dog': ['medium', 'fourlegs', 'hair', 'run'],
 'Dove': ['small', 'twolegs', 'feathers', 'fly'],
 'Duck': ['small', 'twolegs', 'feathers', 'fly', 'swim'],
 'Eagle': ['medium', 'twolegs', 'feathers', 'fly', 'hunt'],
 'Fox': ['medium', 'fourlegs', 'hunt', 'hair', 'run'],
 'Goose': ['small', 'twolegs', 'feathers', 'fly', 'swim'],
 'Hawk': ['small', 'twolegs', 'feathers', 'fly', 'hunt'],
 'Hen': ['small', 'twolegs', 'feathers'],
 'Horse': ['big', 'fourlegs', 'hair', 'run', 'mane', 'hooves'],
 'Lion': ['big', 'fourlegs', 'hair', 'hunt', 'run', 'mane'],
 'Owl': ['small', 'twolegs', 'feathers', 'fly', 'hunt'],
 'Tiger': ['big', 'fourlegs', 'hair', 'hunt', 'run'],
 'Wolf': ['medium', 'fourlegs', 'hair', 'hunt', 'run', 'mane'],
 'Zebra': ['big', 'fourlegs', 'hair', 'run', 'mane', 'hooves']}
>>> pprint(ANIMAL_ATTRS)
['small',
 'medium',
 'big',
 'twolegs',
 'fourlegs',
 'hair',
 'feathers',
 'fly',
 'swim',
 'run',
 'hunt',
 'mane',
 'hooves']
>>> from galactic.algebras.concept.core import create_context_from_dataset
>>> context = create_context_from_dataset(ANIMAL_DATA, ANIMAL_ATTRS)
>>> context
<galactic.algebras.concept.core.Context object at 0x...>
>>> context.domain
<galactic.algebras.concept.core.ItemUniverse object at 0x...>
>>> [str(item) for item in context.domain]
['Dove', 'Hen', 'Duck', 'Goose', ..., 'Tiger', 'Lion', 'Horse', 'Zebra', 'Cow']
>>> context.co_domain
<galactic.algebras.concept.core.AttrUniverse object at 0x...>
>>> [str(attribute) for attribute in context.co_domain]
['small', 'medium', 'big', 'twolegs', 'fourlegs', ..., 'hooves']
>>> [(str(item), str(attribute)) for item, attribute in context]
[('Dove', 'small'), ('Dove', 'twolegs'), ..., ('Cow', 'hooves')]