<commit_before>'use strict';
var util = require('util');
var _ = require('lodash');
var log = require('./../logger');
function Context(obj) {
    function f() {
        return this['()'].apply(this, arguments)
    }

    var ctx = Context.compile(obj);
    ctx[Context.marker] = true;
    _.extend(f, ctx);
    return f;
}
Context.prototype['()'] = function () {
};
Context.marker = Symbol();
Context.isContext = function (obj) {
    return obj && obj[Context.marker];
};
Context.compile = function (obj) {
    if (!obj) {
        return {};
    }
    log.verbose(`Context.compile(): compiling objrct ${util.inspect(JSON.stringify(obj))}`);
    var ctx = {};
    var objkeys = Object.getOwnPropertyNames(obj);
    for (let prop in obj) {
        if (objkeys.indexOf(prop) === -1) {
            continue;
        }
        var val = obj[prop];
        var type = typeof val;
        if (val == obj) {
            log.verbose(`skipping ${prop}, because it is circular`);
            continue;
        }
        if (type == 'string' || type == 'number') {
            log.verbose(`skipping ${prop}, because it is of primitive type`);
            continue;
        }
        //TODO skip classes
        log.verbose('compiling %s, it\'s type is %s', prop, type);
        if (type === 'function') {
            ctx[prop] = Context.compile.func(val,prop);
        } else if (type === 'object') {
            ctx[prop] = Context.compile(val);
        }
    }
    log.verbose('Context.compile(): result is %j', ctx);
    return ctx;
};
Context.compile.func = function (func,name) {
    log.verbose('Context.compile.func(): compiling function %s', func.name||name);
    return function () {
        //which will be called in generator
        return {
            fn: func,
            args: Array.prototype.slice.call(arguments)
        }
    }
};
Context.compile.module = function (modulename) {<commit_msg>improved circular's skipping<commit_after>'use strict';
var util = require('util');
var _ = require('lodash');
var log = require('./../logger');
function Context(obj) {
    function f() {
        return this['()'].apply(this, arguments)
    }

    var ctx = Context.compile(obj);
    ctx[Context.marker] = true;
    _.extend(f, ctx);
    return f;
}
Context.prototype['()'] = function () {
};
Context.marker = Symbol();
Context.isContext = function (obj) {
    return obj && obj[Context.marker];
};
Context.compile = function (obj) {
    if (!obj) {
        return {};
    }
    log.verbose(`Context.compile(): compiling objrct ${util.inspect(obj)}`);
    var ctx = {};
    var objkeys = Object.getOwnPropertyNames(obj);
    for (let prop in obj) {
        if (objkeys.indexOf(prop) === -1) {
            continue;
        }
        var val = obj[prop];
        var type = typeof val;
        try{
            JSON.stringify(obj[prop])
        }catch(_){
            continue;
        }

        if (type == 'string' || type == 'number') {
            log.verbose(`skipping ${prop}, because it is of primitive type`);
            continue;
        }
        //TODO skip classes
        log.verbose('compiling %s, it\'s type is %s', prop, type);
        if (type === 'function') {
            ctx[prop] = Context.compile.func(val,prop);
        } else if (type === 'object') {
            ctx[prop] = Context.compile(val);
        }
    }
    log.verbose('Context.compile(): result is %j', ctx);
    return ctx;
};
Context.compile.func = function (func,name) {
    log.verbose('Context.compile.func(): compiling function %s', func.name||name);
    return function () {
        //which will be called in generator
        return {
            fn: func,
            args: Array.prototype.slice.call(arguments)
        }
    }
};
Context.compile.module = function (modulename) {
{'fraction_non_alphanumeric': 0.16247018287834614, 'fraction_numerical': 0.0005300821627352239, 'mean_word_length': 2.2562553925798103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1507957', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1107, 'n_words': 284}