Fixed #41 : Implement concept 'and'

This commit is contained in:
2021-03-06 19:12:22 +01:00
parent 05577012f3
commit bd8e027827
6 changed files with 153 additions and 98 deletions
+29
View File
@@ -18,6 +18,22 @@ EVAL_STEPS = PARSE_STEPS + [BuiltinConcepts.BEFORE_EVALUATION, BuiltinConcepts.E
PARSERS = ["EmptyString", "ShortTermMemory", "Sequence", "Bnf", "Sya", "Python"]
def remove_python_nodes(context, return_values):
"""
Try to reduce the number of return_values by removing return values with python node
:param context:
:param return_values:
:return:
"""
res = []
for ret_val in return_values:
value = context.sheerka.objvalue(ret_val)
if not hasattr(value, "get_python_node"):
res.append(ret_val)
return res
def is_same_success(context, return_values):
"""
Returns True if all returns values are successful and have the same value
@@ -89,12 +105,25 @@ def expect_one(context, return_values):
# too many winners, which one to choose ?
if number_of_successful > 1:
# first, try to remove python node results.
# In case of conflict, the concept take precedence over the natural Python result
# as it is considered as an override (overload ?)
successful_results = remove_python_nodes(context, successful_results)
if len(successful_results) == 1:
return sheerka.ret(
context.who,
True,
successful_results[0].body,
parents=return_values)
if is_same_success(context, successful_results):
return sheerka.ret(
context.who,
True,
successful_results[0].value,
parents=return_values)
else:
if context.logger and context.logger.isEnabledFor(logging.DEBUG):
context.log(f"Too many successful results found by expect_one()", context.who)
+3 -3
View File
@@ -1,12 +1,12 @@
To make Jupyter notebook recognize Sheerka,
the file kernel.json must be copied where the kernels are declared
* First, open the kernel.json file and make sure that the path to SheerkaKernel is correct.
* First, open the kernel.json file and make sure that the path to SheerkaKernel.py is correct.
* The copy it to the correct location
* You can use the command 'jupyter kernelspec install </path/to/kernel>'
* or simply copy it using cp ;-)
* or simply copy 'Sheerka/kernel.json' into the folder 'kernels' (You may have to create it!)
Valid locations for kernel.json are
Valid locations for 'Sheerka/kernel.json' are
| | Unix | Windows |
|----|------| ---------------|
+1 -1
View File
@@ -57,7 +57,7 @@ class Event(object):
return self._digest
if not isinstance(self.message, str):
raise NotImplementedError
raise NotImplementedError(f"message={self.message}")
to_hash = f"Event:{self.user_id}{self.date}{self.message}{self.parents}".encode("utf-8")
self._digest = hashlib.sha256(to_hash).hexdigest()