<commit_before>(function _aChainer_s_() {

'use strict';

if( typeof module !== 'undefined' )
{

  if( typeof _global_ === 'undefined' || !_global_.wBase )
  {
    let toolsPath = '../../../dwtools/Base.s';
    let toolsExternal = 0;
    try
    {
      toolsPath = require.resolve( toolsPath );
    }
    catch( err )
    {
      toolsExternal = 1;
      require( 'wTools' );
    }
    if( !toolsExternal )
    require( toolsPath );
  }

  let _ = _global_.wTools;

  _.include( 'wProto' );

}

//

/**
 * @class wChainer
 */

var _global = _global_;
var _ = _global_.wTools;
var Parent = null;
var Self = function wChainer( o )
{
  if( !( this instanceof Self ) )
  if( o instanceof Self )
  return o;
  else
  return new( _.routineJoin( Self, Self, arguments ) );
  return Self.prototype.init.apply( this,arguments );
}

Self.nameShort = 'Chainer';

// --
// inter
// --

function init( o )
{
  var self = this;

  _.instanceInit( self );

  Object.preventExtensions( self );

  if( o )
  self.copy( o );

  return self;
}

//

function finit()
{
  var self = this;
  debugger;xxx

  self.unchainEverything();

  _.Copyable.finit.call( self );
}

//

function _chain( o )
{
  let self = this;
  let result = 0;

  o = _.routineOptions( self._chain, arguments );
  _.assert( arguments.length === 1 );
  _.assert( _.printerLike( o.outputPrinter ) || _._arrayLike( o.outputPrinter ) );
  _.assert( _.printerLike( o.inputPrinter ) || _._arrayLike( o.inputPrinter ) );
  _.assert( _.arrayHas( _.PrinterChainingMixin.Combining, o.outputCombining ), () => 'unknown outputCombining mode ' + _.strQuote( o.outputCombining ) );
  _.assert( _.arrayHas( _.PrinterChainingMixin.Combining, o.inputCombining ), () => 'unknown inputCombining mode ' + _.strQuote( o.inputCombining ) );

  /* */

  if( self.outputs.length )
  {
    if( o.outputCombining === 'supplement' )
    {
      debugger; xxx
      result = 0;
      return result;
    }
    else if( o.outputCombining === 'rewrite' )
    {
      debugger;
      self.outputUnchain();
    }
  }

  /* */

  if( self.inputs.length )
  {
    if( o.inputCombining === 'supplement' )
    {
      debugger; xxx
      result = 0;
      return result;
    }
    else if( o.inputCombining === 'rewrite' )
    {
      self.inputUnchain();
    }
  }

  /* */

  if( _._arrayLike( o.outputPrinter ) )
  {

    o.outputPrinter.forEach( ( outputPrinter ) =>
    {
      debugger; xxx
      var o2 = _.mapExtend( null, o );
      o2.outputPrinter = outputPrinter;
      result += self._chain( o2 );
    });

    return result;
  }

  /* */

  if( _._arrayLike( o.inputPrinter ) )
  {

    o.inputPrinter.forEach( ( inputPrinter ) =>
    {
      debugger; xxx
      var o2 = _.mapExtend( null, o );
      o2.inputPrinter = inputPrinter;
      result += self._chain( o2 );
    });

    return result;
  }

  /* */

  _.assert( o.outputPrinter, 'expects {-o.outputPrinter-}' );
  _.assert( o.inputPrinter !== o.outputPrinter, 'Output to itself is not correct chaining' );

  let cd = self._chainDescriptorMake( o );

  // if( !cd.combining )
  // _.assert( self.outputs.length === 0, 'if combining is off then multiple outputs are not allowed' );

  let inputChainer = cd.inputPrinter[ chainerSymbol ] || self._chainerMakeFor( cd.inputPrinter );
  let outputChainer = cd.outputPrinter[ chainerSymbol ] || self._chainerMakeFor( cd.outputPrinter );

  /* output check */

  if( Config.debug )
  if( inputChainer.hasOutputClose( o.outputPrinter ) )
  _.assert( 0, () => _.strConcat([ 'inputPrinter', _.toStrShort( o.inputPrinter ), 'already has outputPrinter', _.toStrShort( o.outputPrinter ), 'in outputs' ] ) );

  /* input check */

  if( Config.debug )
  if( inputChainer.hasInputClose( o.outputPrinter ) )
  _.assert( 0, () => _.strConcat([ 'Close loop, inputPrinter', _.toStrShort( o.inputPrinter ), 'to outputPrinter', _.toStrShort( o.outputPrinter ) ]) );

  /*
    no need to check inputs if chaining is originalOutput
  */

  if( Config.debug )
  if( !o.originalOutput )
  if( inputChainer.hasInputDeep( o.outputPrinter ) )
  _.assert( 0, () => _.strConcat([ 'Deep loop, inputPrinter', _.toStrShort( o.inputPrinter ), 'to outputPrinter', _.toStrShort( o.outputPrinter ) ]) );<commit_msg>Chainer._chain : adjusted close loop check<commit_after>(function _aChainer_s_() {

'use strict';

if( typeof module !== 'undefined' )
{

  if( typeof _global_ === 'undefined' || !_global_.wBase )
  {
    let toolsPath = '../../../dwtools/Base.s';
    let toolsExternal = 0;
    try
    {
      toolsPath = require.resolve( toolsPath );
    }
    catch( err )
    {
      toolsExternal = 1;
      require( 'wTools' );
    }
    if( !toolsExternal )
    require( toolsPath );
  }

  let _ = _global_.wTools;

  _.include( 'wProto' );

}

//

/**
 * @class wChainer
 */

var _global = _global_;
var _ = _global_.wTools;
var Parent = null;
var Self = function wChainer( o )
{
  if( !( this instanceof Self ) )
  if( o instanceof Self )
  return o;
  else
  return new( _.routineJoin( Self, Self, arguments ) );
  return Self.prototype.init.apply( this,arguments );
}

Self.nameShort = 'Chainer';

// --
// inter
// --

function init( o )
{
  var self = this;

  _.instanceInit( self );

  Object.preventExtensions( self );

  if( o )
  self.copy( o );

  return self;
}

//

function finit()
{
  var self = this;
  debugger;xxx

  self.unchainEverything();

  _.Copyable.finit.call( self );
}

//

function _chain( o )
{
  let self = this;
  let result = 0;

  o = _.routineOptions( self._chain, arguments );
  _.assert( arguments.length === 1 );
  _.assert( _.printerLike( o.outputPrinter ) || _._arrayLike( o.outputPrinter ) );
  _.assert( _.printerLike( o.inputPrinter ) || _._arrayLike( o.inputPrinter ) );
  _.assert( _.arrayHas( _.PrinterChainingMixin.Combining, o.outputCombining ), () => 'unknown outputCombining mode ' + _.strQuote( o.outputCombining ) );
  _.assert( _.arrayHas( _.PrinterChainingMixin.Combining, o.inputCombining ), () => 'unknown inputCombining mode ' + _.strQuote( o.inputCombining ) );

  /* */

  if( self.outputs.length )
  {
    if( o.outputCombining === 'supplement' )
    {
      debugger; xxx
      result = 0;
      return result;
    }
    else if( o.outputCombining === 'rewrite' )
    {
      debugger;
      self.outputUnchain();
    }
  }

  /* */

  if( self.inputs.length )
  {
    if( o.inputCombining === 'supplement' )
    {
      debugger; xxx
      result = 0;
      return result;
    }
    else if( o.inputCombining === 'rewrite' )
    {
      self.inputUnchain();
    }
  }

  /* */

  if( _._arrayLike( o.outputPrinter ) )
  {

    o.outputPrinter.forEach( ( outputPrinter ) =>
    {
      debugger; xxx
      var o2 = _.mapExtend( null, o );
      o2.outputPrinter = outputPrinter;
      result += self._chain( o2 );
    });

    return result;
  }

  /* */

  if( _._arrayLike( o.inputPrinter ) )
  {

    o.inputPrinter.forEach( ( inputPrinter ) =>
    {
      debugger; xxx
      var o2 = _.mapExtend( null, o );
      o2.inputPrinter = inputPrinter;
      result += self._chain( o2 );
    });

    return result;
  }

  /* */

  _.assert( o.outputPrinter, 'expects {-o.outputPrinter-}' );
  _.assert( o.inputPrinter !== o.outputPrinter, 'Output to itself is not correct chaining' );

  let cd = self._chainDescriptorMake( o );

  // if( !cd.combining )
  // _.assert( self.outputs.length === 0, 'if combining is off then multiple outputs are not allowed' );

  let inputChainer = cd.inputPrinter[ chainerSymbol ] || self._chainerMakeFor( cd.inputPrinter );
  let outputChainer = cd.outputPrinter[ chainerSymbol ] || self._chainerMakeFor( cd.outputPrinter );

  /* output check */

  if( Config.debug )
  if( inputChainer.hasOutputClose( o.outputPrinter ) )
  _.assert( 0, () => _.strConcat([ 'inputPrinter', _.toStrShort( o.inputPrinter ), 'already has outputPrinter', _.toStrShort( o.outputPrinter ), 'in outputs' ] ) );

  /* input check */

  if( Config.debug )
  if( !o.originalOutput )
  if( inputChainer.hasInputClose( o.outputPrinter ) )
  _.assert( 0, () => _.strConcat([ 'Close loop, inputPrinter', _.toStrShort( o.inputPrinter ), 'to outputPrinter', _.toStrShort( o.outputPrinter ) ]) );

  /*
    no need to check inputs if chaining is originalOutput
  */

  if( Config.debug )
  if( !o.originalOutput )
  if( inputChainer.hasInputDeep( o.outputPrinter ) )
  _.assert( 0, () => _.strConcat([ 'Deep loop, inputPrinter', _.toStrShort( o.inputPrinter ), 'to outputPrinter', _.toStrShort( o.outputPrinter ) ]) );
{'fraction_non_alphanumeric': 0.15306723183798424, 'fraction_numerical': 0.003767808783704227, 'mean_word_length': 2.7468019408910456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3387159', 'n_tokens_mistral': 3007, 'n_tokens_neox': 2906, 'n_words': 660}