<commit_before>// # Recline Backbone Models
this.recline = this.recline || {};
this.recline.Model = this.recline.Model || {};

(function($, my) {
  // ## A Dataset model
  //
  // Other than standard list of Backbone methods it has two important attributes:
  //
  // * currentDocuments: a DocumentList containing the Documents we have currently loaded for viewing (you update currentDocuments by calling getRows)
  // * docCount: total number of documents in this dataset (obtained on a fetch for this Dataset)
  my.Dataset = Backbone.Model.extend({
    __type__: 'Dataset',
    initialize: function(model, backend) {
      this.backend = backend;
      if (backend && backend.constructor == String) {
        this.backend = my.backends[backend];
      }
      this.currentDocuments = new my.DocumentList();
      this.docCount = null;
      this.defaultQuery = {
        size: 100
        , offset: 0
      };
      // this.queryState = {};
    },

    // ### getDocuments
    //
    // AJAX method with promise API to get rows (documents) from the backend.
    //
    // Resulting DocumentList are used to reset this.currentDocuments and are
    // also returned.
    //
    // :param numRows: passed onto backend getDocuments.
    // :param start: passed onto backend getDocuments.
    //
    // this does not fit very well with Backbone setup. Backbone really expects you to know the ids of objects your are fetching (which you do in classic RESTful ajax-y world). But this paradigm does not fill well with data set up we have here.
    // This also illustrates the limitations of separating the Dataset and the Backend
    query: function(queryObj) {
      var self = this;
      this.queryState = queryObj || this.defaultQuery;
      this.queryState = _.extend({size: 100, offset: 0}, this.queryState);
      var dfd = $.Deferred();
      this.backend.query(this, this.queryState).done(function(rows) {
        var docs = _.map(rows, function(row) {
          var _doc = new my.Document(row);
          _doc.backend = self.backend;
          _doc.dataset = self;
          return _doc;
        });
        self.currentDocuments.reset(docs);
        dfd.resolve(self.currentDocuments);
      })
      .fail(function(arguments) {
        dfd.reject(arguments);
      });
      return dfd.promise();
    },

    toTemplateJSON: function() {
      var data = this.toJSON();
      data.docCount = this.docCount;
      return data;
    }
  });

  // ## A Document (aka Row)
  // 
  // A single entry or row in the dataset
  my.Document = Backbone.Model.extend({
    __type__: 'Document'
  });

  // ## A Backbone collection of Documents
  my.DocumentList = Backbone.Collection.extend({
    __type__: 'DocumentList',
    model: my.Document
  });

  // ## Backend registry
  //
  // Backends will register themselves by id into this registry
  my.backends = {};

}(jQuery, this.recline.Model));

<commit_msg>[whitespace][xs]: whitespace.<commit_after>// # Recline Backbone Models
this.recline = this.recline || {};
this.recline.Model = this.recline.Model || {};

(function($, my) {

// ## A Dataset model
//
// Other than standard list of Backbone methods it has two important attributes:
//
// * currentDocuments: a DocumentList containing the Documents we have currently loaded for viewing (you update currentDocuments by calling getRows)
// * docCount: total number of documents in this dataset (obtained on a fetch for this Dataset)
my.Dataset = Backbone.Model.extend({
  __type__: 'Dataset',
  initialize: function(model, backend) {
    this.backend = backend;
    if (backend && backend.constructor == String) {
      this.backend = my.backends[backend];
    }
    this.currentDocuments = new my.DocumentList();
    this.docCount = null;
    this.defaultQuery = {
      size: 100
      , offset: 0
    };
    // this.queryState = {};
  },

  // ### getDocuments
  //
  // AJAX method with promise API to get rows (documents) from the backend.
  //
  // Resulting DocumentList are used to reset this.currentDocuments and are
  // also returned.
  //
  // :param numRows: passed onto backend getDocuments.
  // :param start: passed onto backend getDocuments.
  //
  // this does not fit very well with Backbone setup. Backbone really expects you to know the ids of objects your are fetching (which you do in classic RESTful ajax-y world). But this paradigm does not fill well with data set up we have here.
  // This also illustrates the limitations of separating the Dataset and the Backend
  query: function(queryObj) {
    var self = this;
    this.queryState = queryObj || this.defaultQuery;
    this.queryState = _.extend({size: 100, offset: 0}, this.queryState);
    var dfd = $.Deferred();
    this.backend.query(this, this.queryState).done(function(rows) {
      var docs = _.map(rows, function(row) {
        var _doc = new my.Document(row);
        _doc.backend = self.backend;
        _doc.dataset = self;
        return _doc;
      });
      self.currentDocuments.reset(docs);
      dfd.resolve(self.currentDocuments);
    })
    .fail(function(arguments) {
      dfd.reject(arguments);
    });
    return dfd.promise();
  },

  toTemplateJSON: function() {
    var data = this.toJSON();
    data.docCount = this.docCount;
    return data;
  }
});

// ## A Document (aka Row)
// 
// A single entry or row in the dataset
my.Document = Backbone.Model.extend({
  __type__: 'Document'
});

// ## A Backbone collection of Documents
my.DocumentList = Backbone.Collection.extend({
  __type__: 'DocumentList',
  model: my.Document
});

// ## Backend registry
//
// Backends will register themselves by id into this registry
my.backends = {};

}(jQuery, this.recline.Model));


{'fraction_non_alphanumeric': 0.11754355094140419, 'fraction_numerical': 0.0028154143938060885, 'mean_word_length': 2.759259259259259, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7005029', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1613, 'n_words': 531}