<commit_before>var util = require('util');
var net = require('net');
var http = require('http');
var WebsocketServer = require('websocket').server;
var assert = require('assert');
var errors = require('./errors');
var EventEmitter = require('events').EventEmitter;
var MessageSocket = require('./message-socket.js').MessageSocket;

var isDefined = function (x) {
    if (typeof x === 'undefined' || x === null) {
        return false;
    }
    return true;
};

var createDaemon = function () {
    var peers = {};
    var elements = {};
    var routes = {};

    var daemon = new EventEmitter();

    var routeResponse = function (peer, message) {
        var route = routes[message.id];
        if (route) {
            delete routes[message.id];
            message.id = route.id;
            route.receiver.sendMessage(message);
        } else {
            console.log('cannot router message', message);
        }
    };

    /* publishes a notification to all subsbribers / fetchers */
    var publish = function (notification) {
        daemon.emit('publish', notification);
        for (var peerId in peers) {
            var peer = peers[peerId];
            var fetchers = peer.fetchers;
            var refetch;
            for (var fetchId in fetchers) {
                try {
                    refetch = fetchers[fetchId](notification);
                } catch (e) {
                    console.log('fetch failed', e);
                }
                if (refetch) {
                    for (var path in elements) {
                        fetchers[fetchId]({
                            path: path,
                            value: elements[path].value,
                            event: 'add'
                        });
                    }
                }
            }
        }
    };

    var createPathMatcher = function (options) {
        var match = options.match;
        var unmatch = options.unmatch;
        var equalsNot = options.equalsNot;
        if (!match && !unmatch && !equalsNot) {
            return function () {
                return true;
            };
        }
        match = match || [];
        unmatch = unmatch || [];
        equalsNot = equalsNot || [];
        if (options.caseInsensitive) {
            var t = [match, unmatch, equalsNot];
            var m;
            for (var i in t) {
                m = t[i];
                for (var i in m) {
                    m[i] = m[i].toLowerCase();
                }
            }
        }
        return function (path) {
            if (options.caseInsensitive) {
                path = path.toLowerCase();
            }
            for (var i in unmatch) {
                if (path.match(unmatch[i])) {
                    return false;
                }
            }
            for (var i in equalsNot) {
                if (path == equalsNot[i])
                    return false;
            }
            for (var i in match) {
                if (path.match(match[i])) {
                    return true;
                }
            }
            return false;
        };
    };

    var createValueMatcher = function (options) {
        var ops = {
            lessThan: function (a, b) {
                return a < b;
            },
            greaterThan: function (a, b) {
                return a > b;
            },
            equals: function (a, b) {
                return a === b;
            },
            equalsNot: function (a, b) {
                return a !== b;
            }
        };
        if (options.where) {
            if (utils.isArray(options.where) && options.where.length > 1) {
                return function (value) {
                    var isObject = typeof value === 'object';
                    var w;
                    var needObject;
                    var op;
                    var comp;
                    for (var i in options.where) {
                        w = options.where[i];
                        if (!w.prop || w.prop === '') {
                            needObject = false;
                        } else {
                            needObject = true;
                        }
                        if (needObject && !isObject) {
                            return false;
                        }
                        op = ops[w.op];
                        if (needObject) {
                            comp = value[w.prop];
                        } else {
                            comp = value;
                        }
                        try {
                            return op(comp, w.value);
                        } catch (e) {
                            return false;
                        }
                    }
                };
            } else {
                if (utils.isArray(options.where) && options.where.length === 1) {
                    options.where = options.where[0];
                }
                var where = options.where;
                var op = ops[where.op];
                var ref = where.value;
                if (!w.prop || w.prop === '') {
                    return function (value) {
                        var isObject = typeof value === 'object';
                        if (isObject) {
                            return false;
                        }
                        try {
                            return op(value, ref);
                        } catch (e) {
                            return false;
                        }
                    };
                } else {
                    return function (value) {
                        var isObject = typeof value === 'object';
                        if (!isObject) {
                            return false;<commit_msg>sort bugfix<commit_after>var util = require('util');
var net = require('net');
var http = require('http');
var WebsocketServer = require('websocket').server;
var assert = require('assert');
var errors = require('./errors');
var EventEmitter = require('events').EventEmitter;
var MessageSocket = require('./message-socket.js').MessageSocket;

var isDefined = function (x) {
    if (typeof x === 'undefined' || x === null) {
        return false;
    }
    return true;
};

var createDaemon = function () {
    var peers = {};
    var elements = {};
    var routes = {};

    var daemon = new EventEmitter();

    var routeResponse = function (peer, message) {
        var route = routes[message.id];
        if (route) {
            delete routes[message.id];
            message.id = route.id;
            route.receiver.sendMessage(message);
        } else {
            console.log('cannot router message', message);
        }
    };

    /* publishes a notification to all subsbribers / fetchers */
    var publish = function (notification) {
        daemon.emit('publish', notification);
        for (var peerId in peers) {
            var peer = peers[peerId];
            var fetchers = peer.fetchers;
            var refetch;
            for (var fetchId in fetchers) {
                try {
                    refetch = fetchers[fetchId](notification);
                } catch (e) {
                    console.log('fetch failed', e);
                }
                if (refetch) {
                    for (var path in elements) {
                        fetchers[fetchId]({
                            path: path,
                            value: elements[path].value,
                            event: 'add'
                        });
                    }
                }
            }
        }
    };

    var createPathMatcher = function (options) {
        var match = options.match;
        var unmatch = options.unmatch;
        var equalsNot = options.equalsNot;
        if (!match && !unmatch && !equalsNot) {
            return function () {
                return true;
            };
        }
        match = match || [];
        unmatch = unmatch || [];
        equalsNot = equalsNot || [];
        if (options.caseInsensitive) {
            var t = [match, unmatch, equalsNot];
            var m;
            for (var i in t) {
                m = t[i];
                for (var i in m) {
                    m[i] = m[i].toLowerCase();
                }
            }
        }
        return function (path) {
            if (options.caseInsensitive) {
                path = path.toLowerCase();
            }
            for (var i in unmatch) {
                if (path.match(unmatch[i])) {
                    return false;
                }
            }
            for (var i in equalsNot) {
                if (path == equalsNot[i])
                    return false;
            }
            for (var i in match) {
                if (path.match(match[i])) {
                    return true;
                }
            }
            return false;
        };
    };

    var createValueMatcher = function (options) {
        var ops = {
            lessThan: function (a, b) {
                return a < b;
            },
            greaterThan: function (a, b) {
                return a > b;
            },
            equals: function (a, b) {
                return a === b;
            },
            equalsNot: function (a, b) {
                return a !== b;
            }
        };
        if (options.where) {
            if (util.isArray(options.where) && options.where.length > 1) {
                return function (value) {
                    var isObject = typeof value === 'object';
                    var w;
                    var needObject;
                    var op;
                    var comp;
                    for (var i in options.where) {
                        w = options.where[i];
                        if (!w.prop || w.prop === '') {
                            needObject = false;
                        } else {
                            needObject = true;
                        }
                        if (needObject && !isObject) {
                            return false;
                        }
                        op = ops[w.op];
                        if (needObject) {
                            comp = value[w.prop];
                        } else {
                            comp = value;
                        }
                        try {
                            return op(comp, w.value);
                        } catch (e) {
                            return false;
                        }
                    }
                };
            } else {
                if (util.isArray(options.where) && options.where.length === 1) {
                    options.where = options.where[0];
                }
                var where = options.where;
                var op = ops[where.op];
                var ref = where.value;
                if (!where.prop || where.prop === '') {
                    return function (value) {
                        var isObject = typeof value === 'object';
                        if (isObject) {
                            return false;
                        }
                        try {
                            return op(value, ref);
                        } catch (e) {
                            return false;
                        }
                    };
                } else {
                    return function (value) {
                        var isObject = typeof value === 'object';
                        if (!isObject) {
                            return false;
{'fraction_non_alphanumeric': 0.1032986111111111, 'fraction_numerical': 0.0005208333333333333, 'mean_word_length': 0.9030393128510076, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6913723', 'n_tokens_mistral': 2789, 'n_tokens_neox': 2645, 'n_words': 712}