<commit_before>"use strict";

/* Dependency Tree Handler with Diff capabilities
 *
 * This service has not much to do - the tree itself is handled
 * completely by the dependencyTree directive.
 *
 * It has however additional diff capabilities, that are triggered
 * by a global diffLoaded event.
 * Knows how to pass style information to the tree visualization in
 * case a comparison/review was done.
 *
 * One could experiment here that this code should go back to a diff plugin
 * itself.
 * A diff plugin would calculate style information and pass this data load
 * through the diffLoaded event. The depTree service would listen to this
 * and pass the style info to its tree.
 *
 * Let's wait on a decision for this until we have done more work on the
 * diff plugin itself and resolved issue #80.
 * (https://github.com/latin-language-toolkit/llt-annotation_environment/issues/80)
 */

angular.module('arethusa.depTree').service('depTree', function(state, configurator, $rootScope) {
  var self = this;

  function configure() {
    configurator.getConfAndDelegate('depTree', self);
    console.log(self.conf);
    self.diffMode = false;
  }

  configure();

  this.toggleDiff = function() {
    self.diffMode = ! self.diffMode;
  };

  // We have three things we can colorize as wrong in the tree
  //   Label
  //   Head
  //   and the word itself for morphological stuff
  function analyseDiffs(tokens) {
    return arethusaUtil.inject({}, tokens, function(memo, id, token) {
      var diff = token.diff;
      if (diff) {
        memo[id] = analyseDiff(diff);
      }
    });
  }

  function analyseDiff(diff) {
    return arethusaUtil.inject({}, diff, function(memo, key, val) {
      if (key === 'relation') {
        memo.label = { color: 'red' };
      } else {
        if (key === 'head') {
          memo.edge = { stroke: 'red', 'stroke-width': '1px'};
        } else {
          memo.token = { color: 'red' };
        }
      }
    });
  }

  this.diffStyles = function() {
    if (self.diffMode) {
      return self.diffInfo;
    } else {
      return false;
    }
  };

  $rootScope.$on('diffLoaded', function() {
    self.diffPresent = true;
    self.diffInfo = analyseDiffs(state.tokens);
    self.diffMode = true;
  });

  this.tokensWithoutHeadCount = function() {
    return state.countTokens(function(token) {
      return ! (token.head || {}).id;
    });
  };

  this.init = function() {
    configure();
  };
});
<commit_msg>Console.log again... sloppy.<commit_after>"use strict";

/* Dependency Tree Handler with Diff capabilities
 *
 * This service has not much to do - the tree itself is handled
 * completely by the dependencyTree directive.
 *
 * It has however additional diff capabilities, that are triggered
 * by a global diffLoaded event.
 * Knows how to pass style information to the tree visualization in
 * case a comparison/review was done.
 *
 * One could experiment here that this code should go back to a diff plugin
 * itself.
 * A diff plugin would calculate style information and pass this data load
 * through the diffLoaded event. The depTree service would listen to this
 * and pass the style info to its tree.
 *
 * Let's wait on a decision for this until we have done more work on the
 * diff plugin itself and resolved issue #80.
 * (https://github.com/latin-language-toolkit/llt-annotation_environment/issues/80)
 */

angular.module('arethusa.depTree').service('depTree', function(state, configurator, $rootScope) {
  var self = this;

  function configure() {
    configurator.getConfAndDelegate('depTree', self);
    self.diffMode = false;
  }

  configure();

  this.toggleDiff = function() {
    self.diffMode = ! self.diffMode;
  };

  // We have three things we can colorize as wrong in the tree
  //   Label
  //   Head
  //   and the word itself for morphological stuff
  function analyseDiffs(tokens) {
    return arethusaUtil.inject({}, tokens, function(memo, id, token) {
      var diff = token.diff;
      if (diff) {
        memo[id] = analyseDiff(diff);
      }
    });
  }

  function analyseDiff(diff) {
    return arethusaUtil.inject({}, diff, function(memo, key, val) {
      if (key === 'relation') {
        memo.label = { color: 'red' };
      } else {
        if (key === 'head') {
          memo.edge = { stroke: 'red', 'stroke-width': '1px'};
        } else {
          memo.token = { color: 'red' };
        }
      }
    });
  }

  this.diffStyles = function() {
    if (self.diffMode) {
      return self.diffInfo;
    } else {
      return false;
    }
  };

  $rootScope.$on('diffLoaded', function() {
    self.diffPresent = true;
    self.diffInfo = analyseDiffs(state.tokens);
    self.diffMode = true;
  });

  this.tokensWithoutHeadCount = function() {
    return state.countTokens(function(token) {
      return ! (token.head || {}).id;
    });
  };

  this.init = function() {
    configure();
  };
});

{'fraction_non_alphanumeric': 0.12098916819946863, 'fraction_numerical': 0.0020437359493153486, 'mean_word_length': 2.8085603112840465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '5821103', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1438, 'n_words': 467}