extract-cbd-shape
Version:
Extract an entity based on CBD and a SHACL shape
67 lines (66 loc) • 2.48 kB
TypeScript
import { RdfDereferencer } from "rdf-dereference";
import { RDFMap } from "./Shape";
import { RdfStore } from "rdf-stores";
import { Quad, Term } from "@rdfjs/types";
import { ShapesGraph } from "./ShapesGraph";
type CBDShapeExtractorOptions = {
cbdDefaultGraph: boolean;
fetch?: typeof fetch;
};
/**
* Usage:
* import {ShapeExtractor} from "extract-cbd-shape";
* ...
* let shapeExtractor = new ShapeExtractor(shape, dereferencer);
* let entityquads = await shapeExtractor.extract(store, entity);
*/
export declare class CBDShapeExtractor {
dereferencer: RdfDereferencer;
shapesGraph?: ShapesGraph;
options: CBDShapeExtractorOptions;
constructor(shapesGraphStore?: RdfStore, dereferencer?: RdfDereferencer<Quad>, options?: Partial<CBDShapeExtractorOptions>);
bulkExtract(store: RdfStore, ids: Array<Term>, shapeId?: Term, graphsToIgnore?: Array<Term>, itemExtracted?: (member: {
subject: Term;
quads: Quad[];
}) => void): Promise<Array<{
subject: Term;
quads: Quad[];
}>>;
/**
* Extracts:
* * first level quads,
* * their blank nodes with their quads (recursively),
* * all quads in the namedgraph of this entity,
* * all quads of required paths found in the shape
* * the same algorithm on top of all found node links
* @param store The RdfStore loaded with a set of initial quads
* @param id The entity to be described/extracted
* @param shapeId The optional SHACL NodeShape identifier
* @param graphsToIgnore The optional parameter of graph to ignore when other entities are mentioned in the current context
* @returns Promise of a quad array of the described entity
*/
extract(store: RdfStore, id: Term, shapeId?: Term, graphsToIgnore?: Array<Term>): Promise<Array<Quad>>;
}
export type Extracted = {
forwards: {
[node: string]: Extracted;
};
backwards: {
[node: string]: Extracted;
};
};
export type ExtractReasons = {
cbd: boolean;
shape: boolean;
};
export declare class CbdExtracted {
topology: Extracted;
cbdExtractedMap: RDFMap<ExtractReasons>;
constructor(topology?: Extracted, cbdExtracted?: RDFMap<ExtractReasons>);
addCBDTerm(term: Term): void;
addShapeTerm(term: Term): void;
cbdExtracted(term: Term): boolean;
push(term: Term, inverse: boolean): CbdExtracted;
enter(term: Term, inverse: boolean): CbdExtracted | undefined;
}
export {};