UNPKG

sparnatural

Version:

Visual client-side SPARQL query builder and knowledge graph exploration tool

179 lines 9.96 kB
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _OWLSpecificationEntity_instances, _OWLSpecificationEntity__isSparnaturalClass, _OWLSpecificationEntity__readPropertiesWithDomain, _OWLSpecificationEntity__readImmediateSuperClasses, _OWLSpecificationEntity__readImmediateSubClasses; import { OWLSpecificationEntry } from "./OWLSpecificationEntry"; import { OWL } from "./OWLSpecificationProvider"; import { Config } from "../../ontologies/SparnaturalConfig"; import { OWLSpecificationProperty } from "./OWLSpecificationProperty"; import { DataFactory } from 'rdf-data-factory'; import { Dag } from "../../dag/Dag"; import { RDFS } from "../../../rdf/vocabularies/RDFS"; import { RDF } from "../BaseRDFReader"; const factory = new DataFactory(); export class OWLSpecificationEntity extends OWLSpecificationEntry { constructor(uri, provider, n3store, lang) { super(uri, provider, n3store, lang); _OWLSpecificationEntity_instances.add(this); } getConnectedEntities() { var items = new Set(); const properties = __classPrivateFieldGet(this, _OWLSpecificationEntity_instances, "m", _OWLSpecificationEntity__readPropertiesWithDomain).call(this, this.uri); // now read their ranges for (const aProperty of properties) { let prop = new OWLSpecificationProperty(aProperty, this.provider, this.store, this.lang); var classesInRange = prop.getRange(); for (const aClass of classesInRange) { // if it is not a Sparnatural Class, read all its subClasses that are Sparnatural classes if (!__classPrivateFieldGet(this, _OWLSpecificationEntity_instances, "m", _OWLSpecificationEntity__isSparnaturalClass).call(this, aClass)) { // TODO : recursivity var subClasses = __classPrivateFieldGet(this, _OWLSpecificationEntity_instances, "m", _OWLSpecificationEntity__readImmediateSubClasses).call(this, aClass); for (const aSubClass of subClasses) { if (__classPrivateFieldGet(this, _OWLSpecificationEntity_instances, "m", _OWLSpecificationEntity__isSparnaturalClass).call(this, aSubClass)) { items.add(aSubClass); } } } else { items.add(aClass); } } } // recreate an array from the set // and sort it return this.provider._sort(Array.from(items)); } getConnectedEntitiesTree() { // 1. get the entities that are in a domain of a property let entities = this.getConnectedEntities().map(s => this.provider.getEntity(s)); // build dag from flat list let dag = new Dag(); dag.initFlatTreeFromFlatList(entities); return dag; } hasConnectedEntities() { return this.getConnectedEntities().length > 0; } getConnectingProperties(range) { const items = new Set(); const properties = __classPrivateFieldGet(this, _OWLSpecificationEntity_instances, "m", _OWLSpecificationEntity__readPropertiesWithDomain).call(this, this.uri); for (const aProperty of properties) { let prop = new OWLSpecificationProperty(aProperty, this.provider, this.store, this.lang); var classesInRange = prop.getRange(); if (classesInRange.indexOf(range) > -1) { items.add(aProperty); } else { // potentially the select rangeClassId is a subClass, let's look up for (const aClass of classesInRange) { // TODO : recursivity var subClasses = __classPrivateFieldGet(this, _OWLSpecificationEntity_instances, "m", _OWLSpecificationEntity__readImmediateSubClasses).call(this, aClass); if (subClasses.indexOf(range) > -1) { items.add(aProperty); } } } } // recreate an array from the set // and sort it return this.provider._sort(Array.from(items)); } /** * Return the tree of properties connecting this entity to the specified range entity * @param range The URI of the selected target entity * @returns */ getConnectingPropertiesTree(range) { // 1. get list of properties let entities = this.getConnectingProperties(range).map(s => this.provider.getProperty(s)); // 2. turn it into a flat tree let dag = new Dag(); dag.initFlatTreeFromFlatList(entities); return dag; } isLiteralEntity() { return (this.store.getQuads(factory.namedNode(this.uri), RDFS.SUBCLASS_OF, factory.namedNode(Config.RDFS_LITERAL), null).length > 0); } hasTypeCriteria() { return (this.store.getQuads(factory.namedNode(this.uri), RDFS.SUBCLASS_OF, factory.namedNode(Config.NOT_INSTANTIATED_CLASS), null).length == 0); } getDefaultLabelProperty() { return this.graph.readSingleProperty(factory.namedNode(this.uri), factory.namedNode(Config.DEFAULT_LABEL_PROPERTY))?.value; } // unsupported in OWL config couldBeSkosConcept() { return false; } /*** Handling of UNION classes ***/ _isInUnion(classUri) { return (this.store.getQuads(null, RDF.FIRST, classUri, null).length > 0); } _readUnionsContaining(classId) { var unions = Array(); var listsContainingThisClass = this.store .getQuads(null, RDF.FIRST, factory.namedNode(classId), null) .map((quad) => quad.subject); for (const aListContainingThisClass of listsContainingThisClass) { var rootList = this.graph.readRootList(aListContainingThisClass); // now read the union pointing to this list var unionPointingToThisList = this.store .getQuads(null, OWL.UNION_OF, rootList, null) .map((quad) => quad.subject); if (unionPointingToThisList.length > 0) { unions.push(unionPointingToThisList[0]); } } return unions; } } _OWLSpecificationEntity_instances = new WeakSet(), _OWLSpecificationEntity__isSparnaturalClass = function _OWLSpecificationEntity__isSparnaturalClass(classUri) { return (this.store.getQuads(factory.namedNode(classUri), RDFS.SUBCLASS_OF, factory.namedNode(Config.SPARNATURAL_CLASS), null).length > 0 || this.store.getQuads(factory.namedNode(classUri), RDFS.SUBCLASS_OF, factory.namedNode(Config.NOT_INSTANTIATED_CLASS), null).length > 0 || this.store.getQuads(factory.namedNode(classUri), RDFS.SUBCLASS_OF, factory.namedNode(Config.RDFS_LITERAL), null).length > 0); }, _OWLSpecificationEntity__readPropertiesWithDomain = function _OWLSpecificationEntity__readPropertiesWithDomain(classId) { const properties = new Set(); const propertyQuads = this.store.getQuads(null, RDFS.DOMAIN, factory.namedNode(classId), null); for (const aQuad of propertyQuads) { // only select properties with proper Sparnatural configuration if (new OWLSpecificationProperty(aQuad.subject.value, this.provider, this.store, this.lang).getPropertyType("")) { properties.add(aQuad.subject.value); } } // read also the properties having as a domain a union containing this class var unionsContainingThisClass = this._readUnionsContaining(classId); for (const aUnionContainingThisClass of unionsContainingThisClass) { const propertyQuadsHavingUnionAsDomain = this.store.getQuads(null, RDFS.DOMAIN, aUnionContainingThisClass, null); for (const aQuad of propertyQuadsHavingUnionAsDomain) { // only select properties with proper Sparnatural configuration if (new OWLSpecificationProperty(aQuad.subject.value, this.provider, this.store, this.lang).getPropertyType("")) { properties.add(aQuad.subject.value); } } } // read also the properties having as a domain a super-class of this class var superClassesOfThisClass = __classPrivateFieldGet(this, _OWLSpecificationEntity_instances, "m", _OWLSpecificationEntity__readImmediateSuperClasses).call(this, classId); for (const anImmediateSuperClass of superClassesOfThisClass) { var propertiesFromSuperClass = __classPrivateFieldGet(this, _OWLSpecificationEntity_instances, "m", _OWLSpecificationEntity__readPropertiesWithDomain).call(this, anImmediateSuperClass); for (const aProperty of propertiesFromSuperClass) { properties.add(aProperty); } } return Array.from(properties); }, _OWLSpecificationEntity__readImmediateSuperClasses = function _OWLSpecificationEntity__readImmediateSuperClasses(classId) { const classes = new Set(); const subClassQuads = this.store.getQuads(factory.namedNode(classId), RDFS.SUBCLASS_OF, null, null); for (const aQuad of subClassQuads) { classes.add(aQuad.object.value); } return Array.from(classes); }, _OWLSpecificationEntity__readImmediateSubClasses = function _OWLSpecificationEntity__readImmediateSubClasses(classId) { const classes = new Set(); const subClassQuads = this.store.getQuads(null, RDFS.SUBCLASS_OF, factory.namedNode(classId), null); for (const aQuad of subClassQuads) { classes.add(aQuad.subject.value); } return Array.from(classes); }; //# sourceMappingURL=OWLSpecificationEntity.js.map