<commit_before>/* This file is part of the YAZ toolkit.
 * Copyright (C) 1995-2009 Index Data
 * See the file LICENSE for details.
 */

/** \file
 * \brief yaz-ztest Generic Frontend Server
 */

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <yaz/log.h>
#include <yaz/backend.h>
#include <yaz/ill.h>
#include <yaz/diagbib1.h>

#include "ztest.h"

static int log_level=0;
static int log_level_set=0;

int ztest_search(void *handle, bend_search_rr *rr);
int ztest_sort(void *handle, bend_sort_rr *rr);
int ztest_present(void *handle, bend_present_rr *rr);
int ztest_esrequest(void *handle, bend_esrequest_rr *rr);
int ztest_delete(void *handle, bend_delete_rr *rr);

/** \brief use term value as hit count 
    \param s RPN structure
    \return >= 0: search term number or -1: not found
   
    Traverse RPN tree 'in order' and use term value as hit count.
    Only terms  that looks a numeric is used.. Returns -1 if
    no sub tree has a hit count term
*/
static Odr_int get_term_hit(Z_RPNStructure *s)
{
    Odr_int h = -1;
    switch(s->which)
    {
    case Z_RPNStructure_simple:
        if (s->u.simple->which == Z_Operand_APT)
        {
            Z_AttributesPlusTerm *apt = s->u.simple->u.attributesPlusTerm;
            if (apt->term->which == Z_Term_general)
            {
                Odr_oct *oct = apt->term->u.general;
                if (oct->len > 0 && oct->buf[0] >= '0' && oct->buf[0] <= '9')
                {
                    char *endptr;
                    WRBUF hits_str = wrbuf_alloc();
                    wrbuf_write(hits_str, (const char *) oct->buf, oct->len);
#ifdef WIN32
                    h = _strtoui64(wrbuf_cstr(hits_str), &endptr, 10);
#else
                    h = strtoll(wrbuf_cstr(hits_str), &endptr, 10);
#endif
                    wrbuf_destroy(hits_str);<commit_msg>Use odr_atoi to decode fake hit count (in term)<commit_after>/* This file is part of the YAZ toolkit.
 * Copyright (C) 1995-2009 Index Data
 * See the file LICENSE for details.
 */

/** \file
 * \brief yaz-ztest Generic Frontend Server
 */

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <yaz/log.h>
#include <yaz/backend.h>
#include <yaz/ill.h>
#include <yaz/diagbib1.h>

#include "ztest.h"

static int log_level=0;
static int log_level_set=0;

int ztest_search(void *handle, bend_search_rr *rr);
int ztest_sort(void *handle, bend_sort_rr *rr);
int ztest_present(void *handle, bend_present_rr *rr);
int ztest_esrequest(void *handle, bend_esrequest_rr *rr);
int ztest_delete(void *handle, bend_delete_rr *rr);

/** \brief use term value as hit count 
    \param s RPN structure
    \return >= 0: search term number or -1: not found
   
    Traverse RPN tree 'in order' and use term value as hit count.
    Only terms  that looks a numeric is used.. Returns -1 if
    no sub tree has a hit count term
*/
static Odr_int get_term_hit(Z_RPNStructure *s)
{
    Odr_int h = -1;
    switch(s->which)
    {
    case Z_RPNStructure_simple:
        if (s->u.simple->which == Z_Operand_APT)
        {
            Z_AttributesPlusTerm *apt = s->u.simple->u.attributesPlusTerm;
            if (apt->term->which == Z_Term_general)
            {
                Odr_oct *oct = apt->term->u.general;
                if (oct->len > 0 && oct->buf[0] >= '0' && oct->buf[0] <= '9')
                {
                    char *endptr;
                    WRBUF hits_str = wrbuf_alloc();
                    wrbuf_write(hits_str, (const char *) oct->buf, oct->len);
                    h = odr_atoi(wrbuf_cstr(hits_str));
                    wrbuf_destroy(hits_str);
{'fraction_non_alphanumeric': 0.12368064952638701, 'fraction_numerical': 0.012990527740189444, 'mean_word_length': 2.5334608030592736, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 53, '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': '2074664', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1290, 'n_words': 359}