272 return this.currentAnnotations(currentTime, this.getChapitrage())[0]; |
272 return this.currentAnnotations(currentTime, this.getChapitrage())[0]; |
273 }; |
273 }; |
274 |
274 |
275 /** returns a list of ids of tweet lines (aka: groups in cinelab) */ |
275 /** returns a list of ids of tweet lines (aka: groups in cinelab) */ |
276 IriSP.JSONSerializer.prototype.getTweetIds = function() { |
276 IriSP.JSONSerializer.prototype.getTweetIds = function() { |
277 if (typeof(this._data.lists) === "undefined" || this._data.lists === null) |
277 if (IriSP.null_or_undefined(this._data.lists) || IriSP.null_or_undefined(this._data.lists) || |
|
278 IriSP.null_or_undefined(this._data.views) || IriSP.null_or_undefined(this._data.views[0])) |
278 return []; |
279 return []; |
279 |
280 |
280 var tweetsId = []; |
281 |
281 |
282 /* Get the displayable types |
282 /* first get the list containing the tweets */ |
283 We've got to jump through a few hoops because the json sometimes defines |
283 var tweets = IriSP.underscore.filter(this._data.lists, function(entry) { return entry.id.indexOf("tweet") !== -1 }); |
284 fields with underscores and sometimes with dashes |
284 |
285 */ |
285 if (tweets.length === 0) |
286 var annotation_types = this._data.views[0]["annotation_types"]; |
286 return []; |
287 if (IriSP.null_or_undefined(annotation_types)) { |
287 |
288 annotation_types = this._data.views[0]["annotation-types"]; |
288 // FIXME: collect tweets from multiple sources ? |
289 if (IriSP.null_or_undefined(annotation_types)) { |
289 tweetsId = IriSP.underscore.pluck(tweets[0].items, "id-ref"); |
290 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
290 |
291 return; |
|
292 } |
|
293 } |
|
294 |
|
295 var available_types = this._data["available_types"]; |
|
296 if (IriSP.null_or_undefined(available_types)) { |
|
297 available_types = this._data["available-types"]; |
|
298 if (IriSP.null_or_undefined(available_types)) { |
|
299 console.log("neither available_types nor available-types are defined"); |
|
300 return; |
|
301 } |
|
302 } |
|
303 |
|
304 var potential_types = []; |
|
305 |
|
306 // Get the list of types which contain "Tw" in their content |
|
307 for (var i = 0; i < available_types.length; i++) { |
|
308 if (/Tw/i.test(available_types[i]["dc:title"])) { |
|
309 potential_types.push(available_types[i].id); |
|
310 } |
|
311 } |
|
312 |
|
313 // Get the intersection of both. |
|
314 var tweetsId = IriSP.underscore.intersection(annotation_types, potential_types); |
|
315 |
291 return tweetsId; |
316 return tweetsId; |
292 }; |
317 }; |
293 |
318 |
294 /** this function returns a list of lines which are not tweet lines */ |
319 /** this function returns a list of lines which are not tweet lines */ |
295 IriSP.JSONSerializer.prototype.getNonTweetIds = function() { |
320 IriSP.JSONSerializer.prototype.getNonTweetIds = function() { |
296 if (typeof(this._data.lists) === "undefined" || this._data.lists === null) |
321 if (IriSP.null_or_undefined(this._data.lists) || IriSP.null_or_undefined(this._data.lists) || |
|
322 IriSP.null_or_undefined(this._data.views) || IriSP.null_or_undefined(this._data.views[0])) |
297 return []; |
323 return []; |
298 |
324 |
299 /* complicated : for each list in this._data.lists, get the id-ref. |
325 /* Get the displayable types |
300 flatten the returned array because pluck returns a string afterwards. |
326 We've got to jump through a few hoops because the json sometimes defines |
|
327 fields with underscores and sometimes with dashes |
301 */ |
328 */ |
302 var ids = IriSP.underscore.flatten(IriSP.underscore.map(this._data.lists, function(entry) { |
329 var annotation_types = this._data.views[0]["annotation_types"]; |
303 return IriSP.underscore.pluck(entry.items, "id-ref"); })); |
330 if (IriSP.null_or_undefined(annotation_types)) { |
304 |
331 annotation_types = this._data.views[0]["annotation-types"]; |
305 var illegal_values = this.getTweetIds(); |
332 if (IriSP.null_or_undefined(annotation_types)) { |
306 return IriSP.underscore.difference(ids, illegal_values); |
333 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
|
334 return; |
|
335 } |
|
336 } |
|
337 |
|
338 var available_types = this._data["annotation_types"]; |
|
339 if (IriSP.null_or_undefined(available_types)) { |
|
340 available_types = this._data["annotation-types"]; |
|
341 if (IriSP.null_or_undefined(available_types)) { |
|
342 console.log("neither available_types nor available-types are defined"); |
|
343 return; |
|
344 } |
|
345 } |
|
346 |
|
347 var potential_types = []; |
|
348 |
|
349 // Get the list of types which do not contain "Tw" in their content |
|
350 for (var i = 0; i < available_types.length; i++) { |
|
351 if (!(/Tw/i.test(available_types[i]["dc:title"]))) { |
|
352 potential_types.push(available_types[i].id); |
|
353 } |
|
354 } |
|
355 console.log("pot", potential_types, "avail", annotation_types); |
|
356 // Get the intersection of both. |
|
357 var nonTweetsId = IriSP.underscore.intersection(annotation_types, potential_types); |
|
358 |
|
359 return nonTweetsId; |
307 |
360 |
308 }; |
361 }; |
309 |
362 |
310 /** return the id of the ligne de temps which contains name |
363 /** return the id of the ligne de temps which contains name |
311 @param name of the ligne de temps |
364 @param name of the ligne de temps |