<commit_before>var UID = "_U_";
var MULTI_TYPE = "_multi";

function Node(id, name, type) {
  if (typeof (name) === 'undefined') {
    name = id;
  }
  if (typeof (type) === 'undefined') {
    type = 'analysis';
  }
  this.id = id;
  this.name = name;
  this.isMulti = (type.search(/_multi$/) >= 0);
  this.type = this.isMulti ?
    type.substr(0, type.length - MULTI_TYPE.length) : type;
}

Node.prototype.isMdo = function() {
  return this.type === "mdo";
};

Node.prototype.getScenarioId = function() {
  if (this.isMdo()) {
    var idxscn = this.name.indexOf("_scn-");
    if (idxscn === -1) {
      console.log("Warning: MDO Scenario not found. " +
                  "Bad type or name for node: " + JSON.stringify(this));
      return null;
    }
    return this.name.substr(idxscn + 1);
  }
  return null;
};

function Edge(from, to, name, row, col, isMulti) {
  this.id = "link_" + from + "_" + to;
  this.name = name;
  this.row = row;
  this.col = col;
  this.iotype = row < col ? "in" : "out";
  this.io = {
    fromU: (from === UID),
    toU: (to === UID)
  };
  this.isMulti = isMulti;
}

Edge.prototype.isIO = function() {
  return this.io.fromU || this.io.toU;
};

function Graph(mdo, refname) {
  this.nodes = [new Node(UID, UID, "user")];
  this.edges = [];
  this.chains = [];
  this.refname = refname || "";
  this._newNodeCount = 0;

  var numbering = Graph.number(mdo.workflow);
  var numPrefixes = numbering.toNum;
  this.nodesByStep = numbering.toNode;

  mdo.nodes.forEach(function(item) {
    var num = numPrefixes[item.id];
    this.nodes.push(new Node(item.id,
      num ? num + ":" + item.name : item.name,
      item.type));
  }, this);

  mdo.edges.forEach(function(item) {
    var idA = this.idxOf(item.from);
    var idB = this.idxOf(item.to);
    var isMulti = this.nodes[idA].isMulti || this.nodes[idB].isMulti;
    this.edges.push(new Edge(item.from, item.to, item.name, idA, idB, isMulti));
  }, this);

  var echain = Graph.expand(mdo.workflow);
  echain.forEach(function(leafChain) {
    if (leafChain.length < 2) {
      throw new Error("Bad process chain (" + leafChain.length + "elt)");
    } else {
      this.chains.push([]);
      var ids = this.nodes.map(function(elt) {
        return elt.id;
      });
      leafChain.forEach(function(item, j) {
        if (j !== 0) {
          var idA = ids.indexOf(leafChain[j - 1]);
          if (idA < 0) {
            throw new Error("Process chain element (" +
                            leafChain[j - 1] + ") not found");
          }
          var idB = ids.indexOf(leafChain[j]);
          if (idB < 0) {
            throw new Error("Process chain element (" +
                            leafChain[j] + ") not found");
          }
          if (idA !== idB) {
            this.chains[this.chains.length - 1].push([idA, idB]);
          }
        }
      }, this);
    }
  }, this);
}

Graph.prototype.idxOf = function(nodeId) {
  return this.nodes.map(function(elt) {
    return elt.id;
  }).indexOf(nodeId);
};

Graph.prototype.getNode = function(nodeId) {
  return this.nodes[this.ids.indexOf(nodeId)];
};

Graph.prototype.addNode = function(nodeName) {
  this._newNodeCount += 1;
  this.nodes.push(
      new Node("NewNode" + this._newNodeCount, nodeName, "analysis"));
};

