Example #1
0
 def autocnf_from_file(filepath):
     output = []
     with open(filepath, "r+") as file:
         for line in file.read().splitlines():
             if line.startswith("#") or not line.strip():
                 continue
             cnf_format = Node(line.lower()).evaluate()
             output.append(Clause.clauses_to_string(cnf_format))
     return "\n".join(output)
Example #2
0
        elif self.operator == "=":
            return Clause.equalityOperator(left_cnf, right_cnf)
        elif self.operator == ">":
            return Clause.implicationOperator(left_cnf, right_cnf)
        else:
            raise ValueError("Invalid operator! '{}'".format(self.operator))

    def __repr__(self):
        return self.expression

    @staticmethod
    def autocnf_from_file(filepath):
        output = []
        with open(filepath, "r+") as file:
            for line in file.read().splitlines():
                if line.startswith("#") or not line.strip():
                    continue
                cnf_format = Node(line.lower()).evaluate()
                output.append(Clause.clauses_to_string(cnf_format))
        return "\n".join(output)


if __name__ == "__main__":
    x = '~(C v D) v ((~A v F) & (J v O))'
    print(x)

    root = Node(x)
    root_cnf = root.evaluate()
    print(root_cnf)
    print(Clause.clauses_to_string(root_cnf))