<commit_before>import Backbone from 'backbone';
import Properties from './Properties';

export default Backbone.Model.extend({
  defaults: {
    index: '',
    value: '',
    values: {},
    active: false,
    preview: false,
    properties: []
  },

  initialize() {
    const properties = this.get('properties');
    var value = this.get('value');
    this.set(
      'properties',
      properties instanceof Properties ? properties : new Properties(properties)
    );
    this.get('properties').forEach(item => {
      const { collection } = this;
      item.parent = collection && collection.property;
    });

    // If there is no value I'll try to get it from values
    // I need value setted to make preview working
    if (!value) {
      var val = '';
      var values = this.get('values');

      for (var prop in values) {
        val += ' ' + values[prop];
      }

      this.set('value', val.trim());
    }
  },

  /**
   * Get property at some index
   * @param  {Number} index
   * @return {Object}
   */
  getPropertyAt(index) {
    return this.get('properties').at(index);
  },

  getPropertyValue(property) {
    let result = '';
    this.get('properties').each(prop => {
      if (prop.get('property') == property) {
        result = prop.getFullValue();
      }
    });
    return result;
  },

  getFullValue() {
    let result = [];
    this.get('properties').each(prop => result.push(prop.getFullValue()));
    return result.join(' ');
  }
});<commit_msg>Trim values in layers<commit_after>import Backbone from 'backbone';
import Properties from './Properties';

export default Backbone.Model.extend({
  defaults: {
    index: '',
    value: '',
    values: {},
    active: false,
    preview: false,
    properties: []
  },

  initialize() {
    const properties = this.get('properties');
    var value = this.get('value');
    this.set(
      'properties',
      properties instanceof Properties ? properties : new Properties(properties)
    );
    this.get('properties').forEach(item => {
      const { collection } = this;
      item.parent = collection && collection.property;
    });

    // If there is no value I'll try to get it from values
    // I need value setted to make preview working
    if (!value) {
      var val = '';
      var values = this.get('values');

      for (var prop in values) {
        val += ' ' + values[prop];
      }

      this.set('value', val.trim());
    }
  },

  /**
   * Get property at some index
   * @param  {Number} index
   * @return {Object}
   */
  getPropertyAt(index) {
    return this.get('properties').at(index);
  },

  getPropertyValue(property) {
    let result = '';
    this.get('properties').each(prop => {
      if (prop.get('property') == property) {
        result = prop.getFullValue();
      }
    });
    return result;
  },

  getFullValue() {
    let result = [];
    this.get('properties').each(prop => result.push(prop.getFullValue()));
    return result.join(' ').trim();
  }
});
{'fraction_non_alphanumeric': 0.1587781134608929, 'fraction_numerical': 0.0, 'mean_word_length': 2.534994068801898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2209681', 'n_tokens_mistral': 885, 'n_tokens_neox': 867, 'n_words': 222}