src/js/serializers/JSONSerializer.js
author hamidouk
Mon, 06 Feb 2012 16:04:46 +0100
branchpopcorn-port
changeset 783 591b117c19ca
parent 693 6328901da7bf
child 797 8407313c144f
permissions -rw-r--r--
be more picky about what we get.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
528
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
     1
/** @class This class implement a serializer for the JSON-Cinelab format
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
     2
    @params DataLoader a dataloader reference
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
     3
    @url the url from which to get our cinelab
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
     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
f3fec80dd31c renames and inheritance bug fixes.
hamidouk
parents: 108
diff changeset
     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
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
    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
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
    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
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
    21
/** load JSON-cinelab data and also sort the annotations by start time
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
    22
    @param callback function to call when the data is ready.
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
    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
f3fec80dd31c renames and inheritance bug fixes.
hamidouk
parents: 108
diff changeset
    26
137
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    27
  var self = this;
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    28
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    29
  var fn = function(data) {      
610
7533dd920805 handle the edge case where passed data is null.
hamidouk
parents: 601
diff changeset
    30
      self._data = data;  
7533dd920805 handle the edge case where passed data is null.
hamidouk
parents: 601
diff changeset
    31
      if (typeof(self._data["annotations"]) === "undefined" ||
7533dd920805 handle the edge case where passed data is null.
hamidouk
parents: 601
diff changeset
    32
          self._data["annotations"] === null)
7533dd920805 handle the edge case where passed data is null.
hamidouk
parents: 601
diff changeset
    33
          self._data["annotations"] = [];
7533dd920805 handle the edge case where passed data is null.
hamidouk
parents: 601
diff changeset
    34
      
7533dd920805 handle the edge case where passed data is null.
hamidouk
parents: 601
diff changeset
    35
      // sort the data too       
137
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    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
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    41
     
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    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
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    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
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
    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
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
    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
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    55
   Note: it ignores tweets.
528
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
    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
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    59
    /* we can have many types of annotations. We want search to only look for regular segments */
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    60
    /* the next two lines are a bit verbose because for some test data, _serializer.data.view is either
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    61
       null or undefined.
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    62
    */
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    63
    var view;
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    64
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    65
    if (typeof(this._data.views) !== "undefined" && this._data.views !== null)
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    66
       view = this._data.views[0];
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    67
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    68
    var searchViewType = "";
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    69
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    70
    if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) {
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    71
            searchViewType = view.annotation_types[0];
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    72
    }
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    73
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    74
    var filterfn = function(annotation) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    75
      if( searchViewType  != "" && 
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    76
          typeof(annotation.meta) !== "undefined" && 
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    77
          typeof(annotation.meta["id-ref"]) !== "undefined" &&
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    78
          annotation.meta["id-ref"] !== searchViewType) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    79
        return true; // don't pass
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    80
      } else {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    81
          return false;
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    82
      }
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    83
    };
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    84
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    85
    return this.searchAnnotationsFilter(title, description, keyword, filterfn);
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    86
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    87
};
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    88
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    89
/* only look for tweets */
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    90
IriSP.JSONSerializer.prototype.searchTweets = function(title, description, keyword) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    91
    /* we can have many types of annotations. We want search to only look for regular segments */
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    92
    /* the next two lines are a bit verbose because for some test data, _serializer.data.view is either
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    93
       null or undefined.
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    94
    */
666
08d1656c608a fixed stupid bug due to convoluted function
hamidouk
parents: 639
diff changeset
    95
    
08d1656c608a fixed stupid bug due to convoluted function
hamidouk
parents: 639
diff changeset
    96
    var searchViewType = this.getTweets();
