<commit_before><commit_msg>+datasourcemanager<commit_after>var jsonfn = require('jsonfn');

/**
 * @brief makeDataSourceManager builds a DataSourceManager object.
 * @param JSONData the JSON string holding the DataSource objects to be parsed.
 */
function makeDataSourceManager(JSONData) {

  var dataSourcesDict = {};

  var manager = {
    /**
     * @brief dataSources return the dataSources object. Each datasource is
     * stored as value, and has for key its name.
     */
    dataSources: function() {
      return dataSourcesDict;
    },

    /**
     * @brief addDataSource adds a data source to the managed sources.
     * @param ds the DataSourceObject to add. If the data source was already
     * managed, it will be overwritten.
     * TODO could add a param to choose between overwriting or fail when trying
     * to add a source whose name is already present.
     */
    addDataSource: function(ds) {
      dataSourcesDict[ds.name] = ds;
    },

    /**
     * @brief removeDataSource removes a data source from the managed list.
     * @param dsIndex the index of the DataSource to remove in the managed list.
     * @return true if the removal was successful, false otherwise.
     * The removal can fail if the index is out of bounds wrt the data sources
     * list.
     */
    removeDataSource: function(dsIndex) {
      if (dsIndex in dataSourcesArray) {
        dataSourcesArray.splice(dsIndex, 1);
        return true;
      }
      return false;
    }

    /**
     * @brief exportToJSON exports the current managed list to a JSON string
     * @return the JSON string encoding the data sources.
     */
    exportToJSON: function() {
      return jsonfn.stringify(dataSourcesArray);
    }
  };

  return manager;
}

module.exports.makeDataSourceManager = makeDataSourceManager;
{'fraction_non_alphanumeric': 0.0774764803541782, 'fraction_numerical': 0.0005534034311012728, 'mean_word_length': 2.830508474576271, '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': '7445690', 'n_tokens_mistral': 480, 'n_tokens_neox': 468, 'n_words': 189}