UNPKG

lincd

Version:

LINCD is a JavaScript library for building user interfaces with linked data (also known as 'structured data', or RDF)

36 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ForwardReasoning = void 0; const rdf_1 = require("../ontologies/rdf"); const rdfs_1 = require("../ontologies/rdfs"); const owl_1 = require("../ontologies/owl"); class ForwardReasoning { /** * Checks if a node has a certain type using forward reasoning. * Mimics inference of rdf:type & rdfs:subClassOf relations * @param node * @param targetType * @private */ static hasType(node, targetType) { //checks if any of the types matches the target type, or is a subclass of the target type (then the node also has that inferred type) or if the type is a subclass of a type that is a subclass of the target type (iteratively, so could be any level deep) //OR in the presence of an owl:equivalentClass property, if any of the equivalentClasses is equivalent to the target type, or is a subClassOf the targetClass return node.getAll(rdf_1.rdf.type).some((type) => { return type === targetType || this.isSubClassOf(type, targetType) || (type.hasProperty(owl_1.owl.equivalentClass) && type.getAll(owl_1.owl.equivalentClass).some(equivalentClass => { return equivalentClass === targetType || this.isSubClassOf(equivalentClass, targetType); })); }); } /** * Checks if a type is a subClass of another type using forward reasoning. * Mimics inference of rdfs:subClassOf relations * @param type * @param targetType */ static isSubClassOf(type, targetType) { return (type.has(rdfs_1.rdfs.subClassOf, targetType) || type.getAll(rdfs_1.rdfs.subClassOf).some((superType) => this.isSubClassOf(superType, targetType))); } } exports.ForwardReasoning = ForwardReasoning; //# sourceMappingURL=ForwardReasoning.js.map