@faubulous/mentor-rdf
Version:
A library for working with RDF vocabularies with support for basic RDFS and OWL inference.
196 lines (195 loc) • 10 kB
TypeScript
import * as rdfjs from "@rdfjs/types";
import { EventEmitter } from "stream";
import { Reasoner } from "./reasoners/reasoner";
/**
* Indicates an error when a triple is not found in the store.
*/
export declare class TripleNotFoundError extends Error {
/**
* Create a new instance of the error.
* @param message The error message.
*/
constructor(subject: rdfjs.Quad_Subject | null, predicate: rdfjs.Quad_Predicate | null, object: rdfjs.Quad_Object | null);
}
export declare class Store implements rdfjs.Source<rdfjs.Quad> {
/**
* The adapted RDF.js triple store implementation.
*
* Note: Please do not use this directly, but rather use the `_ds` property to access the dataset.
*/
private readonly _store;
/**
* The RDF dataset containing the triples in the store, which should primarily be used
* for any operations so that the store can be swapped out with a different implementation.
*/
private readonly _ds;
/**
* The reasoner to be used for inference.
*/
readonly reasoner?: Reasoner;
/**
* Get the number of triples in all graphs of the store.
*/
get size(): number;
/**
* Get the RDF.js DataFactory used by the store.
*/
get dataFactory(): rdfjs.DataFactory;
/**
* Create a new RDF triple store.
* @param reasoner The reasoner to be used for inference.
*/
constructor(reasoner?: Reasoner);
[Symbol.iterator](): Iterator<rdfjs.Quad, any, any>;
/**
* Loads a set of W3C Standard ontologies into the store (RDF, RDFA, RDFS, OWL, SKOS, SHACL, XSD).
*/
loadFrameworkOntologies(executeInference?: boolean): Promise<void>;
/**
* Add a quad to the store. Existing quads with the same subject, predicate, object, and graph will be ignored.
* @param quad The quad to be added.
* @returns The store instance.
*/
add(quad: rdfjs.Quad): this;
/**
* Delete a quad from the store.
* @param quad The quad to be deleted.
* @returns The store instance.
*/
delete(quad: rdfjs.Quad): this;
/**
* Indicates if the store contains a specific quad.
* @param quad The quad to be checked.
* @returns `true` if the quad is found in the store, `false` otherwise.
*/
has(quad: rdfjs.Quad): boolean;
/**
* Get the URIs of the graphs in the triple store.
* @returns An array of graph URIs in no particular order.
*/
getGraphs(): string[];
/**
* Load a set of triples into the store.
* @param quads An array of quads to be loaded into the store.
* @param graphUri The target graph URI.
* @param executeInference Indicates if inference should be executed after loading the triples.
* @param clearGraph Indicates if the graph should be cleared before loading.
* @param onQuad A callback function that will be called for each parsed triple.
*/
private _remapBlankNodes;
private _loadQuads;
/**
* Create an RDF store from Turtle, N3 or N-Triples data.
* @param input Input string in Turtle, N3 or N-Triples format.
* @param graphUri URI of the graph to in which the triples will be created.
* @param executeInference Indicates if inference should be executed after loading the triples.
* @param clearGraph Indicates if the graph should be cleared before loading.
* @param onQuad Callback function that will be called for each parsed triple.
* @returns A promise that resolves to an RDF store.
*/
loadTurtle(input: string, graphUri: string, executeInference?: boolean, clearGraph?: boolean, onQuad?: (quad: rdfjs.Quad) => void): Store;
/**
* Create an RDF store from N-Quads data.
* @param input Input string in N-Quads format.
* @param graphUri URI of the default graph to use when quads have no graph component.
* @param executeInference Indicates if inference should be executed after loading the triples.
* @param clearGraph Indicates if the graph should be cleared before loading.
* @param onQuad Callback function that will be called for each parsed triple.
* @returns The store instance.
*/
loadNQuads(input: string, graphUri: string, executeInference?: boolean, clearGraph?: boolean, onQuad?: (quad: rdfjs.Quad) => void): Store;
/**
* Create an RDF store from RDF/XML data.
* @param input Input data or stream format to be parsed.
* @param graphUri URI of the graph to in which the triples will be created.
* @param executeInference Indicates if inference should be executed after loading the triples.
* @param clearGraph Indicates if the graph should be cleared before loading.
* @param onQuad Callback function that will be called for each parsed triple.
* @returns A promise that resolves to an RDF store.
*/
loadFromXmlStream(input: string | EventEmitter, graphUri: string, executeInference?: boolean, clearGraph?: boolean, onQuad?: (quad: rdfjs.Quad) => void): Promise<Store>;
/**
* Write the triples in the store into a string in Turtle format.
* @param sourceGraphUri A graph URI.
* @param targetFormat Optional mime type of the serialization format (e.g., 'text/turtle').
* @param targetGraphUri Optional target graph URI. If not provided, the source graph URI will be used for serialization formats that support quads.
* @param prefixes Optional prefixes to be used in the serialization.
* @returns A string serialization of the triples in the graph in the specified format.
*/
serializeGraph(sourceGraphUri: string, targetFormat?: string, targetGraphUri?: string, prefixes?: Record<string, string>): Promise<string>;
/**
* Indicates if the store contains triples in a given graph.
* @param graphUri A graph URI.
* @returns `true` if the store contains triples in the graph URI, `false` otherwise.
*/
hasGraph(graphUri: rdfjs.Quad_Graph | string): boolean;
/**
* Apply inference to the given graph and store the triples in the associated inference graph.
* @param graphUri A graph URI.
*/
executeInference(graphUri: rdfjs.Quad_Graph | string): void;
/**
* Delete named graphs from the store.
* @param graphUris URIs of the graphs to be deleted.
*/
deleteGraphs(graphUris: string[]): void;
/**
* Get the URIs of ordered list members in the store.
* @param graphUris Optional graph URI or array of graph URIs to query.
* @param listUri URI of the list to get the items from.
* @returns An array of URIs of the items in the list.
*/
getListItems(graphUris: string | string[] | undefined, listUri: string): string[];
private _getListItems;
/**
* Returns the exact cardinality of the quads matching the pattern.
* @param subject The optional subject.
* @param predicate The optional predicate.
* @param object The optional object.
* @param graph The optional graph.
*/
countQuads(subject?: rdfjs.Term | null, predicate?: rdfjs.Term | null, object?: rdfjs.Term | null, graph?: rdfjs.Term | null): number;
/**
* Returns a stream of quads matching the given pattern.
* @param subject The optional subject.
* @param predicate The optional predicate.
* @param object The optional object.
* @param graph The optional graph.
* @returns A stream of matching quads.
*/
match(subject?: rdfjs.Term | null, predicate?: rdfjs.Term | null, object?: rdfjs.Term | null, graph?: rdfjs.Term | null): rdfjs.Stream<rdfjs.Quad>;
/**
* Query the store for triples matching the given pattern supporting multiple graphs.
* @param graphUris Optional graph URI or array of graph URIs to query.
* @param subject A subject URI or null to match any subject.
* @param predicate A predicate URI or null to match any predicate.
* @param object An object URI or null to match any object.
*/
matchAll(graphUris: string | string[] | undefined, subject: rdfjs.Quad_Subject | null, predicate: rdfjs.Quad_Predicate | null, object: rdfjs.Quad_Object | null, includeInferred?: boolean): Generator<rdfjs.Quad, void, any>;
/**
* Indicate if there are triples matching the given pattern in the store.
* @param graphUris Optional graph URI or array of graph URIs to query.
* @param subject A subject URI or null to match any subject.
* @param predicate A predicate URI or null to match any predicate.
* @param object An object URI or null to match any object.
* @returns `true` if there are triples matching the pattern, `false` otherwise.
*/
any(graphUris: string | string[] | undefined, subject: rdfjs.Quad_Subject | null, predicate: rdfjs.Quad_Predicate | null, object: rdfjs.Quad_Object | null, includeInferred?: boolean): boolean;
/**
* Get a new DatasetCore containing all quads from the specified graphs.
* @param graphUris Optional graph URI or array of graph URIs. If undefined, all quads are included.
* @param includeInferred Whether to include inferred triples. Defaults to false.
* @returns A new DatasetCore instance with the matching quads.
*/
getDataset(graphUris?: string | string[], includeInferred?: boolean): rdfjs.DatasetCore;
/**
* Get the first triple matching the given pattern in the store.
* @param graphUris Optional graph URI or array of graph URIs to query.
* @param subject A subject URI or null to match any subject.
* @param predicate A predicate URI or null to match any predicate.
* @param object An object URI or null to match any object.
* @returns The first triple that matches the pattern.
* @throws {TripleNotFoundError} If no triple is found matching the pattern.
*/
first(graphUris: string | string[] | undefined, subject: rdfjs.Quad_Subject | null, predicate: rdfjs.Quad_Predicate | null, object: rdfjs.Quad_Object | null, includeInferred?: boolean): rdfjs.Quad;
}