Refactored to use a single implementation for concept evaluation

This commit is contained in:
2019-12-21 15:08:06 +01:00
parent b24b858b81
commit 41e0885486
17 changed files with 920 additions and 644 deletions
+48 -11
View File
@@ -41,10 +41,11 @@ class BuiltinConcepts(Enum):
INVALID_RETURN_VALUE = "invalid return value" # the return value of an evaluator is not correct
CONCEPT_ALREADY_DEFINED = "concept already defined" # when you try to add the same concept twice
NOP = "no operation" # no operation concept. Does nothing
PROPERTY_EVAL_ERROR = "property evaluation error" # cannot evaluate a property of a concept
CONCEPT_EVAL_ERROR = "concept evaluation error" # cannot evaluate a property or metadata of a concept
ENUMERATION = "enum" # represents a list or a set
LIST = "list" # represents a list
CANNOT_RESOLVE_VALUE_ERROR = "value cannot be resolved" # don't know how to find concept value
CONCEPT_NOT_INITIALIZED = "concept not evaluated" # Try to work on a concept that is not evaluated
NODE = "node"
GENERIC_NODE = "generic node"
@@ -56,6 +57,21 @@ class BuiltinConcepts(Enum):
def __str__(self):
return "__" + self.name
BuiltinErrors = [str(e) for e in {
BuiltinConcepts.ERROR,
BuiltinConcepts.UNKNOWN_CONCEPT,
BuiltinConcepts.CONCEPT_TOO_LONG,
BuiltinConcepts.UNKNOWN_PROPERTY,
BuiltinConcepts.TOO_MANY_SUCCESS,
BuiltinConcepts.TOO_MANY_ERRORS,
BuiltinConcepts.INVALID_RETURN_VALUE,
BuiltinConcepts.CONCEPT_ALREADY_DEFINED,
BuiltinConcepts.CONCEPT_EVAL_ERROR,
BuiltinConcepts.CANNOT_RESOLVE_VALUE_ERROR,
BuiltinConcepts.CONCEPT_NOT_INITIALIZED
}]
"""
Some concepts have a specific implementation
It's mainly to a have proper __repr__ implementation, or because they are singleton (is_unique=True)
@@ -251,31 +267,52 @@ class AfterEvaluationConcept(Concept):
super().__init__(BuiltinConcepts.AFTER_EVALUATION, True, True, BuiltinConcepts.AFTER_EVALUATION)
class PropertyEvalError(Concept):
def __init__(self, property_name=None, concept=None, error=None):
super().__init__(BuiltinConcepts.PROPERTY_EVAL_ERROR,
class ConceptEvalError(Concept):
def __init__(self, error=None, concept=None, property_name=None):
super().__init__(BuiltinConcepts.CONCEPT_EVAL_ERROR,
True,
False,
BuiltinConcepts.PROPERTY_EVAL_ERROR,
property_name)
BuiltinConcepts.CONCEPT_EVAL_ERROR,
error)
self.set_prop("concept", concept)
self.set_prop("error", error)
self.set_prop("property_name", property_name)
def __repr__(self):
return f"PropertyEvalError(property={self.property_name}, concept={self.concept}), error={self.error})"
return f"ConceptEvalError(error={self.error}, concept={self.concept}, property={self.property_name})"
@property
def error(self):
return self.body
@property
def concept(self):
return self.props["concept"].value
@property
def error(self):
return self.props["error"].value
def property_name(self):
return self.props["property_name"].value
class ConceptNotInitialized(Concept):
def __init__(self, error=None, concept=None, property_name=None):
super().__init__(BuiltinConcepts.CONCEPT_NOT_INITIALIZED,
True,
False,
BuiltinConcepts.CONCEPT_NOT_INITIALIZED,
error)
self.set_prop("concept", concept)
def __repr__(self):
return f"ConceptNotInitialized(error={self.error}, concept={self.concept})"
@property
def property_name(self):
def error(self):
return self.body
@property
def concept(self):
return self.props["concept"].value
class EnumerationConcept(Concept):
def __init__(self, iteration=None):