<commit_before>import { IGraph } from '../types/index';
import { minBy } from 'lodash';

const findLessNeighborsMaker = (graph: IGraph, nodesToRemove: string[]) => () => {
  if (nodesToRemove.length == 1) return nodesToRemove.shift();
  
  const nodeId = minBy(nodesToRemove, (node) => graph.getNeighborsOf(node).length)
  const nodeIdIndex = nodesToRemove.indexOf(nodeId);

  nodesToRemove.splice(nodeIdIndex, 1);
  return nodeId;
};

export const buildTriangulatedGraph = (moralGraph: IGraph) => {
  const triangulatedGraph = moralGraph.clone();
  const clonedGraph = triangulatedGraph.clone();
  const nodesToRemove = [ ...clonedGraph.getNodesId() ];
  const findLessNeighbors = findLessNeighborsMaker(triangulatedGraph, nodesToRemove);

  while (nodesToRemove.length > 0) {
    const nodeToRemove = findLessNeighbors();
    const neighbors = clonedGraph.getNeighborsOf(nodeToRemove)
      .filter(id => nodesToRemove.indexOf(id) > -1);
    
    for (let i = 0; i < neighbors.length; i++) {
      const neighborA = neighbors[i];

      for (let j = i + 1; j < neighbors.length; j++) {  
        const neighborB = neighbors[j];

        if (!clonedGraph.containsNodeId(neighborA) || !clonedGraph.containsNodeId(neighborB)) {
          continue;
        }

        if (!clonedGraph.areConnected(neighborA, neighborB)) {
          clonedGraph.addEdge(neighborA, neighborB);
          triangulatedGraph.addEdge(neighborA, neighborB);
        }
      }
    }
    
    clonedGraph.removeNodeId(nodeToRemove);<commit_msg>Fixed lint file<commit_after>import { IGraph } from '../types/index';
import { minBy } from 'lodash';

const findLessNeighborsMaker = (graph: IGraph, nodesToRemove: string[]) => () => {
  if (nodesToRemove.length == 1) return nodesToRemove.shift();

  const nodeId = minBy(nodesToRemove, node => graph.getNeighborsOf(node).length)
  const nodeIdIndex = nodesToRemove.indexOf(nodeId);

  nodesToRemove.splice(nodeIdIndex, 1);
  return nodeId;
};

export const buildTriangulatedGraph = (moralGraph: IGraph) => {
  const triangulatedGraph = moralGraph.clone();
  const clonedGraph = triangulatedGraph.clone();
  const nodesToRemove = [ ...clonedGraph.getNodesId() ];
  const findLessNeighbors = findLessNeighborsMaker(triangulatedGraph, nodesToRemove);

  while (nodesToRemove.length > 0) {
    const nodeToRemove = findLessNeighbors();
    const neighbors = clonedGraph.getNeighborsOf(nodeToRemove)
      .filter(id => nodesToRemove.indexOf(id) > -1);

    for (let i = 0; i < neighbors.length; i++) {
      const neighborA = neighbors[i];

      for (let j = i + 1; j < neighbors.length; j++) {
        const neighborB = neighbors[j];

        if (!clonedGraph.containsNodeId(neighborA) || !clonedGraph.containsNodeId(neighborB)) {
          continue;
        }

        if (!clonedGraph.areConnected(neighborA, neighborB)) {
          clonedGraph.addEdge(neighborA, neighborB);
          triangulatedGraph.addEdge(neighborA, neighborB);
        }
      }
    }

    clonedGraph.removeNodeId(nodeToRemove);
{'fraction_non_alphanumeric': 0.1257445400397088, 'fraction_numerical': 0.003970880211780278, 'mean_word_length': 3.7456828885400313, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7198001', 'n_tokens_mistral': 988, 'n_tokens_neox': 942, 'n_words': 189}