def remove_non_semantic_nodes()

in utils/trees.py [0:0]


    def remove_non_semantic_nodes(tree_rep):
        '''
        Method functionally removes the non-semantic nodes from a tree representation.

        :param: (AnyNode) Pointer to the input tree.
        :return: (AnyNode) Pointer to a new tree carrying only semantic nodes.
        '''
        # Check if all the children are terminal.
        if all(c.is_leaf for c in tree_rep.children):
            return AnyNode(id=tree_rep.id, children=[AnyNode(id=c.id) for c in tree_rep.children])

        # If the above check fails, filter the terminal children
        # and get the non-terminal child nodes.
        non_terminal_children = filter(lambda c: not c.is_leaf, tree_rep.children)
        new_children = [TopSemanticTree.remove_non_semantic_nodes(c) for c in non_terminal_children]
        
        return AnyNode(id=tree_rep.id, children=new_children)