rdf-dataset-fragmenter
Version:
Fragments an RDF dataset into multiple parts
62 lines (61 loc) • 2.39 kB
TypeScript
import type * as RDF from '@rdfjs/types';
/**
* A helper class for tracking resources of a given type.
*
* It allows resources of a given type to be mapped to a certain value.
*/
export declare class ResourceIdentifier<T> {
private readonly type;
private readonly targetPredicate;
readonly buffer: Record<string, IResource>;
readonly resourceMapping: Record<string, T>;
constructor(typeRegex: string, targetPredicateRegex: string);
/**
* Check if the subject of the given quad occurs within the buffer as a resource.
* @param quad A quad
* @param allowedComponent The quad component on which transformation is allowed.
* If undefined, then all components must be considered.
*/
isQuadBuffered(quad: RDF.Quad, allowedComponent?: 'subject' | 'object'): boolean;
/**
* Return the buffer entry for the given subject resource.
* @param quad A quad
*/
getBufferResource(quad: RDF.Quad): IResource;
/**
* Check if the subject resource is of the expected type, and if so, initialize a buffer entry for it.
* @param quad A quad
* @return boolean True if the buffer was initialized.
*/
tryInitializingBuffer(quad: RDF.Quad): boolean;
/**
* If the quad's predicate matches with the expected predicate, store it within the resource.
* @param resource A resource.
* @param quad A quad.
* @return boolean True if the target was set.
*/
tryStoringTarget(resource: IResource, quad: RDF.Quad): boolean;
/**
* If the subject or object in the given quad was mapped, invoke the given callback for them.
* @param quad A quad.
* @param callback A callback.
* @return boolean True if at least one of the subject or object components were matched.
*/
forEachMappedResource(quad: RDF.Quad, callback: (mapping: T, component: 'subject' | 'object') => void): boolean;
/**
* Remove the buffer entry for the given resource subject, and store the given mapping for it.
* @param quad A quad.
* @param mapping A mapping value to set.
*/
applyMapping(quad: RDF.Quad, mapping: T): void;
/**
* This should be invoked when transformers end.
*/
onEnd(): void;
}
export interface IResource {
id?: RDF.Term;
target?: RDF.NamedNode;
quads: RDF.Quad[];
type: RDF.NamedNode;
}