| author | hamidouk |
| Fri, 13 Jan 2012 15:45:29 +0100 | |
| branch | popcorn-port |
| changeset 628 | 55282f5ef477 |
| parent 613 | c2726c5c6477 |
| child 633 | 00a59060d78d |
| permissions | -rw-r--r-- |
| 528 | 1 |
/** @class This class implement a serializer for the JSON-Cinelab format |
2 |
@params DataLoader a dataloader reference |
|
3 |
@url the url from which to get our cinelab |
|
4 |
*/ |
|
|
108
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
5 |
IriSP.JSONSerializer = function(DataLoader, url) { |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
6 |
IriSP.Serializer.call(this, DataLoader, url); |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
7 |
}; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
8 |
|
| 128 | 9 |
IriSP.JSONSerializer.prototype = new IriSP.Serializer(); |
|
108
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
10 |
|
| 528 | 11 |
/** serialize data */ |
|
108
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
12 |
IriSP.JSONSerializer.prototype.serialize = function(data) { |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
13 |
return JSON.stringify(data); |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
14 |
}; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
15 |
|
| 528 | 16 |
/** deserialize data */ |
|
108
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
17 |
IriSP.JSONSerializer.prototype.deserialize = function(data) { |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
18 |
return JSON.parse(data); |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
19 |
}; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
20 |
|
| 528 | 21 |
/** load JSON-cinelab data and also sort the annotations by start time |
22 |
@param callback function to call when the data is ready. |
|
23 |
*/ |
|
|
108
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
24 |
IriSP.JSONSerializer.prototype.sync = function(callback) { |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
25 |
/* we don't have to do much because jQuery handles json for us */ |
| 128 | 26 |
|
| 137 | 27 |
var self = this; |
28 |
||
29 |
var fn = function(data) { |
|
| 610 | 30 |
self._data = data; |
31 |
if (typeof(self._data["annotations"]) === "undefined" || |
|
32 |
self._data["annotations"] === null) |
|
33 |
self._data["annotations"] = []; |
|
34 |
|
|
35 |
// sort the data too |
|
| 137 | 36 |
self._data["annotations"].sort(function(a, b) |
|
108
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
37 |
{ var a_begin = +a.begin; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
38 |
var b_begin = +b.begin; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
39 |
return a_begin - b_begin; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
40 |
}); |
| 137 | 41 |
|
42 |
callback(data); |
|
|
108
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
43 |
}; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
44 |
|
| 137 | 45 |
this._DataLoader.get(this._url, fn); |
|
108
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
46 |
}; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
47 |
|
| 528 | 48 |
/** @return the metadata about the media being read FIXME: always return the first media. */ |
|
108
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
49 |
IriSP.JSONSerializer.prototype.currentMedia = function() { |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
50 |
return this._data.medias[0]; /* FIXME: don't hardcode it */ |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
51 |
}; |
|
147
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
52 |
|
| 528 | 53 |
/** searches for an annotation which matches title, description and keyword |
|
147
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
54 |
"" matches any field. |
| 395 | 55 |
Note: it ignores tweets. |
| 528 | 56 |
@return a list of matching ids. |
|
147
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
57 |
*/ |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
58 |
IriSP.JSONSerializer.prototype.searchAnnotations = function(title, description, keyword) { |
| 352 | 59 |
/* we can have many types of annotations. We want search to only look for regular segments */ |
60 |
/* the next two lines are a bit verbose because for some test data, _serializer.data.view is either |
|
61 |
null or undefined. |
|
62 |
*/ |
|
63 |
var view; |
|
64 |
||
65 |
if (typeof(this._data.views) !== "undefined" && this._data.views !== null) |
|
66 |
view = this._data.views[0]; |
|
67 |
||
68 |
var searchViewType = ""; |
|
69 |
||
70 |
if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) { |
|
71 |
searchViewType = view.annotation_types[0]; |
|
72 |
} |
|
73 |
||
| 395 | 74 |
var filterfn = function(annotation) { |
75 |
if( searchViewType != "" && |
|
76 |
typeof(annotation.meta) !== "undefined" && |
|
77 |
typeof(annotation.meta["id-ref"]) !== "undefined" && |
|
78 |
annotation.meta["id-ref"] !== searchViewType) { |
|
79 |
return true; // don't pass |
|
80 |
} else { |
|
81 |
return false; |
|
82 |
} |
|
83 |
}; |
|
84 |
||
85 |
return this.searchAnnotationsFilter(title, description, keyword, filterfn); |
|
86 |
||
87 |
}; |
|
88 |
||
89 |
/* only look for tweets */ |
|
90 |
IriSP.JSONSerializer.prototype.searchTweets = function(title, description, keyword) { |
|
91 |
/* we can have many types of annotations. We want search to only look for regular segments */ |
|
92 |
/* the next two lines are a bit verbose because for some test data, _serializer.data.view is either |
|
93 |
null or undefined. |
|
94 |
*/ |
|
95 |
var view; |
|
96 |
||
97 |
if (typeof(this._data.views) !== "undefined" && this._data.views !== null) |
|
98 |
view = this._data.views[0]; |
|
99 |
||
100 |
var searchViewType = ""; |
|
101 |
||
102 |
if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) { |
|
103 |
searchViewType = view.annotation_types[0]; |
|
104 |
} |
|
105 |
||
106 |
var filterfn = function(annotation) { |
|
107 |
if( searchViewType != "" && |
|
108 |
typeof(annotation.meta) !== "undefined" && |
|
109 |
typeof(annotation.meta["id-ref"]) !== "undefined" && |
|
110 |
annotation.meta["id-ref"] !== searchViewType) { |
|
111 |
return false; // pass |
|
112 |
} else { |
|
113 |
return true; |
|
114 |
} |
|
115 |
}; |
|
116 |
||
117 |
return this.searchAnnotationsFilter(title, description, keyword, filterfn); |
|
118 |
||
119 |
}; |
|
120 |
||
| 528 | 121 |
/** |
122 |
search an annotation according to its title, description and keyword |
|
123 |
@param filter a function to filter the results with. Used to select between annotation types. |
|
| 395 | 124 |
*/ |
125 |
IriSP.JSONSerializer.prototype.searchAnnotationsFilter = function(title, description, keyword, filter) { |
|
126 |
||
|
147
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
127 |
var rTitle; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
128 |
var rDescription; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
129 |
var rKeyword; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
130 |
/* match anything if given the empty string */ |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
131 |
if (title == "") |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
132 |
title = ".*"; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
133 |
if (description == "") |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
134 |
description = ".*"; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
135 |
if (keyword == "") |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
136 |
keyword = ".*"; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
137 |
|
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
138 |
rTitle = new RegExp(title, "i"); |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
139 |
rDescription = new RegExp(description, "i"); |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
140 |
rKeyword = new RegExp(keyword, "i"); |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
141 |
|
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
142 |
var ret_array = []; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
143 |
|
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
144 |
var i; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
145 |
for (i in this._data.annotations) { |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
146 |
var annotation = this._data.annotations[i]; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
147 |
|
| 352 | 148 |
/* filter the annotations whose type is not the one we want */ |
| 395 | 149 |
if (filter(annotation)) { |
| 352 | 150 |
continue; |
151 |
} |
|
| 395 | 152 |
|
|
147
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
153 |
if (rTitle.test(annotation.content.title) && |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
154 |
rDescription.test(annotation.content.description)) { |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
155 |
/* FIXME : implement keyword support */ |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
156 |
ret_array.push(annotation); |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
157 |
} |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
158 |
} |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
159 |
|
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
160 |
return ret_array; |
|
149
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
161 |
}; |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
162 |
|
| 528 | 163 |
/** breaks a string in words and searches each of these words. Returns an array |
|
149
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
164 |
of objects with the id of the annotation and its number of occurences. |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
165 |
|
| 528 | 166 |
@param searchString a string of words. |
|
149
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
167 |
FIXME: optimize ? seems to be n^2 in the worst case. |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
168 |
*/ |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
169 |
IriSP.JSONSerializer.prototype.searchOccurences = function(searchString) { |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
170 |
var ret = { }; |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
171 |
var keywords = searchString.split(/\s+/); |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
172 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
173 |
for (var i in keywords) { |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
174 |
var keyword = keywords[i]; |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
175 |
|
| 150 | 176 |
// search this keyword in descriptions and title |
|
149
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
177 |
var found_annotations = [] |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
178 |
found_annotations = found_annotations.concat(this.searchAnnotations(keyword, "", "")); |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
179 |
found_annotations = found_annotations.concat(this.searchAnnotations("", keyword, "")); |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
180 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
181 |
for (var j in found_annotations) { |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
182 |
var current_annotation = found_annotations[j]; |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
183 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
184 |
if (!ret.hasOwnProperty(current_annotation.id)) { |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
185 |
ret[current_annotation.id] = 1; |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
186 |
} else { |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
187 |
ret[current_annotation.id] += 1; |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
188 |
} |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
189 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
190 |
} |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
191 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
192 |
}; |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
193 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
194 |
return ret; |
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
195 |
}; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
196 |
|
| 528 | 197 |
/** breaks a string in words and searches each of these words. Returns an array |
| 395 | 198 |
of objects with the id of the annotation and its number of occurences. |
199 |
|
|
200 |
FIXME: optimize ? seems to be n^2 in the worst case. |
|
201 |
*/ |
|
202 |
IriSP.JSONSerializer.prototype.searchTweetsOccurences = function(searchString) { |
|
203 |
var ret = { }; |
|
204 |
var keywords = searchString.split(/\s+/); |
|
205 |
|
|
206 |
for (var i in keywords) { |
|
207 |
var keyword = keywords[i]; |
|
208 |
|
|
209 |
// search this keyword in descriptions and title |
|
210 |
var found_annotations = [] |
|
211 |
found_annotations = found_annotations.concat(this.searchTweets(keyword, "", "")); |
|
212 |
found_annotations = found_annotations.concat(this.searchTweets("", keyword, "")); |
|
213 |
|
|
214 |
for (var j in found_annotations) { |
|
215 |
var current_annotation = found_annotations[j]; |
|
216 |
|
|
217 |
if (!ret.hasOwnProperty(current_annotation.id)) { |
|
218 |
ret[current_annotation.id] = 1; |
|
219 |
} else { |
|
220 |
ret[current_annotation.id] += 1; |
|
221 |
} |
|
222 |
|
|
223 |
} |
|
224 |
||
225 |
}; |
|
226 |
|
|
227 |
return ret; |
|
228 |
}; |
|
229 |
||
| 528 | 230 |
/** returns all the annotations that are displayable at the moment |
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
231 |
NB: only takes account the first type of annotations - ignores tweets |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
232 |
currentTime is in seconds. |
| 528 | 233 |
|
234 |
@param currentTime the time at which we search. |
|
|
595
29d86e6c61a6
finished going through the widgets to add stricter line checking.
hamidouk
parents:
591
diff
changeset
|
235 |
@param (optional) the if of the type of the annotations we want to get. |
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
236 |
*/ |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
237 |
|
|
595
29d86e6c61a6
finished going through the widgets to add stricter line checking.
hamidouk
parents:
591
diff
changeset
|
238 |
IriSP.JSONSerializer.prototype.currentAnnotations = function(currentTime, id) { |
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
239 |
var view; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
240 |
var currentTimeMs = 1000 * currentTime; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
241 |
|
|
595
29d86e6c61a6
finished going through the widgets to add stricter line checking.
hamidouk
parents:
591
diff
changeset
|
242 |
if (typeof(id) === "undefined") { |
|
29d86e6c61a6
finished going through the widgets to add stricter line checking.
hamidouk
parents:
591
diff
changeset
|
243 |
var legal_ids = this.getNonTweetIds(); |
| 601 | 244 |
} else { |
|
595
29d86e6c61a6
finished going through the widgets to add stricter line checking.
hamidouk
parents:
591
diff
changeset
|
245 |
legal_ids = [id]; |
|
29d86e6c61a6
finished going through the widgets to add stricter line checking.
hamidouk
parents:
591
diff
changeset
|
246 |
} |
|
536
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
247 |
|
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
248 |
var ret_array = []; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
249 |
|
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
250 |
var i; |
|
536
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
251 |
|
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
252 |
for (i in this._data.annotations) { |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
253 |
var annotation = this._data.annotations[i]; |
| 320 | 254 |
|
|
590
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
255 |
if (IriSP.underscore.include(legal_ids, annotation.meta["id-ref"]) && |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
256 |
annotation.begin <= currentTimeMs && |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
257 |
annotation.end >= currentTimeMs) |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
258 |
ret_array.push(annotation); |
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
259 |
} |
|
590
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
260 |
|
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
261 |
if (ret_array == []) { |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
262 |
console.log("ret_array empty, ", legal_ids); |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
263 |
} |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
264 |
|
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
265 |
return ret_array; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
266 |
}; |
|
513
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
267 |
|
| 613 | 268 |
/** return the current chapitre |
269 |
@param currentTime the current time, in seconds. |
|
270 |
*/ |
|
271 |
IriSP.JSONSerializer.prototype.currentChapitre = function(currentTime) { |
|
272 |
return this.currentAnnotations(currentTime, this.getChapitrage())[0]; |
|
273 |
}; |
|
|
513
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
274 |
|
| 528 | 275 |
/** returns a list of ids of tweet lines (aka: groups in cinelab) */ |
|
513
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
276 |
IriSP.JSONSerializer.prototype.getTweetIds = function() { |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
277 |
if (typeof(this._data.lists) === "undefined" || this._data.lists === null) |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
278 |
return []; |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
279 |
|
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
280 |
var tweetsId = []; |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
281 |
|
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
282 |
/* first get the list containing the tweets */ |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
283 |
var tweets = IriSP.underscore.filter(this._data.lists, function(entry) { return entry.id.indexOf("tweet") !== -1 }); |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
284 |
|
|
566
098929cd2d62
made the polemicwidget adjust its size automatically and fixed a couple edgecases.
hamidouk
parents:
536
diff
changeset
|
285 |
if (tweets.length === 0) |
|
098929cd2d62
made the polemicwidget adjust its size automatically and fixed a couple edgecases.
hamidouk
parents:
536
diff
changeset
|
286 |
return []; |
|
098929cd2d62
made the polemicwidget adjust its size automatically and fixed a couple edgecases.
hamidouk
parents:
536
diff
changeset
|
287 |
|
|
513
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
288 |
// FIXME: collect tweets from multiple sources ? |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
289 |
tweetsId = IriSP.underscore.pluck(tweets[0].items, "id-ref"); |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
290 |
|
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
291 |
return tweetsId; |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
292 |
}; |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
293 |
|
| 528 | 294 |
/** this function returns a list of lines which are not tweet lines */ |
|
513
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
295 |
IriSP.JSONSerializer.prototype.getNonTweetIds = function() { |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
296 |
if (typeof(this._data.lists) === "undefined" || this._data.lists === null) |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
297 |
return []; |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
298 |
|
|
536
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
299 |
/* complicated : for each list in this._data.lists, get the id-ref. |
|
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
300 |
flatten the returned array because pluck returns a string afterwards. |
|
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
301 |
*/ |
|
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
302 |
var ids = IriSP.underscore.flatten(IriSP.underscore.map(this._data.lists, function(entry) { |
|
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
303 |
return IriSP.underscore.pluck(entry.items, "id-ref"); })); |
|
513
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
304 |
|
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
305 |
var illegal_values = this.getTweetIds(); |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
306 |
return IriSP.underscore.difference(ids, illegal_values); |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
307 |
|
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
308 |
}; |
|
590
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
309 |
|
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
310 |
/** return the id of the ligne de temps which contains name |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
311 |
@param name of the ligne de temps |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
312 |
*/ |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
313 |
IriSP.JSONSerializer.prototype.getId = function(name) { |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
314 |
if (typeof(this._data.lists) === "undefined" || this._data.lists === null) |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
315 |
return; |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
316 |
|
| 628 | 317 |
name = name.toUpperCase(); |
318 |
var e; |
|
|
590
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
319 |
e = IriSP.underscore.find(this._data["annotation-types"], |
| 628 | 320 |
function(entry) { return (entry["dc:title"].toUpperCase().indexOf(name) !== -1) }); |
|
590
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
321 |
|
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
322 |
if (typeof(e) === "undefined") |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
323 |
return; |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
324 |
|
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
325 |
var id = e.id; |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
326 |
|
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
327 |
return id; |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
328 |
}; |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
329 |
|
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
330 |
/** return the id of the ligne de temps named "Chapitrage" */ |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
331 |
IriSP.JSONSerializer.prototype.getChapitrage = function() { |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
332 |
return this.getId("Chapitrage"); |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
333 |
}; |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
334 |
|
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
335 |
/** return the id of the ligne de temps named "Tweets" */ |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
336 |
IriSP.JSONSerializer.prototype.getTweets = function() { |
| 628 | 337 |
var val = this.getId("Tweets"); |
338 |
if (typeof(val) === "undefined") |
|
339 |
val = this.getId("Tweet"); |
|
340 |
if (typeof(val) === "undefined") |
|
341 |
val = this.getId("Twitter"); |
|
342 |
if (typeof(val) === "undefined") |
|
343 |
val = this.getId("twit"); |
|
344 |
if (typeof(val) === "undefined") |
|
345 |
val = this.getId("Polemic"); |
|
346 |
|
|
347 |
return val; |
|
|
590
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
348 |
}; |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
349 |
|
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
350 |
/** return the id of the ligne de temps named "Contributions" */ |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
351 |
IriSP.JSONSerializer.prototype.getContributions = function() { |
|
495ea8d73bed
added a couple function to return the ids of some lignes de temps.
hamidouk
parents:
566
diff
changeset
|
352 |
return this.getId("Contributions"); |
| 628 | 353 |
}; |