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

/**
 * \file logrpn.c
 * \brief Implements Z39.50 Query Printing
 */

#include <stdio.h>
#include <assert.h>

#include <yaz/log.h>
#include <yaz/logrpn.h>
#include <yaz/oid_db.h>

static const char *relToStr(Odr_int v)
{
    const char *str = 0;
    switch (v)
    {
    case 1: str = "Less than"; break;
    case 2: str = "Less than or equal"; break;
    case 3: str = "Equal"; break;
    case 4: str = "Greater or equal"; break;
    case 5: str = "Greater than"; break;
    case 6: str = "Not equal"; break;
    case 100: str = "Phonetic"; break;
    case 101: str = "Stem"; break;
    case 102: str = "Relevance"; break;
    case 103: str = "AlwaysMatches"; break;
    }
    return str;
}

static void attrStr(Odr_int type, Odr_int value, char *str)
{
    const char *rstr;
    *str = '\0';
    switch (type)
    {
    case 1:
        sprintf(str, "use");
        break;
    case 2:
        rstr = relToStr(value);
        if (rstr)
            sprintf(str, "relation=%s", rstr);
        else
            sprintf(str, "relation=%d", value);
        break;
    case 3:
        switch (value)
        {
        case 1:
            sprintf(str, "position=First in field");
            break;
        case 2:
            sprintf(str, "position=First in any subfield");
            break;
        case 3:
            sprintf(str, "position=Any position in field");
            break;
        default:
            sprintf(str, "position");
        }
        break;
    case 4:
        switch (value)
        {
        case 1:
            sprintf(str, "structure=Phrase");
            break;
        case 2:
            sprintf(str, "structure=Word");
            break;
        case 3:
            sprintf(str, "structure=Key");
            break;
        case 4:
            sprintf(str, "structure=Year");
            break;
        case 5:
            sprintf(str, "structure=Date");
            break;
        case 6:
            sprintf(str, "structure=Word list");
            break;
        case 100:
            sprintf(str, "structure=Date (un)");
            break;
        case 101:
            sprintf(str, "structure=Name (norm)");
            break;
        case 102:
            sprintf(str, "structure=Name (un)");
            break;
        case 103:
            sprintf(str, "structure=Structure");
            break;
        case 104:
            sprintf(str, "structure=urx");
            break;
        case 105:
            sprintf(str, "structure=free-form-text");
            break;
        case 106:
            sprintf(str, "structure=document-text");
            break;
        case 107:
            sprintf(str, "structure=local-number");
            break;
        case 108:
            sprintf(str, "structure=string");
            break;
        case 109:
            sprintf(str, "structure=numeric string");
            break;
        default:
            sprintf(str, "structure");
        }
        break;
    case 5:
        switch (value)
        {
        case 1:
            sprintf(str, "truncation=Right");
            break;
        case 2:
            sprintf(str, "truncation=Left");
            break;
        case 3:
            sprintf(str, "truncation=Left&right");
            break;
        case 100:
            sprintf(str, "truncation=Do not truncate");
            break;
        case 101:
            sprintf(str, "truncation=Process #");
            break;
        case 102:
            sprintf(str, "truncation=re-1");
            break;
        case 103:
            sprintf(str, "truncation=re-2");
            break;
        case 104:
            sprintf(str, "truncation=CCL");
            break;
        default:
            sprintf(str, "truncation");
        }
        break;
    case 6:
        switch(value)
        {
        case 1:
            sprintf(str, "completeness=Incomplete subfield");
            break;
        case 2:
            sprintf(str, "completeness=Complete subfield");
            break;
        case 3:
            sprintf(str, "completeness=Complete field");
            break;
        default:
            sprintf(str, "completeness");
        }
        break;
    }
    if (*str)
        sprintf(str + strlen(str), " (%d=%d)", type, value);
    else
        sprintf(str, "%d=%d", type, value);
}

/*
 * zlog_attributes: print attributes of term
 */
