forked from linkeddata/rdflib.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblank-node.js
More file actions
96 lines (93 loc) · 2.59 KB
/
blank-node.js
File metadata and controls
96 lines (93 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _classOrder = _interopRequireDefault(require("./class-order"));
var _nodeInternal = _interopRequireDefault(require("./node-internal"));
var _types = require("./types");
/**
* An RDF blank node is a Node without a URI
* @link https://rdf.js.org/data-model-spec/#blanknode-interface
*/
class BlankNode extends _nodeInternal.default {
static getId(id) {
if (id) {
if (typeof id !== 'string') {
throw new Error('Bad id argument to new blank node: ' + id);
}
if (id.includes('#')) {
// Is a URI with hash fragment
let 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
*/
constructor(id) {
super(BlankNode.getId(id));
(0, _defineProperty2.default)(this, "termType", _types.BlankNodeTermType);
(0, _defineProperty2.default)(this, "classOrder", _classOrder.default.BlankNode);
/** Whether this is a blank node */
(0, _defineProperty2.default)(this, "isBlank", 1);
/**
* This type of node is a variable.
*
* Note that the existence of this property already indicates that it is a variable.
*/
(0, _defineProperty2.default)(this, "isVar", 1);
}
/**
* The identifier for the blank node
*/
get id() {
return this.value;
}
set id(value) {
this.value = value;
}
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
*/
copy(formula) {
// depends on the formula
var bnodeNew = new BlankNode();
formula.copyTo(this, bnodeNew);
return bnodeNew;
}
toCanonical() {
return BlankNode.NTAnonymousNodePrefix + this.value;
}
toString() {
return BlankNode.NTAnonymousNodePrefix + this.id;
}
}
exports.default = BlankNode;
/**
* The next unique identifier for blank nodes
*/
(0, _defineProperty2.default)(BlankNode, "nextId", 0);
(0, _defineProperty2.default)(BlankNode, "NTAnonymousNodePrefix", '_:');