예제 #1
0
    def convert(self, formula):
        '''Convert tupled formula parse tree into graph

        Parameters
        ----------
        formula : tuple
            Tupled tree representation of a formula

        Returns
        -------
        Graph
            DAG representation of a formula
        '''
        self.scope = Scope()
        self.graph = []
        self.root = None
        self.tail = None
        Node.reset_id()
        append_infer_node = False

        if isinstance(formula,
                      tuple) and len(formula) == 2 and formula[0] == '|-:c':
            formula = formula[1]
            append_infer_node = True
            while isinstance(formula, tuple) and formula[0] == '!!':
                formula = formula[2]

        node = self._formula_to_graph(formula)
        if self.tail is not None:
            self.tail.outgoing.append(node)
            node.incoming.append(self.tail)
        else:
            self.root = node

        if append_infer_node:
            node = Node(NodeType.CONSTFUNC, '|-:c')
            self.graph.append(node)
            node.outgoing.append(self.root)
            self.root.incoming.append(node)
            self.root = node

        if not self.debug:
            self._finalize_graph()

        return self.graph
예제 #2
0
    def convert(self, formula):
        '''Convert tupled formula parse tree into tree

        Parameters
        ----------
        formula : tuple
            Tupled tree representation of a formula

        Returns
        -------
        Graph
            tree representation of a formula
        '''
        self.graph = []
        Node.reset_id()

        node = self._formula_to_tree(formula)

        return self.graph