UNPKG

link-rdflib

Version:

an RDF library for node.js, patched for speed.

130 lines (108 loc) 4.56 kB
'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } var NamedNode = require('./named-node'); var _require = require('./util'), lookup = _require.lookup, writeToMap = _require.writeToMap; // The default graph shouldn't have a name, but 'chrome:theSession' is used for backwards compatibility var defaultGraphNode = new NamedNode('chrome:theSession'); var Statement = /*#__PURE__*/ function () { _createClass(Statement, null, [{ key: "from", value: function from(s, p, o, g) { var existing = lookup(s, p, o, g || Statement.defaultGraph, Statement.stMap); if (existing) { return existing; } return new Statement(s, p, o, g || Statement.defaultGraph); } /* Construct a new statment ** ** @param {Term} subject - The subject of the triple. What the efact is about ** @ param {Term} predciate - The relationship which is assrted between the subject and object ** @param {Term} object - The thing or data value which is asserted to be related to the subject ** @param {NamedNode} why - The document where thr triple is or was or will be stored on the web. ** ** The why param is a named node of the document in which the triple when ** it is stored on the web. ** It is called “why” because when you have read data from varou slaces the ** “why” tells you why you have the triple. (At the moment, it is just the ** document, in future it could be an inference step). When you do ** UpdateManager.update() then the why’s of all the statmemts must be the same, ** and give the document you are patching. In future, we may have a more ** powerful update() which can update more than one docment. */ }, { key: "defaultGraph", /** * The default graph has no name (https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph), which * would mean `null`, so we default to a special NamedNode to keep interfaces consistent. */ get: function get() { return defaultGraphNode; } }]); function Statement(subject, predicate, object, graph) { _classCallCheck(this, Statement); this.subject = subject; this.predicate = predicate; this.object = object; this.why = graph || Statement.defaultGraph; var existing = lookup(this.subject, this.predicate, this.object, this.why, Statement.stMap); if (existing) { return existing; } writeToMap(this.subject.sI, this.predicate.sI, this.object.sI, this.why.sI, this, Statement.stMap); } _createClass(Statement, [{ key: "equals", value: function equals(other) { return this === other; } }, { key: "substitute", value: function substitute(bindings) { var y = new Statement(this.subject.substitute(bindings), this.predicate.substitute(bindings), this.object.substitute(bindings), this.why.substitute(bindings)); // 2016 console.log('@@@ statement substitute:' + y); return y; } }, { key: "toCanonical", value: function toCanonical() { var terms = [this.subject.toCanonical(), this.predicate.toCanonical(), this.object.toCanonical()]; if (this.graph && this.graph.termType !== 'DefaultGraph') { terms.push(this.graph.toCanonical()); } return terms.join(' ') + ' .'; } }, { key: "toNT", value: function toNT() { return [this.subject.toNT(), this.predicate.toNT(), this.object.toNT()].join(' ') + ' .'; } }, { key: "toQuad", value: function toQuad() { return [this.subject, this.predicate, this.object, this.why]; } }, { key: "toString", value: function toString() { return this.toNT(); } }, { key: "graph", get: function get() { return this.why; }, set: function set(g) { this.why = g; } }]); return Statement; }(); Statement.stMap = []; module.exports = Statement;