08d1656c608a fixed stupid bug due to convoluted function
hamidouk
parents: 639
diff changeset
    97
    if (typeof(searchViewType) === "undefined") {
08d1656c608a fixed stupid bug due to convoluted function
hamidouk
parents: 639
diff changeset
    98
      var view;
08d1656c608a fixed stupid bug due to convoluted function
hamidouk
parents: 639
diff changeset
    99
      
08d1656c608a fixed stupid bug due to convoluted function
hamidouk
parents: 639
diff changeset
   100
      if (typeof(this._data.views) !== "undefined" && this._data.views !== null)
08d1656c608a fixed stupid bug due to convoluted function
hamidouk
parents: 639
diff changeset
   101
         view = this._data.views[0];    
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   102
666
08d1656c608a fixed stupid bug due to convoluted function
hamidouk
parents: 639
diff changeset
   103
      if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) {
08d1656c608a fixed stupid bug due to convoluted function
hamidouk
parents: 639
diff changeset
   104
              searchViewType = view.annotation_types[0];
08d1656c608a fixed stupid bug due to convoluted function
hamidouk
parents: 639
diff changeset
   105
      }
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   106
    }
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   107
    var filterfn = function(annotation) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   108
      if( searchViewType  != "" && 
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   109
          typeof(annotation.meta) !== "undefined" && 
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   110
          typeof(annotation.meta["id-ref"]) !== "undefined" &&
666
08d1656c608a fixed stupid bug due to convoluted function
hamidouk
parents: 639
diff changeset
   111
          annotation.meta["id-ref"] === searchViewType) {
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   112
        return false; // pass
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   113
      } else {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   114
          return true;
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   115
      }
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   116
    };
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   117
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   118
    return this.searchAnnotationsFilter(title, description, keyword, filterfn);
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   119
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   120
};
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   121
528
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
   122
/**
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
   123
  search an annotation according to its title, description and keyword
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
   124
  @param filter a function to filter the results with. Used to select between annotation types.
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   125
 */    
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   126
IriSP.JSONSerializer.prototype.searchAnnotationsFilter = function(title, description, keyword, filter) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   127
147
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   128
    var rTitle;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   129
    var rDescription;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   130
    var rKeyword;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   131
    /* match anything if given the empty string */
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   132
    if (title == "")
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   133
      title = ".*";
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   134
    if (description == "")
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   135
      description = ".*";
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   136
    if (keyword == "")
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   137
      keyword = ".*";
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   138
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   139
    rTitle = new RegExp(title, "i");  
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   140
    rDescription = new RegExp(description, "i");  
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   141
    rKeyword = new RegExp(keyword, "i");  
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   142
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   143
    var ret_array = [];
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   144
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   145
    var i;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   146
    for (i in this._data.annotations) {
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   147
      var annotation = this._data.annotations[i];
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   148
      
352
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
   149
      /* filter the annotations whose type is not the one we want */
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   150
      if (filter(annotation)) {
352
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
   151
          continue;
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
   152
      }
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   153
      
147
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   154
      if (rTitle.test(annotation.content.title) && 
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   155
          rDescription.test(annotation.content.description)) {
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   156
          /* FIXME : implement keyword support */
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   157
          ret_array.push(annotation);
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
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   161
    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
   162
};
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   163
528
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
   164
/** 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
   165
   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
   166
   
528
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
   167
   @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
   168
   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
   169
*/
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   170
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
   171
  var ret = { };
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   172
  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
   173
  
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   174
  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
   175
    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
   176
    
150
40cf046b7049 added a comment.
hamidouk
parents: 149
diff changeset
   177
    // 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
   178
    var found_annotations = []
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
    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
   181
    
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   182
    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
   183
      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
   184
      
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   185
      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
   186
        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
   187
      } else {
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   188
        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
   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
  
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   195
  return ret;
317
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   196
};
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   197
528
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
   198
/** breaks a string in words and searches each of these words. Returns an array
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   199
   of objects with the id of the annotation and its number of occurences.
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   200
   
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   201
   FIXME: optimize ? seems to be n^2 in the worst case.
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   202
*/
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   203
IriSP.JSONSerializer.prototype.searchTweetsOccurences = function(searchString) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   204
  var ret = { };
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   205
  var keywords = searchString.split(/\s+/);
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   206
  
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   207
  for (var i in keywords) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   208
    var keyword = keywords[i];
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   209
    
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   210
    // search this keyword in descriptions and title
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   211
    var found_annotations = []
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   212
    found_annotations = found_annotations.concat(this.searchTweets(keyword, "", ""));
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   213
    found_annotations = found_annotations.concat(this.searchTweets("", keyword, ""));
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   214
    
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   215
    for (var j in found_annotations) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   216
      var current_annotation = found_annotations[j];
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   217
      
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   218
      if (!ret.hasOwnProperty(current_annotation.id)) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   219
        ret[current_annotation.id] = 1;
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   220
      } else {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   221
        ret[current_annotation.id] += 1;
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   222
      }
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   223
      
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   224
    }
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   225
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   226
  };
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   227
  
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   228
  return ret;
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   229
};
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   230
528
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
   231
