Parser of berki style problems and generator of latex file
Samo Penic
2018-10-31 7029ac1681eecdd35113cc26f32a538ee2065bca
Picture parser started.
2 files modified
32 ■■■■■ changed files
tools/BerkiParse.py 27 ●●●●● patch | view | raw | blame | history
tools/Problem.py 5 ●●●●● patch | view | raw | blame | history
tools/BerkiParse.py
@@ -6,6 +6,8 @@
    def __init__(self, text=None):
        self.text = text.split("\n")
        self.introduction = None
        self.picture=None
        self.parsedPicture=None
        self.subproblems = []
        self.solutions = None
        self.parsedSolutions = None
@@ -58,6 +60,13 @@
            varlist.append("\n".join(self.text[start:end]))
        return varlist
    def findPicture(self):
        gen = self.findStartEndMarkers("Pic")
        varlist = []
        for stat, end in gen:
            varlist.append("\n".join(self.text[start:end]))
        return varlist
    def parseSections(self):
        self.introduction = self.findIntroduction()
        self.subproblems = self.findSubproblems()
@@ -66,6 +75,23 @@
        self.variables = self.findVariables()
        self.parsedVariables = self.parseVariables()
        self.variableGenerator = self.prepareGenerators()
        self.picture = self.findPicture()
        self.parsedPicture = self.parsePicture()
    def parsePicture(self):
        parsedPictures = []
        for p in self.picture:
            retval = {"filename": [], "size:": [], "position": []}
            for r in p.split("\n"):
                sp = r.split(":")
                if sp[0].strip("\n\t'") == "ime":
                    retval["filename"].append(sp[1].strip("\n\t"))
                elif sp[0].strip("\n\t'") == "sirina":
                    retval["size"].append(sp[1].strip("\n\t"))
                elif sp[0].strip("\n\t'") == "polozaj":
                    retval["position"].append(sp[1].strip("\n\t"))
            parsedPictures.append(retval)
        return parsedPictures
    def parseSolutions(self):
        parsedSolutions = []
@@ -124,6 +150,7 @@
    def get_parsed_sections(self):
        return (
            self.introduction,
            self.parsedPicture,
            self.subproblems,
            self.parsedVariables,
            self.parsedSolutions,
tools/Problem.py
@@ -83,12 +83,13 @@
    def __init__(self, parser=None):
        self.introduction = None
        self.subproblems = None
        self.picture= None
        self.parsedSolutions = None
        self.parsedVariables = None
        self.variableGenerator = None
        self.varDict = {}
        if parser is not None:
            self.introduction, self.subproblems, self.parsedVariables, self.parsedSolutions, self.variableGenerator = (
            self.introduction, self.picture, self.subproblems, self.parsedVariables, self.parsedSolutions, self.variableGenerator = (
                parser.get_parsed_sections()
            )
            # self.generateVariables()
@@ -161,4 +162,4 @@
        for p in self.subproblems:
            sp.append(self.substitute_variables(p))
        sol = self.generateSolutions()
        return {"introduction": intro, "subproblems": sp, "solutions": sol}
        return {"introduction": intro, "subproblems": sp, "picture": self.picture, "solutions": sol}