| author | hamidouk |
| Wed, 28 Dec 2011 10:39:54 +0100 | |
| branch | popcorn-port |
| changeset 536 | b7e545e35287 |
| parent 528 | a5894f09825a |
| child 566 | 098929cd2d62 |
| 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) { |
|
30 |
self._data = data; |
|
31 |
// sort the data too |
|
32 |
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
|
33 |
{ var a_begin = +a.begin; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
34 |
var b_begin = +b.begin; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
35 |
return a_begin - b_begin; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
36 |
}); |
| 137 | 37 |
|
38 |
callback(data); |
|
|
108
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
39 |
}; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
40 |
|
| 137 | 41 |
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
|
42 |
}; |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
43 |
|
| 528 | 44 |
/** @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
|
45 |
IriSP.JSONSerializer.prototype.currentMedia = function() { |
|
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff
changeset
|
46 |
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
|
47 |
}; |
|
147
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
48 |
|
| 528 | 49 |
/** 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
|
50 |
"" matches any field. |
| 395 | 51 |
Note: it ignores tweets. |
| 528 | 52 |
@return a list of matching ids. |
|
147
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
53 |
*/ |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
54 |
IriSP.JSONSerializer.prototype.searchAnnotations = function(title, description, keyword) { |
| 352 | 55 |
/* we can have many types of annotations. We want search to only look for regular segments */ |
56 |
/* the next two lines are a bit verbose because for some test data, _serializer.data.view is either |
|
57 |
null or undefined. |
|
58 |
*/ |
|
59 |
var view; |
|
60 |
||
61 |
if (typeof(this._data.views) !== "undefined" && this._data.views !== null) |
|
62 |
view = this._data.views[0]; |
|
63 |
||
64 |
var searchViewType = ""; |
|
65 |
||
66 |
if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) { |
|
67 |
searchViewType = view.annotation_types[0]; |
|
68 |
} |
|
69 |
||
| 395 | 70 |
var filterfn = function(annotation) { |
71 |
if( searchViewType != "" && |
|
72 |
typeof(annotation.meta) !== "undefined" && |
|
73 |
typeof(annotation.meta["id-ref"]) !== "undefined" && |
|
74 |
annotation.meta["id-ref"] !== searchViewType) { |
|
75 |
return true; // don't pass |
|
76 |
} else { |
|
77 |
return false; |
|
78 |
} |
|
79 |
}; |
|
80 |
||
81 |
return this.searchAnnotationsFilter(title, description, keyword, filterfn); |
|
82 |
||
83 |
}; |
|
84 |
||
85 |
/* only look for tweets */ |
|
86 |
IriSP.JSONSerializer.prototype.searchTweets = function(title, description, keyword) { |
|
87 |
/* we can have many types of annotations. We want search to only look for regular segments */ |
|
88 |
/* the next two lines are a bit verbose because for some test data, _serializer.data.view is either |
|
89 |
null or undefined. |
|
90 |
*/ |
|
91 |
var view; |
|
92 |
||
93 |
if (typeof(this._data.views) !== "undefined" && this._data.views !== null) |
|
94 |
view = this._data.views[0]; |
|
95 |
||
96 |
var searchViewType = ""; |
|
97 |
||
98 |
if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) { |
|
99 |
searchViewType = view.annotation_types[0]; |
|
100 |
} |
|
101 |
||
102 |
var filterfn = function(annotation) { |
|
103 |
if( searchViewType != "" && |
|
104 |
typeof(annotation.meta) !== "undefined" && |
|
105 |
typeof(annotation.meta["id-ref"]) !== "undefined" && |
|
106 |
annotation.meta["id-ref"] !== searchViewType) { |
|
107 |
return false; // pass |
|
108 |
} else { |
|
109 |
return true; |
|
110 |
} |
|
111 |
}; |
|
112 |
||
113 |
return this.searchAnnotationsFilter(title, description, keyword, filterfn); |
|
114 |
||
115 |
}; |
|
116 |
||
| 528 | 117 |
/** |
118 |
search an annotation according to its title, description and keyword |
|
119 |
@param filter a function to filter the results with. Used to select between annotation types. |
|
| 395 | 120 |
*/ |
121 |
IriSP.JSONSerializer.prototype.searchAnnotationsFilter = function(title, description, keyword, filter) { |
|
122 |
||
|
147
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
123 |
var rTitle; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
124 |
var rDescription; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
125 |
var rKeyword; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
126 |
/* match anything if given the empty string */ |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
127 |
if (title == "") |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
128 |
title = ".*"; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
129 |
if (description == "") |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
130 |
description = ".*"; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
131 |
if (keyword == "") |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
132 |
keyword = ".*"; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
133 |
|
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
134 |
rTitle = new RegExp(title, "i"); |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
135 |
rDescription = new RegExp(description, "i"); |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
136 |
rKeyword = new RegExp(keyword, "i"); |
|
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 |
var ret_array = []; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
139 |
|
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
140 |
var i; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
141 |
for (i in this._data.annotations) { |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
142 |
var annotation = this._data.annotations[i]; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
143 |
|
| 352 | 144 |
/* filter the annotations whose type is not the one we want */ |
| 395 | 145 |
if (filter(annotation)) { |
| 352 | 146 |
continue; |
147 |
} |
|
| 395 | 148 |
|
|
147
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
149 |
if (rTitle.test(annotation.content.title) && |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
150 |
rDescription.test(annotation.content.description)) { |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
151 |
/* FIXME : implement keyword support */ |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
152 |
ret_array.push(annotation); |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
153 |
} |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
154 |
} |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
155 |
|
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
156 |
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
|
157 |
}; |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
158 |
|
| 528 | 159 |
/** 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
|
160 |
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
|
161 |
|
| 528 | 162 |
@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
|
163 |
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
|
164 |
*/ |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
165 |
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
|
166 |
var ret = { }; |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
167 |
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
|
168 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
169 |
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
|
170 |
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
|
171 |
|
| 150 | 172 |
// 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
|
173 |
var found_annotations = [] |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
174 |
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
|
175 |
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
|
176 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
177 |
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
|
178 |
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
|
179 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
} else { |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
183 |
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
|
184 |
} |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
185 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
186 |
} |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
187 |
|
|
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 |
return ret; |
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
191 |
}; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
192 |
|
| 528 | 193 |
/** breaks a string in words and searches each of these words. Returns an array |
| 395 | 194 |
of objects with the id of the annotation and its number of occurences. |
195 |
|
|
196 |
FIXME: optimize ? seems to be n^2 in the worst case. |
|
197 |
*/ |
|
198 |
IriSP.JSONSerializer.prototype.searchTweetsOccurences = function(searchString) { |
|
199 |
var ret = { }; |
|
200 |
var keywords = searchString.split(/\s+/); |
|
201 |
|
|
202 |
for (var i in keywords) { |
|
203 |
var keyword = keywords[i]; |
|
204 |
|
|
205 |
// search this keyword in descriptions and title |
|
206 |
var found_annotations = [] |
|
207 |
found_annotations = found_annotations.concat(this.searchTweets(keyword, "", "")); |
|
208 |
found_annotations = found_annotations.concat(this.searchTweets("", keyword, "")); |
|
209 |
|
|
210 |
for (var j in found_annotations) { |
|
211 |
var current_annotation = found_annotations[j]; |
|
212 |
|
|
213 |
if (!ret.hasOwnProperty(current_annotation.id)) { |
|
214 |
ret[current_annotation.id] = 1; |
|
215 |
} else { |
|
216 |
ret[current_annotation.id] += 1; |
|
217 |
} |
|
218 |
|
|
219 |
} |
|
220 |
||
221 |
}; |
|
222 |
|
|
223 |
return ret; |
|
224 |
}; |
|
225 |
||
| 528 | 226 |
/** 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
|
227 |
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
|
228 |
currentTime is in seconds. |
| 528 | 229 |
|
230 |
@param currentTime the time at which we search. |
|
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
231 |
*/ |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
232 |
|
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
233 |
IriSP.JSONSerializer.prototype.currentAnnotations = function(currentTime) { |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
234 |
var view; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
235 |
var currentTimeMs = 1000 * currentTime; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
236 |
|
|
536
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
237 |
var legal_ids = this.getNonTweetIds(); |
|
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
238 |
|
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
239 |
var ret_array = []; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
240 |
|
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
241 |
var i; |
|
536
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
242 |
|
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
243 |
for (i in this._data.annotations) { |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
244 |
var annotation = this._data.annotations[i]; |
| 320 | 245 |
|
|
536
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
246 |
if (IriSP.underscore.include(legal_ids, annotation.meta["id-ref"]) && annotation.begin <= currentTimeMs && annotation.end >= currentTimeMs) |
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
247 |
ret_array.push(annotation); |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
248 |
} |
| 320 | 249 |
|
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
250 |
return ret_array; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
251 |
}; |
|
513
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
252 |
|
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
253 |
|
| 528 | 254 |
/** 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
|
255 |
IriSP.JSONSerializer.prototype.getTweetIds = function() { |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
256 |
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
|
257 |
return []; |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
258 |
|
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
259 |
var tweetsId = []; |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
260 |
|
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
261 |
/* 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
|
262 |
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
|
263 |
|
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
264 |
// FIXME: collect tweets from multiple sources ? |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
265 |
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
|
266 |
|
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
267 |
return tweetsId; |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
268 |
}; |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
269 |
|
| 528 | 270 |
/** 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
|
271 |
IriSP.JSONSerializer.prototype.getNonTweetIds = function() { |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
272 |
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
|
273 |
return []; |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
274 |
|
|
536
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
275 |
/* 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
|
276 |
flatten the returned array because pluck returns a string afterwards. |
|
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
277 |
*/ |
|
b7e545e35287
fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents:
528
diff
changeset
|
278 |
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
|
279 |
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
|
280 |
|
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
281 |
var illegal_values = this.getTweetIds(); |
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
282 |
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
|
283 |
|
|
4589b90fe1ad
added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents:
395
diff
changeset
|
284 |
}; |