-
Notifications
You must be signed in to change notification settings - Fork 5
/
Step.js
115 lines (91 loc) · 2.49 KB
/
Step.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
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
109
110
111
112
113
114
115
var isEqual = require('lodash.isequal');
var Class = require('../ext/Class');
var NodeFactory = require('../rdf/NodeFactory');
var Triple = require('../rdf/Triple');
var ElementTriplesBlock = require('../sparql/element/ElementTriplesBlock');
var ObjectUtils = require('../util/ObjectUtils');
/**
*
* @param direction
* @param resource
* @returns {ns.Step}
*/
var Step = Class.create({
classLabel: 'jassa.facete.Step',
initialize: function(propertyName, isInverse) {
this.type = 'property';
this.propertyName = propertyName;
this._isInverse = isInverse;
},
toJson: function() {
var result = {
isInverse: this.isInverse,
propertyName: this.propertyName
};
return result;
},
getPropertyName: function() {
return this.propertyName;
},
isInverse: function() {
return this._isInverse;
},
equals: function(that) {
//return ObjectUtils.isEqual(this, other);
var result =
this._isInverse === that._isInverse &&
this.propertyName === that.propertyName;
return result;
},
hashCode: function() {
if(this.hash == null) {
this.hash =
(this._isInverse ? 3 : 7) *
ObjectUtils.hashCodeStr(this.propertyName);
}
return this.hash;
},
toString: function() {
if(this._isInverse) {
return '<' + this.propertyName;
} else {
return this.propertyName;
}
},
createElement: function(sourceVar, targetVar, generator) {
var propertyNode = NodeFactory.createUri(this.propertyName);
var triple;
if(this._isInverse) {
triple = new Triple(targetVar, propertyNode, sourceVar);
} else {
triple = new Triple(sourceVar, propertyNode, targetVar);
}
var result = new ElementTriplesBlock([triple]);
return result;
}
});
/**
* Create a Step from a json specification:
* {
* propertyName: ... ,
* isInverse:
* }
*
* @param json
*/
Step.fromJson = function(json) {
var propertyName = json.propertyName;
var isInverse = json.IsInverse();
var result = new Step(propertyName, isInverse);
return result;
};
Step.parse = function(str) {
var result;
if(str.charAt(0) === '<') {
result = new Step(str.substring(1), true);
} else {
result = new Step(str, false);
}
return result;
};
module.exports = Step;