UNPKG

@faubulous/mentor-rdf

Version:

A library for working with RDF vocabularies with support for basic RDFS and OWL inference.

85 lines (84 loc) 3.84 kB
import * as rdfjs from "@rdfjs/types"; /** * A handler to generate graph URIs from any given URI. */ export interface GraphUriGenerator { /** * Generate a graph URI from a given URI. * @param uri A URI. */ getGraphUri(uri: string | rdfjs.Quad_Graph): string; } /** * Default implementation of the InferenceGraphHandler interface. It generates URIs * for inference graphs using a Mentor specific URN scheme. */ export declare class DefaultInferenceGraphHandler implements GraphUriGenerator { getGraphUri(uri: string | rdfjs.Quad_Graph): string; /** * Check if a given URI is an inference graph URI. * @param uri A URI. * @returns `true` if the URI is an inference graph URI, `false` otherwise. */ isInferenceGraphUri(uri: string | rdfjs.Quad_Graph): boolean; } /** * An interface for reasoners that operate on existing graphs in the RDF store and * materialise the inferred triples in an inference graph. */ export interface Reasoner { /** * A handler to generate inference graph URIs from any given graph URI if no explicit target graph is provided. */ targetUriGenerator: GraphUriGenerator; /** * Apply inference on the source graph and store the inferred triples in the target graph. * @param store The store to be inferenced. * @param sourceGraph The source graph where to find the triples to be inferenced. * @param targetGraph The optional target graph where to store the inferred triples. If none is provided, the graph from getGraphUri will be used. */ expand(store: rdfjs.DatasetCore, sourceGraph: string | rdfjs.Quad_Graph, targetGraph?: string | rdfjs.Quad_Graph): rdfjs.DatasetCore; } /** * A base class for reasoners that expand graphs with inferred triples. */ export declare abstract class ReasonerBase implements Reasoner { protected store: rdfjs.DatasetCore; sourceGraph?: rdfjs.Quad_Graph; targetGraph?: rdfjs.Quad_Graph; readonly errors: { message: string; quad: rdfjs.Quad; }[]; readonly targetUriGenerator: GraphUriGenerator; constructor(targetUriGenerator: GraphUriGenerator); protected getGraphNode(graph: string | rdfjs.Quad_Graph): rdfjs.Quad_Graph; protected isW3CNode(term: rdfjs.Quad_Subject | rdfjs.Quad_Object): boolean; /** * 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(listUri: string): rdfjs.Quad_Object[]; private _getListItems; /** * 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. * @todo Refactor and merge with the same method in the Mentor RDF Store class. */ match(graph: rdfjs.Quad_Graph, subject: rdfjs.Quad_Subject | null, predicate: rdfjs.Quad_Predicate | null, object: rdfjs.Quad_Object | null): Generator<rdfjs.Quad, void, any>; expand(store: rdfjs.DatasetCore, sourceGraph: string | rdfjs.Quad_Graph, targetGraph?: string | rdfjs.Quad_Graph): rdfjs.DatasetCore; protected beforeInference(): void; protected afterInference(): void; protected resetState(): void; abstract applyInference(quad: rdfjs.Quad): void; /** * Indicate if a given resource should *not* be inferred to be a owl:NamedIndividual. * @param id A resource URI or blank node identifier. */ protected abstract isClass(id: string): boolean; }