<commit_before>import re
from exc import *
from metadata import metadata as m
from util import classproperty

class BaseQuery(object):

    def __init__(self, string='', params=None):
        self.string = string or ''
        self.params = params or {}

    def copy(self):
        return self.__class__(string=self.string, params=self.params.copy())

    def __copy__(self):
        return self.copy()

    def execute(self, string=None, automap=True):
        return m.cypher(string or self.string, params=self.params, automap=automap)

class Query(BaseQuery):

    @property
    def string(self):
        return '\n'.join([self._clauses, self._return, self._order, self._skip, self._limit]).strip()

    @string.setter
    def string(self, string):
        self._clauses = re.split(re.compile(r'\s+return\s+', flags=re.I), string)[0].strip()
        self._return = ''
        self._order = ''
        self._skip = ''
        self._limit = ''
        self._set(string)

    def _set(self, string):
        if re.search(re.compile(r'\breturn\b', flags=re.I), string):
            self._return = 'return ' + re.split(re.compile(r'\breturn\b', flags=re.I), string)[1].strip()
            self._return = re.split(re.compile(r'\b(order|skip|limit)\b', flags=re.I), self._return)[0].strip()

        if re.search(re.compile(r'\border\b', flags=re.I), string):
            self._order = 'order ' + re.split(re.compile(r'\border\b', flags=re.I), string)[1].strip()
            self._order = re.split(re.compile(r'\b(skip|limit)\b', flags=re.I), self._order)[0].strip()

        if re.search(re.compile(r'\bskip\b', flags=re.I), string):
            self._skip = 'skip ' + re.split(re.compile(r'\bskip\b', flags=re.I), string)[1].strip()
            self._skip = re.split(re.compile(r'\blimit\b', flags=re.I), self._skip)[0].strip()

        if re.search(re.compile(r'\blimit\b', flags=re.I), string):
            self._limit = 'limit ' + re.split(re.compile(r'\blimit\b', flags=re.I), string)[1].strip()

    def set(self, string):
        copy = self.copy()
        copy._set(string)
        return copy

    def _append(self, string):
        self._clauses += ' ' + string.strip()

    def append(self, string):
        copy = self.copy()
        copy._append(string)
        return copy

    @classmethod
    def node(cls, nodecls):
        string = """
        start classnode=node({classnode_id})
        match instance-[?:__extends__|__instance_of__*..]->classnode
        where instance-[:__instance_of__]->()
        return instance
        """
        return cls(string=string, params={'classnode_id': nodecls.classnode.id})

    """
    WARNING: The methods below are very limited and provided for partial Elixir-like compatibility only
    """
    def start(self, **kwargs):
        copy = self.copy()
        nodes = []<commit_msg>fixed append to set as well<commit_after>import re
from exc import *
from metadata import metadata as m
from util import classproperty

class BaseQuery(object):

    def __init__(self, string='', params=None):
        self.string = string or ''
        self.params = params or {}

    def copy(self):
        return self.__class__(string=self.string, params=self.params.copy())

    def __copy__(self):
        return self.copy()

    def execute(self, string=None, automap=True):
        return m.cypher(string or self.string, params=self.params, automap=automap)

class Query(BaseQuery):

    @property
    def string(self):
        return '\n'.join([self._clauses, self._return, self._order, self._skip, self._limit]).strip()

    @string.setter
    def string(self, string):
        self._clauses = ''
        self._return = ''
        self._order = ''
        self._skip = ''
        self._limit = ''
        self._append(string)

    def _set(self, string):
        if re.search(re.compile(r'\breturn\b', flags=re.I), string):
            self._return = 'return ' + re.split(re.compile(r'\breturn\b', flags=re.I), string)[1].strip()
            self._return = re.split(re.compile(r'\b(order|skip|limit)\b', flags=re.I), self._return)[0].strip()

        if re.search(re.compile(r'\border\b', flags=re.I), string):
            self._order = 'order ' + re.split(re.compile(r'\border\b', flags=re.I), string)[1].strip()
            self._order = re.split(re.compile(r'\b(skip|limit)\b', flags=re.I), self._order)[0].strip()

        if re.search(re.compile(r'\bskip\b', flags=re.I), string):
            self._skip = 'skip ' + re.split(re.compile(r'\bskip\b', flags=re.I), string)[1].strip()
            self._skip = re.split(re.compile(r'\blimit\b', flags=re.I), self._skip)[0].strip()

        if re.search(re.compile(r'\blimit\b', flags=re.I), string):
            self._limit = 'limit ' + re.split(re.compile(r'\blimit\b', flags=re.I), string)[1].strip()

    def set(self, string):
        copy = self.copy()
        copy._set(string)
        return copy

    def _append(self, string):
        self._clauses += re.split(re.compile(r'\breturn\b', flags=re.I), string)[0].strip()
        self._set(string)

    def append(self, string):
        copy = self.copy()
        copy._append(string)
        return copy

    @classmethod
    def node(cls, nodecls):
        string = """
        start classnode=node({classnode_id})
        match instance-[?:__extends__|__instance_of__*..]->classnode
        where instance-[:__instance_of__]->()
        return instance
        """
        return cls(string=string, params={'classnode_id': nodecls.classnode.id})

    """
    WARNING: The methods below are very limited and provided for partial Elixir-like compatibility only
    """
    def start(self, **kwargs):
        copy = self.copy()
        nodes = []
{'fraction_non_alphanumeric': 0.1651166871380944, 'fraction_numerical': 0.0028075100894893843, 'mean_word_length': 2.6774193548387095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2025100', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1799, 'n_words': 363}