<commit_before>class MseWriter:
    def __init__(self, filename):
        self.file = open(filename, "w")
        self.indent_level = 0
        self.blockstack = []

    def indent(self):
        self.file.write(self.indent_level * "\t")

    def increase_indent(self):
        self.indent_level += 1

    def decrease_indent(self):
        self.indent_level -= 1

    def writeline(self, text):
        self.indent()
        self.file.write(text + "\n")

    def addfield(self, fieldname, fieldcontent):
        self.writeline(fieldname + ": " + fieldcontent)

    def startblock(self, blockname):
        self.writeline(blockname + ":")
        self.increase_indent()
        self.blockstack.append(blockname)

    def endblock(self, blockname):
        self.decrease_indent()
        if (blockname != self.blockstack.pop()):
            raise Exception("BlockCloseError")


def writecard(writer, card):
    writer.startblock("card")
    writer.addfield("name", card["name"])
    writer.addfield("casting cost", card["cost"])
    #super type
    #subtype
    writer.startblock("rule text")
    for line in card["rules_text"].split("\n"):
        writer.writeline(card["rules_text"])
    writer.endblock("rule text")
    if "pt" in card:
        power, toughness = card["pt"].split("/")
        writer.addfield("power", power)
        writer.addfield("toughness", toughness)

if __name__ == "__main__":
    squire = {"name": "Squire", "cost": "1W", "pt": "1/2", "types": "Creature - Human Soldier", "rules_text": "Winning"}
    writecard(MseWriter("test_set"), squire)<commit_msg>Fix output set - add header<commit_after>class MseWriter:
    def __init__(self, filename):
        self.file = open(filename, "w")
        self.indent_level = 0
        self.blockstack = []

    def indent(self):
        self.file.write(self.indent_level * "\t")

    def increase_indent(self):
        self.indent_level += 1

    def decrease_indent(self):
        self.indent_level -= 1

    def writeline(self, text):
        self.indent()
        self.file.write(text + "\n")

    def addfield(self, fieldname, fieldcontent):
        self.writeline(fieldname + ": " + fieldcontent)

    def startblock(self, blockname):
        self.writeline(blockname + ":")
        self.increase_indent()
        self.blockstack.append(blockname)

    def endblock(self, blockname):
        self.decrease_indent()
        if (blockname != self.blockstack.pop()):
            raise Exception("BlockCloseError")

    def writecard(self, card):
        self.startblock("card")
        self.addfield("name", card["name"])
        self.addfield("casting cost", card["cost"])
        #super type
        #subtype
        self.startblock("rule text")
        for line in card["rules_text"].split("\n"):
            self.writeline(card["rules_text"])
        self.endblock("rule text")
        if "pt" in card:
            power, toughness = card["pt"].split("/")
            self.addfield("power", power)
            self.addfield("toughness", toughness)

    def writeheader(self):
        self.addfield("mse version", "0.3.8")
        self.addfield("game", "magic")
        self.addfield("stylesheet", "new")

if __name__ == "__main__":
    squire = {"name": "Squire", "cost": "1W", "pt": "1/2", "types": "Creature - Human Soldier", "rules_text": "Winning"}
    writer = MseWriter("set")
    writer.writeheader()
    writer.writecard(squire)
{'fraction_non_alphanumeric': 0.15258215962441316, 'fraction_numerical': 0.0044014084507042256, 'mean_word_length': 2.746153846153846, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4685918', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1041, 'n_words': 214}