rdf-dataset-fragmenter
Version:
Fragments an RDF dataset into multiple parts
28 lines • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuadMatcherTermValue = void 0;
const MurmurHash3 = 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 {
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 = MurmurHash3(termMatch.at(1) ?? termValue).result();
const hashValueRelativeToMax = hashValue / MURMURHASH3_MAX_VALUE;
return hashValueRelativeToMax <= this.probability;
}
return false;
}
}
exports.QuadMatcherTermValue = QuadMatcherTermValue;
//# sourceMappingURL=QuadMatcherTermValue.js.map