Fixed #18 : Parsing and evaluating Python
This commit is contained in:
@@ -5,7 +5,7 @@ import time
|
||||
from core.Event import Event
|
||||
|
||||
|
||||
class ExecutionContextActions:
|
||||
class ContextActions:
|
||||
TESTING = "Testing"
|
||||
INIT_SHEERKA = "Init Sheerka"
|
||||
EVALUATE_USER_INPUT = "Evaluate user input"
|
||||
@@ -18,9 +18,16 @@ class ExecutionContextActions:
|
||||
EVALUATION = "Evaluation"
|
||||
AFTER_EVALUATION = "After Evaluation"
|
||||
|
||||
EVALUATING_CONCEPT = "Evaluating concept"
|
||||
BUILD_CONCEPT = "Building all attributes"
|
||||
BUILD_CONCEPT_ATTR = "Building one attribute"
|
||||
EVAL_CONCEPT = "Evaluating all attributes"
|
||||
EVAL_CONCEPT_ATTR = "Evaluating one attribute"
|
||||
|
||||
|
||||
class ContextHint:
|
||||
REDUCE_CONCEPTS = "Reduce Concepts" # to tell the process to only keep the meaningful results
|
||||
EXPRESSION_ONLY_REQUESTED = "Expression Only"
|
||||
|
||||
|
||||
ids = {} # keep track of the next execution context id, for a given event id
|
||||
@@ -51,7 +58,7 @@ class ExecutionContext:
|
||||
who: str,
|
||||
event: Event,
|
||||
sheerka,
|
||||
action: ExecutionContextActions,
|
||||
action: ContextActions,
|
||||
action_context: object,
|
||||
desc: str = None,
|
||||
logger=None,
|
||||
@@ -102,6 +109,10 @@ class ExecutionContext:
|
||||
def long_id(self):
|
||||
return f"{self.event.get_digest()}:{self._id}"
|
||||
|
||||
@property
|
||||
def medium_id(self):
|
||||
return f"{self.event.get_digest()[:8]}:{self._id}"
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self._id
|
||||
@@ -143,7 +154,7 @@ class ExecutionContext:
|
||||
|
||||
def push(self,
|
||||
who: str,
|
||||
action: ExecutionContextActions,
|
||||
action: ContextActions,
|
||||
action_context: object,
|
||||
desc: str = None,
|
||||
logger=None):
|
||||
@@ -162,6 +173,9 @@ class ExecutionContext:
|
||||
self._children.append(child)
|
||||
return child
|
||||
|
||||
def get_parent(self):
|
||||
return self._parent
|
||||
|
||||
def get_children(self, level=-1):
|
||||
"""
|
||||
recursively look for children
|
||||
@@ -173,6 +187,30 @@ class ExecutionContext:
|
||||
if level != 1:
|
||||
yield from child.get_children(level - 1)
|
||||
|
||||
def get_parents(self, level=-1):
|
||||
"""
|
||||
recursively look for parent
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
if level == 0 or self._parent is None:
|
||||
return
|
||||
|
||||
yield self._parent
|
||||
yield from self._parent.get_parents(level - 1)
|
||||
|
||||
def in_context(self, hint: ContextHint):
|
||||
return hint in self.protected_hints or \
|
||||
hint in self.global_hints or \
|
||||
hint in self.private_hints
|
||||
|
||||
def get_from_short_term_memory(self, key):
|
||||
return self.sheerka.get_from_short_term_memory(self, key)
|
||||
|
||||
def log(self, message: str, who: str = None):
|
||||
"""Send debug information to logger"""
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
self._start = time.time_ns()
|
||||
return self
|
||||
|
||||
Reference in New Issue
Block a user