@faubulous/mentor-rdf 0.3.2 → 0.3.3

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.
package/README.md CHANGED
@@ -2,10 +2,8 @@
2
2
 
3
3
  A library for working with RDF vocabularies based on the [N3.js](https://github.com/rdfjs/N3.js#readme) library. It provides basic OWL and RDFS inference for retrieving classes, propertis and individuals.
4
4
 
5
- ## Reports
6
-
7
- - **API documentation**: you are here.
8
- - **Test coverage report**: [coverage/](./coverage/)
5
+ - [API Documentation](https://faubulous.github.io/mentor-rdf/):
6
+ - [Test Coverage](https://faubulous.github.io/mentor-rdf/coverage/)
9
7
 
10
8
  ## Installation
11
9
 
package/dist/index.js CHANGED
@@ -1407,7 +1407,7 @@ eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexp
1407
1407
  (__unused_webpack_module, exports, __webpack_require__) {
1408
1408
 
1409
1409
  "use strict";
1410
- eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Store = exports.TripleNotFoundError = 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 src = tslib_1.__importStar(__webpack_require__(/*! ../ontologies/src */ \"./src/ontologies/src.ts\"));\nconst rdf_stores_1 = __webpack_require__(/*! rdf-stores */ \"./node_modules/rdf-stores/index.js\");\nconst ontologies_1 = __webpack_require__(/*! ../ontologies */ \"./src/ontologies/index.ts\");\nconst ontologies_2 = __webpack_require__(/*! ../ontologies */ \"./src/ontologies/index.ts\");\nconst rdfxml_streaming_parser_1 = __webpack_require__(/*! rdfxml-streaming-parser */ \"./node_modules/rdfxml-streaming-parser/index.js\");\nconst { namedNode, blankNode, quad } = n3.DataFactory;\n/**\n * Indicates an error when a triple is not found in the store.\n */\nclass TripleNotFoundError extends Error {\n /**\n * Create a new instance of the error.\n * @param message The error message.\n */\n constructor(subject, predicate, object) {\n super(`No triple was found matching the pattern: ${subject} ${predicate} ${object}`);\n this.name = \"TripleNotFoundError\";\n }\n}\nexports.TripleNotFoundError = TripleNotFoundError;\n/*\n * A store for RDF triples with support for reasoning.\n */\nclass Store {\n /**\n * Get the number of triples in all graphs of the store.\n */\n get size() {\n return this._ds.size;\n }\n /**\n * Create a new RDF triple store.\n * @param reasoner The reasoner to be used for inference.\n */\n constructor(reasoner) {\n /**\n * The adapted RDF.js triple store implementation.\n *\n * Note: Please do not use this directly, but rather use the `_ds` property to access the dataset.\n */\n this._store = rdf_stores_1.RdfStore.createDefault();\n /**\n * The RDF dataset containing the triples in the store, which should primarily be used\n * for any operations so that the store can be swapped out with a different implementation.\n */\n this._ds = this._store.asDataset();\n this.reasoner = reasoner;\n }\n [Symbol.iterator]() {\n return this._ds[Symbol.iterator]();\n }\n /**\n * Loads a set of W3C Standard ontologies into the store (RDF, RDFA, RDFS, OWL, SKOS, SHACL, XSD).\n */\n async loadFrameworkOntologies() {\n await this.loadFromTurtleStream(src.rdf, ontologies_2._RDF);\n await this.loadFromTurtleStream(src.rdfa, ontologies_2._RDFA);\n await this.loadFromTurtleStream(src.rdfs, ontologies_2._RDFS);\n await this.loadFromTurtleStream(src.owl, ontologies_2._OWL);\n await this.loadFromTurtleStream(src.sh, ontologies_2._SH);\n await this.loadFromTurtleStream(src.skos, ontologies_2._SKOS);\n await this.loadFromTurtleStream(src.xsd, ontologies_2._XSD);\n }\n /**\n * Add a quad to the store. Existing quads with the same subject, predicate, object, and graph will be ignored.\n * @param quad The quad to be added.\n * @returns The store instance.\n */\n add(quad) {\n this._ds.add(quad);\n return this;\n }\n /**\n * Delete a quad from the store.\n * @param quad The quad to be deleted.\n * @returns The store instance.\n */\n delete(quad) {\n this._ds.delete(quad);\n return this;\n }\n /**\n * Indicates if the store contains a specific quad.\n * @param quad The quad to be checked.\n * @returns `true` if the quad is found in the store, `false` otherwise.\n */\n has(quad) {\n return this._ds.has(quad);\n }\n /**\n * Get the URIs of the graphs in the triple store.\n * @returns An array of graph URIs in no particular order.\n */\n getGraphs() {\n const result = new Set();\n for (const q of this._ds.match(null, null, null, null)) {\n result.add(q.graph.value);\n }\n return Array.from(result);\n }\n /**\n * Load a set of triples into the store.\n * @param quads An array of quads to be loaded into the store.\n * @param graphUri The target graph URI.\n * @param executeInference Indicates if inference should be executed after loading the triples.\n * @param clearGraph Indicates if the graph should be cleared before loading.\n * @param onQuad A callback function that will be called for each parsed triple.\n */\n _loadQuads(quads, graphUri, executeInference = true, clearGraph = true, onQuad) {\n const graph = namedNode(graphUri.replace('\\\\', '\\/'));\n // Only clear the graph once if there had been no errors.\n if (clearGraph) {\n // Note: Using the match method to clear the graph results in an error because the graph is being modified.\n this.deleteGraphs([graphUri]);\n if (this.reasoner) {\n const inferenceGraph = namedNode(this.reasoner.targetUriGenerator.getGraphUri(graphUri));\n this.deleteGraphs([inferenceGraph.value]);\n }\n }\n for (let q of quads) {\n this._ds.add(quad(q.subject, q.predicate, q.object, graph));\n if (onQuad) {\n onQuad(q);\n }\n }\n if (this.reasoner && executeInference) {\n this.reasoner.expand(this._ds, graphUri);\n }\n }\n /**\n * Create an RDF store from N3, Turtle or N-Triples data.\n * @param input Input data or stream in to be parsed.\n * @param graphUri URI of the graph to in which the triples will be created.\n * @param executeInference Indicates if inference should be executed after loading the triples.\n * @param clearGraph Indicates if the graph should be cleared before loading.\n * @param onQuad Callback function that will be called for each parsed triple.\n * @returns A promise that resolves to an RDF store.\n */\n async loadFromTurtleStream(input, graphUri, executeInference = true, clearGraph = true, onQuad) {\n return new Promise((resolve, reject) => {\n let quads = [];\n new n3.Parser({}).parse(input, (error, quad, done) => {\n if (error) {\n reject(error);\n }\n else if (quad) {\n quads.push(quad);\n }\n else if (done) {\n this._loadQuads(quads, graphUri, executeInference, clearGraph, onQuad);\n resolve(this);\n }\n });\n });\n }\n /**\n * Create an RDF store from RDF/XML data.\n * @param input Input data or stream format to be parsed.\n * @param graphUri URI of the graph to in which the triples will be created.\n * @param executeInference Indicates if inference should be executed after loading the triples.\n * @param clearGraph Indicates if the graph should be cleared before loading.\n * @param onQuad Callback function that will be called for each parsed triple.\n * @returns A promise that resolves to an RDF store.\n */\n async loadFromXmlStream(input, graphUri, executeInference = true, clearGraph = true, onQuad) {\n return new Promise((resolve, reject) => {\n let quads = [];\n const parser = new rdfxml_streaming_parser_1.RdfXmlParser();\n if (typeof input === 'string') {\n parser.on('error', (error) => reject(error));\n parser.on('data', (quad) => quads.push(quad));\n parser.on('end', () => {\n this._loadQuads(quads, graphUri, executeInference, clearGraph, onQuad);\n resolve(this);\n });\n parser.write(input);\n parser.end();\n }\n else {\n parser.import(input)\n .on('error', (error) => reject(error))\n .on('data', (quad) => quads.push(quad))\n .on('end', () => {\n this._loadQuads(quads, graphUri, executeInference, clearGraph, onQuad);\n resolve(this);\n });\n }\n });\n }\n /**\n * Write the triples in the store into a string in Turtle format.\n * @param graphUri A graph URI.\n * @returns A string serialization of the triples in the graph in Turtle format.\n */\n async serializeGraph(graphUri, prefixes, format) {\n return new Promise((resolve, reject) => {\n const writer = new n3.Writer({\n format: format || 'Turtle',\n prefixes: prefixes\n });\n for (let q of this._ds.match(null, null, null, namedNode(graphUri))) {\n writer.addQuad(q.subject, q.predicate, q.object);\n }\n writer.end((error, result) => {\n if (error) {\n reject(error);\n }\n else {\n resolve(result);\n }\n });\n });\n }\n /**\n * Indicates if the store contains triples in a given graph.\n * @param graphUri A graph URI.\n * @returns `true` if the store contains triples in the graph URI, `false` otherwise.\n */\n hasGraph(graphUri) {\n const uri = typeof graphUri === 'string' ? namedNode(graphUri) : graphUri;\n for (const _ of this._ds.match(null, null, null, uri)) {\n return true;\n }\n return false;\n }\n /**\n * Apply inference to the given graph and store the triples in the associated inference graph.\n * @param graphUri A graph URI.\n */\n executeInference(graphUri) {\n if (this.reasoner) {\n this.reasoner.expand(this._ds, graphUri);\n }\n }\n /**\n * Delete named graphs from the store.\n * @param graphUris URIs of the graphs to be deleted.\n */\n deleteGraphs(graphUris) {\n for (let graphUri of graphUris) {\n const g = namedNode(graphUri);\n for (let q of this._ds.match(null, null, null, g)) {\n this._ds.delete(q);\n }\n }\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(graphUris, listUri) {\n // To do: Fix #10\n const list = listUri.includes(':') ? namedNode(listUri) : blankNode(listUri);\n return this._getListItems(graphUris, list).map(t => t.value);\n }\n _getListItems(graphUris, subject) {\n const first = Array.from(this.matchAll(graphUris, subject, ontologies_1.rdf.first, null));\n if (!first.length) {\n return [];\n }\n const rest = Array.from(this.matchAll(graphUris, 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(graphUris, restList);\n return [firstItem, ...restItems];\n }\n }\n /**\n * Returns the exact cardinality of the quads matching the pattern.\n * @param subject The optional subject.\n * @param predicate The optional predicate.\n * @param object The optional object.\n * @param graph The optional graph.\n */\n countQuads(subject, predicate, object, graph) {\n return this._store.countQuads(subject, predicate, object, graph);\n }\n /**\n * Returns a stream of quads matching the given pattern.\n * @param subject The optional subject.\n * @param predicate The optional predicate.\n * @param object The optional object.\n * @param graph The optional graph.\n * @returns A stream of matching quads.\n */\n match(subject, predicate, object, graph) {\n return this._store.match(subject, predicate, object, graph);\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 */\n *matchAll(graphUris, subject, predicate, object, includeInferred) {\n if (includeInferred && !this.reasoner) {\n throw new Error('Reasoner is not available to include inferred triples.');\n }\n const s = subject;\n const p = predicate;\n const o = object;\n if (graphUris !== undefined) {\n const graphs = Array.isArray(graphUris) ? graphUris : [graphUris];\n for (let graph of graphs.map(g => namedNode(g))) {\n for (let q of this._ds.match(s, p, o, graph)) {\n yield q;\n }\n if (includeInferred !== false && this.reasoner) {\n let inferenceGraph = namedNode(this.reasoner.targetUriGenerator.getGraphUri(graph.value));\n for (let q of this._ds.match(s, p, o, inferenceGraph)) {\n yield q;\n }\n }\n }\n }\n else {\n yield* this._ds.match(s, p, o);\n }\n }\n /**\n * Indicate if there are triples matching the given pattern in the store.\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 * @returns `true` if there are triples matching the pattern, `false` otherwise.\n */\n any(graphUris, subject, predicate, object, includeInferred) {\n return this.matchAll(graphUris, subject, predicate, object, includeInferred).next().done === false;\n }\n /**\n * Get the first triple matching the given pattern in the store.\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 * @returns The first triple that matches the pattern.\n * @throws {TripleNotFoundError} If no triple is found matching the pattern.\n */\n first(graphUris, subject, predicate, object, includeInferred) {\n const result = this.matchAll(graphUris, subject, predicate, object, includeInferred).next().value;\n if (!result) {\n throw new TripleNotFoundError(subject, predicate, object);\n }\n return result;\n }\n}\nexports.Store = Store;\n\n\n//# sourceURL=webpack://@faubulous/mentor-rdf/./src/rdf/store.ts?\n}");
1410
+ eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Store = exports.TripleNotFoundError = 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 src = tslib_1.__importStar(__webpack_require__(/*! ../ontologies/src */ \"./src/ontologies/src.ts\"));\nconst rdf_stores_1 = __webpack_require__(/*! rdf-stores */ \"./node_modules/rdf-stores/index.js\");\nconst ontologies_1 = __webpack_require__(/*! ../ontologies */ \"./src/ontologies/index.ts\");\nconst ontologies_2 = __webpack_require__(/*! ../ontologies */ \"./src/ontologies/index.ts\");\nconst rdfxml_streaming_parser_1 = __webpack_require__(/*! rdfxml-streaming-parser */ \"./node_modules/rdfxml-streaming-parser/index.js\");\nconst { namedNode, blankNode, quad } = n3.DataFactory;\n/**\n * Indicates an error when a triple is not found in the store.\n */\nclass TripleNotFoundError extends Error {\n /**\n * Create a new instance of the error.\n * @param message The error message.\n */\n constructor(subject, predicate, object) {\n super(`No triple was found matching the pattern: ${subject} ${predicate} ${object}`);\n this.name = \"TripleNotFoundError\";\n }\n}\nexports.TripleNotFoundError = TripleNotFoundError;\n/*\n * A store for RDF triples with support for reasoning.\n */\nclass Store {\n /**\n * Get the number of triples in all graphs of the store.\n */\n get size() {\n return this._ds.size;\n }\n /**\n * Create a new RDF triple store.\n * @param reasoner The reasoner to be used for inference.\n */\n constructor(reasoner) {\n /**\n * The adapted RDF.js triple store implementation.\n *\n * Note: Please do not use this directly, but rather use the `_ds` property to access the dataset.\n */\n this._store = rdf_stores_1.RdfStore.createDefault();\n /**\n * The RDF dataset containing the triples in the store, which should primarily be used\n * for any operations so that the store can be swapped out with a different implementation.\n */\n this._ds = this._store.asDataset();\n this.reasoner = reasoner;\n }\n [Symbol.iterator]() {\n return this._ds[Symbol.iterator]();\n }\n /**\n * Loads a set of W3C Standard ontologies into the store (RDF, RDFA, RDFS, OWL, SKOS, SHACL, XSD).\n */\n async loadFrameworkOntologies() {\n await this.loadFromTurtleStream(src.rdf, ontologies_2._RDF);\n await this.loadFromTurtleStream(src.rdfa, ontologies_2._RDFA);\n await this.loadFromTurtleStream(src.rdfs, ontologies_2._RDFS);\n await this.loadFromTurtleStream(src.owl, ontologies_2._OWL);\n await this.loadFromTurtleStream(src.sh, ontologies_2._SH);\n await this.loadFromTurtleStream(src.skos, ontologies_2._SKOS);\n await this.loadFromTurtleStream(src.xsd, ontologies_2._XSD);\n }\n /**\n * Add a quad to the store. Existing quads with the same subject, predicate, object, and graph will be ignored.\n * @param quad The quad to be added.\n * @returns The store instance.\n */\n add(quad) {\n this._ds.add(quad);\n return this;\n }\n /**\n * Delete a quad from the store.\n * @param quad The quad to be deleted.\n * @returns The store instance.\n */\n delete(quad) {\n this._ds.delete(quad);\n return this;\n }\n /**\n * Indicates if the store contains a specific quad.\n * @param quad The quad to be checked.\n * @returns `true` if the quad is found in the store, `false` otherwise.\n */\n has(quad) {\n return this._ds.has(quad);\n }\n /**\n * Get the URIs of the graphs in the triple store.\n * @returns An array of graph URIs in no particular order.\n */\n getGraphs() {\n const result = new Set();\n for (const q of this._ds.match(null, null, null, null)) {\n result.add(q.graph.value);\n }\n return Array.from(result);\n }\n /**\n * Load a set of triples into the store.\n * @param quads An array of quads to be loaded into the store.\n * @param graphUri The target graph URI.\n * @param executeInference Indicates if inference should be executed after loading the triples.\n * @param clearGraph Indicates if the graph should be cleared before loading.\n * @param onQuad A callback function that will be called for each parsed triple.\n */\n _loadQuads(quads, graphUri, executeInference = true, clearGraph = true, onQuad) {\n const graph = namedNode(graphUri.replace('\\\\', '\\/'));\n // Only clear the graph once if there had been no errors.\n if (clearGraph) {\n // Note: Using the match method to clear the graph results in an error because the graph is being modified.\n this.deleteGraphs([graphUri]);\n if (this.reasoner) {\n const inferenceGraph = namedNode(this.reasoner.targetUriGenerator.getGraphUri(graphUri));\n this.deleteGraphs([inferenceGraph.value]);\n }\n }\n for (let q of quads) {\n this._ds.add(quad(q.subject, q.predicate, q.object, graph));\n if (onQuad) {\n onQuad(q);\n }\n }\n if (this.reasoner && executeInference) {\n this.reasoner.expand(this._ds, graphUri);\n }\n }\n /**\n * Create an RDF store from N3, Turtle or N-Triples data.\n * @param input Input data or stream in to be parsed.\n * @param graphUri URI of the graph to in which the triples will be created.\n * @param executeInference Indicates if inference should be executed after loading the triples.\n * @param clearGraph Indicates if the graph should be cleared before loading.\n * @param onQuad Callback function that will be called for each parsed triple.\n * @returns A promise that resolves to an RDF store.\n */\n async loadFromTurtleStream(input, graphUri, executeInference = true, clearGraph = true, onQuad) {\n return new Promise((resolve, reject) => {\n let quads = [];\n new n3.Parser({}).parse(input, (error, quad, done) => {\n if (error) {\n reject(error);\n }\n else if (quad) {\n quads.push(quad);\n }\n else if (done) {\n this._loadQuads(quads, graphUri, executeInference, clearGraph, onQuad);\n resolve(this);\n }\n });\n });\n }\n /**\n * Create an RDF store from RDF/XML data.\n * @param input Input data or stream format to be parsed.\n * @param graphUri URI of the graph to in which the triples will be created.\n * @param executeInference Indicates if inference should be executed after loading the triples.\n * @param clearGraph Indicates if the graph should be cleared before loading.\n * @param onQuad Callback function that will be called for each parsed triple.\n * @returns A promise that resolves to an RDF store.\n */\n async loadFromXmlStream(input, graphUri, executeInference = true, clearGraph = true, onQuad) {\n return new Promise((resolve, reject) => {\n let quads = [];\n const parser = new rdfxml_streaming_parser_1.RdfXmlParser();\n if (typeof input === 'string') {\n parser.on('error', (error) => reject(error));\n parser.on('data', (quad) => quads.push(quad));\n parser.on('end', () => {\n this._loadQuads(quads, graphUri, executeInference, clearGraph, onQuad);\n resolve(this);\n });\n parser.write(input);\n parser.end();\n }\n else {\n parser.import(input)\n .on('error', (error) => reject(error))\n .on('data', (quad) => quads.push(quad))\n .on('end', () => {\n this._loadQuads(quads, graphUri, executeInference, clearGraph, onQuad);\n resolve(this);\n });\n }\n });\n }\n /**\n * Write the triples in the store into a string in Turtle format.\n * @param sourceGraphUri A graph URI.\n * @param prefixes Optional prefixes to be used in the serialization.\n * @param format Optional mime type of the serialization format (e.g., 'text/turtle').\n * @param targetGraphUri Optional target graph URI. If not provided, the source graph URI will be used.\n * @returns A string serialization of the triples in the graph in Turtle format.\n */\n async serializeGraph(sourceGraphUri, prefixes, format, targetGraphUri) {\n return new Promise((resolve, reject) => {\n const writer = new n3.Writer({\n format: format,\n prefixes: prefixes\n });\n const sourceGraph = namedNode(sourceGraphUri);\n const targetGraph = targetGraphUri ? namedNode(targetGraphUri) : undefined;\n for (let q of this._ds.match(null, null, null, sourceGraph)) {\n writer.addQuad(q.subject, q.predicate, q.object, targetGraph);\n }\n writer.end((error, result) => {\n if (error) {\n reject(error);\n }\n else {\n resolve(result);\n }\n });\n });\n }\n /**\n * Indicates if the store contains triples in a given graph.\n * @param graphUri A graph URI.\n * @returns `true` if the store contains triples in the graph URI, `false` otherwise.\n */\n hasGraph(graphUri) {\n const uri = typeof graphUri === 'string' ? namedNode(graphUri) : graphUri;\n for (const _ of this._ds.match(null, null, null, uri)) {\n return true;\n }\n return false;\n }\n /**\n * Apply inference to the given graph and store the triples in the associated inference graph.\n * @param graphUri A graph URI.\n */\n executeInference(graphUri) {\n if (this.reasoner) {\n this.reasoner.expand(this._ds, graphUri);\n }\n }\n /**\n * Delete named graphs from the store.\n * @param graphUris URIs of the graphs to be deleted.\n */\n deleteGraphs(graphUris) {\n for (let graphUri of graphUris) {\n const g = namedNode(graphUri);\n for (let q of this._ds.match(null, null, null, g)) {\n this._ds.delete(q);\n }\n }\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(graphUris, listUri) {\n // To do: Fix #10\n const list = listUri.includes(':') ? namedNode(listUri) : blankNode(listUri);\n return this._getListItems(graphUris, list).map(t => t.value);\n }\n _getListItems(graphUris, subject) {\n const first = Array.from(this.matchAll(graphUris, subject, ontologies_1.rdf.first, null));\n if (!first.length) {\n return [];\n }\n const rest = Array.from(this.matchAll(graphUris, 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(graphUris, restList);\n return [firstItem, ...restItems];\n }\n }\n /**\n * Returns the exact cardinality of the quads matching the pattern.\n * @param subject The optional subject.\n * @param predicate The optional predicate.\n * @param object The optional object.\n * @param graph The optional graph.\n */\n countQuads(subject, predicate, object, graph) {\n return this._store.countQuads(subject, predicate, object, graph);\n }\n /**\n * Returns a stream of quads matching the given pattern.\n * @param subject The optional subject.\n * @param predicate The optional predicate.\n * @param object The optional object.\n * @param graph The optional graph.\n * @returns A stream of matching quads.\n */\n match(subject, predicate, object, graph) {\n return this._store.match(subject, predicate, object, graph);\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 */\n *matchAll(graphUris, subject, predicate, object, includeInferred) {\n if (includeInferred && !this.reasoner) {\n throw new Error('Reasoner is not available to include inferred triples.');\n }\n const s = subject;\n const p = predicate;\n const o = object;\n if (graphUris !== undefined) {\n const graphs = Array.isArray(graphUris) ? graphUris : [graphUris];\n for (let graph of graphs.map(g => namedNode(g))) {\n for (let q of this._ds.match(s, p, o, graph)) {\n yield q;\n }\n if (includeInferred !== false && this.reasoner) {\n let inferenceGraph = namedNode(this.reasoner.targetUriGenerator.getGraphUri(graph.value));\n for (let q of this._ds.match(s, p, o, inferenceGraph)) {\n yield q;\n }\n }\n }\n }\n else {\n yield* this._ds.match(s, p, o);\n }\n }\n /**\n * Indicate if there are triples matching the given pattern in the store.\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 * @returns `true` if there are triples matching the pattern, `false` otherwise.\n */\n any(graphUris, subject, predicate, object, includeInferred) {\n return this.matchAll(graphUris, subject, predicate, object, includeInferred).next().done === false;\n }\n /**\n * Get the first triple matching the given pattern in the store.\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 * @returns The first triple that matches the pattern.\n * @throws {TripleNotFoundError} If no triple is found matching the pattern.\n */\n first(graphUris, subject, predicate, object, includeInferred) {\n const result = this.matchAll(graphUris, subject, predicate, object, includeInferred).next().value;\n if (!result) {\n throw new TripleNotFoundError(subject, predicate, object);\n }\n return result;\n }\n}\nexports.Store = Store;\n\n\n//# sourceURL=webpack://@faubulous/mentor-rdf/./src/rdf/store.ts?\n}");
1411
1411
 
1412
1412
  /***/ },
1413
1413
 
@@ -1429,7 +1429,7 @@ eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexp
1429
1429
  (__unused_webpack_module, exports, __webpack_require__) {
1430
1430
 
1431
1431
  "use strict";
1432
- eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.VocabularyRepository = 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 uri_1 = __webpack_require__(/*! ./uri */ \"./src/rdf/uri.ts\");\nconst shape_repository_1 = __webpack_require__(/*! ./shape-repository */ \"./src/rdf/shape-repository.ts\");\nconst { namedNode } = n3.DataFactory;\n/**\n * A repository for retrieving ontologies and ontology concepts from graphs.\n */\nclass VocabularyRepository extends shape_repository_1.ShapeRepository {\n /**\n * Get all concept schemes in the repository.\n * @param graphUris URIs of the graphs to search.\n * @returns An iterator of all concept schemes in the repository.\n */\n *getConceptSchemes(graphUris) {\n const yielded = new Set();\n for (const q of this.store.matchAll(graphUris, null, ontologies_1.rdf.type, ontologies_1.skos.ConceptScheme)) {\n const s = q.subject;\n if (s.termType != \"NamedNode\") {\n continue;\n }\n if (!yielded.has(s.value)) {\n yielded.add(s.value);\n yield s.value;\n }\n }\n }\n /**\n * Indicates whether the repository contains any concept schemes.\n * @param graphUris URIs of the graphs to search.\n * @returns `true` if the repository contains any concept schemes, `false` otherwise.\n */\n hasConceptSchemes(graphUris) {\n for (const _ of this.getConceptSchemes(graphUris)) {\n return true;\n }\n return false;\n }\n /**\n * Get all ontologies in the repository.\n * @param graphUris URIs of the graphs to search.\n * @returns An iterator of all ontologies in the repository.\n */\n *getOntologies(graphUris) {\n const yielded = new Set();\n for (const q of this.store.matchAll(graphUris, null, ontologies_1.rdf.type, ontologies_1.owl.Ontology)) {\n const s = q.subject;\n if (s.termType != \"NamedNode\") {\n continue;\n }\n if (!yielded.has(s.value)) {\n yielded.add(s.value);\n yield s.value;\n }\n }\n }\n /**\n * Indicates whether the repository contains any ontology headers.\n * @param graphUris URIs of the graphs to search.\n * @returns `true` if the repository contains any ontology headers, `false` otherwise.\n */\n hasOntologies(graphUris) {\n for (const _ of this.getOntologies(graphUris)) {\n return true;\n }\n return false;\n }\n /**\n * Get the version (owl:versionInfo) of an ontology. If the version is a date, it is returned as a string in the format \"YYYY-MM-DD\".\n * @param graphUris URIs of the graphs to search.\n * @param ontologyUri URI of the ontology.\n * @returns The version of the ontology, or undefined if it is not found.\n */\n getOntologyVersionInfo(graphUris, ontologyUri) {\n const s = namedNode(ontologyUri);\n for (const q of this.store.matchAll(graphUris, s, ontologies_1.owl.versionInfo, null)) {\n // If the version is a date, return it in the format \"YYYY-MM-DD\".\n const match = q.object.value.match(/(\\d{4}[\\/-]\\d{2}[\\/-]\\d{2})/);\n if (match && match.length > 1) {\n return new Date(match[1]).toISOString().substring(0, 10);\n }\n else {\n return q.object.value;\n }\n }\n }\n /**\n * Get the sources of definitions for a given graph. These are ontology definitions\n * or the objects of `rdfs:isDefinedBy` triples. If the rdfs:isDefinedBy object can be\n * matched with an ontology definition, the ontology URI is returned.\n * @param graphUris URIs of the graphs to search.\n * @returns An iterator of sources of definitions for the given graph.\n */\n *getDefinitionSources(graphUris, includeOntologies = false) {\n const yielded = new Set();\n // Load all ontologies in the graph in a normalized form.\n const ontologies = {};\n // Store the normalized versions of the ontology URI so that we can detect \n // equality even if different namespace seperators ('#' and '/') are used.\n for (let o of this.getOntologies(graphUris)) {\n const uri = uri_1.Uri.getNormalizedUri(o);\n ontologies[uri] = o;\n }\n for (const q of this.store.matchAll(graphUris, null, ontologies_1.rdfs.isDefinedBy, null)) {\n const s = q.subject;\n const o = q.object;\n if (s.termType != \"NamedNode\" || o.termType != \"NamedNode\") {\n continue;\n }\n // Do not include ontologies in the list of sources. However, if there are other\n // terms defined by the object it will be included by subsequent iterations.\n const s_ = uri_1.Uri.getNormalizedUri(s.value);\n const o_ = uri_1.Uri.getNormalizedUri(o.value);\n let isOntology = s_ in ontologies;\n if (!isOntology || includeOntologies) {\n let sourceValue;\n if (o_ in ontologies) {\n sourceValue = ontologies[o_];\n }\n else {\n sourceValue = o.value;\n }\n if (!yielded.has(sourceValue)) {\n yielded.add(sourceValue);\n yield sourceValue;\n }\n }\n }\n }\n}\nexports.VocabularyRepository = VocabularyRepository;\n\n\n//# sourceURL=webpack://@faubulous/mentor-rdf/./src/rdf/vocabulary-repository.ts?\n}");
1432
+ eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.VocabularyRepository = 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 uri_1 = __webpack_require__(/*! ./uri */ \"./src/rdf/uri.ts\");\nconst shape_repository_1 = __webpack_require__(/*! ./shape-repository */ \"./src/rdf/shape-repository.ts\");\nconst { namedNode } = n3.DataFactory;\n/**\n * A repository for retrieving ontologies and ontology concepts from graphs.\n */\nclass VocabularyRepository extends shape_repository_1.ShapeRepository {\n /**\n * Get all concept schemes in the repository.\n * @param graphUris URIs of the graphs to search.\n * @returns An iterator of all concept schemes in the repository.\n */\n *getConceptSchemes(graphUris) {\n const yielded = new Set();\n for (const q of this.store.matchAll(graphUris, null, ontologies_1.rdf.type, ontologies_1.skos.ConceptScheme)) {\n const s = q.subject;\n if (s.termType != \"NamedNode\") {\n continue;\n }\n if (!yielded.has(s.value)) {\n yielded.add(s.value);\n yield s.value;\n }\n }\n }\n /**\n * Indicates whether the repository contains any concept schemes.\n * @param graphUris URIs of the graphs to search.\n * @returns `true` if the repository contains any concept schemes, `false` otherwise.\n */\n hasConceptSchemes(graphUris) {\n for (const _ of this.getConceptSchemes(graphUris)) {\n return true;\n }\n return false;\n }\n /**\n * Get all ontologies in the repository.\n * @param graphUris URIs of the graphs to search.\n * @returns An iterator of all ontologies in the repository.\n */\n *getOntologies(graphUris) {\n const yielded = new Set();\n for (const q of this.store.matchAll(graphUris, null, ontologies_1.rdf.type, ontologies_1.owl.Ontology)) {\n const s = q.subject;\n if (s.termType != \"NamedNode\") {\n continue;\n }\n if (!yielded.has(s.value)) {\n yielded.add(s.value);\n yield s.value;\n }\n }\n }\n /**\n * Indicates whether the repository contains any ontology headers.\n * @param graphUris URIs of the graphs to search.\n * @returns `true` if the repository contains any ontology headers, `false` otherwise.\n */\n hasOntologies(graphUris) {\n for (const _ of this.getOntologies(graphUris)) {\n return true;\n }\n return false;\n }\n /**\n * Get the version (owl:versionInfo) of an ontology. If the version is a date, it is returned as a string in the format \"YYYY-MM-DD\".\n * @param graphUris URIs of the graphs to search.\n * @param ontologyUri URI of the ontology.\n * @returns The version of the ontology, or undefined if it is not found.\n */\n getOntologyVersionInfo(graphUris, ontologyUri) {\n const s = namedNode(ontologyUri);\n for (const q of this.store.matchAll(graphUris, s, ontologies_1.owl.versionInfo, null)) {\n // If the version is a date, return it in the format \"YYYY-MM-DD\".\n const match = q.object.value.match(/(\\d{4}[\\/-]\\d{2}[\\/-]\\d{2})/);\n if (match && match.length > 1) {\n // Don't rely on Date parsing or timezone conversions; keep it purely lexical.\n // The source is already YYYY-MM-DD or YYYY/MM/DD, normalize to YYYY-MM-DD.\n return match[1].replace(/\\//g, '-');\n }\n else {\n return q.object.value;\n }\n }\n }\n /**\n * Get the sources of definitions for a given graph. These are ontology definitions\n * or the objects of `rdfs:isDefinedBy` triples. If the rdfs:isDefinedBy object can be\n * matched with an ontology definition, the ontology URI is returned.\n * @param graphUris URIs of the graphs to search.\n * @returns An iterator of sources of definitions for the given graph.\n */\n *getDefinitionSources(graphUris, includeOntologies = false) {\n const yielded = new Set();\n // Load all ontologies in the graph in a normalized form.\n const ontologies = {};\n // Store the normalized versions of the ontology URI so that we can detect \n // equality even if different namespace seperators ('#' and '/') are used.\n for (let o of this.getOntologies(graphUris)) {\n const uri = uri_1.Uri.getNormalizedUri(o);\n ontologies[uri] = o;\n }\n for (const q of this.store.matchAll(graphUris, null, ontologies_1.rdfs.isDefinedBy, null)) {\n const s = q.subject;\n const o = q.object;\n if (s.termType != \"NamedNode\" || o.termType != \"NamedNode\") {\n continue;\n }\n // Do not include ontologies in the list of sources. However, if there are other\n // terms defined by the object it will be included by subsequent iterations.\n const s_ = uri_1.Uri.getNormalizedUri(s.value);\n const o_ = uri_1.Uri.getNormalizedUri(o.value);\n let isOntology = s_ in ontologies;\n if (!isOntology || includeOntologies) {\n let sourceValue;\n if (o_ in ontologies) {\n sourceValue = ontologies[o_];\n }\n else {\n sourceValue = o.value;\n }\n if (!yielded.has(sourceValue)) {\n yielded.add(sourceValue);\n yield sourceValue;\n }\n }\n }\n }\n}\nexports.VocabularyRepository = VocabularyRepository;\n\n\n//# sourceURL=webpack://@faubulous/mentor-rdf/./src/rdf/vocabulary-repository.ts?\n}");
1433
1433
 
1434
1434
  /***/ }
1435
1435
 
@@ -95,12 +95,15 @@ export declare class Store implements rdfjs.Source<rdfjs.Quad> {
95
95
  loadFromXmlStream(input: string | EventEmitter, graphUri: string, executeInference?: boolean, clearGraph?: boolean, onQuad?: (quad: rdfjs.Quad) => void): Promise<Store>;
96
96
  /**
97
97
  * Write the triples in the store into a string in Turtle format.
98
- * @param graphUri A graph URI.
98
+ * @param sourceGraphUri A graph URI.
99
+ * @param prefixes Optional prefixes to be used in the serialization.
100
+ * @param format Optional mime type of the serialization format (e.g., 'text/turtle').
101
+ * @param targetGraphUri Optional target graph URI. If not provided, the source graph URI will be used.
99
102
  * @returns A string serialization of the triples in the graph in Turtle format.
100
103
  */
101
- serializeGraph(graphUri: string, prefixes?: {
104
+ serializeGraph(sourceGraphUri: string, prefixes?: {
102
105
  [prefix: string]: rdfjs.NamedNode<string>;
103
- }, format?: string): Promise<string>;
106
+ }, format?: string, targetGraphUri?: string): Promise<string>;
104
107
  /**
105
108
  * Indicates if the store contains triples in a given graph.
106
109
  * @param graphUri A graph URI.
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "ontology",
11
11
  "vocabulary"
12
12
  ],
13
- "version": "0.3.2",
13
+ "version": "0.3.3",
14
14
  "private": false,
15
15
  "author": {
16
16
  "name": "Sebastian Faubel"