<commit_before>/** Model object to encapsulate the current user preferences */

modulejs.define( "preferences", [
  "lib/lodash",
  "lib/jquery"
], function(
  _,
  $
) {
  "use strict";

  var Preferences = function() {
    this.initialize();
  };

  _.extend( Preferences.prototype, {
    initialize: function() {
      this._prefs = {};
      var prefs = this._prefs;

      var selections = $("#preferences").serializeArray();
      _.each( selections, function( selection ) {
        var name = selection.name;

        if (name.match( /\[\]/ )) {
          var simpleName = name.replace( "[]", "" );

          if (!prefs[simpleName]) {
            prefs[simpleName] = [];
          }
          prefs[simpleName].push( selection.value );
        }
        else {
          prefs[name] = selection.value;
        }
      } );
    },

    region: function() {
      return this._prefs.region;
    },

    from: function() {
      return this._prefs.from;
    },

    to: function() {
      return this._prefs.to;
    },

    aspects: function() {
      var inds = this._prefs.ai || [];
      var cats = this._prefs.ac || [];
      var pairs = cartesianProductOf( inds, cats );

      return _.map( pairs, function( pair ) {
        return pair[0] + _.upperFirst( pair[1] );
      } );
    }
  } );
<commit_msg>Extend preferences to return the indicator and category parts of the selected aspects separately. Also added basic filtering, so that only aspects of interest can be selected.<commit_after>/** Model object to encapsulate the current user preferences */

modulejs.define( "preferences", [
  "lib/lodash",
  "lib/jquery"
], function(
  _,
  $
) {
  "use strict";

  var Preferences = function() {
    this.initialize();
  };

  _.extend( Preferences.prototype, {
    initialize: function() {
      this._prefs = {};
      var prefs = this._prefs;

      var selections = $("#preferences").serializeArray();
      _.each( selections, function( selection ) {
        var name = selection.name;

        if (name.match( /\[\]/ )) {
          var simpleName = name.replace( "[]", "" );

          if (!prefs[simpleName]) {
            prefs[simpleName] = [];
          }
          prefs[simpleName].push( selection.value );
        }
        else {
          prefs[name] = selection.value;
        }
      } );
    },

    region: function() {
      return this._prefs.region;
    },

    from: function() {
      return this._prefs.from;
    },

    to: function() {
      return this._prefs.to;
    },

    /** @return The currently selected indicators, optionally limited to just a given selection */
    indicators: function( only ) {
      var ai = this._prefs.ai || [];
      if (only && only.indicators) {
        ai = _.intersection( only.indicators, ai );
      }

      return ai;
    },

    /** @return The currently selected categories, optionally limited to just a given selection */
    categories: function( only ) {
      var ac = this._prefs.ac || [];
      if (only && only.categories) {
        ac = _.intersection( only.categories, ac );
      }

      return ac;
    },

    /** @return The selected aspects, optionally limited to only certain indicators or categories */
    aspects: function( only ) {
      var pairs = cartesianProductOf( this.indicators( only ), this.categories( only ) );

      return _.map( pairs, function( pair ) {
        return pair[0] + _.upperFirst( pair[1] );
      } );
    }
  } );

{'fraction_non_alphanumeric': 0.14223512336719885, 'fraction_numerical': 0.0011611030478955006, 'mean_word_length': 2.13557779799818, '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': '2121708', 'n_tokens_mistral': 1028, 'n_tokens_neox': 994, 'n_words': 259}