UNPKG

@bahulneel/rdflib

Version:

an RDF library for node.js. Suitable for client and server side.

135 lines (110 loc) 3.38 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import ClassOrder from './class-order'; import Node from './node-internal'; import { BlankNodeTermType } from './types'; /** * An RDF blank node is a Node without a URI * @link https://rdf.js.org/data-model-spec/#blanknode-interface */ var BlankNode = /*#__PURE__*/ function (_Node) { _inherits(BlankNode, _Node); _createClass(BlankNode, null, [{ key: "getId", /** * The next unique identifier for blank nodes */ value: function getId(id) { if (id) { if (typeof id !== 'string') { console.log('Bad blank id:', id); throw new Error('Bad id argument to new blank node: ' + id); } if (id.includes('#')) { // Is a URI with hash fragment var fragments = id.split('#'); return fragments[fragments.length - 1]; } return id; } return 'n' + BlankNode.nextId++; } }]); /** * Initializes this node * @param [id] The identifier for the blank node */ function BlankNode(id) { var _this; _classCallCheck(this, BlankNode); _this = _possibleConstructorReturn(this, _getPrototypeOf(BlankNode).call(this, BlankNode.getId(id))); _defineProperty(_assertThisInitialized(_this), "termType", BlankNodeTermType); _defineProperty(_assertThisInitialized(_this), "classOrder", ClassOrder.BlankNode); _defineProperty(_assertThisInitialized(_this), "isBlank", 1); _defineProperty(_assertThisInitialized(_this), "isVar", 1); return _this; } /** * The identifier for the blank node * @deprecated use [[value]] instead. */ _createClass(BlankNode, [{ key: "compareTerm", value: function compareTerm(other) { if (this.classOrder < other.classOrder) { return -1; } if (this.classOrder > other.classOrder) { return +1; } if (this.id < other.id) { return -1; } if (this.id > other.id) { return +1; } return 0; } /** * Gets a copy of this blank node in the specified formula * @param formula The formula */ }, { key: "copy", value: function copy(formula) { // depends on the formula var bnodeNew = new BlankNode(); formula.copyTo(this, bnodeNew); return bnodeNew; } }, { key: "toCanonical", value: function toCanonical() { return BlankNode.NTAnonymousNodePrefix + this.value; } }, { key: "toString", value: function toString() { return BlankNode.NTAnonymousNodePrefix + this.id; } }, { key: "id", get: function get() { return this.value; }, set: function set(value) { this.value = value; } }]); return BlankNode; }(Node); _defineProperty(BlankNode, "nextId", 0); _defineProperty(BlankNode, "NTAnonymousNodePrefix", '_:'); export { BlankNode as default };