<commit_before>(function() {
    var Ockham = {
        error: function(message) {
            return {
                name: "OckhamError",
                level: "Show Stopper",
                message: message,
                htmlMessage: message,
                toString: function() {
                    return this.name + ": " + this.message;
                }
            };
        },
        state: function(ockham, name, parent) {
            var from_transitions = [],
                getCompleteName = function() {
                    var names = [];
                    if (parent) {
                        names.push(parent.getCompleteName());
                    }
                    names.push(name);
                    return names.join('-');
                },
                addTransition = function(from, transition) {
                    // Only one final state for each transition
                    from_transitions[from] = transition;
                },
                can = function(transition) {
                    if (!_.isUndefined(from_transitions[transition])) {
                        return true;
                    }
                    // If the transition is not defined in this state,
                    // search it on the parents
                    if (parent) {
                        return parent.can(transition);
                    }
                    return false;
                },
                doTransition = function(fsm, transition, options) {
                    var promise,
                        transition_fn = from_transitions[transition];

                    // If this state does not allow the transition, pass it to
                    // the parents
                    if (from_transitions[transition]) {
                        if (_.isFunction(transition_fn)) {
                            promise = transition_fn(fsm, options);
                        } else {
                            promise = Promise.resolve(from_transitions[transition], options);
                        }
                    } else {
                        if (parent) {
                            promise = parent.doTransition(fsm, transition, options);
                        }
                    }

                    // Check if the transtion can be done
                    if (promise) {
                        return promise;
                    }
                    return Promise.reject(new ockham.error("No transition '" + transition + "' in state: '" + getCompleteName() + "'"));
                };

            return {
                getCompleteName: getCompleteName,
                addTransition: addTransition,
                can: can,
                doTransition: doTransition
            };
        },

        fsm: function(cfg) {
            var current = null,
                states = {},
                transition_queue = [],
                _createState = function(ockham, name, data, parent) {
                    var state_obj;
                    // Create and save the state
                    state_obj = new ockham.state(ockham, name, parent);
                    states[state_obj.getCompleteName()] = state_obj;

                    _.each(data, function(data, key) {
                        if (key === 'states') {
                            // Create the child states
                            _.each(data, function(state_data, substate) {
                                _createState(ockham, substate, state_data, state_obj);
                            }, this);
                        } else {
                            // Create the transitions
                            state_obj.addTransition(key, data);
                        }
                    }, this);
                },
                can = function(transition) {
                    // We always expect a current state
                    return current.can(transition);
                },
                cannot = function(transition) {
                    return !can(transition);
                },
                currentName = function() {
                    return current.getCompleteName();
                },
                is = function(state) {
                    // We always expect a current state
                    return current.getCompleteName() === state;
                },
                doTransition = function(transition, options) {
                    var from, eventData, that = this;

                    // Delegate transition to the current state
                    return current.doTransition(that, transition, options).then(function(to) {
                        from = current.getCompleteName();

                        // Change to target state
                        current = states[to];

                        eventData = {
                            from: from,
                            to: current.getCompleteName(),
                            transition: transition,
                            options: options
                        };
                        return eventData;
                    }).then(function(eventData) {
                        return processTransitionQueue(eventData);
                    });
                },
                deferTransition = function(transition, options) {
                    transition_queue.push({
                        transition: transition,
                        options: options
                    });
                },
                processTransitionQueue = function(eventData) {
                    var promise_queue, data, promise;

                    if (_.isEmpty(transition_queue)) {
                        return Promise.resolve(eventData);
                    }

                    // Return first element of the transition queue
                    data = _.first(transition_queue);
                    promise = doTransition(data.transition, data.options);

                    // Remove elemento from the array
                    transition_queue.splice(0, 1);
                    return promise;
                },
                ret = _.extend({
                    can: can,
                    cannot: cannot,
                    currentName: currentName,
                    deferTransition: deferTransition,
                    doTransition: doTransition,
                    is: is
                }, cfg.config(this));

            // Travel each state configuration
            _.each(ret.states, function(data, state) {
                // Create root states
                _createState(this, state, data, null);
            }, this);

            // Always start with "none" state
            // TODO: Should it be configurable??
            current = states.none;

            return ret;
        },

        create: function(cfg) {
            return this.fsm(cfg);
        }
    };

    // For node
    if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
        module.exports = Ockham;
    } else {
        if (typeof define === 'function' && define.amd) {
            // For AMD
            define([], function() {
                return Ockham;
            });
        } else {
            // For Browser
            window.Ockham = Ockham;
        }
    }
}());<commit_msg>Publish as node module<commit_after>(function() {
    var Ockham = (function(){
      return {
        error: function(message) {
            return {
                name: "OckhamError",
                level: "Show Stopper",
                message: message,
                htmlMessage: message,
                toString: function() {
                    return this.name + ": " + this.message;
                }
            };
        },
        state: function(ockham, name, parent) {
            var from_transitions = [],
                getCompleteName = function() {
                    var names = [];
                    if (parent) {
                        names.push(parent.getCompleteName());
                    }
                    names.push(name);
                    return names.join('-');
                },
                addTransition = function(from, transition) {
                    // Only one final state for each transition
                    from_transitions[from] = transition;
                },
                can = function(transition) {
                    if (!_.isUndefined(from_transitions[transition])) {
                        return true;
                    }
                    // If the transition is not defined in this state,
                    // search it on the parents
                    if (parent) {
                        return parent.can(transition);
                    }
                    return false;
                },
                doTransition = function(fsm, transition, options) {
                    var promise,
                        transition_fn = from_transitions[transition];

                    // If this state does not allow the transition, pass it to
                    // the parents
                    if (from_transitions[transition]) {
                        if (_.isFunction(transition_fn)) {
                            promise = transition_fn(fsm, options);
                        } else {
                            promise = Promise.resolve(from_transitions[transition], options);
                        }
                    } else {
                        if (parent) {
                            promise = parent.doTransition(fsm, transition, options);
                        }
                    }

                    // Check if the transtion can be done
                    if (promise) {
                        return promise;
                    }
                    return Promise.reject(new ockham.error("No transition '" + transition + "' in state: '" + getCompleteName() + "'"));
                };

            return {
                getCompleteName: getCompleteName,
                addTransition: addTransition,
                can: can,
                doTransition: doTransition
            };
        },

        fsm: function(cfg) {
            var current = null,
                states = {},
                transition_queue = [],
                _createState = function(ockham, name, data, parent) {
                    var state_obj;
                    // Create and save the state
                    state_obj = new ockham.state(ockham, name, parent);
                    states[state_obj.getCompleteName()] = state_obj;

                    _.each(data, function(data, key) {
                        if (key === 'states') {
                            // Create the child states
                            _.each(data, function(state_data, substate) {
                                _createState(ockham, substate, state_data, state_obj);
                            }, this);
                        } else {
                            // Create the transitions
                            state_obj.addTransition(key, data);
                        }
                    }, this);
                },
                can = function(transition) {
                    // We always expect a current state
                    return current.can(transition);
                },
                cannot = function(transition) {
                    return !can(transition);
                },
                currentName = function() {
                    return current.getCompleteName();
                },
                is = function(state) {
                    // We always expect a current state
                    return current.getCompleteName() === state;
                },
                doTransition = function(transition, options) {
                    var from, eventData, that = this;

                    // Delegate transition to the current state
                    return current.doTransition(that, transition, options).then(function(to) {
                        from = current.getCompleteName();

                        // Change to target state
                        current = states[to];

                        eventData = {
                            from: from,
                            to: current.getCompleteName(),
                            transition: transition,
                            options: options
                        };
                        return eventData;
                    }).then(function(eventData) {
                        return processTransitionQueue(eventData);
                    });
                },
                deferTransition = function(transition, options) {
                    transition_queue.push({
                        transition: transition,
                        options: options
                    });
                },
                processTransitionQueue = function(eventData) {
                    var promise_queue, data, promise;

                    if (_.isEmpty(transition_queue)) {
                        return Promise.resolve(eventData);
                    }

                    // Return first element of the transition queue
                    data = _.first(transition_queue);
                    promise = doTransition(data.transition, data.options);

                    // Remove elemento from the array
                    transition_queue.splice(0, 1);
                    return promise;
                },
                ret = _.extend({
                    can: can,
                    cannot: cannot,
                    currentName: currentName,
                    deferTransition: deferTransition,
                    doTransition: doTransition,
                    is: is
                }, cfg.config(this));

            // Travel each state configuration
            _.each(ret.states, function(data, state) {
                // Create root states
                _createState(this, state, data, null);
            }, this);

            // Always start with "none" state
            // TODO: Should it be configurable??
            current = states.none;

            return ret;
        },

        create: function(cfg) {
            return this.fsm(cfg);
        }
      };
    })();

    // For node
    if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
        module.exports = Ockham;
     } else {
        // For Browser
        window.Ockham = Ockham;
    }
})();
{'fraction_non_alphanumeric': 0.08381004893514371, 'fraction_numerical': 0.00027569095044455166, 'mean_word_length': 0.9565803667745415, 'pattern_counts': {'":': 2, '<': 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': '4574123', 'n_tokens_mistral': 3155, 'n_tokens_neox': 2873, 'n_words': 751}