<commit_before>__all__ = ['Query', 'And', 'Or', 'HasAgent', 'FromMeshIds', 'HasHash',
           'HasSources', 'HasOnlySource', 'HasReadings', 'HasDatabases',
           'HasType', 'HasNumAgents', 'HasNumEvidence', 'FromPapers',
           'EmptyQuery']

from indra.sources.indra_db_rest.util import make_db_rest_request


class Query:
    """The parent of all query objects."""
    def __init__(self):
        self._inverted = False
        self.__compiled_json = None
        self.__compiled_str = None

    # Here are defined some other functions to get info from the server.

    def get(self, result_type, limit=None, sort_by=None, offset=None,
            **other_params):
        """Get results from the API of the given type.

        Parameters
        ----------
        result_type : str
            The options are 'statements', 'interactions', 'relations', 'agents',
            and 'hashes', indicating the type of result you want.
        limit : Optional[int]
            The maximum number of statements you want to try and retrieve. The
            server will by default limit the results, and any value exceeding
            that limit will be "overruled".
        sort_by : Optional[str]
            The value can be 'default', 'ev_count', or 'belief'.
        offset : Optional[int]
            The offset of the query to begin at.

        Other Parameters
        ----------------
        'statements'
        filter_ev : bool
            Indicate whether evidence should have the same filters applied as
            the statements themselves, where appropriate (e.g. in the case of a
            filter by paper).
        ev_limit : int
            Limit the number of evidence returned per Statement.

        'relations' and 'agents'
        with_hashes : bool
            Choose whether the hashes for each Statement be included along with
            each grouped heading.

        'agents'
        complexes_covered : list[int]
            A list (or set) of complexes that have already come up in the agent
            groups returned. This prevents duplication.
        """
        simple = self.__compiled_json is None
        if simple:
            query_json = self.to_json()
        else:
            query_json = self.__compiled_json
        resp = make_db_rest_request('post', f'query/{result_type}',
                                    data={'query': query_json,
                                          'kwargs': other_params},
                                    params=dict(limit=limit, sort_by=sort_by,
                                                offset=offset, simple=simple))
        resp_json = resp.json()
        self.__compiled_json = resp_json['query_json']
        self.__compiled_str = None
        return resp_json<commit_msg>Return QueryResult object from `get` method.<commit_after>__all__ = ['Query', 'And', 'Or', 'HasAgent', 'FromMeshIds', 'HasHash',
           'HasSources', 'HasOnlySource', 'HasReadings', 'HasDatabases',
           'HasType', 'HasNumAgents', 'HasNumEvidence', 'FromPapers',
           'EmptyQuery']

from indra.sources.indra_db_rest.query_results import QueryResult
from indra.sources.indra_db_rest.util import make_db_rest_request


class Query:
    """The parent of all query objects."""
    def __init__(self):
        self._inverted = False
        self.__compiled_json = None
        self.__compiled_str = None

    # Here are defined some other functions to get info from the server.

    def get(self, result_type, limit=None, sort_by=None, offset=None,
            **other_params):
        """Get results from the API of the given type.

        Parameters
        ----------
        result_type : str
            The options are 'statements', 'interactions', 'relations', 'agents',
            and 'hashes', indicating the type of result you want.
        limit : Optional[int]
            The maximum number of statements you want to try and retrieve. The
            server will by default limit the results, and any value exceeding
            that limit will be "overruled".
        sort_by : Optional[str]
            The value can be 'default', 'ev_count', or 'belief'.
        offset : Optional[int]
            The offset of the query to begin at.

        Other Parameters
        ----------------
        'statements'
        filter_ev : bool
            Indicate whether evidence should have the same filters applied as
            the statements themselves, where appropriate (e.g. in the case of a
            filter by paper).
        ev_limit : int
            Limit the number of evidence returned per Statement.

        'relations' and 'agents'
        with_hashes : bool
            Choose whether the hashes for each Statement be included along with
            each grouped heading.

        'agents'
        complexes_covered : list[int]
            A list (or set) of complexes that have already come up in the agent
            groups returned. This prevents duplication.
        """
        simple = self.__compiled_json is None
        if simple:
            query_json = self.to_json()
        else:
            query_json = self.__compiled_json
        resp = make_db_rest_request('post', f'query/{result_type}',
                                    data={'query': query_json,
                                          'kwargs': other_params},
                                    params=dict(limit=limit, sort_by=sort_by,
                                                offset=offset, simple=simple))
        resp_json = resp.json()
        self.__compiled_json = resp_json['query_json']
        self.__compiled_str = None
        return QueryResult.from_json(resp_json)
{'fraction_non_alphanumeric': 0.0859704641350211, 'fraction_numerical': 0.0, 'mean_word_length': 1.8834262544348708, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3851735', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1380, 'n_words': 494}