Implemented a first and basic version of a Rete rule engine
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from core.builtin_concepts_ids import BuiltinConcepts
|
||||
from core.concept import Concept, ConceptParts
|
||||
from core.error import ErrorObj
|
||||
from core.global_symbols import ErrorObj
|
||||
|
||||
|
||||
class UserInputConcept(Concept):
|
||||
@@ -167,6 +167,37 @@ class ParserResultConcept(Concept):
|
||||
return parser.name if isinstance(parser, BaseParser) else str(parser)
|
||||
|
||||
|
||||
class RuleEvaluationResultConcept(Concept):
|
||||
"""
|
||||
Result of the evaluation of a rule, using the Rete algorithm
|
||||
"""
|
||||
|
||||
ALL_ATTRIBUTES = ["rule"]
|
||||
|
||||
def __init__(self, rule=None, concept_id=None):
|
||||
Concept.__init__(self,
|
||||
BuiltinConcepts.RULE_EVALUATION_RESULT,
|
||||
True,
|
||||
False,
|
||||
BuiltinConcepts.RULE_EVALUATION_RESULT,
|
||||
id=concept_id,
|
||||
bound_body="rule")
|
||||
self.set_value("rule", rule)
|
||||
self._metadata.is_evaluated = True
|
||||
|
||||
def __repr__(self):
|
||||
return f"RuleEvaluationResult(rule={self.rule})"
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, RuleEvaluationResultConcept):
|
||||
return False
|
||||
|
||||
return self.rule == other.rule
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self._metadata.name, self.rule))
|
||||
|
||||
|
||||
class InvalidReturnValueConcept(Concept, ErrorObj):
|
||||
"""
|
||||
Error returned when an evaluator is not correctly coded
|
||||
|
||||
Reference in New Issue
Block a user