UNPKG

@faubulous/mentor-rdf

Version:

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

139 lines (138 loc) 5.76 kB
import { Quad_Subject, Quad_Object } from "@rdfjs/types"; import { Store } from "./store"; /** * Parameters for matching triples in the store. */ export interface QueryOptions { /** * Indicates if inferred triples should be included in the result. If `undefined`, * the default value is `true` when a reasoner associated with the store and `false` otherwise. */ includeInferred?: boolean; } /** * Parameters for querying resources in the store that have an explicitly asserted type in the document. */ export interface DefinitionQueryOptions extends QueryOptions { /** * URI of the vocabulary that defines the resources. If `null`, returns only resources that have no `rdfs:isDefinedBy` property. */ definedBy?: string | null; /** * URIs of the vocabularies in which the resources must not be defined, either by sharing a namespace or by `rdfs:isDefinedBy`. */ notDefinedBy?: Set<string>; /** * Indicate if terms what are not *defined* in the ontology should be included in the result (default: false). */ includeReferenced?: boolean; /** * Indicate if blank nodes should be included in the result (default: false). */ includeBlankNodes?: boolean; } /** * Parameters for store queries that support filtering on the type of resource. */ export interface TypedInstanceQueryOptions extends QueryOptions { /** * Indicate if instances of a subclasses of the type should be included in the result. */ includeSubTypes?: boolean; } /** * Maps a language tag to the number of occurrences in the document. */ export interface LanguageTagUsageStats { [key: string]: number; } /** * Maps a predicate IRI to information about its usage in the document. */ export interface PredicateUsageStats { [key: string]: PredicateUsageInfo; } /** * Information about the usage of a single predicate in a document. */ export interface PredicateUsageInfo { /** * The predicate IRI. */ predicateIri: string; /** * The set of subjects that use the predicate. */ subjects: Set<string>; /** * The number of occurrences of the predicate in a document. */ usageFrequency: number; /** * Information about the language tags used in the object of triples with the predicate. */ languageTags: { [key: string]: number; }; } /** * A repository for retrieving resources from graphs. */ export declare class ResourceRepository { /** * The RDF triple store. */ readonly store: Store; constructor(store: Store); /** * Inidiates if a node should not be included in the result of a definition query. * @param graphUris URIs of the graphs to search. * @param subject The focus node. * @param options Definition query options. * @param optionDefaults Custom default values for the query options. * @returns */ protected skip(graphUris: string | string[] | undefined, subject: Quad_Subject | Quad_Object, options?: DefinitionQueryOptions, optionDefaults?: DefinitionQueryOptions): boolean; /** * Indicate if a given URI exists as the subject of a triple in the graph. * @param graphUris URIs of the graphs to search. * @param subjectUri URI of the subject to search for. * @returns true if the URI is a subject, false otherwise. */ hasSubject(graphUris: string | string[] | undefined, subjectUri: string | Quad_Subject | Quad_Object): boolean; /** * Indicate if a node is explicitly defined by the given URI using the `rdfs:isDefinedBy` property, or implicitly by sharing the same namespace. * @param graphUris URIs of the graphs to search. * @param node A named node to check if it is defined by the given URI. * @param definedBy URI of the vocabulary that defines the resource (rdfs:isDefinedBy). Provide `null` to only return resources that have no `rdfs:isDefinedBy` property. * @returns `true` if the node is defined by the given URI, `false` otherwise. */ isDefinedBy(graphUris: string | string[] | undefined, node: Quad_Subject, definedBy: string | null): boolean; /** * Indicate if a resource has a given type in the graph. * @param graphUris URIs of the graphs to search. * @param subjectUri URI or blank node id of the subject to match. * @param typeUri URI of the type to match. * @param options Optional query parameters. * @returns `true` if the resource has the type, `false` otherwise. */ hasType(graphUris: string | string[] | undefined, subjectUri: string, typeUri: string, options?: QueryOptions): boolean; /** * Get information about the usage of predicates in the document such as the frequency of use and the use of language tags. * @param graphUris URIs of the graphs to search. * @param predicateUris URIs of the predicates to match. */ getPredicateUsageStats(graphUris: string | string[] | undefined, predicateUris?: string[] | undefined): PredicateUsageStats; /** * Get the language tags used in the object of triples with a given set of predicates. * @param graphUris URIs of the graphs to search. * @param predicateUris URIs of the predicates to match. * @returns An array of language tag statistics, sorted by the number of occurrences in descending order. */ getLanguageTagUsageStats(graphUris: string | string[] | undefined): LanguageTagUsageStats; /** * Get the most frequently used language tag in the object of triples with a given set of predicates. * @param graphUris URIs of the graphs to search. */ getMostFrequentLanguageTag(graphUris: string | string[] | undefined): string | undefined; }