static void zlog_attributes(Z_AttributesPlusTerm *t, int depth,
                            const Odr_oid *ast, int loglevel)
{
    int of, i;
    char str[80];
    int num_attributes = t->attributes->num_attributes;
    
    for (of = 0; of < num_attributes; of++)
    {
        char attset_name_buf[OID_STR_MAX];
        const char *attset_name = 0;
        Z_AttributeElement *element;
        element = t->attributes->attributes[of];
        if (element->attributeSet)
        {
            attset_name = yaz_oid_to_string_buf(element->attributeSet,
                                                0, attset_name_buf);
        }<commit_msg>Fix print in logrpn<commit_after>/* This file is part of the YAZ toolkit.
 * Copyright (C) 1995-2010 Index Data
 * See the file LICENSE for details.
 */

/**
 * \file logrpn.c
 * \brief Implements Z39.50 Query Printing
 */

#include <stdio.h>
#include <assert.h>

#include <yaz/log.h>
#include <yaz/logrpn.h>
#include <yaz/oid_db.h>

static const char *relToStr(Odr_int v)
{
    const char *str = 0;
    switch (v)
    {
    case 1: str = "Less than"; break;
    case 2: str = "Less than or equal"; break;
    case 3: str = "Equal"; break;
    case 4: str = "Greater or equal"; break;
    case 5: str = "Greater than"; break;
    case 6: str = "Not equal"; break;
    case 100: str = "Phonetic"; break;
    case 101: str = "Stem"; break;
    case 102: str = "Relevance"; break;
    case 103: str = "AlwaysMatches"; break;
    }
    return str;
}

static void attrStr(Odr_int type, Odr_int value, char *str)
{
    const char *rstr;
    *str = '\0';
    switch (type)
    {
    case 1:
        sprintf(str, "use");
        break;
    case 2:
        rstr = relToStr(value);
        if (rstr)
            sprintf(str, "relation=%s", rstr);
        else
            sprintf(str, "relation=" ODR_INT_PRINTF, value);
        break;
    case 3:
        switch (value)
        {
        case 1:
            sprintf(str, "position=First in field");
            break;
        case 2:
            sprintf(str, "position=First in any subfield");
            break;
        case 3:
            sprintf(str, "position=Any position in field");
            break;
        default:
            sprintf(str, "position");
        }
        break;
    case 4:
        switch (value)
        {
        case 1:
            sprintf(str, "structure=Phrase");
            break;
        case 2:
            sprintf(str, "structure=Word");
            break;
        case 3:
            sprintf(str, "structure=Key");
            break;
        case 4:
            sprintf(str, "structure=Year");
            break;
        case 5:
            sprintf(str, "structure=Date");
            break;
        case 6:
            sprintf(str, "structure=Word list");
            break;
        case 100:
            sprintf(str, "structure=Date (un)");
            break;
        case 101:
            sprintf(str, "structure=Name (norm)");
            break;
        case 102:
            sprintf(str, "structure=Name (un)");
            break;
        case 103:
            sprintf(str, "structure=Structure");
            break;
        case 104:
            sprintf(str, "structure=urx");
            break;
        case 105:
            sprintf(str, "structure=free-form-text");
            break;
        case 106:
            sprintf(str, "structure=document-text");
            break;
        case 107:
            sprintf(str, "structure=local-number");
            break;
        case 108:
            sprintf(str, "structure=string");
            break;
        case 109:
            sprintf(str, "structure=numeric string");
            break;
        default:
            sprintf(str, "structure");
        }
        break;
    case 5:
        switch (value)
        {
        case 1:
            sprintf(str, "truncation=Right");
            break;
        case 2:
            sprintf(str, "truncation=Left");
            break;
        case 3:
            sprintf(str, "truncation=Left&right");
            break;
        case 100:
            sprintf(str, "truncation=Do not truncate");
            break;
        case 101:
            sprintf(str, "truncation=Process #");
            break;
        case 102:
            sprintf(str, "truncation=re-1");
            break;
        case 103:
            sprintf(str, "truncation=re-2");
            break;
        case 104:
            sprintf(str, "truncation=CCL");
            break;
        default:
            sprintf(str, "truncation");
        }
        break;
    case 6:
        switch(value)
        {
        case 1:
            sprintf(str, "completeness=Incomplete subfield");
            break;
        case 2:
            sprintf(str, "completeness=Complete subfield");
            break;
        case 3:
            sprintf(str, "completeness=Complete field");
            break;
        default:
            sprintf(str, "completeness");
        }
        break;
    }
    if (*str)
        sprintf(str + strlen(str), " (" ODR_INT_PRINTF "=" ODR_INT_PRINTF")",
                type, value);
    else
        sprintf(str, ODR_INT_PRINTF "=" ODR_INT_PRINTF, type, value);
}

/*
 * zlog_attributes: print attributes of term
 */
static void zlog_attributes(Z_AttributesPlusTerm *t, int depth,
                            const Odr_oid *ast, int loglevel)
{
    int of, i;
    char str[80];
    int num_attributes = t->attributes->num_attributes;
    
    for (of = 0; of < num_attributes; of++)
    {
        char attset_name_buf[OID_STR_MAX];
        const char *attset_name = 0;
        Z_AttributeElement *element;
        element = t->attributes->attributes[of];
        if (element->attributeSet)
        {
            attset_name = yaz_oid_to_string_buf(element->attributeSet,
                                                0, attset_name_buf);
        }
{'fraction_non_alphanumeric': 0.11686676994577846, 'fraction_numerical': 0.020333075135553835, 'mean_word_length': 1.521728515625, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4349401', 'n_tokens_mistral': 3227, 'n_tokens_neox': 3074, 'n_words': 804}