def query():
    entries = []
    # get query paramaters
    qParams = get_query_params(request)
    # fills in default_parameters for those not set
    sParams = dict_merge(default_params, qParams)
    # does some clean-up and returns terms as list
    sParams['terms'] = return_terms(sParams['terms'])
    # gets total number of statements
    nTerms = len(sParams['terms'])
    # loops through each term, interpreting it and generating query
    for i in range(nTerms):
        # invokes term parser
        ngrams, qType, lParams = termParser(i, sParams)
        # starts the query factory for interprated term
        sql, args, label, lang, corpus = query_factory(ngrams, lParams['lang'], lParams['case_sens'], lParams['corpus'])
        # run query depending on amount of results from query_factory
        if len(sql) == 1:
            entries += return_single_results(sql,args,lang,label,corpus)
        elif len(sql) > 1:
            if qType == 'agg':
                entries += return_agg_results(sql, args, lang, label, corpus)
            elif qType == 'wildcard' or qType == 'trunctated':
                entries += return_single_results(sql,args,lang,label,corpus)
            else:
                pass
        else:
            pass

    jsonOutput = export_to_json(entries)
    return Response(jsonOutput, mimetype='application/json')