rdf-dataset-fragmenter
Version:
Fragments an RDF dataset into multiple parts
41 lines • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuadMatcherResourceType = void 0;
/**
* A quad matcher that matches all resources of the given type.
*
* Blank nodes are not supported.
*
* WARNING: This matcher assumes that all the applicable resources
* have `rdf:type` occurring as first triple with the resource IRI as subject.
*/
class QuadMatcherResourceType {
type;
matchFullResource;
matchingSubjects;
/**
* @param typeRegex Regular expression for type IRIs that need to be matched.
* @param matchFullResource If not only the quad containing the type must be matched,
* but also all other quads sharing the same subject of that quad.
*/
constructor(typeRegex, matchFullResource) {
this.type = new RegExp(typeRegex, 'u');
this.matchFullResource = matchFullResource;
this.matchingSubjects = {};
}
matches(quad) {
// Add buffer entry on applicable resource type
if (quad.subject.termType === 'NamedNode' &&
quad.predicate.value === 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' &&
quad.object.termType === 'NamedNode' && this.type.test(quad.object.value)) {
if (this.matchFullResource) {
this.matchingSubjects[quad.subject.value] = true;
}
return true;
}
return this.matchFullResource &&
quad.subject.termType === 'NamedNode' && quad.subject.value in this.matchingSubjects;
}
}
exports.QuadMatcherResourceType = QuadMatcherResourceType;
//# sourceMappingURL=QuadMatcherResourceType.js.map