master > master: Schema robuster gemacht; simple class, um Aspekte leichter aufzurufen

This commit is contained in:
RD
2021-05-06 23:34:25 +02:00
parent 6f6de00296
commit 28a1e313b3
4 changed files with 131 additions and 73 deletions

View File

@@ -5,7 +5,7 @@
# IMPORTS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from __future__ import annotations;
from __future__ import annotations
from lark import Tree;
from typing import List;
@@ -15,10 +15,12 @@ from aussagenlogik.schema import isTrueSymbol;
from aussagenlogik.schema import isFalseSymbol;
from aussagenlogik.schema import isNegation;
from aussagenlogik.schema import isConjunction;
from aussagenlogik.schema import isLongConjunction;
from aussagenlogik.schema import isDisjunction;
from aussagenlogik.schema import isLongDisjunction;
from aussagenlogik.schema import isImplication;
from aussagenlogik.schema import getTeilformeln;
from aussagenlogik.schema import getName;
from aussagenlogik.schema import SyntaxBaum;
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# GLOBALE KONSTANTEN
@@ -30,8 +32,8 @@ from aussagenlogik.schema import getName;
# METHODEN
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def rekursiv_eval(fml: Tree, I: List[str]) -> int:
teilfml = getTeilformeln(fml);
def rekursiv_eval(fml: SyntaxBaum, I: List[str]) -> int:
subfml = fml.children;
if isAtom(fml):
name = getName(fml);
return 1 if (name in I) else 0;
@@ -43,19 +45,25 @@ def rekursiv_eval(fml: Tree, I: List[str]) -> int:
elif isFalseSymbol(fml):
return 0;
elif isNegation(fml):
val0 = rekursiv_eval(teilfml[0], I);
val0 = rekursiv_eval(subfml[0], I);
return 1 - val0;
elif isConjunction(fml):
val0 = rekursiv_eval(teilfml[0], I);
val1 = rekursiv_eval(teilfml[1], I);
val0 = rekursiv_eval(subfml[0], I);
val1 = rekursiv_eval(subfml[1], I);
return min(val0, val1);
elif isLongConjunction(fml):
values = [rekursiv_eval(t, I) for t in subfml];
return min(values);
elif isDisjunction(fml):
val0 = rekursiv_eval(teilfml[0], I);
val1 = rekursiv_eval(teilfml[1], I);
val0 = rekursiv_eval(subfml[0], I);
val1 = rekursiv_eval(subfml[1], I);
return max(val0, val1);
elif isLongDisjunction(fml):
values = [rekursiv_eval(t, I) for t in subfml];
return max(values);
elif isImplication(fml):
val0 = rekursiv_eval(teilfml[0], I);
val1 = rekursiv_eval(teilfml[1], I);
val0 = rekursiv_eval(subfml[0], I);
val1 = rekursiv_eval(subfml[1], I);
return 0 if val0 == 1 and val1 == 0 else 1;
raise Exception('Evaluation nicht möglich!');