@faubulous/mentor-rdf 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1308,7 +1308,7 @@ eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexp
1308
1308
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
1309
1309
 
1310
1310
  "use strict";
1311
- eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.PropertyRepository = void 0;\nconst tslib_1 = __webpack_require__(/*! tslib */ \"./node_modules/tslib/tslib.es6.mjs\");\nconst n3 = tslib_1.__importStar(__webpack_require__(/*! n3 */ \"./node_modules/n3/src/index.js\"));\nconst ontologies_1 = __webpack_require__(/*! ../ontologies */ \"./src/ontologies/index.ts\");\nconst class_repository_1 = __webpack_require__(/*! ./class-repository */ \"./src/rdf/class-repository.ts\");\nconst { namedNode } = n3.DataFactory;\n/**\n * A repository for retrieving properties from graphs.\n */\nclass PropertyRepository extends class_repository_1.ClassRepository {\n constructor(store) {\n super(store);\n /**\n * The predicate used to indicate the domain of a property.\n */\n this.domainPredicate = ontologies_1.rdfs.domain;\n /**\n * The predicate used to indicate the range of a property.\n */\n this.rangePredicate = ontologies_1.rdfs.range;\n }\n /**\n * Get all properties in the repository.\n * @param options Optional options for retrieving properties.\n * @returns A list of all properties in the repository.\n */\n *getProperties(graphUris, options) {\n const yielded = new Set();\n for (let q of this.store.matchAll(graphUris, null, ontologies_1.rdf.type, ontologies_1.rdf.Property, options?.includeInferred)) {\n if (this.skip(graphUris, q.subject, options)) {\n continue;\n }\n if (!yielded.has(q.subject.value)) {\n yielded.add(q.subject.value);\n yield q.subject.value;\n }\n }\n }\n /**\n * Get properties of a given type.\n * @param typeUri URI of a property type.\n * @param includeInferred Indicate if properties of a more specific type should be included in the result.\n * @returns An iterator of properties of the given type.\n */\n *getRootPropertiesOfType(graphUris, typeUri, options) {\n const yielded = new Set();\n const type = namedNode(typeUri);\n for (let q of this.store.matchAll(graphUris, null, ontologies_1.rdf.type, type, options?.includeInferred)) {\n if (this.skip(graphUris, q.subject, options)) {\n continue;\n }\n let hasSuperProperty = false;\n let referencedSuperProperty = null;\n for (let q2 of this.store.matchAll(graphUris, q.subject, ontologies_1.rdfs.subPropertyOf, null, options?.includeInferred)) {\n // Note: We have not skipped the property so it is relevant for our result. However, if we want \n // to include referenced properties, then we include the referenced super property instead of the\n // current one.\n if (options?.includeReferenced && !this.hasSubject(graphUris, q2.object.value)) {\n // We must assume that the referenced super property is of the same type as the given type or a super type of it.\n referencedSuperProperty = q2.object.value;\n }\n else if (this.skip(graphUris, q2.object, options)) {\n // If the super property is skipped, then we ignore it.\n continue;\n }\n hasSuperProperty = true;\n break;\n }\n // Yield referenced super property if applicable\n if (referencedSuperProperty && !yielded.has(referencedSuperProperty)) {\n yielded.add(referencedSuperProperty);\n yield referencedSuperProperty;\n }\n if (hasSuperProperty) {\n continue;\n }\n let shouldYield = false;\n if (typeUri === ontologies_1.RDF.Property && options?.includeInferred === false) {\n // In the case of rdf:Property, we do not want to include properties that have a more specific type.\n const t = Array.from(this.store.matchAll(graphUris, q.subject, ontologies_1.rdf.type, null, options?.includeInferred)).map(q => q.object.value);\n if (new Set(t).size == 1) {\n shouldYield = true;\n }\n }\n else {\n shouldYield = true;\n }\n if (shouldYield && !yielded.has(q.subject.value)) {\n yielded.add(q.subject.value);\n yield q.subject.value;\n }\n }\n }\n /**\n * Get the super properties of a given property.\n * @param subjectUri URI of a property.\n * @param options Optional options for retrieving properties.\n * @returns An array of super properties of the given property, an empty array if the property has no super properties.\n */\n *getSuperProperties(graphUris, subjectUri, options) {\n const yielded = new Set();\n const s = namedNode(subjectUri);\n for (let q of this.store.matchAll(graphUris, s, ontologies_1.rdfs.subPropertyOf, null, options?.includeInferred)) {\n if (this.skip(graphUris, q.object, options)) {\n continue;\n }\n if (!yielded.has(q.object.value)) {\n yield q.object.value;\n }\n yielded.add(q.object.value);\n }\n }\n /**\n * Recursively find the first path from a given property to a root property.\n * @param subjectUri URI of a property.\n * @param path The current property path.\n * @param backtrack Set of URIs that have already been visited.\n * @param options Optional options for retrieving properties.\n * @returns The first path that is found from the given property to a root class.\n */\n _getRootPropertyPath(graphUris, subjectUri, path, backtrack, options) {\n const superClasses = [...this.getSuperProperties(graphUris, subjectUri, options)];\n for (let o of superClasses.filter(o => !backtrack.has(o))) {\n backtrack.add(o);\n return this._getRootPropertyPath(graphUris, o, [...path, o], backtrack, options);\n }\n return path;\n }\n /**\n * Get the first discovered path from a given property to a root property.\n * @param subjectUri URI of a property.\n * @param options Optional options for retrieving properties.\n * @returns A string array containing the first path that is found from the given property to a root property.\n */\n getRootPropertiesPath(graphUris, subjectUri, options) {\n return this._getRootPropertyPath(graphUris, subjectUri, [], new Set(), options);\n }\n /**\n * Indicate if a given property is direct or indirect (inferred) sub property of another property.\n * @param graphUris URIs of the graphs to search, `undefined` for the default graph.\n * @param subjectUri URI of the sub property.\n * @param classUri URI of the super property.\n * @param options Optional query parameters.\n * @returns `true` if the property is a sub property of the other property, false otherwise.\n */\n isSubPropertyOf(graphUris, subjectUri, classUri, options) {\n return this.getRootPropertiesPath(graphUris, subjectUri, options).includes(classUri);\n }\n /**\n * Indicate if there are sub properties of a given property.\n * @param subjectUri URI of a property.\n * @param options Optional options for retrieving properties.\n * @returns true if the property has sub properties, false otherwise.\n */\n hasSubProperties(graphUris, subjectUri, options) {\n const o = namedNode(subjectUri);\n for (let q of this.store.matchAll(graphUris, null, ontologies_1.rdfs.subPropertyOf, o, options?.includeInferred)) {\n if (!this.skip(graphUris, q.subject, options)) {\n return true;\n }\n }\n return false;\n }\n /**\n * Get the sub properties of a given property or all root properties.\n * @param subjectUri URI of a property or undefined to get all root properties.\n * @param options Optional options for retrieving properties.\n * @returns An array of sub properties of the given property, an empty array if the property has no sub properties.\n */\n *getSubProperties(graphUris, subjectUri, options) {\n if (subjectUri) {\n const yielded = new Set();\n const o = namedNode(subjectUri);\n for (let q of this.store.matchAll(graphUris, null, ontologies_1.rdfs.subPropertyOf, o, options?.includeInferred)) {\n if (this.skip(graphUris, q.subject, options)) {\n continue;\n }\n if (!yielded.has(q.subject.value)) {\n yield q.subject.value;\n }\n yielded.add(q.subject.value);\n }\n }\n else {\n yield* this.getRootProperties(graphUris, options);\n }\n }\n /**\n * Get all properties from the repository that have no super properties.\n * @param options Optional options for retrieving properties.\n * @returns An iterator of root properties in the repository.\n */\n *getRootProperties(graphUris, options) {\n const yielded = new Set();\n const properties = new Set(this.getProperties(graphUris, options));\n for (let p of properties) {\n let hasSuperProperty = false;\n for (let q of this.store.matchAll(graphUris, namedNode(p), ontologies_1.rdfs.subPropertyOf, null, options?.includeInferred)) {\n const includeReferenced = options?.includeReferenced ?? false;\n const skip = this.skip(graphUris, q.object, options);\n // Do not skip the super property if it is only referenced and the includeReferenced option is set.\n if (q.object.termType != \"NamedNode\" || skip && (!includeReferenced || includeReferenced && this.hasSubject(graphUris, q.object.value))) {\n continue;\n }\n // We have at least one super property that is not the property itself.\n hasSuperProperty = q.object.value != q.subject.value;\n // If we have a super property that is not in the list of properties and not excluded by the options, we add it to the result.\n if (!properties.has(q.object.value) && !yielded.has(q.object.value)) {\n yielded.add(q.object.value);\n yield q.object.value;\n }\n break;\n }\n if (!hasSuperProperty && !yielded.has(p)) {\n yielded.add(p);\n yield p;\n }\n }\n }\n /**\n * Indicate if there is an equivalent property of a given property.\n * @param propertyUri URI of a property.\n * @returns true if the property has an equivalent property, false otherwise.\n */\n hasEquivalentProperty(graphUris, propertyUri) {\n const s = namedNode(propertyUri);\n // The OWL resoner will assert the equivalent class relationship in both directions.\n for (let _ of this.store.matchAll(graphUris, s, ontologies_1.owl.equivalentProperty, null)) {\n return true;\n }\n return false;\n }\n /**\n * Get the domain of a given property.\n * @param propertyUri URI of a property.\n * @returns The URI of the domain of the given property. If no domain is specified, rdfs:Resource is returned.\n */\n getDomain(graphUris, propertyUri) {\n const s = namedNode(propertyUri);\n for (let q of this.store.matchAll(graphUris, s, this.domainPredicate, null)) {\n return q.object.value;\n }\n return ontologies_1.rdfs.Resource.value;\n }\n /**\n * Get the range of a given property.\n * @param propertyUri URI of a property.\n * @returns The URI of the range of the given property. If no range is specified, `undefined` is returned.\n */\n getRange(graphUris, propertyUri) {\n const s = namedNode(propertyUri);\n for (let q of this.store.matchAll(graphUris, s, this.rangePredicate, null)) {\n return q.object.value;\n }\n return undefined;\n }\n /**\n * Get all asserted and inferred property types.\n * @param graphUris The URI of the graph or an array of graphs to search for property types.\n * @param options Optional options for retrieving properties.\n * @returns An iterator of all property types in the repository.\n */\n *getPropertyTypes(graphUris, options) {\n const yielded = new Set();\n for (let property of this.getProperties(graphUris, options)) {\n const p = namedNode(property);\n const types = new Set(Array.from(this.store.matchAll(graphUris, p, ontologies_1.rdf.type, null, false)).map(t => t.object.value));\n if (types.size > 0) {\n for (let t of types) {\n // Do not assert rdf:Property for properties that have multiple types.\n if ((t !== ontologies_1.RDF.Property || types.size == 1) && !yielded.has(t)) {\n yielded.add(t);\n yield t;\n }\n }\n }\n else {\n // If there are no asserted types, we need to infer rdf:Property.\n if (!yielded.has(ontologies_1.RDF.Property)) {\n yielded.add(ontologies_1.RDF.Property);\n yield ontologies_1.RDF.Property;\n }\n }\n }\n }\n}\nexports.PropertyRepository = PropertyRepository;\n\n\n//# sourceURL=webpack://@faubulous/mentor-rdf/./src/rdf/property-repository.ts?\n}");
1311
+ eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.PropertyRepository = void 0;\nconst tslib_1 = __webpack_require__(/*! tslib */ \"./node_modules/tslib/tslib.es6.mjs\");\nconst n3 = tslib_1.__importStar(__webpack_require__(/*! n3 */ \"./node_modules/n3/src/index.js\"));\nconst ontologies_1 = __webpack_require__(/*! ../ontologies */ \"./src/ontologies/index.ts\");\nconst class_repository_1 = __webpack_require__(/*! ./class-repository */ \"./src/rdf/class-repository.ts\");\nconst { namedNode } = n3.DataFactory;\n/**\n * A repository for retrieving properties from graphs.\n */\nclass PropertyRepository extends class_repository_1.ClassRepository {\n constructor(store) {\n super(store);\n /**\n * The predicate used to indicate the domain of a property.\n */\n this.domainPredicate = ontologies_1.rdfs.domain;\n /**\n * The predicate used to indicate the range of a property.\n */\n this.rangePredicate = ontologies_1.rdfs.range;\n }\n /**\n * Get all properties in the repository.\n * @param options Optional options for retrieving properties.\n * @returns A list of all properties in the repository.\n */\n *getProperties(graphUris, options) {\n const yielded = new Set();\n for (let q of this.store.matchAll(graphUris, null, ontologies_1.rdf.type, ontologies_1.rdf.Property, options?.includeInferred)) {\n if (this.skip(graphUris, q.subject, options)) {\n continue;\n }\n if (!yielded.has(q.subject.value)) {\n yielded.add(q.subject.value);\n yield q.subject.value;\n }\n }\n }\n /**\n * Get properties of a given type.\n * @param typeUri URI of a property type.\n * @param includeInferred Indicate if properties of a more specific type should be included in the result.\n * @returns An iterator of properties of the given type.\n */\n *getRootPropertiesOfType(graphUris, typeUri, options) {\n const yielded = new Set();\n const type = namedNode(typeUri);\n for (let q of this.store.matchAll(graphUris, null, ontologies_1.rdf.type, type, options?.includeInferred)) {\n if (this.skip(graphUris, q.subject, options)) {\n continue;\n }\n let hasSuperProperty = false;\n let referencedSuperProperty = null;\n for (let q2 of this.store.matchAll(graphUris, q.subject, ontologies_1.rdfs.subPropertyOf, null, options?.includeInferred)) {\n // Note: We have not skipped the property so it is relevant for our result. However, if we want \n // to include referenced properties, then we include the referenced super property instead of the\n // current one.\n if (options?.includeReferenced && !this.hasSubject(graphUris, q2.object.value)) {\n // We must assume that the referenced super property is of the same type as the given type or a super type of it.\n referencedSuperProperty = q2.object.value;\n }\n else if (this.skip(graphUris, q2.object, options)) {\n // If the super property is skipped, then we ignore it.\n continue;\n }\n hasSuperProperty = q2.object.value != q2.subject.value;\n break;\n }\n // Yield referenced super property if applicable\n if (referencedSuperProperty && !yielded.has(referencedSuperProperty)) {\n yielded.add(referencedSuperProperty);\n yield referencedSuperProperty;\n }\n if (hasSuperProperty) {\n continue;\n }\n let shouldYield = false;\n if (typeUri === ontologies_1.RDF.Property && options?.includeInferred === false) {\n // In the case of rdf:Property, we do not want to include properties that have a more specific type.\n const t = Array.from(this.store.matchAll(graphUris, q.subject, ontologies_1.rdf.type, null, options?.includeInferred)).map(q => q.object.value);\n if (new Set(t).size == 1) {\n shouldYield = true;\n }\n }\n else {\n shouldYield = true;\n }\n if (shouldYield && !yielded.has(q.subject.value)) {\n yielded.add(q.subject.value);\n yield q.subject.value;\n }\n }\n }\n /**\n * Get the super properties of a given property.\n * @param subjectUri URI of a property.\n * @param options Optional options for retrieving properties.\n * @returns An array of super properties of the given property, an empty array if the property has no super properties.\n */\n *getSuperProperties(graphUris, subjectUri, options) {\n const yielded = new Set();\n const s = namedNode(subjectUri);\n for (let q of this.store.matchAll(graphUris, s, ontologies_1.rdfs.subPropertyOf, null, options?.includeInferred)) {\n if (this.skip(graphUris, q.object, options)) {\n continue;\n }\n if (!yielded.has(q.object.value)) {\n yield q.object.value;\n }\n yielded.add(q.object.value);\n }\n }\n /**\n * Recursively find the first path from a given property to a root property.\n * @param subjectUri URI of a property.\n * @param path The current property path.\n * @param backtrack Set of URIs that have already been visited.\n * @param options Optional options for retrieving properties.\n * @returns The first path that is found from the given property to a root class.\n */\n _getRootPropertyPath(graphUris, subjectUri, path, backtrack, options) {\n const superClasses = [...this.getSuperProperties(graphUris, subjectUri, options)];\n for (let o of superClasses.filter(o => !backtrack.has(o))) {\n backtrack.add(o);\n return this._getRootPropertyPath(graphUris, o, [...path, o], backtrack, options);\n }\n return path;\n }\n /**\n * Get the first discovered path from a given property to a root property.\n * @param subjectUri URI of a property.\n * @param options Optional options for retrieving properties.\n * @returns A string array containing the first path that is found from the given property to a root property.\n */\n getRootPropertiesPath(graphUris, subjectUri, options) {\n return this._getRootPropertyPath(graphUris, subjectUri, [], new Set(), options);\n }\n /**\n * Indicate if a given property is direct or indirect (inferred) sub property of another property.\n * @param graphUris URIs of the graphs to search, `undefined` for the default graph.\n * @param subjectUri URI of the sub property.\n * @param classUri URI of the super property.\n * @param options Optional query parameters.\n * @returns `true` if the property is a sub property of the other property, false otherwise.\n */\n isSubPropertyOf(graphUris, subjectUri, classUri, options) {\n return this.getRootPropertiesPath(graphUris, subjectUri, options).includes(classUri);\n }\n /**\n * Indicate if there are sub properties of a given property.\n * @param subjectUri URI of a property.\n * @param options Optional options for retrieving properties.\n * @returns true if the property has sub properties, false otherwise.\n */\n hasSubProperties(graphUris, subjectUri, options) {\n const o = namedNode(subjectUri);\n for (let q of this.store.matchAll(graphUris, null, ontologies_1.rdfs.subPropertyOf, o, options?.includeInferred)) {\n if (!this.skip(graphUris, q.subject, options)) {\n return true;\n }\n }\n return false;\n }\n /**\n * Get the sub properties of a given property or all root properties.\n * @param subjectUri URI of a property or undefined to get all root properties.\n * @param options Optional options for retrieving properties.\n * @returns An array of sub properties of the given property, an empty array if the property has no sub properties.\n */\n *getSubProperties(graphUris, subjectUri, options) {\n if (subjectUri) {\n const yielded = new Set();\n const o = namedNode(subjectUri);\n for (let q of this.store.matchAll(graphUris, null, ontologies_1.rdfs.subPropertyOf, o, options?.includeInferred)) {\n if (this.skip(graphUris, q.subject, options)) {\n continue;\n }\n if (!yielded.has(q.subject.value)) {\n yield q.subject.value;\n }\n yielded.add(q.subject.value);\n }\n }\n else {\n yield* this.getRootProperties(graphUris, options);\n }\n }\n /**\n * Get all properties from the repository that have no super properties.\n * @param options Optional options for retrieving properties.\n * @returns An iterator of root properties in the repository.\n */\n *getRootProperties(graphUris, options) {\n const yielded = new Set();\n const properties = new Set(this.getProperties(graphUris, options));\n for (let p of properties) {\n let hasSuperProperty = false;\n for (let q of this.store.matchAll(graphUris, namedNode(p), ontologies_1.rdfs.subPropertyOf, null, options?.includeInferred)) {\n const includeReferenced = options?.includeReferenced ?? false;\n const skip = this.skip(graphUris, q.object, options);\n // Do not skip the super property if it is only referenced and the includeReferenced option is set.\n if (q.object.termType != \"NamedNode\" || skip && (!includeReferenced || includeReferenced && this.hasSubject(graphUris, q.object.value))) {\n continue;\n }\n // We have at least one super property that is not the property itself.\n hasSuperProperty = q.object.value != q.subject.value;\n // If we have a super property that is not in the list of properties and not excluded by the options, we add it to the result.\n if (!properties.has(q.object.value) && !yielded.has(q.object.value)) {\n yielded.add(q.object.value);\n yield q.object.value;\n }\n break;\n }\n if (!hasSuperProperty && !yielded.has(p)) {\n yielded.add(p);\n yield p;\n }\n }\n }\n /**\n * Indicate if there is an equivalent property of a given property.\n * @param propertyUri URI of a property.\n * @returns true if the property has an equivalent property, false otherwise.\n */\n hasEquivalentProperty(graphUris, propertyUri) {\n const s = namedNode(propertyUri);\n // The OWL resoner will assert the equivalent class relationship in both directions.\n for (let _ of this.store.matchAll(graphUris, s, ontologies_1.owl.equivalentProperty, null)) {\n return true;\n }\n return false;\n }\n /**\n * Get the domain of a given property.\n * @param propertyUri URI of a property.\n * @returns The URI of the domain of the given property. If no domain is specified, rdfs:Resource is returned.\n */\n getDomain(graphUris, propertyUri) {\n const s = namedNode(propertyUri);\n for (let q of this.store.matchAll(graphUris, s, this.domainPredicate, null)) {\n return q.object.value;\n }\n return ontologies_1.rdfs.Resource.value;\n }\n /**\n * Get the range of a given property.\n * @param propertyUri URI of a property.\n * @returns The URI of the range of the given property. If no range is specified, `undefined` is returned.\n */\n getRange(graphUris, propertyUri) {\n const s = namedNode(propertyUri);\n for (let q of this.store.matchAll(graphUris, s, this.rangePredicate, null)) {\n return q.object.value;\n }\n return undefined;\n }\n /**\n * Get all asserted and inferred property types.\n * @param graphUris The URI of the graph or an array of graphs to search for property types.\n * @param options Optional options for retrieving properties.\n * @returns An iterator of all property types in the repository.\n */\n *getPropertyTypes(graphUris, options) {\n const yielded = new Set();\n for (let property of this.getProperties(graphUris, options)) {\n const p = namedNode(property);\n const types = new Set(Array.from(this.store.matchAll(graphUris, p, ontologies_1.rdf.type, null, false)).map(t => t.object.value));\n if (types.size > 0) {\n for (let t of types) {\n // Do not assert rdf:Property for properties that have multiple types.\n if ((t !== ontologies_1.RDF.Property || types.size == 1) && !yielded.has(t)) {\n yielded.add(t);\n yield t;\n }\n }\n }\n else {\n // If there are no asserted types, we need to infer rdf:Property.\n if (!yielded.has(ontologies_1.RDF.Property)) {\n yielded.add(ontologies_1.RDF.Property);\n yield ontologies_1.RDF.Property;\n }\n }\n }\n }\n}\nexports.PropertyRepository = PropertyRepository;\n\n\n//# sourceURL=webpack://@faubulous/mentor-rdf/./src/rdf/property-repository.ts?\n}");
1312
1312
 
1313
1313
  /***/ }),
1314
1314
 
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "ontology",
11
11
  "vocabulary"
12
12
  ],
13
- "version": "0.3.0",
13
+ "version": "0.3.1",
14
14
  "private": false,
15
15
  "author": {
16
16
  "name": "Sebastian Faubel"