rdf-dataset-fragmenter
Version:
Fragments an RDF dataset into multiple parts
77 lines • 5.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuadTransformerAppendResourceSolidTypeIndex = void 0;
const rdf_data_factory_1 = require("rdf-data-factory");
const relative_to_absolute_iri_1 = require("relative-to-absolute-iri");
const ResourceIdentifier_1 = require("./identifier/ResourceIdentifier");
const DF = new rdf_data_factory_1.DataFactory();
/**
* A quad transformer that appends SCL policies to resources of the given type.
*/
class QuadTransformerAppendResourceSolidTypeIndex {
/* eslint-disable ts/naming-convention */
static PREFIX_SOLID = 'http://www.w3.org/ns/solid/terms#';
static IRI_SOLID_PUBLIC_TYPE_INDEX = DF.namedNode(`${QuadTransformerAppendResourceSolidTypeIndex.PREFIX_SOLID}publicTypeIndex`);
static IRI_SOLID_TYPE_INDEX = DF.namedNode(`${QuadTransformerAppendResourceSolidTypeIndex.PREFIX_SOLID}TypeIndex`);
static IRI_SOLID_LISTED_DOCUMENT = DF.namedNode(`${QuadTransformerAppendResourceSolidTypeIndex.PREFIX_SOLID}ListedDocument`);
static IRI_SOLID_TYPE_REGISTRATION = DF.namedNode(`${QuadTransformerAppendResourceSolidTypeIndex.PREFIX_SOLID}TypeRegistration`);
static IRI_SOLID_FOR_CLASS = DF.namedNode(`${QuadTransformerAppendResourceSolidTypeIndex.PREFIX_SOLID}forClass`);
static IRI_SOLID_INSTANCE = DF.namedNode(`${QuadTransformerAppendResourceSolidTypeIndex.PREFIX_SOLID}instance`);
static IRI_SOLID_INSTANCE_CONTAINER = DF.namedNode(`${QuadTransformerAppendResourceSolidTypeIndex.PREFIX_SOLID}instanceContainer`);
static IRI_A = DF.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#type`);
/* eslint-enable ts/naming-convention */
resourceIdentifier;
typeIndex;
entrySuffix;
entryReference;
entryContainer;
/**
* @param typeRegex The RDF type that should be used to capture resources.
* @param profilePredicateRegex Predicate regex on the resource that contains a reference to the relevant Solid
* profile.
* @param typeIndex URL relative to the Solid profile URL for the type index.
* @param entrySuffix String to append to the type index entry.
* @param entryReference URL relative to the Solid profile URL for the type index instances reference.
* @param entryContainer If the `entryReference` refers to a Solid container, otherwise it refers to a single index
* file.
*/
constructor(typeRegex, profilePredicateRegex, typeIndex, entrySuffix, entryReference, entryContainer) {
this.resourceIdentifier = new ResourceIdentifier_1.ResourceIdentifier(typeRegex, profilePredicateRegex);
this.typeIndex = typeIndex;
this.entrySuffix = entrySuffix;
this.entryReference = entryReference;
this.entryContainer = entryContainer;
}
transform(quad) {
const returnQuads = [quad];
// Add buffer entry on applicable resource type
this.resourceIdentifier.tryInitializingBuffer(quad);
// If this resource is buffered
if (this.resourceIdentifier.isQuadBuffered(quad)) {
const resource = this.resourceIdentifier.getBufferResource(quad);
// Try to set the target
this.resourceIdentifier.tryStoringTarget(resource, quad);
// Check if resource is complete
if (resource.target) {
const typeIndex = DF.namedNode((0, relative_to_absolute_iri_1.resolve)(this.typeIndex, resource.target.value));
// Push quad for link from target profile to type index
returnQuads.push(DF.quad(resource.target, QuadTransformerAppendResourceSolidTypeIndex.IRI_SOLID_PUBLIC_TYPE_INDEX, typeIndex));
// Push quads for the type index definition
returnQuads.push(DF.quad(typeIndex, QuadTransformerAppendResourceSolidTypeIndex.IRI_A, QuadTransformerAppendResourceSolidTypeIndex.IRI_SOLID_TYPE_INDEX));
returnQuads.push(DF.quad(typeIndex, QuadTransformerAppendResourceSolidTypeIndex.IRI_A, QuadTransformerAppendResourceSolidTypeIndex.IRI_SOLID_LISTED_DOCUMENT));
// Push quads for type index entry
const typeIndexEntry = DF.namedNode(typeIndex.value + this.entrySuffix);
returnQuads.push(DF.quad(typeIndexEntry, QuadTransformerAppendResourceSolidTypeIndex.IRI_A, QuadTransformerAppendResourceSolidTypeIndex.IRI_SOLID_TYPE_REGISTRATION));
returnQuads.push(DF.quad(typeIndexEntry, QuadTransformerAppendResourceSolidTypeIndex.IRI_SOLID_FOR_CLASS, resource.type));
returnQuads.push(DF.quad(typeIndexEntry, this.entryContainer ?
QuadTransformerAppendResourceSolidTypeIndex.IRI_SOLID_INSTANCE_CONTAINER :
QuadTransformerAppendResourceSolidTypeIndex.IRI_SOLID_INSTANCE, DF.namedNode((0, relative_to_absolute_iri_1.resolve)(this.entryReference, resource.target.value))));
// Clear the buffer, and set rewriting rule
this.resourceIdentifier.applyMapping(quad, true);
}
}
return returnQuads;
}
}
exports.QuadTransformerAppendResourceSolidTypeIndex = QuadTransformerAppendResourceSolidTypeIndex;
//# sourceMappingURL=QuadTransformerAppendResourceSolidTypeIndex.js.map