rdf-dataset-fragmenter
Version:
Fragments an RDF dataset into multiple parts
34 lines • 1.3 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuadMatcherTermValue = void 0;
const imurmurhash_1 = __importDefault(require("imurmurhash"));
// MurmurHash3 produces 32-bit (unsigned, according to the docs) integer values
const MURMURHASH3_MAX_VALUE = Number.MAX_SAFE_INTEGER >>> 0;
/**
* Matches a quad by the given component regex, with optional probability.
*/
class QuadMatcherTermValue {
term;
regex;
probability;
constructor(options) {
this.term = options.term;
this.regex = new RegExp(options.regex, 'u');
this.probability = options.probability;
}
matches(quad) {
const termValue = quad[this.term].value;
const termMatch = this.regex.exec(termValue);
if (termMatch) {
const hashValue = (0, imurmurhash_1.default)(termMatch.at(1) ?? termValue).result();
const hashValueRelativeToMax = hashValue / MURMURHASH3_MAX_VALUE;
return hashValueRelativeToMax <= this.probability;
}
return false;
}
}
exports.QuadMatcherTermValue = QuadMatcherTermValue;
//# sourceMappingURL=QuadMatcherTermValue.js.map