master > master: Teile auslagern + Vereinfachungen
This commit is contained in:
@@ -6,11 +6,11 @@
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from __future__ import annotations;
|
||||
import re;
|
||||
# install: lark; lark-parser; lark-parser[regex].
|
||||
# https://lark-parser.readthedocs.io/en/latest/grammar.html
|
||||
from lark import Lark;
|
||||
from lark import Tree;
|
||||
from typing import List;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# GLOBALE KONSTANTEN
|
||||
@@ -53,12 +53,61 @@ lexerAussagenlogik = Lark(
|
||||
);
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# MAIN METHOD string -> parts
|
||||
# METHODE: string -> Syntaxbaum
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
def string_to_parts(u: str) -> Tree:
|
||||
def stringToSyntaxbaum(u: str) -> Tree:
|
||||
try:
|
||||
u_lexed = lexerAussagenlogik.parse(u);
|
||||
return u_lexed;
|
||||
except:
|
||||
raise Exception('Ausdruck \033[1m{}\033[0m konnte nicht erkannt werden!'.format(u));
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# METHODEN: Erkennung von Formeltypen
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
def isAtom(fml: Tree) -> bool:
|
||||
return fml.data == 'atom';
|
||||
|
||||
def isBeliebig(fml: Tree) -> bool:
|
||||
return fml.data == 'beliebig';
|
||||
|
||||
def isTrueSymbol(fml: Tree) -> bool:
|
||||
return fml.data == 'wahr';
|
||||
|
||||
def isFalseSymbol(fml: Tree) -> bool:
|
||||
return fml.data == 'falsch';
|
||||
|
||||
def isNegation(fml: Tree) -> bool:
|
||||
return fml.data == 'negation';
|
||||
|
||||
def isConjunction(fml: Tree) -> bool:
|
||||
return fml.data == 'konjunktion';
|
||||
|
||||
def isDisjunction(fml: Tree) -> bool:
|
||||
return fml.data == 'disjunktion';
|
||||
|
||||
def isImplication(fml: Tree) -> bool:
|
||||
return fml.data == 'implikation';
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# METHODEN: Formel -> Teilformeln
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
def getTeilformeln(fml: Tree) -> List[Tree]:
|
||||
return [
|
||||
part for part in fml.children
|
||||
if isinstance(part, Tree)
|
||||
and not part.data == 'junktor'
|
||||
];
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# METHODEN: Formel (Atom/Beliebig) -> Name
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
def getName(fml: Tree) -> str:
|
||||
text = fml.children[0];
|
||||
if isinstance(text, str):
|
||||
return text;
|
||||
raise Exception('Konnte Textinhalt nicht ablesen!');
|
||||
|
||||
Reference in New Issue
Block a user