/** 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
   232
   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
   233
   currentTime is in seconds.
528
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
   234
   
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
   235
   @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
   236
   @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
   237
 */
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   238
595
29d86e6c61a6 finished going through the widgets to add stricter line checking.
hamidouk
parents: 591
diff changeset
   239
IriSP.JSONSerializer.prototype.currentAnnotations = function(currentTime, id) {
317
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   240
  var view;
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   241
  var currentTimeMs = 1000 * currentTime;
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   242
595
29d86e6c61a6 finished going through the widgets to add stricter line checking.
hamidouk
parents: 591
diff changeset
   243
  if (typeof(id) === "undefined") {
29d86e6c61a6 finished going through the widgets to add stricter line checking.
hamidouk
parents: 591
diff changeset
   244
      var legal_ids = this.getNonTweetIds();
601
02b857c0c9f1 slight change
hamidouk
parents: 595
diff changeset
   245
  } else {
595
29d86e6c61a6 finished going through the widgets to add stricter line checking.
hamidouk
parents: 591
diff changeset
   246
      legal_ids = [id];
29d86e6c61a6 finished going through the widgets to add stricter line checking.
hamidouk
parents: 591
diff changeset
   247
  }
536
b7e545e35287 fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents: 528
diff changeset
   248
  
317
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   249
  var ret_array = [];
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   250
  
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   251
  var i;
536
b7e545e35287 fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents: 528
diff changeset
   252
  
317
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   253
  for (i in this._data.annotations) {
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   254
    var annotation = this._data.annotations[i];
320
b693ba1a83be fixed bug in search method
hamidouk
parents: 317
diff changeset
   255
    
590
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   256
    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
   257
        annotation.begin <= currentTimeMs &&
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   258
        annotation.end >= currentTimeMs)
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   259
          ret_array.push(annotation);
317
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   260
  }
590
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   261
 
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   262
  if (ret_array == []) {
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   263
    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
   264
  }
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   265
  
317
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   266
  return ret_array;
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   267
};
513
4589b90fe1ad added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents: 395
diff changeset
   268
613
c2726c5c6477 added a method to get the current chapitre.
hamidouk
parents: 610
diff changeset
   269
/** return the current chapitre
c2726c5c6477 added a method to get the current chapitre.
hamidouk
parents: 610
diff changeset
   270
    @param currentTime the current time, in seconds.
c2726c5c6477 added a method to get the current chapitre.
hamidouk
parents: 610
diff changeset
   271
*/
c2726c5c6477 added a method to get the current chapitre.
hamidouk
parents: 610
diff changeset
   272
IriSP.JSONSerializer.prototype.currentChapitre = function(currentTime) {
c2726c5c6477 added a method to get the current chapitre.
hamidouk
parents: 610
diff changeset
   273
  return this.currentAnnotations(currentTime, this.getChapitrage())[0];
c2726c5c6477 added a method to get the current chapitre.
hamidouk
parents: 610
diff changeset
   274
};
513
4589b90fe1ad added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents: 395
diff changeset
   275
528
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
   276
/** 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
   277
IriSP.JSONSerializer.prototype.getTweetIds = function() {
636
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   278
  if (IriSP.null_or_undefined(this._data.lists) || IriSP.null_or_undefined(this._data.lists) ||
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   279
      IriSP.null_or_undefined(this._data.views) || IriSP.null_or_undefined(this._data.views[0]))
513
4589b90fe1ad added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents: 395
diff changeset
   280
    return [];
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
  
636
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   283
  /* Get the displayable types
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   284
     We've got to jump through a few hoops because the json sometimes defines
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   285
     fields with underscores and sometimes with dashes
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   286
  */
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   287
  var annotation_types = this._data.views[0]["annotation_types"];
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   288
  if (IriSP.null_or_undefined(annotation_types)) {
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   289
    annotation_types = this._data.views[0]["annotation-types"];
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   290
    if (IriSP.null_or_undefined(annotation_types)) {
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   291
      console.log("neither view.annotation_types nor view.annotation-types are defined");      
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   292
      return;
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   293
    }
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   294
  }
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   295
639
f18233d3a7fa fixed copypasta bug.
hamidouk
parents: 636
diff changeset
   296
  var available_types = this._data["annotation_types"];    
