forked from linkeddata/rdflib.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-internal.js
More file actions
108 lines (99 loc) · 2.46 KB
/
node-internal.js
File metadata and controls
108 lines (99 loc) · 2.46 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
97
98
99
100
101
102
103
104
105
106
107
108
import _defineProperty from "@babel/runtime/helpers/defineProperty";
/**
* The superclass of all RDF Statement objects, that is
* NamedNode, Literal, BlankNode, etc.
* Should not be instantiated directly.
* Also called Term.
* @link https://rdf.js.org/data-model-spec/#term-interface
* @class Node
*/
export default class Node {
constructor(value) {
/** The type of node */
_defineProperty(this, "termType", void 0);
/** The class order for this node */
_defineProperty(this, "classOrder", void 0);
/** The node's value */
_defineProperty(this, "value", void 0);
this.value = value;
}
/**
* Creates the substituted node for this one, according to the specified bindings
* @param bindings - Bindings of identifiers to nodes
*/
substitute(bindings) {
return this;
}
/**
* Compares this node with another
* @see {equals} to check if two nodes are equal
* @param other - The other node
*/
compareTerm(other) {
if (this.classOrder < other.classOrder) {
return -1;
}
if (this.classOrder > other.classOrder) {
return +1;
}
if (this.value < other.value) {
return -1;
}
if (this.value > other.value) {
return +1;
}
return 0;
}
/**
* Compares whether the two nodes are equal
* @param other The other node
*/
equals(other) {
if (!other) {
return false;
}
return this.termType === other.termType && this.value === other.value;
}
/**
* Creates a hash for this node
* @deprecated use {rdfFactory.id} instead if possible
*/
hashString() {
return this.toCanonical();
}
/**
* Compares whether this node is the same as the other one
* @param other - Another node
*/
sameTerm(other) {
return this.equals(other);
}
/**
* Creates a canonical string representation of this node
*/
toCanonical() {
return this.toNT();
}
/**
* Creates a n-triples string representation of this node
*/
toNT() {
return this.toString();
}
/**
* Creates a n-quads string representation of this node
*/
toNQ() {
return this.toNT();
}
/**
* Creates a string representation of this node
*/
toString() {
throw new Error('Node.toString() is abstract - see the subclasses instead');
}
}
// Specified in './node.ts' to prevent circular dependency
_defineProperty(Node, "fromValue", void 0);
// Specified in './node.ts' to prevent circular dependency
_defineProperty(Node, "toJS", void 0);