<commit_before>from copy import deepcopy
from semantix.parsers import caosql
from semantix.parsers.caosql import nodes
from semantix.caos import ConceptClass

class Query(object):
    def __init__(self, text, vars=None, context=None):
        self.text = text
        self.vars = vars
        self.context = context

class ParseContext(object):
    pass

class CaosQLQueryAdapter(object):
    def __init__(self):
        self.parser = caosql.CaosQLParser()

    def adapt(self, query, vars=None):
        xtree = self.parser.parse(query)

        qtree = self._transform_tree(xtree)

        qtext = self._render_query(qtree)

        return Query(qtext, vars)

    def _transform_tree(self, xtree):

        qtree = deepcopy(xtree)
        query = qtree.child_nodes[0]
        nodetype = type(query)

        if nodetype != nodes.SelectQueryNode:
            selnode = nodes.SelectQueryNode()
            selnode.targets = [query]
            query = selnode

        context = ParseContext()
        self._transform_select(context, query)

        return qtree

    def _transform_select(self, context, tree):
        self._transform_select_from(context, tree.fromlist)
        self._transform_select_targets(context, tree.targets)
        pass

    def _transform_select_from(self, context, fromlist):
        pass

    def _transform_select_targets(self, context, targets):
        pass

    def _render_query(self, qtree):
        return 'dummy'<commit_msg>caosql: Port to generic AST<commit_after>from copy import deepcopy
from semantix.parsers import caosql
from semantix.parsers.caosql import nodes
from semantix.caos import ConceptClass

class Query(object):
    def __init__(self, text, vars=None, context=None):
        self.text = text
        self.vars = vars
        self.context = context

class ParseContext(object):
    pass

class CaosQLQueryAdapter(object):
    def __init__(self):
        self.parser = caosql.CaosQLParser()

    def adapt(self, query, vars=None):
        xtree = self.parser.parse(query)

        qtree = self._transform_tree(xtree)

        qtext = self._render_query(qtree)

        return Query(qtext, vars)

    def _transform_tree(self, xtree):

        qtree = deepcopy(xtree)
        query = qtree.children[0]
        nodetype = type(query)

        if nodetype != nodes.SelectQueryNode:
            selnode = nodes.SelectQueryNode()
            selnode.targets = [query]
            query = selnode

        context = ParseContext()
        self._transform_select(context, query)

        return qtree

    def _transform_select(self, context, tree):
        self._transform_select_from(context, tree.fromlist)
        self._transform_select_targets(context, tree.targets)
        pass

    def _transform_select_from(self, context, fromlist):
        pass

    def _transform_select_targets(self, context, targets):
        pass

    def _render_query(self, qtree):
        return 'dummy'
{'fraction_non_alphanumeric': 0.08551959114139693, 'fraction_numerical': 0.0006814310051107325, 'mean_word_length': 2.7306226175349426, 'pattern_counts': {'":': 0, '<': 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': '4615946', 'n_tokens_mistral': 895, 'n_tokens_neox': 851, 'n_words': 201}