Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 1 | var KorAP = KorAP || {}; |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 2 | |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 3 | // TODO: Implement a working localization solution! |
| 4 | // TODO: Support 'update' method to update elements on change |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 5 | // TODO: Implement "toQuery" |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 6 | |
| 7 | /* |
| 8 | * Error codes: |
| 9 | 701: "JSON-LD group has no @type attribute" |
| 10 | 704: "Operation needs operand list" |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 11 | 802: "Match type is not supported by value type" |
| 12 | 804: "Unknown value type" |
| 13 | 805: "Value is invalid" |
| 14 | 806: "Value is not a valid date string" |
| 15 | 807: "Value is not a valid regular expression" |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 16 | 810: "Unknown document group operation" (like 711) |
| 17 | 811: "Document group expects operation" (like 703) |
| 18 | 812: "Operand not supported in document group" (like 744) |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 19 | 813: "Collection type is not supported" (like 713) |
| 20 | */ |
| 21 | |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 22 | (function (KorAP) { |
| 23 | "use strict"; |
| 24 | |
| 25 | // Default log message |
| 26 | KorAP.log = KorAP.log || function (type, msg) { |
| 27 | console.log(type + ": " + msg); |
| 28 | }; |
| 29 | |
| 30 | KorAP._validStringMatchRE = new RegExp("^(?:eq|ne|contains)$"); |
| 31 | KorAP._validRegexMatchRE = new RegExp("^(?:eq|ne)$"); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 32 | KorAP._validDateMatchRE = new RegExp("^[lg]?eq$"); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 33 | KorAP._validDateRE = new RegExp("^(?:\\d{4})(?:-\\d\\d(?:-\\d\\d)?)?$"); |
| 34 | KorAP._validGroupOpRE = new RegExp("^(?:and|or)$"); |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 35 | KorAP._quote = new RegExp("([\"\\\\])", 'g'); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 36 | |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 37 | var loc = (KorAP.Locale = KorAP.Locale || {} ); |
| 38 | loc.AND = loc.AND || 'and'; |
| 39 | loc.OR = loc.OR || 'or'; |
| 40 | loc.DEL = loc.DEL || '×'; |
| 41 | loc.EMPTY = loc.EMPTY || '⋯' |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 42 | |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 43 | function _bool (bool) { |
| 44 | return (bool === undefined || bool === false) ? false : true; |
| 45 | }; |
| 46 | |
| 47 | function _removeChildren (node) { |
| 48 | // Remove everything underneath |
| 49 | while (node.firstChild) { |
| 50 | node.removeChild(node.firstChild); |
| 51 | }; |
| 52 | }; |
| 53 | |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 54 | KorAP.VirtualCollection = { |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 55 | ldType : function () { |
| 56 | return null; |
| 57 | }, |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 58 | create : function () { |
| 59 | return Object.create(KorAP.VirtualCollection); |
| 60 | }, |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 61 | render : function (json) { |
| 62 | var obj = Object.create(KorAP.VirtualCollection); |
| 63 | |
| 64 | if (json !== undefined) { |
| 65 | // Root object |
| 66 | if (json['@type'] == 'korap:doc') { |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 67 | obj._root = KorAP.Doc.create(obj, json); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 68 | } |
| 69 | else if (json['@type'] == 'korap:docGroup') { |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 70 | obj._root = KorAP.DocGroup.create(obj, json); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 71 | } |
| 72 | else { |
| 73 | KorAP.log(813, "Collection type is not supported"); |
| 74 | return; |
| 75 | }; |
| 76 | } |
| 77 | |
| 78 | else { |
| 79 | // Add unspecified object |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 80 | obj._root = KorAP.UnspecifiedDoc.create(obj); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | // Add root element to root node |
| 84 | obj.element().appendChild( |
| 85 | obj._root.element() |
| 86 | ); |
| 87 | |
| 88 | return obj; |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 89 | }, |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 90 | root : function (obj) { |
| 91 | if (arguments.length === 1) |
| 92 | this._root = obj; |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 93 | return this._root; |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 94 | }, |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 95 | element : function () { |
| 96 | if (this._element !== undefined) |
| 97 | return this._element; |
| 98 | |
| 99 | this._element = document.createElement('div'); |
| 100 | this._element.setAttribute('class', 'vc'); |
| 101 | return this._element; |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 102 | }, |
| 103 | toJson : function () { |
| 104 | return this._root.toJson(); |
| 105 | }, |
| 106 | toString : function () { |
| 107 | return this._root.toString(); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 108 | } |
| 109 | }; |
| 110 | |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 111 | KorAP._or = function (e) { |
| 112 | var obj = this.parentNode.refTo; |
| 113 | }; |
| 114 | |
| 115 | KorAP._and = function (e) { |
| 116 | var obj = this.parentNode.refTo; |
| 117 | }; |
| 118 | |
| 119 | KorAP._delete = function (e) { |
| 120 | var obj = this.parentNode.refTo; |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 121 | obj.parent().delOperand(obj).update(); |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 122 | // Todo: CLEAR ALL THE THINGS! |
| 123 | }; |
| 124 | |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 125 | /** |
| 126 | * Operators for criteria |
| 127 | */ |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 128 | KorAP.Operators = { |
| 129 | create : function (and, or, del) { |
| 130 | var op = Object.create(KorAP.Operators); |
| 131 | op.and(and); |
| 132 | op.or(or); |
| 133 | op.del(del); |
| 134 | return op; |
| 135 | }, |
| 136 | update : function () { |
| 137 | |
| 138 | // Init the element |
| 139 | if (this._element === undefined) |
| 140 | return this.element(); |
| 141 | |
| 142 | var op = this._element; |
| 143 | |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 144 | op.refTo = this.parent(); |
| 145 | |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 146 | // Remove everything underneath |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 147 | _removeChildren(op); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 148 | |
| 149 | // Add and button |
| 150 | if (this._and === true) { |
| 151 | var andE = document.createElement('span'); |
| 152 | andE.setAttribute('class', 'and'); |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 153 | andE.addEventListener('click', KorAP._and, false); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 154 | andE.appendChild(document.createTextNode(KorAP.Locale.AND)); |
| 155 | op.appendChild(andE); |
| 156 | }; |
| 157 | |
| 158 | // Add or button |
| 159 | if (this._or === true) { |
| 160 | var orE = document.createElement('span'); |
| 161 | orE.setAttribute('class', 'or'); |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 162 | orE.addEventListener('click', KorAP._or, false); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 163 | orE.appendChild(document.createTextNode(KorAP.Locale.OR)); |
| 164 | op.appendChild(orE); |
| 165 | }; |
| 166 | |
| 167 | // Add delete button |
| 168 | if (this._del === true) { |
| 169 | var delE = document.createElement('span'); |
| 170 | delE.setAttribute('class', 'delete'); |
| 171 | delE.appendChild(document.createTextNode(KorAP.Locale.DEL)); |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 172 | delE.addEventListener('click', KorAP._delete, false); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 173 | op.appendChild(delE); |
| 174 | }; |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 175 | |
| 176 | return op; |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 177 | }, |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 178 | |
| 179 | // Be aware! This may be cyclic |
| 180 | parent : function (obj) { |
| 181 | if (arguments.length === 1) |
| 182 | this._parent = obj; |
| 183 | return this._parent; |
| 184 | }, |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 185 | |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 186 | element : function () { |
| 187 | |
| 188 | // Return existing element |
| 189 | if (this._element !== undefined) |
| 190 | return this._element; |
| 191 | |
| 192 | this._element = document.createElement('div'); |
| 193 | this._element.setAttribute('class', 'operators'); |
| 194 | |
| 195 | // Init elements |
| 196 | this.update(); |
| 197 | return this._element; |
| 198 | }, |
| 199 | and : function (bool) { |
| 200 | if (arguments.length === 1) |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 201 | this._and = _bool(bool); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 202 | return this._and; |
| 203 | }, |
| 204 | or : function (bool) { |
| 205 | if (arguments.length === 1) |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 206 | this._or = _bool(bool); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 207 | return this._or; |
| 208 | }, |
| 209 | del : function (bool) { |
| 210 | if (arguments.length === 1) |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 211 | this._del = _bool(bool); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 212 | return this._del; |
| 213 | } |
| 214 | }; |
| 215 | |
| 216 | |
| 217 | /** |
| 218 | * Unspecified criterion |
| 219 | */ |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 220 | KorAP.UnspecifiedDoc = { |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 221 | _ldType : "doc", |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 222 | create : function (parent) { |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 223 | var obj = Object.create(KorAP.JsonLD).upgradeTo(KorAP.UnspecifiedDoc); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 224 | if (parent !== undefined) |
| 225 | obj._parent = parent; |
| 226 | return obj; |
| 227 | }, |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 228 | update : function () { |
| 229 | if (this._element === undefined) |
| 230 | return this.element(); |
| 231 | |
| 232 | _removeChildren(this._element); |
| 233 | |
| 234 | var ellipsis = document.createElement('span'); |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 235 | ellipsis.appendChild(document.createTextNode(loc.EMPTY)); |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 236 | this._element.appendChild(ellipsis); |
| 237 | |
| 238 | // Set operators |
| 239 | var op = this.operators( |
| 240 | false, |
| 241 | false, |
| 242 | // No delete object, if this is the root |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 243 | (this._parent !== undefined && this.parent().ldType() !== null) ? true : false |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 244 | ); |
| 245 | |
| 246 | this._element.appendChild( |
| 247 | op.element() |
| 248 | ); |
| 249 | |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 250 | return this.element(); |
| 251 | }, |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 252 | element : function () { |
| 253 | if (this._element !== undefined) |
| 254 | return this._element; |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 255 | |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 256 | this._element = document.createElement('div'); |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 257 | this._element.setAttribute('class', 'unspecified'); |
| 258 | |
| 259 | this.update(); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 260 | return this._element; |
| 261 | } |
| 262 | }; |
| 263 | |
| 264 | |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 265 | /** |
| 266 | * Virtual collection doc criterion. |
| 267 | */ |
| 268 | KorAP.Doc = { |
| 269 | _ldType : "doc", |
| 270 | _obj : function () { return KorAP.Doc; }, |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 271 | |
| 272 | create : function (parent, json) { |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 273 | var obj = Object(KorAP.JsonLD).create().upgradeTo(KorAP.Doc).fromJson(json); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 274 | if (parent !== undefined) |
| 275 | obj._parent = parent; |
| 276 | return obj; |
| 277 | }, |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 278 | |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 279 | update : function () { |
| 280 | if (this._element === undefined) |
| 281 | return this.element(); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 282 | |
| 283 | // Added key |
| 284 | var key = document.createElement('span'); |
| 285 | key.setAttribute('class', 'key'); |
| 286 | if (this.key()) |
| 287 | key.appendChild(document.createTextNode(this.key())); |
| 288 | |
| 289 | // Added match operator |
| 290 | var matchop = document.createElement('span'); |
| 291 | matchop.setAttribute('data-type', this.type()); |
| 292 | matchop.setAttribute('class', 'match'); |
| 293 | matchop.appendChild(document.createTextNode(this.matchop())); |
| 294 | |
| 295 | // Added match operator |
| 296 | var value = document.createElement('span'); |
| 297 | value.setAttribute('data-type', this.type()); |
| 298 | value.setAttribute('class', 'value'); |
| 299 | if (this.value()) |
| 300 | value.appendChild(document.createTextNode(this.value())); |
| 301 | |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 302 | var e = this._element; |
| 303 | |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 304 | // Add spans |
| 305 | e.appendChild(key); |
| 306 | e.appendChild(matchop); |
| 307 | e.appendChild(value); |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 308 | |
| 309 | // Set operators |
| 310 | var op = this.operators(true, true, true); |
| 311 | |
| 312 | e.appendChild(op.element()); |
| 313 | |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 314 | return e; |
| 315 | }, |
| 316 | |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 317 | element : function () { |
| 318 | if (this._element !== undefined) |
| 319 | return this._element; |
| 320 | |
| 321 | this._element = document.createElement('div'); |
| 322 | this._element.setAttribute('class', 'doc'); |
| 323 | |
| 324 | this.update(); |
| 325 | return this._element; |
| 326 | }, |
| 327 | |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 328 | // Wrap a new operation around the doc element |
| 329 | wrap : function (op) { |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 330 | /* |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 331 | var group = KorAP.DocGroup.create(undefined); |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 332 | group.append(this); |
| 333 | group.append(null); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 334 | this.parent(group); |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 335 | var div = document.createElement('div'); |
| 336 | div.setAttribute('data-operation', op); |
| 337 | var parent = this.element.parent; |
| 338 | parent.removeChild(this.element); |
| 339 | parent.appendChild(div); |
| 340 | div.appendChild(this.element); |
| 341 | return div; |
| 342 | */ |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 343 | }, |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 344 | // Deserialize from json |
| 345 | fromJson : function (json) { |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 346 | if (json === undefined) |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 347 | return this; |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 348 | |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 349 | if (json["@type"] !== "korap:doc") { |
| 350 | KorAP.log(701, "JSON-LD group has no @type attribute"); |
| 351 | return; |
| 352 | }; |
| 353 | |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 354 | if (json["value"] === undefined || |
| 355 | typeof json["value"] != 'string') { |
| 356 | KorAP.log(805, "Value is invalid"); |
| 357 | return; |
| 358 | }; |
| 359 | |
| 360 | // There is a defined key |
| 361 | if (json["key"] !== undefined && |
| 362 | typeof json["key"] === 'string') { |
| 363 | |
| 364 | // Set key |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 365 | this.key(json["key"]); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 366 | |
| 367 | // Set match operation |
| 368 | if (json["match"] !== undefined) { |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 369 | if (typeof json["match"] === 'string') { |
| 370 | this.matchop(json["match"]); |
| 371 | } |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 372 | else { |
| 373 | KorAP.log(802, "Match type is not supported by value type"); |
| 374 | return; |
| 375 | }; |
| 376 | }; |
| 377 | |
| 378 | // Key is a string |
| 379 | if (json["type"] === undefined || |
| 380 | json["type"] == "type:string") { |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 381 | this.type("string"); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 382 | |
| 383 | // Check match type |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 384 | if (!KorAP._validStringMatchRE.test(this.matchop())) { |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 385 | KorAP.log(802, "Match type is not supported by value type"); |
| 386 | return; |
| 387 | }; |
| 388 | |
| 389 | // Set string value |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 390 | this.value(json["value"]); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | // Key is a date |
| 394 | else if (json["type"] === "type:date") { |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 395 | this.type("date"); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 396 | |
| 397 | if (json["value"] !== undefined && |
| 398 | KorAP._validDateRE.test(json["value"])) { |
| 399 | |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 400 | if (!KorAP._validDateMatchRE.test(this.matchop())) { |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 401 | KorAP.log(802, "Match type is not supported by value type"); |
| 402 | return; |
| 403 | }; |
| 404 | |
| 405 | // Set value |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 406 | this.value(json["value"]); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 407 | } |
| 408 | else { |
| 409 | KorAP.log(806, "Value is not a valid date string"); |
| 410 | return; |
| 411 | }; |
| 412 | } |
| 413 | |
| 414 | // Key is a regular expression |
| 415 | else if (json["type"] === "type:regex") { |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 416 | this.type("regex"); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 417 | |
| 418 | try { |
| 419 | |
| 420 | // Try to create a regular expression |
| 421 | var check = new RegExp(json["value"]); |
| 422 | |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 423 | if (!KorAP._validRegexMatchRE.test(this.matchop())) { |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 424 | KorAP.log(802, "Match type is not supported by value type"); |
| 425 | return; |
| 426 | }; |
| 427 | |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 428 | this.value(json["value"]); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 429 | } |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 430 | |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 431 | catch (e) { |
| 432 | KorAP.log(807, "Value is not a valid regular expression"); |
| 433 | return; |
| 434 | }; |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 435 | this.type("regex"); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | else { |
| 439 | KorAP.log(804, "Unknown value type"); |
| 440 | return; |
| 441 | }; |
| 442 | }; |
| 443 | |
| 444 | return this; |
| 445 | }, |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 446 | key : function (value) { |
| 447 | if (arguments.length === 1) |
| 448 | this._key = value; |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 449 | return this._key; |
| 450 | }, |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 451 | matchop : function (match) { |
| 452 | if (arguments.length === 1) |
| 453 | this._matchop = match.replace(/^match:/, ''); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 454 | return this._matchop || "eq"; |
| 455 | }, |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 456 | type : function (type) { |
| 457 | if (arguments.length === 1) |
| 458 | this._type = type; |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 459 | return this._type || "string"; |
| 460 | }, |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 461 | value : function (value) { |
| 462 | if (arguments.length === 1) |
| 463 | this._value = value; |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 464 | return this._value; |
| 465 | }, |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 466 | toJson : function () { |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 467 | if (!this.matchop() || !this.key()) |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 468 | return {}; |
| 469 | |
| 470 | return { |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 471 | "@type" : "korap:" + this.ldType(), |
| 472 | "key" : this.key(), |
| 473 | "match" : "match:" + this.matchop(), |
| 474 | "value" : this.value() || '', |
| 475 | "type" : "type:" + this.type() |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 476 | }; |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 477 | }, |
| 478 | toString : function () { |
| 479 | if (!this.matchop() || !this.key()) |
| 480 | return ""; |
| 481 | |
| 482 | // Build doc string based on key |
| 483 | var string = this.key() + ' '; |
| 484 | |
| 485 | // Add match operator |
| 486 | switch (this.matchop()) { |
| 487 | case "ne": |
| 488 | string += '!='; |
| 489 | break; |
| 490 | case "contains": |
| 491 | string += '~'; |
| 492 | break; |
| 493 | case "geq": |
| 494 | string += 'since'; |
| 495 | break; |
| 496 | case "leq": |
| 497 | string += 'until'; |
| 498 | break; |
| 499 | default: |
| 500 | string += (this.type() == 'date') ? 'in' : '='; |
| 501 | break; |
| 502 | }; |
| 503 | |
| 504 | string += ' '; |
| 505 | |
| 506 | // Add value |
| 507 | switch (this.type()) { |
| 508 | case "date": |
| 509 | return string + this.value(); |
| 510 | break; |
| 511 | case "regex": |
| 512 | return string + '/' + this.value() + '/'; |
| 513 | break; |
| 514 | case "string": |
| 515 | return string + '"' + this.value().replace(KorAP._quote, '\\$1') + '"'; |
| 516 | break; |
| 517 | }; |
| 518 | |
| 519 | return "..."; |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 520 | } |
| 521 | }; |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 522 | |
| 523 | /** |
| 524 | * Virtual collection group criterion. |
| 525 | */ |
| 526 | KorAP.DocGroup = { |
| 527 | _ldType : "docGroup", |
| 528 | |
| 529 | create : function (parent, json) { |
| 530 | var obj = Object.create(KorAP.JsonLD).upgradeTo(KorAP.DocGroup); |
| 531 | obj._operands = []; |
| 532 | obj.fromJson(json); |
| 533 | if (parent !== undefined) |
| 534 | obj._parent = parent; |
| 535 | return obj; |
| 536 | }, |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 537 | append : function (operand) { |
| 538 | |
| 539 | // Append unspecified object |
| 540 | if (operand === undefined) { |
| 541 | |
| 542 | // Be aware of cyclic structures! |
| 543 | operand = KorAP.UnspecifiedDoc.create(this); |
| 544 | this._operands.push(operand); |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 545 | return operand; |
| 546 | }; |
| 547 | |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 548 | switch (operand["@type"]) { |
| 549 | case undefined: |
| 550 | if (operand["ldType"] !== undefined) { |
| 551 | if (operand.ldType() !== 'doc' && |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 552 | operand.ldType() !== 'docGroup') { |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 553 | KorAP.log(812, "Operand not supported in document group"); |
| 554 | return; |
| 555 | }; |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 556 | // Be aware of cyclic structures! |
| 557 | operand.parent(this); |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 558 | this._operands.push(operand); |
| 559 | return operand; |
| 560 | }; |
| 561 | |
| 562 | KorAP.log(701, "JSON-LD group has no @type attribute"); |
| 563 | return; |
| 564 | |
| 565 | case "korap:doc": |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 566 | // Be aware of cyclic structures! |
| 567 | var doc = KorAP.Doc.create(this, operand); |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 568 | if (doc === undefined) |
| 569 | return; |
| 570 | this._operands.push(doc); |
| 571 | return doc; |
| 572 | |
| 573 | case "korap:docGroup": |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 574 | // Be aware of cyclic structures! |
| 575 | var docGroup = KorAP.DocGroup.create(this, operand); |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 576 | if (docGroup === undefined) |
| 577 | return; |
| 578 | this._operands.push(docGroup); |
| 579 | return docGroup; |
| 580 | |
| 581 | default: |
| 582 | KorAP.log(812, "Operand not supported in document group"); |
| 583 | return; |
| 584 | }; |
| 585 | }, |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 586 | update : function () { |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 587 | |
| 588 | // There is only one operand in group |
| 589 | if (this._operands.length === 1) { |
| 590 | var parent = this.parent(); |
| 591 | |
| 592 | // Parent is a group |
| 593 | if (parent.ldType() !== null) { |
| 594 | return parent.replaceOperand( |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 595 | this, |
| 596 | this.getOperand(0) |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 597 | ).update(); |
| 598 | } |
| 599 | |
| 600 | // Parent is vc root |
| 601 | else { |
| 602 | console.log("parent is vc"); |
| 603 | parent.root(this.getOperand(0)); |
| 604 | this.destroy(); |
| 605 | return parent.root(); |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 606 | }; |
| 607 | }; |
| 608 | |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 609 | if (this._element === undefined) |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 610 | return this; |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 611 | |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 612 | var group = this._element; |
| 613 | group.setAttribute('data-operation', this.operation()); |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 614 | |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 615 | _removeChildren(group); |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 616 | |
| 617 | // Append operands |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 618 | for (var i in this._operands) { |
| 619 | group.appendChild( |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 620 | this.getOperand(i).element() |
| 621 | ); |
| 622 | }; |
| 623 | |
| 624 | // Set operators |
| 625 | var op = this.operators( |
| 626 | this.operation() == 'and' ? false : true, |
| 627 | this.operation() == 'or' ? false : true, |
| 628 | true |
| 629 | ); |
| 630 | |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 631 | group.appendChild( |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 632 | op.element() |
| 633 | ); |
| 634 | |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 635 | return this; |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 636 | }, |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 637 | element : function () { |
| 638 | if (this._element !== undefined) |
| 639 | return this._element; |
| 640 | |
| 641 | this._element = document.createElement('div'); |
| 642 | this._element.setAttribute('class', 'docGroup'); |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 643 | |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 644 | // Update the object - including optimization |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 645 | this.update(); |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 646 | |
| 647 | return this._element; |
| 648 | }, |
| 649 | operation : function (op) { |
| 650 | if (arguments.length === 1) { |
| 651 | if (KorAP._validGroupOpRE.test(op)) { |
| 652 | this._op = op; |
| 653 | } |
| 654 | else { |
| 655 | KorAP.log(810, "Unknown operation type"); |
| 656 | return; |
| 657 | }; |
| 658 | }; |
| 659 | return this._op || 'and'; |
| 660 | }, |
| 661 | operands : function () { |
| 662 | return this._operands; |
| 663 | }, |
| 664 | getOperand : function (index) { |
| 665 | return this._operands[index]; |
| 666 | }, |
| 667 | |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 668 | // Replace operand |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 669 | replaceOperand : function (oldOp, newOp) { |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 670 | for (var i in this._operands) { |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 671 | if (this._operands[i] === oldOp) { |
| 672 | |
| 673 | // Just insert a doc |
| 674 | if (newOp.ldType() === "doc") { |
| 675 | console.log("Insert doc in group"); |
| 676 | this._operands[i] = newOp; |
| 677 | } |
| 678 | // Insert a group of a different operation |
| 679 | // (i.e. "and" in "or"/"or" in "and") |
| 680 | else if (newOp.operation() != oldOp.operation()) { |
| 681 | console.log("Insert group in group - no flatten"); |
| 682 | this._operands[i] = newOp; |
| 683 | } |
| 684 | |
| 685 | // Flatten the group |
| 686 | else { |
| 687 | console.log("Insert group in group - flatten"); |
| 688 | for (var op in newOp.operands().reverse()) |
| 689 | this._operands.splice(i, 1, newOp.getOperand(op)) |
| 690 | }; |
| 691 | oldOp.destroy(); |
| 692 | return this; |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 693 | } |
| 694 | }; |
| 695 | return false; |
| 696 | }, |
| 697 | |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 698 | // Delete operand from group |
| 699 | delOperand : function (obj) { |
| 700 | for (var i in this._operands) { |
| 701 | if (this._operands[i] === obj) { |
| 702 | this._operands.splice(i,1); |
| 703 | |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 704 | // Destroy object for cyclic references |
| 705 | obj.destroy(); |
| 706 | |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 707 | // Todo: Update has to check |
| 708 | // that this may mean the group is empty etc. |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 709 | return this; |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 710 | }; |
| 711 | }; |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 712 | |
| 713 | // Operand not found |
| 714 | return undefined; |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 715 | }, |
| 716 | |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 717 | // Deserialize from json |
| 718 | fromJson : function (json) { |
| 719 | if (json === undefined) |
| 720 | return this; |
| 721 | |
| 722 | if (json["@type"] !== "korap:docGroup") { |
| 723 | KorAP.log(701, "JSON-LD group has no @type attribute"); |
| 724 | return; |
| 725 | }; |
| 726 | |
| 727 | if (json["operation"] === undefined || |
| 728 | typeof json["operation"] !== 'string') { |
| 729 | KorAP.log(811, "Document group expects operation"); |
| 730 | return; |
| 731 | }; |
| 732 | |
| 733 | var operation = json["operation"]; |
| 734 | |
| 735 | this.operation(operation.replace(/^operation:/,'')); |
| 736 | |
| 737 | if (json["operands"] === undefined || |
| 738 | !(json["operands"] instanceof Array)) { |
| 739 | KorAP.log(704, "Operation needs operand list") |
| 740 | return; |
| 741 | }; |
| 742 | |
| 743 | // Add all documents |
| 744 | for (var i in json["operands"]) { |
| 745 | var operand = json["operands"][i]; |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 746 | this.append(operand); |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 747 | }; |
| 748 | |
| 749 | return this; |
| 750 | }, |
| 751 | toJson : function () { |
| 752 | var opArray = new Array(); |
| 753 | for (var i in this._operands) { |
| 754 | opArray.push(this._operands[i].toJson()); |
| 755 | }; |
| 756 | return { |
| 757 | "@type" : "korap:" + this.ldType(), |
| 758 | "operation" : "operation:" + this.operation(), |
| 759 | "operands" : opArray |
| 760 | }; |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 761 | }, |
| 762 | toString : function () { |
| 763 | return this._operands. |
| 764 | map(function (op) { |
| 765 | return op.ldType() === 'docGroup' ? '(' + op.toString() + ')' : op.toString() |
| 766 | }). |
| 767 | join(this.operation() === 'or' ? ' | ' : ' & ') |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 768 | } |
| 769 | }; |
| 770 | |
| 771 | |
| 772 | // Abstract JsonLD object |
| 773 | KorAP.JsonLD = { |
| 774 | create : function () { |
| 775 | return Object.create(KorAP.JsonLD); |
| 776 | }, |
| 777 | |
| 778 | /** |
| 779 | * Upgrade this object to another object |
| 780 | * while private data stays intact |
| 781 | */ |
| 782 | upgradeTo : function (props) { |
| 783 | for (var prop in props) { |
| 784 | this[prop] = props[prop]; |
| 785 | }; |
| 786 | return this; |
| 787 | }, |
| 788 | ldType : function (type) { |
| 789 | if (arguments.length === 1) |
| 790 | this._ldType = type; |
| 791 | return this._ldType; |
| 792 | }, |
| 793 | parent : function (obj) { |
| 794 | if (arguments.length === 1) |
| 795 | this._parent = obj; |
| 796 | return this._parent; |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 797 | }, |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 798 | |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 799 | // Destroy object - especially for |
| 800 | // acyclic structures! |
| 801 | // I'm a paranoid chicken! |
| 802 | destroy : function () { |
| 803 | if (this._ops != undefined) { |
| 804 | this._ops._parent = undefined; |
| 805 | if (this._ops._element !== undefined) |
| 806 | this._ops._element.refTo = undefined; |
| 807 | this._ops = undefined; |
| 808 | }; |
| 809 | if (this._element !== undefined) |
| 810 | this._element = undefined; |
| 811 | |
| 812 | // In case of a group, destroy all operands |
| 813 | if (this._operands !== undefined) { |
| 814 | for (var i in this._operands) |
| 815 | this.getOperand(i).destroy(); |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame^] | 816 | this._operands = []; |
Nils Diewald | 5c817a4 | 2015-01-06 01:08:56 +0000 | [diff] [blame] | 817 | }; |
| 818 | }, |
| 819 | |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 820 | // Be aware! This may be cyclic |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 821 | operators : function (and, or, del) { |
| 822 | if (arguments === 0) |
| 823 | return this._ops; |
| 824 | this._ops = KorAP.Operators.create( |
| 825 | and, or, del |
| 826 | ); |
Nils Diewald | 0297ba1 | 2015-01-05 21:56:12 +0000 | [diff] [blame] | 827 | this._ops.parent(this); |
Nils Diewald | 966abf1 | 2014-12-20 02:27:45 +0000 | [diff] [blame] | 828 | return this._ops; |
| 829 | }, |
| 830 | toJson : function () { |
| 831 | return { |
| 832 | // Unspecified object |
| 833 | "@type" : "korap:" + this.ldType() |
| 834 | }; |
Nils Diewald | 8f4e254 | 2014-12-19 04:42:09 +0000 | [diff] [blame] | 835 | } |
| 836 | }; |
| 837 | |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 838 | }(this.KorAP)); |