<commit_before>#include <stdlib.h>
#include <string.h>
#include <ruby.h>

#include <AlpinoCorpus/capi.h>

#include "alpinocorpus.h"

/* Classes*/
VALUE cCorpusReader;
VALUE cQuery;
VALUE cMarkerQuery;

/* Utility functions */

#define Data_Get_Struct_Ptr(obj,type,sval) do {\
    Check_Type(obj, T_DATA); \
    sval = (type)DATA_PTR(obj);\
} while (0)


VALUE static entries_iterator(alpinocorpus_reader reader, alpinocorpus_iter iter)
{
    do {
        char *val;
        if ((val = alpinocorpus_iter_value(iter)) == NULL)
            rb_raise(rb_eRuntimeError, "coul not retrieve iterator value");
        
        VALUE rString = rb_str_new2(val);
        free(val);

        int status;
        rb_protect(rb_yield, rString, &status);
        
        if (status) {
            alpinocorpus_iter_destroy(iter);
            rb_jump_tag(status);
        }

    } while (alpinocorpus_iter_next(reader, iter));

    alpinocorpus_iter_destroy(iter);

    return Qnil;
}

marker_query_t *markers_to_c_markers(VALUE markers, long *len)
{<commit_msg>Ruby: error message typo.<commit_after>#include <stdlib.h>
#include <string.h>
#include <ruby.h>

#include <AlpinoCorpus/capi.h>

#include "alpinocorpus.h"

/* Classes*/
VALUE cCorpusReader;
VALUE cQuery;
VALUE cMarkerQuery;

/* Utility functions */

#define Data_Get_Struct_Ptr(obj,type,sval) do {\
    Check_Type(obj, T_DATA); \
    sval = (type)DATA_PTR(obj);\
} while (0)


VALUE static entries_iterator(alpinocorpus_reader reader, alpinocorpus_iter iter)
{
    do {
        char *val;
        if ((val = alpinocorpus_iter_value(iter)) == NULL)
            rb_raise(rb_eRuntimeError, "couldn't retrieve iterator value");
        
        VALUE rString = rb_str_new2(val);
        free(val);

        int status;
        rb_protect(rb_yield, rString, &status);
        
        if (status) {
            alpinocorpus_iter_destroy(iter);
            rb_jump_tag(status);
        }

    } while (alpinocorpus_iter_next(reader, iter));

    alpinocorpus_iter_destroy(iter);

    return Qnil;
}

marker_query_t *markers_to_c_markers(VALUE markers, long *len)
{
{'fraction_non_alphanumeric': 0.11633428300094967, 'fraction_numerical': 0.001899335232668566, 'mean_word_length': 3.115234375, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4989053', 'n_tokens_mistral': 779, 'n_tokens_neox': 745, 'n_words': 144}