636
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   297
  if (IriSP.null_or_undefined(available_types)) {
639
f18233d3a7fa fixed copypasta bug.
hamidouk
parents: 636
diff changeset
   298
    available_types = this._data["annotation-types"];
636
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   299
    if (IriSP.null_or_undefined(available_types)) {
639
f18233d3a7fa fixed copypasta bug.
hamidouk
parents: 636
diff changeset
   300
      console.log("neither annotation_types nor annotation-types are defined");      
636
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   301
      return;
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   302
    }
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   303
  }
566
098929cd2d62 made the polemicwidget adjust its size automatically and fixed a couple edgecases.
hamidouk
parents: 536
diff changeset
   304
  
636
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   305
  var potential_types = [];
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   306
  
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   307
  // Get the list of types which contain "Tw" in their content
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   308
  for (var i = 0; i < available_types.length; i++) {
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   309
    if (/Tw/i.test(available_types[i]["dc:title"])) {
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   310
      potential_types.push(available_types[i].id);
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   311
    }
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   312
  }
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   313
  
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   314
  // Get the intersection of both.
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   315
  var tweetsId = IriSP.underscore.intersection(annotation_types, potential_types);
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   316
  
513
4589b90fe1ad added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents: 395
diff changeset
   317
  return tweetsId;
4589b90fe1ad added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents: 395
diff changeset
   318
};
4589b90fe1ad added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents: 395
diff changeset
   319
528
a5894f09825a added docs.
hamidouk
parents: 513
diff changeset
   320
/** 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
   321
IriSP.JSONSerializer.prototype.getNonTweetIds = function() {
636
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   322
  if (IriSP.null_or_undefined(this._data.lists) || IriSP.null_or_undefined(this._data.lists) ||
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   323
      IriSP.null_or_undefined(this._data.views) || IriSP.null_or_undefined(this._data.views[0]))
513
4589b90fe1ad added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents: 395
diff changeset
   324
    return [];
636
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   325
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   326
  /* Get the displayable types
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   327
     We've got to jump through a few hoops because the json sometimes defines
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   328
     fields with underscores and sometimes with dashes
536
b7e545e35287 fixed an elusive "id-ref" bug in currentAnnotation
hamidouk
parents: 528
diff changeset
   329
  */
636
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   330
  var annotation_types = this._data.views[0]["annotation_types"];
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   331
  if (IriSP.null_or_undefined(annotation_types)) {
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   332
    annotation_types = this._data.views[0]["annotation-types"];
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   333
    if (IriSP.null_or_undefined(annotation_types)) {
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   334
      console.log("neither view.annotation_types nor view.annotation-types are defined");      
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   335
      return;
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   336
    }
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   337
  }
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   338
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   339
  var available_types = this._data["annotation_types"];    
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   340
  if (IriSP.null_or_undefined(available_types)) {
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   341
    available_types = this._data["annotation-types"];
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   342
    if (IriSP.null_or_undefined(available_types)) {
639
f18233d3a7fa fixed copypasta bug.
hamidouk
parents: 636
diff changeset
   343
      console.log("neither annotation_types nor annotation-types are defined");      
636
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   344
      return;
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   345
    }
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   346
  }
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   347
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   348
  var potential_types = [];
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   349
  
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   350
  // Get the list of types which do not contain "Tw" in their content
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   351
  for (var i = 0; i < available_types.length; i++) {
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   352
    if (!(/Tw/i.test(available_types[i]["dc:title"]))) {
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   353
      potential_types.push(available_types[i].id);
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   354
    }
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   355
  }
639
f18233d3a7fa fixed copypasta bug.
hamidouk
parents: 636
diff changeset
   356
636
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   357
  // Get the intersection of both.
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   358
  var nonTweetsId = IriSP.underscore.intersection(annotation_types, potential_types);
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   359
  
