<commit_before>const indexApp = angular.module('indexApp', []);
indexApp.controller('indexCtrl', ($scope) => {
  $scope.appName = 'Inverted Index';
  $scope.myInvertedIndex = new InvertedIndex();
  $scope.indexTable = '';
  $scope.indexTableFiles = [];
  $scope.currentFileName = null;
  $scope.liveSearchResult = false;
  $scope.liveSearchKeys = false;
  $scope.indexedFiles = [];

  $scope.getBookDocs = (fileName) => {
    const fileLength = $scope.myInvertedIndex.files[fileName].length;
    return Array.from({ length: fileLength }, (value, key) => key);
  };

  $scope.indexFile = () => {
    $scope.myInvertedIndex.createIndex($scope.currentFileName);
    $scope.indexTable = $scope.myInvertedIndex.indexMap;
    $scope.indexTableFiles.push($scope.currentFileName);
    $scope.indexedFiles.push($scope.currentFileName);
    $scope.currentFileName = '';
  };

  /* Validate JSON, read and store file  */
  $scope.readAndCheckFile = (selectedFile) => {
    const fileReader = new FileReader();
    fileReader.onload = () => {
      const fileJSONContent = JSON.parse(fileReader.result);
      if (!$scope.myInvertedIndex.isValidJSON(fileJSONContent)) {
        Materialize.toast('Invalid JSON file', 2000, 'red');
      } else {
        $scope.myInvertedIndex.storeFile(selectedFile.name, fileJSONContent);
        $scope.$apply(() => {
          $scope.currentFileName = selectedFile.name;
          $scope.indexTableFiles.push($scope.currentFileName);
        });
      }
    };

    fileReader.readAsText(selectedFile);
  };


  /* Handling file upload and extension checking */
  const fileInputField = document.getElementById('fileInput');
  fileInputField.addEventListener('change', (e) => {
    const selectedFile = e.target.files[0];
    const acceptedFileType = 'application/json';
    const selectedFileType = selectedFile.type;
    const isValidFileType = Object.is(selectedFileType, acceptedFileType);
    if (!isValidFileType) {
      Materialize.toast('Invalid File Type', 2000, 'cyan');
      $('#fileInput').val('');
    } else {
      $scope.readAndCheckFile(selectedFile);
    }
  });

  $('#search').on('keyup', () => {
    if (Object.keys($scope.myInvertedIndex.indexMap).length === 0) {
      Materialize.toast('Index a file first', 500, 'orange');
    }
    const searchTerm = $('#search').val();
    //const searchResult =
      $scope.myInvertedIndex.searchIndex(searchTerm);
    $scope.$apply(() => {
      $scope.liveSearchResult =
        $scope.myInvertedIndex.searchIndex(searchTerm);
      $scope.liveSearchKeys = Object.keys($scope.liveSearchResult);
    });
  });
});

$(document).ready(() => {
  $('.modal').modal();
});<commit_msg>remove console and unused code<commit_after>const indexApp = angular.module('indexApp', []);
indexApp.controller('indexCtrl', ($scope) => {
  $scope.appName = 'Inverted Index';
  $scope.myInvertedIndex = new InvertedIndex();
  $scope.indexTable = '';
  $scope.indexTableFiles = [];
  $scope.currentFileName = null;
  $scope.liveSearchResult = false;
  $scope.liveSearchKeys = false;
  $scope.indexedFiles = [];

  $scope.getBookDocs = (fileName) => {
    const fileLength = $scope.myInvertedIndex.files[fileName].length;
    return Array.from({ length: fileLength }, (value, key) => key);
  };

  $scope.indexFile = () => {
    $scope.myInvertedIndex.createIndex($scope.currentFileName);
    $scope.indexTable = $scope.myInvertedIndex.indexMap;
    $scope.indexTableFiles.push($scope.currentFileName);
    $scope.indexedFiles.push($scope.currentFileName);
    $scope.currentFileName = '';
  };

  /* Validate JSON, read and store file  */
  $scope.readAndCheckFile = (selectedFile) => {
    const fileReader = new FileReader();
    fileReader.onload = () => {
      const fileJSONContent = JSON.parse(fileReader.result);
      if (!$scope.myInvertedIndex.isValidJSON(fileJSONContent)) {
        Materialize.toast('Invalid JSON file', 2000, 'red');
      } else {
        $scope.myInvertedIndex.storeFile(selectedFile.name, fileJSONContent);
        $scope.$apply(() => {
          $scope.currentFileName = selectedFile.name;
          $scope.indexTableFiles.push($scope.currentFileName);
        });
      }
    };

    fileReader.readAsText(selectedFile);
  };


  /* Handling file upload and extension checking */
  const fileInputField = document.getElementById('fileInput');
  fileInputField.addEventListener('change', (e) => {
    const selectedFile = e.target.files[0];
    const acceptedFileType = 'application/json';
    const selectedFileType = selectedFile.type;
    const isValidFileType = Object.is(selectedFileType, acceptedFileType);
    if (!isValidFileType) {
      Materialize.toast('Invalid File Type', 2000, 'cyan');
      $('#fileInput').val('');
    } else {
      $scope.readAndCheckFile(selectedFile);
    }
  });

  $('#search').on('keyup', () => {
    if (Object.keys($scope.myInvertedIndex.indexMap).length === 0) {
      Materialize.toast('Index a file first', 500, 'orange');
    }
    const searchTerm = $('#search').val();
    $scope.myInvertedIndex.searchIndex(searchTerm);
    $scope.$apply(() => {
      $scope.liveSearchResult =
        $scope.myInvertedIndex.searchIndex(searchTerm);
      $scope.liveSearchKeys = Object.keys($scope.liveSearchResult);
    });
  });
});

$(document).ready(() => {
  $('.modal').modal();
});
{'fraction_non_alphanumeric': 0.16234984984984985, 'fraction_numerical': 0.00487987987987988, 'mean_word_length': 3.741103202846975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '1491800', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1587, 'n_words': 256}