<commit_before>var f = require( 'util' ).format
  , path = require( 'path' )
  , resolve = path.resolve
  , dirname = path.dirname
;

/**
 * Provides the simplest posible API (a function)
 * to perform requires relative to module without
 * knowing dirname when calling the API.
 *
 * @function loader( {string} root )
 *   @returns function load
 *
 * @function load( {string} path )
 *   @param path: the path to be required, relative to `root`
 *   @returns the required module
 */

module.exports = function loader( module ) {
  if( !module || !module.require || !module.filename ){
    throw TypeError( "module given is not a valid module");
  }
  return function load( path ) {
    if( !path ){
      throw Error( f( "Cannot load '%s'", path ) )
    }
    try {
      return module.require( path );
    } catch(err){
      parseError( err );
    }
   // try {
      return require( resolve( dirname(module.filename) , path ) );
    /*} catch(err) {
      parseError( err );
      throw err;
    }*/
  };
}

var notFound = /cannot find module/i

function parseError( err ){
  if( !notFound.test( err.message ) ){
    throw err;
    //throw Error( f( "Cannot load '%s' because %s", path, err.message ) );
  }
}<commit_msg>add 'iai-' auto prefix as the last try on load function<commit_after>var f = require( 'util' ).format
  , npath = require( 'path' )
  , resolve = npath.resolve
  , dirname = npath.dirname
  , basename = npath.basename
;

/**
 * Provides the simplest posible API (a function)
 * to perform requires relative to module without
 * knowing dirname when calling the API.
 *
 * @function loader( {string} root )
 *   @returns function load
 *
 * @function load( {string} path )
 *   @param path: the path to be required, relative to `root`
 *   @returns the required module
 */

module.exports = function loader( module ) {
  if( !module || !module.require || !module.filename ){
    throw TypeError( "module given is not a valid module");
  }
  return function load( path ) {
    if( !path ){
      throw Error( "Cannot load '"+path+"'" )
    }
    try {
      return module.require( path );
    } catch(err){
      parseError( err );
    }
    try {
      return require( resolve( dirname(module.filename), path ) );
    } catch(err) {
      parseError( err );
    }
    if( !~path.indexOf( "/" ) ){
      try {
        return require( "iai-"+path )
      } catch(err) {
        parseError( err );
      }
    }
    throw Error( "Cannot load '"+ path +"' because cannot find module" );
  }
}

var notFound = /cannot find module/i;

function parseError( err ){
  if( !notFound.test( err.message ) ){
    //throw err;
    throw Error( "Error while loading: "+err.message );
  }
}
{'fraction_non_alphanumeric': 0.1389403482771397, 'fraction_numerical': 0.0, 'mean_word_length': 2.6885245901639343, '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': '1927818', 'n_tokens_mistral': 843, 'n_tokens_neox': 836, 'n_words': 285}