<commit_before><?php

/**
 * CinIsis main class.
 */
class CinIsis {
  /**
   * @var $db
   *   Database resource.
   */  
  var $db;

  /**
   * @var $implementation
   *   Database implementation.
   */
  var $implementation;

  /**
   * Constructor.
   *
   * @param $config
   *   Alternative config file (defaults to 'config/config.yaml').
   *
   * @todo
   *   Config check.
   */   
  function __construct($config = NULL) {
    if ($config == NULL) {
      $config = 'config/config.yaml';
    }

    // Load configuration.
    $config = Spyc::YAMLLoad($config);

    // Load database schema.
    $schema = Spyc::YAMLLoad('schemas/'. $config['database'] .'.yaml');

    // Setup database connection.
    $this->implementation = $config['implementation'] .'Db';
    $this->db             = new $this->implementation($schema);
  }
}<commit_msg>Config file loading<commit_after><?php

/**
 * CinIsis main class.
 */
class CinIsis {
  /**
   * @var $db
   *   Database resource.
   */  
  var $db;

  /**
   * @var $implementation
   *   Database implementation.
   */
  var $implementation;

  /**
   * Constructor.
   *
   * @param $file
   *   Optional parameter to set alternative config file.
   */   
  function __construct($file = 'config/config.yaml') {
    try {
      // Load main configuration.
      $config = $this->config($file);

      // Load database schema.
      $schema = $this->config('schemas/'. $config['database'] .'.yaml');
    } catch (Exception $e) {
      echo '[cinisis] caught exception: ',  $e->getMessage(), "\n";
      return FALSE;
    }

    // Setup database connection.
    $this->implementation = $config['implementation'] .'Db';
    $this->db             = new $this->implementation($schema);
  }

  /**
   * Config file load.
   *
   * @param $file
   *   Config file.
   *
   * @return
   *   Array with configuration.
   */
  function config($file) {
    if (!file_exists($file)) {
      throw new Exception('Config '. $file .' not found.');
    }

    // Load configuration.
    return Spyc::YAMLLoad($file);
  }
}
{'fraction_non_alphanumeric': 0.16601941747572815, 'fraction_numerical': 0.0, 'mean_word_length': 2.2052877138413685, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '6771542', 'n_tokens_mistral': 668, 'n_tokens_neox': 647, 'n_words': 149}