<commit_before>var ARManager = new Class({

  $ARBuilder: null,
  DD: null,
  FL: null,
  stringHelper: null,
  miningManager: null,
  ETreeManager: null,
  settings: null,
  UIPainter: null,
  UITemplateRegistrator: null,

  activeRule: null,
  ETreeValidator: null,
  maxCedentID: 0,
  maxFieldID: 0,
  attributesByGroup: false,

  initialize: function (ARBuilder, DD, FL, miningManager, ETreeManager, settings, UIPainter) {
    this.$ARBuilder = ARBuilder;
    this.DD = DD;
    this.FL = FL;
    this.stringHelper = new StringHelper();
    this.miningManager = miningManager;
    this.ETreeManager = ETreeManager;
    this.settings = settings;
    this.UIPainter = UIPainter;

    this.ETreeValidator = new ETreeValidator();

    this.initARValidator();
    this.initBlankAR();

    this.$ARBuilder.addEvent('updateFL', function (FL) {
      this.FL = FL;
    }.bind(this));
  },

  setDD: function (DD) {
    this.DD = DD;
  },

  initBlankAR: function () {
    this.maxCedentID = 0;
    this.maxFieldID = 0;

    this.activeRule = new AssociationRule(this.initARValidator());

    // antecedent
    var antecedent = this.initCedent('antecedent', 1);
    this.activeRule.addAntecedent(antecedent);

    // default interest measures
    this.FL.getDefaultIMs().each(function (IMPrototype) {
      var IM = IMPrototype.initIMAR();
      if (IM.getName() === 'SUPP') {
        var minimalSupport = this.DD.calculateMinimalSupport();
        if (IM.getThreshold().toFloat() < minimalSupport) {
          IM.setThreshold(minimalSupport);
        }
      }
      this.activeRule.addIM(IM);
    }.bind(this));

    // succedent
    var succedent = this.initCedent('consequent', 1);
    this.activeRule.addSuccedent(succedent);
  },

  initARValidator: function () {
    return new AssociationRuleValidator(this.FL.getRulePattern(), this.FL.getIMCombinations());
  },

  initCedent: function (scope, level, parentCedent) {
    return new Cedent(this.generateCedentID(), level, this.FL.getDefaultConnective(level, this.activeRule.toSettings(), scope), [], scope);
  },

  hasPossibleIMs: function () {
    return Object.getLength(this.FL.getPossibleIMs(this.activeRule.getIMs())) > 0;
  },

  getActiveRule: function () {
    return this.activeRule;
  },

  openAddIMWindow: function () {
    var possibleIMs = this.FL.getPossibleIMs(this.activeRule.getIMs());
    this.UIPainter.renderAddIMWindow(possibleIMs);
  },

  openEditIMWindow: function (selectedIM) {
    var IMs = this.FL.getIMs();
    this.UIPainter.renderEditIMWindow(IMs, selectedIM);
  },

  /**
   * Opens the rename task window overlay.
   * @param taskId Task ID to rename.
   * @param taskName original name of the task
   */
  openRenameTaskWindow: function (taskId, taskName) {
    this.UIPainter.renderRenameTaskWindow(taskId, taskName);
  },

  addAntecedent: function (antecedent) {
    this.activeRule.addAntecedent(antecedent);
  },

  addIM: function (IMPrototype, thresholdValue, alphaValue) {
    var IM = new InterestMeasureAR(IMPrototype.getName(), IMPrototype.getLocalizedName(), IMPrototype.getExplanation(), IMPrototype.getThresholdType(), IMPrototype.getCompareType(), IMPrototype.getFields(), IMPrototype.getStringHelper(), IMPrototype.calculation, IMPrototype.getDefault(), IMPrototype.getRequired(), thresholdValue, alphaValue);
    this.activeRule.addIM(IM);
    this.setActiveRuleChanged();
    this.UIPainter.hideOverlay();
    this.UIPainter.renderActiveRule();
  },

  editIM: function (IMPrototype, thresholdValue, alphaValue) {
    this.activeRule.editIM(IMPrototype, thresholdValue, alphaValue);
    this.setActiveRuleChanged();
    this.UIPainter.hideOverlay();
    this.UIPainter.renderActiveRule();
  },

  removeIM: function (IM) {
    this.activeRule.removeIM(IM.getName());
    this.setActiveRuleChanged();
    this.UIPainter.renderActiveRule();
  },

  addAttribute: function (cedent, attribute) {
    var field = new FieldAR(
      this.generateFieldID(),
      attribute,
      null,
      null,
      new StringHelper()
    );
    cedent.addChild(field);

    this.UIPainter.renderActiveRule();
    this.openAddCoefficientWindow(field);
  },

  addAttributeToCedent: function (attribute, cedent) {
    if (attribute.choices && attribute.choices.length==1){
      var field = new FieldAR(this.generateFieldID(), attribute, 'One category', null, new StringHelper(), attribute.choices[0]);
    }else{
      var field = new FieldAR(this.generateFieldID(), attribute, 'Subset', null, new StringHelper(), 1, 1);
    }

    if (!cedent){
      cedent=this.activeRule.getAntecedent();
    }

    cedent.addChild(field);
    if (!this.attributesByGroup) {
      this.sortAttributes();
    }
    this.UIPainter.renderActiveRule();
  },

  openAddCoefficientWindow: function (field) {<commit_msg>fixed #67<commit_after>var ARManager = new Class({

  $ARBuilder: null,
  DD: null,
  FL: null,
  stringHelper: null,
  miningManager: null,
  ETreeManager: null,
  settings: null,
  UIPainter: null,
  UITemplateRegistrator: null,

  activeRule: null,
  ETreeValidator: null,
  maxCedentID: 0,
  maxFieldID: 0,
  attributesByGroup: false,

  initialize: function (ARBuilder, DD, FL, miningManager, ETreeManager, settings, UIPainter) {
    this.$ARBuilder = ARBuilder;
    this.DD = DD;
    this.FL = FL;
    this.stringHelper = new StringHelper();
    this.miningManager = miningManager;
    this.ETreeManager = ETreeManager;
    this.settings = settings;
    this.UIPainter = UIPainter;

    this.ETreeValidator = new ETreeValidator();

    this.initARValidator();
    this.initBlankAR();

    this.$ARBuilder.addEvent('updateFL', function (FL) {
      this.FL = FL;
    }.bind(this));
  },

  setDD: function (DD) {
    this.DD = DD;
  },

  initBlankAR: function () {
    this.maxCedentID = 0;
    this.maxFieldID = 0;

    this.activeRule = new AssociationRule(this.initARValidator());

    // antecedent
    var antecedent = this.initCedent('antecedent', 1);
    this.activeRule.addAntecedent(antecedent);

    // default interest measures
    this.FL.getDefaultIMs().each(function (IMPrototype) {
      var IM = IMPrototype.initIMAR();
      if (IM.getName() === 'SUPP') {
        var minimalSupport = this.DD.calculateMinimalSupport();
        if (IM.getThreshold().toFloat() < minimalSupport) {
          IM.setThreshold(minimalSupport);
        }
      }
      this.activeRule.addIM(IM);
    }.bind(this));

    // succedent
    var succedent = this.initCedent('consequent', 1);
    this.activeRule.addSuccedent(succedent);
  },

  initARValidator: function () {
    return new AssociationRuleValidator(this.FL.getRulePattern(), this.FL.getIMCombinations());
  },

  initCedent: function (scope, level, parentCedent) {
    return new Cedent(this.generateCedentID(), level, this.FL.getDefaultConnective(level, this.activeRule.toSettings(), scope), [], scope);
  },

  hasPossibleIMs: function () {
    return Object.getLength(this.FL.getPossibleIMs(this.activeRule.getIMs())) > 0;
  },

  getActiveRule: function () {
    return this.activeRule;
  },

  openAddIMWindow: function () {
    var possibleIMs = this.FL.getPossibleIMs(this.activeRule.getIMs());
    this.UIPainter.renderAddIMWindow(possibleIMs);
  },

  openEditIMWindow: function (selectedIM) {
    var IMs = this.FL.getIMs();
    this.UIPainter.renderEditIMWindow(IMs, selectedIM);
  },

  /**
   * Opens the rename task window overlay.
   * @param taskId Task ID to rename.
   * @param taskName original name of the task
   */
  openRenameTaskWindow: function (taskId, taskName) {
    this.UIPainter.renderRenameTaskWindow(taskId, taskName);
  },

  addAntecedent: function (antecedent) {
    this.activeRule.addAntecedent(antecedent);
  },

  addIM: function (IMPrototype, thresholdValue, alphaValue) {
    var IM = new InterestMeasureAR(IMPrototype.getName(), IMPrototype.getLocalizedName(), IMPrototype.getExplanation(), IMPrototype.getThresholdType(), IMPrototype.getCompareType(), IMPrototype.getFields(), IMPrototype.getStringHelper(), IMPrototype.calculation, IMPrototype.getDefault(), IMPrototype.getRequired(), thresholdValue, alphaValue);
    this.activeRule.addIM(IM);
    this.setActiveRuleChanged();
    this.UIPainter.hideOverlay();
    this.UIPainter.renderActiveRule();
  },

  editIM: function (IMPrototype, thresholdValue, alphaValue) {
    this.activeRule.editIM(IMPrototype, thresholdValue, alphaValue);
    this.setActiveRuleChanged();
    this.UIPainter.hideOverlay();
    this.UIPainter.renderActiveRule();
  },

  removeIM: function (IM) {
    this.activeRule.removeIM(IM.getName());
    this.setActiveRuleChanged();
    this.UIPainter.renderActiveRule();
  },

  addAttribute: function (cedent, attribute) {
    var field = new FieldAR(
      this.generateFieldID(),
      attribute,
      null,
      null,
      new StringHelper()
    );
    cedent.addChild(field);

    this.UIPainter.renderActiveRule();
    this.openAddCoefficientWindow(field);
  },

  addAttributeToCedent: function (attribute, cedent) {
    if (attribute.choices && attribute.choices.length==1){
      var field = new FieldAR(this.generateFieldID(), attribute, 'One category', null, new StringHelper(), String(attribute.choices[0]));
    }else{
      var field = new FieldAR(this.generateFieldID(), attribute, 'Subset', null, new StringHelper(), 1, 1);
    }

    if (!cedent){
      cedent=this.activeRule.getAntecedent();
    }

    cedent.addChild(field);
    if (!this.attributesByGroup) {
      this.sortAttributes();
    }
    this.UIPainter.renderActiveRule();
  },

  openAddCoefficientWindow: function (field) {
{'fraction_non_alphanumeric': 0.12974947807933193, 'fraction_numerical': 0.0025052192066805845, 'mean_word_length': 3.7857142857142856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1646624', 'n_tokens_mistral': 3162, 'n_tokens_neox': 3048, 'n_words': 571}