def validateInput(relation, fds, mvds): if len(relation) >MAX_NUM_OF_ATTRIBUTES: return views.getErrorMessageBox("Bitte nicht mehr als "+str(MAX_NUM_OF_ATTRIBUTES)+" Attribute eingeben!") elif not checkIfAllAttributesAreInRelation(fds, mvds, relation): return views.getErrorMessageBox("Es gibt Attribute, die in FDs/MVDs vorkommen, aber nicht in der Relation!") elif fds==[] and mvds==[]: return views.getErrorMessageBox("Ich verstehe deine Eingabe nicht. Hast du die FDs/MVDs korrekt eingegeben?") else: return "OK"
def validateInput(relation, fds, mvds): if len(relation) > MAX_NUM_OF_ATTRIBUTES: return views.getErrorMessageBox("Bitte nicht mehr als " + str(MAX_NUM_OF_ATTRIBUTES) + " Attribute eingeben!") elif not checkIfAllAttributesAreInRelation(fds, mvds, relation): return views.getErrorMessageBox( "Es gibt Attribute, die in FDs/MVDs vorkommen, aber nicht in der Relation!" ) elif fds == [] and mvds == []: return views.getErrorMessageBox( "Ich verstehe deine Eingabe nicht. Hast du die FDs/MVDs korrekt eingegeben?" ) else: return "OK"
def parseInput(input): wordCharacters = "A-Za-z\s" + UMLAUTS #one character attribute names, i.e. in R(ABC) match = re.search( "\[([" + wordCharacters + "]+)\]\[(([" + wordCharacters + "]|\s|->{1,2})+)\]\[(.+)\]", input) #attribute names with multiple characters, like in R(Attr1,Attr2,Attr3) match2 = re.search( "\[([" + wordCharacters + ",]+)\]\[(([" + wordCharacters + ",]|\s|->{1,2})+)\]\[(.+)\]", input) resetDictionaries() if match or match2: if match: relationString = match.group(1).replace(" ", "") fdMvdString = match.group(2).replace(" ", "") numberOfAttributes = match.group(4) else: numberOfAttributes = match2.group(4) relationString = match2.group(1).replace(" ", "") relationStringArray = relationString.split(",") relationString = "" attributes = set("") alphabet = list(string.ascii_uppercase) for attr in relationStringArray: if attr not in attributes: replacement = alphabet[len(attributes)] attributes.add(attr) dictionaryReplToName[replacement] = attr dictionaryNameToRepl[attr] = replacement relationString = relationString + replacement fdMvdString = match2.group(2).replace(" ", "") relation = set(relationString) fds, mvds = parseInputFDsMVDs(fdMvdString) inputCheck = validateInput(relation, fds, mvds) if inputCheck == "OK": return (relation, fds, mvds, numberOfAttributes) else: return (inputCheck, ) else: return (views.getErrorMessageBox( "Falsches Eingabeformat. Bitte überprüfe deine Eingabe!"), )
def parseInput(input): wordCharacters = "A-Za-z\s"+UMLAUTS #one character attribute names, i.e. in R(ABC) match = re.search("\[(["+wordCharacters+"]+)\]\[((["+wordCharacters+"]|\s|->{1,2})+)\]\[(.+)\]", input) #attribute names with multiple characters, like in R(Attr1,Attr2,Attr3) match2 = re.search("\[(["+wordCharacters+",]+)\]\[((["+wordCharacters+",]|\s|->{1,2})+)\]\[(.+)\]", input) resetDictionaries() if match or match2: if match: relationString = match.group(1).replace(" ", "") fdMvdString = match.group(2).replace(" ", "") numberOfAttributes = match.group(4) else: numberOfAttributes = match2.group(4) relationString = match2.group(1).replace(" ", "") relationStringArray = relationString.split(",") relationString = "" attributes = set("") alphabet = list(string.ascii_uppercase) for attr in relationStringArray: if attr not in attributes: replacement = alphabet[len(attributes)] attributes.add(attr) dictionaryReplToName[replacement] = attr dictionaryNameToRepl[attr] = replacement relationString = relationString + replacement fdMvdString = match2.group(2).replace(" ", "") relation = set(relationString) fds, mvds = parseInputFDsMVDs(fdMvdString) inputCheck = validateInput(relation, fds, mvds) if inputCheck == "OK": return(relation, fds, mvds, numberOfAttributes) else: return (inputCheck,) else: return (views.getErrorMessageBox("Falsches Eingabeformat. Bitte überprüfe deine Eingabe!"),)
inputCandidateKeys = str(form['candidatekeys'].value).replace( " ", "") except KeyError: inputCandidateKeys = "" if inputValidation.validateCandidateKeys(relation, fds, inputCandidateKeys): alert = views.getSuccessMessageBox("Richtig!") inputpanel = views.inputToString(relation, fds, mvds, additionalFds, additionalMvds, "default", candidatekeys) numberOfSteps = numberOfSteps + 1 quizform = quizForms.normalForm(numberOfTries, numberOfSteps, relationString, fdsString) + htmlend() else: alert = views.getErrorMessageBox("Leider falsch!") quizform = quizForms.candidateKeys( numberOfTries, numberOfSteps, relationString, fdsString, candidatekeys, noRightSideAttributes) + htmlend() if (step == '3-1'): #validate normal form selectedNF = str(form['normalform'].value) if DBnormalizer.getHighestNormalForm(relation, fds, mvds) == selectedNF: alert = views.getSuccessMessageBox("Richtig!") numberOfSteps = numberOfSteps + 1 quizform = quizForms.canonicalCoverLeftReduction( numberOfTries, numberOfSteps, relationString, fdsString, fds) else: alert = views.getErrorMessageBox("Leider falsch!") quizform = quizForms.normalForm(numberOfTries, numberOfSteps,
#candidate keys numberOfSteps = numberOfSteps + 1 quizform = quizForms.candidateKeys(numberOfTries, numberOfSteps, relationString, fdsString) + htmlend() if (step=='2'): #validate candidate keys try: inputCandidateKeys= str(form['candidatekeys'].value).replace(" ", "") except KeyError: inputCandidateKeys = "" if inputValidation.validateCandidateKeys(relation, fds, inputCandidateKeys): alert = views.getSuccessMessageBox("Richtig!") inputpanel = views.inputToString(relation, fds,mvds, additionalFds, "default", candidatekeys) numberOfSteps = numberOfSteps + 1 quizform = quizForms.normalForm(numberOfTries, numberOfSteps, relationString, fdsString) + htmlend() else: alert = views.getErrorMessageBox("Leider falsch!") quizform = quizForms.candidateKeys(numberOfTries, numberOfSteps, relationString, fdsString) + htmlend() if (step=='3-1'): #validate normal form selectedNF = str(form['normalform'].value) if DBnormalizer.getHighestNormalForm(relation, fds, mvds) == selectedNF: alert = views.getSuccessMessageBox("Richtig!") numberOfSteps = numberOfSteps + 1 quizform = quizForms.canonicalCoverLeftReduction(numberOfTries, numberOfSteps, relationString, fdsString, fds) else: alert = views.getErrorMessageBox("Leider falsch!") quizform = quizForms.normalForm(numberOfTries, numberOfSteps, relationString, fdsString) + htmlend() inputpanel = views.inputToString(relation, fds,mvds, additionalFds, "default", candidatekeys) if (step=='3-2'): #validate left reduction leftSides = []