pyirk._builtin.taxonomy
Taxonomy-related helper functions extracted from :mod:pyirk.builtin_entities.
These functions are pure with respect to import time (they do not need any
module-globals of builtin_entities while this module is being imported).
Functions that use builtin_entities module-globals (I.., R.., qff_*) at
call time access them module-qualified via the _be module object, whose
attributes are only read once the functions are actually called.
Module Contents
Functions
Check if |
|
Recursively iterate over super and parent classes and |
|
Return True if itm1 is an (indirect) subclass (via) R3__is_subclass_of itm2 |
|
Returns True if instance_itm.R4 is cls_itm or an (indirect) subclass (R3) of cls_itm. |
|
Create an instance (R4) of an item. Try to obtain the label by inspection of the calling context (if r1 is None). |
|
Return all direct and indirect instances of a class |
|
Recursively compile a list of all subclasses. |
|
Set R51__instances_are_from for all current instances of a class. |
Data
API
- pyirk._builtin.taxonomy.__all__
[‘allows_instantiation’, ‘get_taxonomy_tree’, ‘is_subclass_of’, ‘is_instance_of’, ‘instance_of’, ‘is…
- pyirk._builtin.taxonomy.allows_instantiation(itm: pyirk.core.Item) bool
Check if
itmis an instance of metaclass or a subclass of it. If true, this entity is considered a class by itself and is thus allowed to have instances and subclassesPossibilities:
I2 = itm -> True (by our definition) I2 -R4-> itm -> True (trivial, itm is an ordinary class) I2 -R4-> I100 -R4-> itm -> False (I100 is ordinary class → itm is ordinary instance) I2 -R3-> itm -> True (subclasses of I2 are also metaclasses) I2 -R3-> I100 -R4-> itm -> True (I100 is subclass of metaclass → itm is metaclass instance) I2 -R3-> I100 -R3-> I101 -R3-> I102 -R4-> itm -> True (same) # multiple times R4: false I2 -R4-> I100 -R3-> I101 -R3-> I102 -R4-> itm -> False (I100 is ordinary class → itm is ordinary instance of its sub-sub-class) I2 -R3-> I100 -R4-> I101 -R3-> I102 -R4-> itm -> False (same) I2 -R3-> I100 -R3-> I101 -R3-> I102 -R4-> itm -> True (same) I2 -R4-> I100 -R3-> I101 -R3-> I102 -R3-> itm -> True (itm is an ordinary sub-sub-sub-subclass) I2 -R3-> I100 -R4-> I101 -R3-> I102 -R3-> itm -> True (itm is an sub-sub-subclass of I101 which is an instance of a subclass of I2):param itm: item to test :return: bool
- pyirk._builtin.taxonomy.get_taxonomy_tree(itm, add_self=True) list
Recursively iterate over super and parent classes and
:param itm: an item :raises NotImplementedError: DESCRIPTION
:return: list of 2-tuples like [(None, I456), (“R3”, I123), (“R4”, I2)] :rtype: dict
- pyirk._builtin.taxonomy.is_subclass_of(itm1: pyirk.core.Item, itm2: pyirk.core.Item, allow_id=False, strict=True) bool
Return True if itm1 is an (indirect) subclass (via) R3__is_subclass_of itm2
:param allow_id: bool, indicate that itm1 == itm2 is also considered as valid. default: False
- pyirk._builtin.taxonomy.is_instance_of(inst_itm: pyirk.core.Item, cls_itm: pyirk.core.Item, allow_R30_secondary: bool = False, strict=True) bool
Returns True if instance_itm.R4 is cls_itm or an (indirect) subclass (R3) of cls_itm.
:param inst_itm: Item representing the instance :param cls_itm: Item representing the class :param allow_R30_secondary: bool, accept also relations via R30__is_secondary_instance_of :param strict: bool; if true we raise an exception if there is no parent class
- pyirk._builtin.taxonomy.instance_of(cls_entity, r1: str = None, r2: str = None, qualifiers: List[pyirk.core.Item] = None, force_key: str = None) pyirk.core.Item
Create an instance (R4) of an item. Try to obtain the label by inspection of the calling context (if r1 is None).
:param cls_entity: the type of which an instance is created :param r1: the label; if None use inspection to fetch it from the left hand side of the assignment :param r2: the description (optional) :param qualifiers: list of RawQualifiers (optional); will be passed to the R4__is_instance_of relation
if
cls_entityhas a defining scope andqualifiersis None, then an appropriate R20__has_defining_scope- qualifier will be added to the R4__is_instance_of-relation of the new item.:return: new item
- pyirk._builtin.taxonomy.is_generic_instance(itm: pyirk.core.Item) bool
- pyirk._builtin.taxonomy.is_relevant_item(itm)
- pyirk._builtin.taxonomy.get_direct_instances_of(cls_item: pyirk.core.Item, filter=None) List[pyirk.core.Item]
- pyirk._builtin.taxonomy.get_all_instances_of(cls_item: pyirk.core.Item, filter=None) List[pyirk.core.Item]
Return all direct and indirect instances of a class
- pyirk._builtin.taxonomy.get_all_subclasses_of(cls_item: pyirk.core.Item, strict=True) List[pyirk.core.Item]
Recursively compile a list of all subclasses.
- pyirk._builtin.taxonomy.close_class_with_R51(cls_item: pyirk.core.Item)
Set R51__instances_are_from for all current instances of a class.
Note: this does not prevent the creation of further instances (because they can be related via R47__is_same_as to the existing instances).
:returns: tuple-item containing all instances