b1629eed3e11 rewrote the function to select annotations to make them clearer.
hamidouk
parents: 633
diff changeset
   360
  return nonTweetsId;
513
4589b90fe1ad added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents: 395
diff changeset
   361
  
4589b90fe1ad added a couple functions to distinguish between tweet ids and regular lines.
hamidouk
parents: 395
diff changeset
   362
};
590
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   363
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   364
/** 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
   365
    @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
   366
*/
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   367
IriSP.JSONSerializer.prototype.getId = function(name) {
693
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   368
  if (IriSP.null_or_undefined(this._data["annotation-types"]))
590
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   369
    return;
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   370
628
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   371
  name = name.toUpperCase();
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   372
  var e;  
590
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   373
  e = IriSP.underscore.find(this._data["annotation-types"], 
783
591b117c19ca be more picky about what we get.
hamidouk
parents: 693
diff changeset
   374
                                  function(entry) { 
591b117c19ca be more picky about what we get.
hamidouk
parents: 693
diff changeset
   375
                                    if (IriSP.null_or_undefined(entry["dc:title"]))
591b117c19ca be more picky about what we get.
hamidouk
parents: 693
diff changeset
   376
                                      return false;
591b117c19ca be more picky about what we get.
hamidouk
parents: 693
diff changeset
   377
                                    
591b117c19ca be more picky about what we get.
hamidouk
parents: 693
diff changeset
   378
                                    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
   379
  
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   380
  if (typeof(e) === "undefined")
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   381
    return;
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   382
    
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   383
  var id = e.id;
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   384
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   385
  return id;
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   386
};
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   387
693
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   388
/** return the list of id's of the ligne de temps which contains name
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   389
    @param name of the ligne de temps
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   390
*/
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   391
IriSP.JSONSerializer.prototype.getIds = function(name) {
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   392
  if (IriSP.null_or_undefined(this._data["annotation-types"]))
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   393
    return;
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   394
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   395
  name = name.toUpperCase();
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   396
  var e = [];  
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   397
  e = IriSP.underscore.filter(this._data["annotation-types"], 
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   398
                                  function(entry) { return (entry["dc:title"].toUpperCase().indexOf(name) !== -1) });
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   399
  return IriSP.underscore.pluck(e, "id");  
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   400
};
6328901da7bf added a method to get a list of lignes with a specified name.
hamidouk
parents: 666
diff changeset
   401
590
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   402
/** 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
   403
IriSP.JSONSerializer.prototype.getChapitrage = function() {
633
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   404
  var val = this.getId("Chapitrage");
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   405
  if (typeof(val) === "undefined")
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   406
    val = this.getId("Chapter");   
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   407
  if (typeof(val) === "undefined")
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   408
    val = this.getId("Chapit");
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   409
  if (typeof(val) === "undefined")
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   410
    val = this.getId("Chap");
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   411
    
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   412
  return val;
590
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   413
};
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   414
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   415
/** 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
   416
IriSP.JSONSerializer.prototype.getTweets = function() {
628
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   417
  var val = this.getId("Tweets");
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   418
  if (typeof(val) === "undefined")
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   419
    val = this.getId("Tweet");
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   420
  if (typeof(val) === "undefined")
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   421
    val = this.getId("Twitter");
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   422
  if (typeof(val) === "undefined")
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   423
    val = this.getId("twit");
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   424
  if (typeof(val) === "undefined")
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   425
    val = this.getId("Polemic");
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   426
  
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   427
  return val;
590
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   428
};
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   429
495ea8d73bed added a couple function to return the ids of some lignes de temps.
hamidouk
parents: 566
diff changeset
   430
/** 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
   431
IriSP.JSONSerializer.prototype.getContributions = function() {
633
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   432
  var val = this.getId("Contribution");
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   433
  if (typeof(val) === "undefined")
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   434
    val = this.getId("Particip");   
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   435
  if (typeof(val) === "undefined")
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   436
    val = this.getId("Contr");
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   437
  if (typeof(val) === "undefined")
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   438
    val = this.getId("Publ");
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   439
    
00a59060d78d more matching for segments types.
hamidouk
parents: 628
diff changeset
   440
  return val;
628
55282f5ef477 search for ids in a case-insensitive way.
hamidouk
parents: 613
diff changeset
   441
};