@faubulous/mentor-rdf 0.2.47 → 0.2.48

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/out/index.js +1 -1
  2. package/package.json +2 -1
package/out/index.js CHANGED
@@ -742,7 +742,7 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexpo
742
742
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
743
743
 
744
744
  "use strict";
745
- eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.ReasonerBase = 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\");\n/**\n * A base class for reasoners that expand graphs with inferred triples.\n */\nclass ReasonerBase {\n constructor() {\n this.store = new n3.Store();\n this.errors = [];\n }\n getInferenceGraphUri(uri) {\n const u = new URL(typeof uri == \"string\" ? uri : uri.value);\n u.protocol = 'mentor:';\n // This reasoner is specifically designed to work with the Mentor platform.\n return u.toString();\n }\n isInferenceGraphUri(uri) {\n const u = new URL(typeof uri == \"string\" ? uri : uri.value);\n return u.protocol === 'mentor:';\n }\n getGraphNode(graph) {\n if (typeof graph === \"string\") {\n return new n3.NamedNode(graph);\n }\n else {\n return graph;\n }\n }\n isW3CNode(term) {\n return term.value.startsWith(\"http://www.w3.org\");\n }\n /**\n * Get the URIs of ordered list members in the store.\n * @param graphUris Optional graph URI or array of graph URIs to query.\n * @param listUri URI of the list to get the items from.\n * @returns An array of URIs of the items in the list.\n */\n getListItems(listUri) {\n // To do: Fix #10\n const list = listUri.includes(':') ? new n3.NamedNode(listUri) : new n3.BlankNode(listUri);\n return this._getListItems(list);\n }\n _getListItems(subject) {\n if (!this.sourceGraph) {\n return [];\n }\n let first = Array.from(this.match(this.sourceGraph, subject, ontologies_1.rdf.first, null));\n if (!first.length) {\n return [];\n }\n const rest = Array.from(this.match(this.sourceGraph, subject, ontologies_1.rdf.rest, null));\n const firstItem = first[0].object;\n const restList = rest[0]?.object;\n if (restList.value === ontologies_1.RDF.nil) {\n return [firstItem];\n }\n else {\n const restItems = this._getListItems(restList);\n return [firstItem, ...restItems];\n }\n }\n /**\n * Query the store for triples matching the given pattern supporting multiple graphs.\n * @param graphUris Optional graph URI or array of graph URIs to query.\n * @param subject A subject URI or null to match any subject.\n * @param predicate A predicate URI or null to match any predicate.\n * @param object An object URI or null to match any object.\n * @todo Refactor and merge with the same method in the Mentor RDF Store class.\n */\n *match(graph, subject, predicate, object) {\n if (graph !== undefined) {\n yield* this.store.match(subject, predicate, object, graph);\n }\n else {\n yield* this.store.match(subject, predicate, object);\n }\n }\n expand(store, sourceGraph, targetGraph) {\n if (!targetGraph) {\n targetGraph = this.getInferenceGraphUri(sourceGraph);\n }\n this.store = store;\n if (this.store.getGraphs(null, null, null).filter(g => g.id == targetGraph).length > 0) {\n // Ensure the target graph is empty so this function is idempotent and consistent.\n store.deleteGraph(targetGraph);\n }\n this.sourceGraph = this.getGraphNode(sourceGraph);\n this.targetGraph = this.getGraphNode(targetGraph);\n this.beforeInference();\n for (let quad of store.match(null, null, null, this.sourceGraph)) {\n let q = quad;\n this.applyInference(q);\n }\n this.afterInference();\n return store;\n }\n beforeInference() { }\n afterInference() { }\n}\nexports.ReasonerBase = ReasonerBase;\n\n\n//# sourceURL=webpack://@faubulous/mentor-rdf/./src/rdf/reasoners/reasoner.ts?");
745
+ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.ReasonerBase = 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\");\n/**\n * A base class for reasoners that expand graphs with inferred triples.\n */\nclass ReasonerBase {\n constructor() {\n this.store = new n3.Store();\n this.errors = [];\n }\n getInferenceGraphUri(uri) {\n const u = typeof uri === \"string\" ? uri : uri.value;\n // Let the function throw an error if the URI is not valid.\n return 'mentor:' + u.substring(u.indexOf(':') + 1);\n }\n isInferenceGraphUri(uri) {\n const u = new URL(typeof uri == \"string\" ? uri : uri.value);\n return u.protocol === 'mentor:';\n }\n getGraphNode(graph) {\n if (typeof graph === \"string\") {\n return new n3.NamedNode(graph);\n }\n else {\n return graph;\n }\n }\n isW3CNode(term) {\n return term.value.startsWith(\"http://www.w3.org\");\n }\n /**\n * Get the URIs of ordered list members in the store.\n * @param graphUris Optional graph URI or array of graph URIs to query.\n * @param listUri URI of the list to get the items from.\n * @returns An array of URIs of the items in the list.\n */\n getListItems(listUri) {\n // To do: Fix #10\n const list = listUri.includes(':') ? new n3.NamedNode(listUri) : new n3.BlankNode(listUri);\n return this._getListItems(list);\n }\n _getListItems(subject) {\n if (!this.sourceGraph) {\n return [];\n }\n let first = Array.from(this.match(this.sourceGraph, subject, ontologies_1.rdf.first, null));\n if (!first.length) {\n return [];\n }\n const rest = Array.from(this.match(this.sourceGraph, subject, ontologies_1.rdf.rest, null));\n const firstItem = first[0].object;\n const restList = rest[0]?.object;\n if (restList.value === ontologies_1.RDF.nil) {\n return [firstItem];\n }\n else {\n const restItems = this._getListItems(restList);\n return [firstItem, ...restItems];\n }\n }\n /**\n * Query the store for triples matching the given pattern supporting multiple graphs.\n * @param graphUris Optional graph URI or array of graph URIs to query.\n * @param subject A subject URI or null to match any subject.\n * @param predicate A predicate URI or null to match any predicate.\n * @param object An object URI or null to match any object.\n * @todo Refactor and merge with the same method in the Mentor RDF Store class.\n */\n *match(graph, subject, predicate, object) {\n if (graph !== undefined) {\n yield* this.store.match(subject, predicate, object, graph);\n }\n else {\n yield* this.store.match(subject, predicate, object);\n }\n }\n expand(store, sourceGraph, targetGraph) {\n if (!targetGraph) {\n targetGraph = this.getInferenceGraphUri(sourceGraph);\n }\n this.store = store;\n if (this.store.getGraphs(null, null, null).filter(g => g.id == targetGraph).length > 0) {\n // Ensure the target graph is empty so this function is idempotent and consistent.\n store.deleteGraph(targetGraph);\n }\n this.sourceGraph = this.getGraphNode(sourceGraph);\n this.targetGraph = this.getGraphNode(targetGraph);\n this.beforeInference();\n for (let quad of store.match(null, null, null, this.sourceGraph)) {\n let q = quad;\n this.applyInference(q);\n }\n this.afterInference();\n return store;\n }\n beforeInference() { }\n afterInference() { }\n}\nexports.ReasonerBase = ReasonerBase;\n\n\n//# sourceURL=webpack://@faubulous/mentor-rdf/./src/rdf/reasoners/reasoner.ts?");
746
746
 
747
747
  /***/ }),
748
748
 
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "ontology",
11
11
  "vocabulary"
12
12
  ],
13
- "version": "0.2.47",
13
+ "version": "0.2.48",
14
14
  "private": false,
15
15
  "author": {
16
16
  "name": "Sebastian Faubel"
@@ -36,6 +36,7 @@
36
36
  "license": "GPL",
37
37
  "scripts": {
38
38
  "prepublish": "npm run build",
39
+ "compile": "tsc -p tsconfig.json",
39
40
  "build": "npx webpack build",
40
41
  "build:ontologies": "npx ts-node build-ontologies.ts",
41
42
  "test": "npx jest",