def is_parseable(self, with_manipulation=False): pdg = DirectedGraph() #parse decision graph for rule in self.rules: a,b = rule.head, rule.tail[0] pdg.add_vertex(a) pdg.add_vertex(b) pdg.add_edge(a,b) if not with_manipulation: if pdg.is_cyclic(): return False for leaf in pdg.leaves(): if not leaf.is_terminal(): return False return True