lincd
Version:
LINCD is a JavaScript library for building user interfaces with linked data (also known as 'structured data', or RDF)
65 lines • 2.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeURIMappings = void 0;
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
const models_js_1 = require("../models.js");
const NodeMap_js_1 = require("./NodeMap.js");
const NodeSet_js_1 = require("./NodeSet.js");
//TODO: rename to something more fitting now that it also handles TMP NamedNodes
class NodeURIMappings extends NodeMap_js_1.NodeMap {
constructor() {
super(...arguments);
this.originalUris = new Map();
}
/**
* Will create a blanknode the first time you give a certain URI
* and return the same blanknode when you request it again.
* Note that the blanknode itself will have its own local URI regardless of the give URI
* this method allows you to parse a set of data that
* uses a certain identifier for a certain blanknode across several places
* and convert it to a local blanknode
* @param {string} givenUri
* @returns {BlankNode}
*/
getOrCreateBlankNode(givenUri) {
//TODO: rename this method to getOrCreateBlankNode
if (this.has(givenUri)) {
return this.get(givenUri);
}
else {
var blankNode = new models_js_1.BlankNode();
this.set(givenUri, blankNode);
this.originalUris.set(blankNode.uri, givenUri);
return blankNode;
}
}
getBlankNodes() {
return new NodeSet_js_1.NodeSet(this.filter((n) => n instanceof models_js_1.BlankNode).values());
}
getOrCreateNamedNode(uri) {
//the temp URI's in one environment may already be used in another environment
//so we need to check for temporary URI's and convert them to a local temporary URI
if (uri.substring(0, models_js_1.NamedNode.TEMP_URI_BASE.length) ==
models_js_1.NamedNode.TEMP_URI_BASE) {
if (!this.has(uri)) {
//create a new temp node that has a LOCAL temp URI
var tmpResource = models_js_1.NamedNode.create();
this.set(uri, tmpResource);
this.originalUris.set(tmpResource.uri, uri);
return tmpResource;
}
return this.get(uri);
}
return models_js_1.NamedNode.getOrCreate(uri);
}
getOriginalUri(localUri) {
//return the original uri, and if we dont have a mapping it will not have changed
return this.originalUris.get(localUri) || localUri;
}
}
exports.NodeURIMappings = NodeURIMappings;
//# sourceMappingURL=NodeURIMappings.js.map