<commit_before>var _ = require('lodash');
var async = require('async');

function init (env, ctx) {
  console.log('Configuring Alexa...');
  function alexa() {
    return alexa;
  }
  var intentHandlers = {};
  var rollup = {};

  // There is no protection for a previously handled metric - one plugin can overwrite the handler of another plugin.
  alexa.configureIntentHandler = function configureIntentHandler(intent, handler, metrics) {
    if (!intentHandlers[intent]) {
      intentHandlers[intent] = {};
    }
    if (metrics) {
      for (var i = 0, len = metrics.length; i < len; i++) {
        if (!intentHandlers[intent][metrics[i]]) {
          intentHandlers[intent][metrics[i]] = {};
        }
        console.log('Storing handler for intent \'' + intent + '\' for metric \'' + metrics[i] + '\'');
        intentHandlers[intent][metrics[i]].handler = handler;
      }
    } else {
      console.log('Storing handler for intent \'' + intent + '\'');
      intentHandlers[intent].handler = handler;
    }
  };

  // This function retrieves a handler based on the intent name and metric requested.
  alexa.getIntentHandler = function getIntentHandler(intentName, metric) {
    if (metric === null) {
      console.log('Looking for handler for intent \'' + intentName + '\'');
      if (intentName
        && intentHandlers[intentName]
        && intentHandlers[intentName].handler
      ) {
        console.log('Found!');
        return intentHandlers[intentName].handler;
      }
    } else {
      console.log('Looking for handler for intent \'' + intentName + '\' for metric \'' + metric + '\'');
      if (intentName
        && intentHandlers[intentName]
        && intentHandlers[intentName][metric]
        && intentHandlers[intentName][metric].handler
      ) {
        console.log('Found!');
        return intentHandlers[intentName][metric].handler
      }
    }

    console.log('Not found!');
    return null;
  };

  alexa.addToRollup = function(rollupGroup, handler, rollupName) {
    if (!rollup[rollupGroup]) {
      console.log('Creating the rollup group: ', rollupGroup);
      rollup[rollupGroup] = [];
    }
    rollup[rollupGroup].push({handler: handler, name: rollupName});<commit_msg>Logic correction<commit_after>var _ = require('lodash');
var async = require('async');

function init (env, ctx) {
  console.log('Configuring Alexa...');
  function alexa() {
    return alexa;
  }
  var intentHandlers = {};
  var rollup = {};

  // There is no protection for a previously handled metric - one plugin can overwrite the handler of another plugin.
  alexa.configureIntentHandler = function configureIntentHandler(intent, handler, metrics) {
    if (!intentHandlers[intent]) {
      intentHandlers[intent] = {};
    }
    if (metrics) {
      for (var i = 0, len = metrics.length; i < len; i++) {
        if (!intentHandlers[intent][metrics[i]]) {
          intentHandlers[intent][metrics[i]] = {};
        }
        console.log('Storing handler for intent \'' + intent + '\' for metric \'' + metrics[i] + '\'');
        intentHandlers[intent][metrics[i]].handler = handler;
      }
    } else {
      console.log('Storing handler for intent \'' + intent + '\'');
      intentHandlers[intent].handler = handler;
    }
  };

  // This function retrieves a handler based on the intent name and metric requested.
  alexa.getIntentHandler = function getIntentHandler(intentName, metric) {
    if (metric === undefined) {
      console.log('Looking for handler for intent \'' + intentName + '\'');
      if (intentName
        && intentHandlers[intentName]
        && intentHandlers[intentName].handler
      ) {
        console.log('Found!');
        return intentHandlers[intentName].handler;
      }
    } else {
      console.log('Looking for handler for intent \'' + intentName + '\' for metric \'' + metric + '\'');
      if (intentName
        && intentHandlers[intentName]
        && intentHandlers[intentName][metric]
        && intentHandlers[intentName][metric].handler
      ) {
        console.log('Found!');
        return intentHandlers[intentName][metric].handler
      }
    }

    console.log('Not found!');
    return null;
  };

  alexa.addToRollup = function(rollupGroup, handler, rollupName) {
    if (!rollup[rollupGroup]) {
      console.log('Creating the rollup group: ', rollupGroup);
      rollup[rollupGroup] = [];
    }
    rollup[rollupGroup].push({handler: handler, name: rollupName});
{'fraction_non_alphanumeric': 0.1436936936936937, 'fraction_numerical': 0.00045045045045045046, 'mean_word_length': 2.9370567375886525, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1264170', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1272, 'n_words': 296}