-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathQuad.js
74 lines (60 loc) · 2.12 KB
/
Quad.js
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
var Class = require('../ext/Class');
var NodeUtils = require('../rdf/NodeUtils');
var NodeFactory = require('../rdf/NodeFactory');
var Triple = require('../rdf/Triple');
// constructor
var Quad = Class.create({
classLabel: 'jassa.sparql.Quad',
// functions
initialize: function(graph, subject, predicate, object) {
this.graph = graph || Quad.defaultGraphNodeGenerated;
this.subject = subject;
this.predicate = predicate;
this.object = object;
},
asTriple: function() {
var result = new Triple(this.subject, this.predicate, this.object);
return result;
},
toString: function() {
return this.graph + ' ' + this.subject + ' ' + this.predicate + ' ' + this.object;
},
copySubstitute: function(fnNodeMap) {
var result = new Quad(
NodeUtils.getSubstitute(this.graph, fnNodeMap),
NodeUtils.getSubstitute(this.subject, fnNodeMap),
NodeUtils.getSubstitute(this.predicate, fnNodeMap),
NodeUtils.getSubstitute(this.object, fnNodeMap)
);
return result;
},
getGraph: function() {
return this.graph;
},
getSubject: function() {
return this.subject;
},
getPredicate: function() {
return this.predicate;
},
getObject: function() {
return this.object;
},
getVarsMentioned: function() {
var result = [];
NodeUtils.pushVar(result, this.graph);
NodeUtils.pushVar(result, this.subject);
NodeUtils.pushVar(result, this.predicate);
NodeUtils.pushVar(result, this.object);
return result;
},
});
Quad.defaultGraphNodeGenerated = NodeFactory.createUri('urn:x-arq:DefaultGraphNode');
Quad.defaultGraphIri = NodeFactory.createUri('urn:x-arq:DefaultGraph');
Quad.unionGraph = NodeFactory.createUri('urn:x-arq:UnionGraph');
Quad.createFromTriple = function(graphNode, triple) {
graphNode = graphNode || Quad.defaultGraphNodeGenerated;
var result = new Quad(graphNode, triple.subject, triple.predicate, triple.object);
return result;
};
module.exports = Quad;