Introduced ConceptsAlgebra

This commit is contained in:
2020-09-27 20:28:50 +02:00
parent 978e5a5939
commit d100b7e8b3
18 changed files with 541 additions and 50 deletions
+32 -2
View File
@@ -53,6 +53,7 @@ class BuiltinConcepts(Enum):
# builtin attributes
ISA = "is a" # when a concept is an instance of another one
HASA = "has a" # when a concept has/owns another concept
AUTO_EVAL = "auto eval" # when the concept must be auto evaluated
# object
@@ -74,7 +75,8 @@ class BuiltinConcepts(Enum):
IS_EMPTY = "is empty" # when a set is empty
NO_RESULT = "no result" # no return value returned
INVALID_RETURN_VALUE = "invalid return value" # the return value of an evaluator is not correct
ALREADY_DEFINED = "already defined" # when you try to add the same object twice (a concept or whatever)
CONCEPT_ALREADY_DEFINED = "concept already defined" # when you try to add the same object twice (a concept or whatever)
PROPERTY_ALREADY_DEFINED = "property already defined" # When you try to add the same element in a property
NOP = "no operation" # no operation concept. Does nothing
CONCEPT_EVAL_ERROR = "concept evaluation error" # cannot evaluate a property or metadata of a concept
ENUMERATION = "enum" # represents a list or a set
@@ -171,7 +173,8 @@ BuiltinErrors = [str(e) for e in {
BuiltinConcepts.TOO_MANY_ERRORS,
BuiltinConcepts.MULTIPLE_ERRORS,
BuiltinConcepts.INVALID_RETURN_VALUE,
BuiltinConcepts.ALREADY_DEFINED,
BuiltinConcepts.CONCEPT_ALREADY_DEFINED,
BuiltinConcepts.PROPERTY_ALREADY_DEFINED,
BuiltinConcepts.CONCEPT_EVAL_ERROR,
BuiltinConcepts.CONCEPT_ALREADY_IN_SET,
BuiltinConcepts.NOT_A_SET,
@@ -479,6 +482,33 @@ class ConceptAlreadyInSet(Concept):
return self.get_value("concept_set")
class PropertyAlreadyDefined(Concept):
def __init__(self, property_name=None, property_value=None, concept=None):
super().__init__(BuiltinConcepts.PROPERTY_ALREADY_DEFINED,
True,
False,
BuiltinConcepts.PROPERTY_ALREADY_DEFINED)
self.set_value(ConceptParts.BODY, property_name)
self.set_value("property_value", property_value)
self.set_value("concept", concept)
self.metadata.is_evaluated = True
def __repr__(self):
return f"PropertyAlreadyDefined(property={self.property_name}, value={self.property_value}, concept={self.concept})"
@property
def property_name(self):
return self.body
@property
def property_value(self):
return self.get_value("property_value")
@property
def concept(self):
return self.get_value("concept")
class ConditionFailed(Concept):
def __init__(self, condition=None, concept=None, prop=None):
super().__init__(BuiltinConcepts.CONDITION_FAILED,