Graph.prototype.removeNode = function(index) {
  var self = this;

  // Update edges
  var edges = this.findEdgesOf(index);
  edges.toRemove.forEach(function(edge) {
    var idx = self.edges.indexOf(edge);
    if (idx > -1) {
      self.edges.splice(idx, 1);<commit_msg>fix getNode: remove this.ids usage<commit_after>var UID = "_U_";
var MULTI_TYPE = "_multi";

function Node(id, name, type) {
  if (typeof (name) === 'undefined') {
    name = id;
  }
  if (typeof (type) === 'undefined') {
    type = 'analysis';
  }
  this.id = id;
  this.name = name;
  this.isMulti = (type.search(/_multi$/) >= 0);
  this.type = this.isMulti ?
    type.substr(0, type.length - MULTI_TYPE.length) : type;
}

Node.prototype.isMdo = function() {
  return this.type === "mdo";
};

Node.prototype.getScenarioId = function() {
  if (this.isMdo()) {
    var idxscn = this.name.indexOf("_scn-");
    if (idxscn === -1) {
      console.log("Warning: MDO Scenario not found. " +
                  "Bad type or name for node: " + JSON.stringify(this));
      return null;
    }
    return this.name.substr(idxscn + 1);
  }
  return null;
};

function Edge(from, to, name, row, col, isMulti) {
  this.id = "link_" + from + "_" + to;
  this.name = name;
  this.row = row;
  this.col = col;
  this.iotype = row < col ? "in" : "out";
  this.io = {
    fromU: (from === UID),
    toU: (to === UID)
  };
  this.isMulti = isMulti;
}

Edge.prototype.isIO = function() {
  return this.io.fromU || this.io.toU;
};

function Graph(mdo, refname) {
  this.nodes = [new Node(UID, UID, "user")];
  this.edges = [];
  this.chains = [];
  this.refname = refname || "";
  this._newNodeCount = 0;

  var numbering = Graph.number(mdo.workflow);
  var numPrefixes = numbering.toNum;
  this.nodesByStep = numbering.toNode;

  mdo.nodes.forEach(function(item) {
    var num = numPrefixes[item.id];
    this.nodes.push(new Node(item.id,
      num ? num + ":" + item.name : item.name,
      item.type));
  }, this);

  mdo.edges.forEach(function(item) {
    var idA = this.idxOf(item.from);
    var idB = this.idxOf(item.to);
    var isMulti = this.nodes[idA].isMulti || this.nodes[idB].isMulti;
    this.edges.push(new Edge(item.from, item.to, item.name, idA, idB, isMulti));
  }, this);

  var echain = Graph.expand(mdo.workflow);
  echain.forEach(function(leafChain) {
    if (leafChain.length < 2) {
      throw new Error("Bad process chain (" + leafChain.length + "elt)");
    } else {
      this.chains.push([]);
      var ids = this.nodes.map(function(elt) {
        return elt.id;
      });
      leafChain.forEach(function(item, j) {
        if (j !== 0) {
          var idA = ids.indexOf(leafChain[j - 1]);
          if (idA < 0) {
            throw new Error("Process chain element (" +
                            leafChain[j - 1] + ") not found");
          }
          var idB = ids.indexOf(leafChain[j]);
          if (idB < 0) {
            throw new Error("Process chain element (" +
                            leafChain[j] + ") not found");
          }
          if (idA !== idB) {
            this.chains[this.chains.length - 1].push([idA, idB]);
          }
        }
      }, this);
    }
  }, this);
}

Graph.prototype.idxOf = function(nodeId) {
  return this.nodes.map(function(elt) {
    return elt.id;
  }).indexOf(nodeId);
};

Graph.prototype.getNode = function(nodeId) {
  var theNode;
  this.nodes.forEach(function(node) {
    if (node.id === nodeId) {
      theNode = node;
    }
  }, this);
  return theNode;
};

Graph.prototype.addNode = function(nodeName) {
  this._newNodeCount += 1;
  this.nodes.push(
      new Node("NewNode" + this._newNodeCount, nodeName, "analysis"));
};

Graph.prototype.removeNode = function(index) {
  var self = this;

  // Update edges
  var edges = this.findEdgesOf(index);
  edges.toRemove.forEach(function(edge) {
    var idx = self.edges.indexOf(edge);
    if (idx > -1) {
      self.edges.splice(idx, 1);
{'fraction_non_alphanumeric': 0.1694255111976631, 'fraction_numerical': 0.004173042147725692, 'mean_word_length': 2.4852157052835677, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 7, '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': '2792031', 'n_tokens_mistral': 2600, 'n_tokens_neox': 2556, 'n_words': 536}