UNPKG

@faubulous/mentor-rdf

Version:

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

73 lines (72 loc) 3.49 kB
import * as rdfjs from "@rdfjs/types"; export interface Reasoner { /** * Get the URI of the graph where the inferred triples are stored. * @param uri A graph URI. */ getInferenceGraphUri(uri: string): string; /** * Indicate if a given URI is the URI of the graph where the inferred triples are stored. * @param uri A graph URI. */ isInferenceGraphUri(uri: string): boolean; /** * 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 { /** * Appendix to the IRI of a graph that is the result of reasoning over another graph. */ protected readonly inferenceGraphKey = "inference=mentor"; protected store: rdfjs.DatasetCore; sourceGraph?: rdfjs.Quad_Graph; targetGraph?: rdfjs.Quad_Graph; readonly errors: { message: string; quad: rdfjs.Quad; }[]; /** * Get the IRI of the graph containing the inferenced triples. * @param uri IRI of the graph to be reasoned upon. * @returns The IRI of the graph containing the inferenced triples. */ getInferenceGraphUri(uri: string | rdfjs.Quad_Graph): string; isInferenceGraphUri(uri: string | rdfjs.Quad_Graph): boolean; 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; }