UNPKG

@jahed/sparql-engine

Version:

SPARQL query engine for servers and web browsers.

75 lines (74 loc) 2.7 kB
import type { NamedNode } from "@rdfjs/types"; import Graph from "./graph.ts"; import UnionGraph from "./union-graph.ts"; /** * An abstraction over an RDF datasets, i.e., a collection of RDF graphs. * @abstract */ export default abstract class Dataset<G extends Graph = Graph> { private _graphFactory; /** * Constructor */ constructor(); abstract get iris(): NamedNode[]; /** * Set the Default Graph of the Dataset * @param g - Default Graph */ abstract setDefaultGraph(g: G): void; /** * Get the Default Graph of the Dataset * @return The Default Graph of the Dataset */ abstract getDefaultGraph(): G; /** * Add a Named Graph to the Dataset * @param iri - IRI of the Named Graph * @param g - RDF Graph */ abstract addNamedGraph(g: G): void; /** * Get a Named Graph using its IRI * @param iri - IRI of the Named Graph to retrieve * @return The corresponding Named Graph */ abstract getNamedGraph(iri: NamedNode): Promise<G>; /** * Delete a Named Graph using its IRI * @param iri - IRI of the Named Graph to delete */ abstract deleteNamedGraph(iri: NamedNode): void; /** * Return True if the Dataset contains a Named graph with the provided IRI * @param iri - IRI of the Named Graph * @return True if the Dataset contains a Named graph with the provided IRI */ abstract hasNamedGraph(iri: NamedNode): boolean; /** * Get an UnionGraph, i.e., the dynamic union of several graphs, * from the RDF Graphs in the Dataset. * @param iris - Iris of the named graphs to include in the union * @param includeDefault - True if the default graph should be included * @return The dynamic union of several graphs in the Dataset */ getUnionGraph(iris: NamedNode[], includeDefault?: boolean): Promise<UnionGraph>; /** * Returns all Graphs in the Dataset, including the Default one * @param includeDefault - True if the default graph should be included * @return The list of all graphs in the Dataset */ getAllGraphs(includeDefault?: boolean): AsyncGenerator<G>; /** * Set the Graph Factory used by te dataset to create new RDF graphs on-demand * @param factory - Graph Factory */ setGraphFactory(factory: (iri: NamedNode) => G | Promise<G>): void; /** * Create a new RDF Graph, using the current Graph Factory. * This Graph factory can be set using the "setGraphFactory" method. * @param iri - IRI of the graph to create * @return A new RDF Graph */ createGraph(iri: NamedNode): Promise<G>; }