<commit_before># -*- coding: utf-8 -*-
# (c) 2013,2014 <NAME>, Elmyra UG
import logging
from cornice import Service
from elmyra.ip.access.epo.imageutil import tiff_to_png
from elmyra.ip.access.epo.ops import ops_published_data_search, get_ops_image, get_ops_client
from elmyra.ip.util.numbers.common import split_patent_number
from elmyra.ip.util.cql.cheshire3_parser import parse as cql_parse, Diagnostic

log = logging.getLogger(__name__)

# ------------------------------------------
#   services
# ------------------------------------------
ops_published_data_search_service = Service(
    name='ops-published-data-search',
    path='/api/ops/published-data/search',
    description="OPS search interface")

ops_family_publication_service = Service(
    name='ops-family-publication',
    path='/api/ops/{patent}/family/publication',
    description="OPS family publication interface")

ops_drawing_service = Service(
    name='ops-drawing',
    path='/api/ops/{patent}/image/drawing',
    description="OPS drawing interface")

ops_fullimage_service = Service(
    name='ops-fullimage',
    path='/api/ops/{patent}/image/full',
    description="OPS fullimage interface")



# ------------------------------------------
#   handlers
# ------------------------------------------
@ops_published_data_search_service.get(accept="application/json")
def ops_published_data_search_handler(request):
    """Search for published-data at OPS"""

    # constituents: abstract, biblio and/or full-cycle
    constituents = request.params.get('constituents', 'biblio')

    # CQL query string
    query = request.params.get('query', '')
    log.info('query start: ' + query)

    # Parse and recompile CQL query string to apply number normalization
    try:
        query_object = cql_parse(query)
        query = query_object.toCQL()
    except Diagnostic as ex:
        log.warn('CQL parse error: query="{0}", reason={1}'.format(query, str(ex)))

    # range: x-y, maximum delta is 100
    range = request.params.get('range', '1-25')

    result = ops_published_data_search(constituents, query, range)
<commit_msg>middleware: log cql query before and after parsing<commit_after># -*- coding: utf-8 -*-
# (c) 2013,2014 <NAME>, Elmyra UG
import logging
from cornice import Service
from elmyra.ip.access.epo.imageutil import tiff_to_png
from elmyra.ip.access.epo.ops import ops_published_data_search, get_ops_image, get_ops_client
from elmyra.ip.util.numbers.common import split_patent_number
from elmyra.ip.util.cql.cheshire3_parser import parse as cql_parse, Diagnostic

log = logging.getLogger(__name__)

# ------------------------------------------
#   services
# ------------------------------------------
ops_published_data_search_service = Service(
    name='ops-published-data-search',
    path='/api/ops/published-data/search',
    description="OPS search interface")

ops_family_publication_service = Service(
    name='ops-family-publication',
    path='/api/ops/{patent}/family/publication',
    description="OPS family publication interface")

ops_drawing_service = Service(
    name='ops-drawing',
    path='/api/ops/{patent}/image/drawing',
    description="OPS drawing interface")

ops_fullimage_service = Service(
    name='ops-fullimage',
    path='/api/ops/{patent}/image/full',
    description="OPS fullimage interface")



# ------------------------------------------
#   handlers
# ------------------------------------------
@ops_published_data_search_service.get(accept="application/json")
def ops_published_data_search_handler(request):
    """Search for published-data at OPS"""

    # constituents: abstract, biblio and/or full-cycle
    constituents = request.params.get('constituents', 'biblio')

    # CQL query string
    query = request.params.get('query', '')
    log.info('query raw: ' + query)

    # Parse and recompile CQL query string to apply number normalization
    try:
        query_object = cql_parse(query)
        query = query_object.toCQL()
    except Diagnostic as ex:
        log.warn('CQL parse error: query="{0}", reason={1}'.format(query, str(ex)))

    log.info('query cql: ' + query)

    # range: x-y, maximum delta is 100
    range = request.params.get('range', '1-25')

    result = ops_published_data_search(constituents, query, range)

{'fraction_non_alphanumeric': 0.19196637085474078, 'fraction_numerical': 0.008407286314806165, 'mean_word_length': 2.9547553093259467, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3103475', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1244, 'n_words': 270}