pyirk._builtin.scopes
Scope-machinery extracted from :mod:pyirk.builtin_entities.
Like :mod:pyirk._builtin.taxonomy, this module only binds the (partially
loaded) builtin_entities module object as _be. All accesses to its
module-globals (items like I16, relations like R20, and already
migrated helpers like instance_of) happen module-qualified and exclusively
at call time inside function/method bodies — never at import time.
Module Contents
Classes
Context manager to for creating (“atomic”) statements in the scope of other (bigger statements). E.g. establishing a relationship between two items as part of the assertions of a theorem-item |
|
Context manager containing methods which are math-related |
|
A scoping context manager to handle conditions |
|
A scoping context manager for universally or existentially quantified statements. |
Functions
Create a namespace-object (dict) and a Scope-Item :param name: the name of the scope :return: |
|
Add relations defined by 3-tuples (sub, rel, obj) to the respective scope. |
|
Return a list of all scope-items which are associated with this entity like [scope:setting, scope:premise, scope:assertion] for a proposition-item. |
|
Convenience method for items which usually have scopes: allow easy access to subscopes |
|
Data
API
- pyirk._builtin.scopes.__all__
[‘_register_scope’, ‘add_relations_to_scope’, ‘get_scopes’, ‘get_items_defined_in_scope’, ‘ScopingCM…
- pyirk._builtin.scopes._register_scope(self, name: str, scope_type: str = None) tuple[dict, pyirk.core.Item]
Create a namespace-object (dict) and a Scope-Item :param name: the name of the scope :return:
- pyirk._builtin.scopes.add_relations_to_scope(relation_tuples: Union[list, tuple], scope: pyirk.core.Entity)
Add relations defined by 3-tuples (sub, rel, obj) to the respective scope.
:param relation_tuples: :param scope: :return:
- pyirk._builtin.scopes.get_scopes(entity: pyirk.core.Entity) List[pyirk.core.Item]
Return a list of all scope-items which are associated with this entity like [scope:setting, scope:premise, scope:assertion] for a proposition-item.
:param entity: :return:
- pyirk._builtin.scopes.get_items_defined_in_scope(scope: pyirk.core.Item) List[pyirk.core.Entity]
- class pyirk._builtin.scopes.ScopingCM(itm: pyirk.core.Item, namespace: dict, scope: pyirk.core.Item, parent_scope_cm=None)
Context manager to for creating (“atomic”) statements in the scope of other (bigger statements). E.g. establishing a relationship between two items as part of the assertions of a theorem-item
Initialization
- _all_instances
[]
- _instances
‘defaultdict(…)’
- valid_subscope_types
None
- __enter__()
implicitly called in the head of the with statement :return:
- __exit__(exc_type, exc_val, exc_tb)
- __getattr__(name: str)
This function allows to use `cm.
instead of I2345. where I2345 is the parent object of the scope. :param name: :return:
- new_var(**kwargs) pyirk.core.Entity
create and register a new variable to the respective scope
:param kwargs: dict of len == 1 (to allow (almost) arbitrary variable names)
:return:
- _new_var(variable_name: str, variable_object: pyirk.core.Entity) pyirk.core.Entity
- new_rel(sub: pyirk.core.Entity, pred: pyirk.core.Relation, obj: pyirk.core.Entity, qualifiers=None, overwrite=False) pyirk.core.Statement
Create a new statement (“relation edge”) in the current scope
:param sub: subject :param pred: predicate (Relation-Instance) :param obj: object :param qualifiers: List of RawQualifiers :param overwrite: boolean flag that the new statement should replace the old one
:return: the newly created Statement
- _check_scope()
- _create_subscope_cm(scope_type: str, cls: type)
:param scope_type: a str like “AND”, “OR”, “NOT” :param cls: the class to instantiate, e.g. RulePremiseSubScopeCM
- copy_from(other_obj: pyirk.core.Item, scope_name: str = None)
- _get_new_var_from_old(old_var: pyirk.core.Item, strict=False) pyirk.core.Item
- _copy_mapping(mapping_item: pyirk.core.Item) pyirk.core.Item
- _get_premise_vars() dict
return a dict of all items that were defined in the associated setting scope.
key: variable names (via R23__has_name_in_scope) value: item objects
- class pyirk._builtin.scopes.AbstractMathRelatedScopeCM(itm: pyirk.core.Item, namespace: dict, scope: pyirk.core.Item, parent_scope_cm=None)
Bases:
pyirk._builtin.scopes.ScopingCMContext manager containing methods which are math-related
Initialization
- new_equation(lhs: pyirk.core.Item, rhs: pyirk.core.Item, force_key: str = None) pyirk.core.Item
convenience method to create a equation-related Statement
:param lhs: :param rhs: :return:
- new_math_relation(lhs: pyirk.core.Item, rsgn: str, rhs: pyirk.core.Item, add_relations: dict = {}, force_key: str = None) pyirk.core.Item
convenience method to create a math_relation-related StatementObject (aka “Statement”)
:param lhs: left hand side :param rsgn: relation sign :param rhs: right hand sign
:return: new instance of
- AND() pyirk._builtin.scopes.ConditionSubScopeCM
Create a new subscope of type “AND”, which can hold arbitrary statements. These statements are considered to be AND-related in a boolean sense.
- OR() pyirk._builtin.scopes.ConditionSubScopeCM
Create a new subscope of type “OR”, which can hold arbitrary statements. These statements are considered to be OR-related in a boolean sense.
- NOT() pyirk._builtin.scopes.ConditionSubScopeCM
Create a new subscope of type “NOT”, which can hold arbitrary statements. These statements are considered to be negated in a boolean sense.
- check_scope_type(*args, **kwargs)
This method might raise an exception in subclasses
- class pyirk._builtin.scopes.ConditionSubScopeCM(*args, **kwargs)
Bases:
pyirk._builtin.scopes.AbstractMathRelatedScopeCMA scoping context manager to handle conditions
Initialization
- valid_subscope_types
None
- add_condition_statement(subj, pred, obj, qualifiers=None)
- add_condition_math_relation(*args, **kwargs)
- new_condition_var(**kwargs)
- check_scope_type(forbidden)
- class pyirk._builtin.scopes.QuantifiedSubScopeCM(*args, **kwargs)
Bases:
pyirk._builtin.scopes.ConditionSubScopeCMA scoping context manager for universally or existentially quantified statements.
Created by methods universally_quantified() and existentially_quantified() of _proposition__CM
Initialization
- pyirk._builtin.scopes._get_subscopes(self)
Convenience method for items which usually have scopes: allow easy access to subscopes
- pyirk._builtin.scopes._get_subscope(self, name: str)