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