<commit_before>/* eslint no-undef:0*/

const app = angular.module('InvertedIndexApp', []);

app.controller('InvertedIndexController', ($scope) => {
    $scope.allValidatedBooks = {};
    $scope.titles = {};
    $scope.arrayLength = {};
    $scope.newIndex = new InvertedIndexClass();

    const indexCount = (n) => {
        const arr = [];
        for (let i = 0; i < n; i += 1) {
            arr.push(i);
        }
        return arr;
    };
    const titlesList = () => { // eslint-no constant
        const arr = [];
        const book = $scope.newIndex.books;
        book.forEach((bookTitle) => {
            arr.push(bookTitle.title);
        });
        // console.log(arr);
        return arr;
    };

    $scope.uploader = () => {
        const fileDoc = document.getElementById('myJsonFile').files[0];
        $scope.fileDocName = fileDoc.name;
        if (typeof(fileDoc !== 'Blob')) {
            $scope.uploaderError = 'select and upload a json object and then create index'; // eslint-no constant condition
        }
        // $scope.newIndex = new InvertedIndexClass();
        const reader = new FileReader();
        reader.readAsText(fileDoc);
        reader.onload = (event) => {
            $scope.readybooks = event.target.result;
            $scope.validationResult = $scope.newIndex.validFiles($scope.readybooks);

            $scope.$apply(() => {
                if ($scope.validationResult[0]) {
                    $scope.allValidatedBooks[$scope.fileDocName] = $scope.readybooks;
                }
            });
            alert($scope.validationResult[1]); // eslint-disable-line no-alert
        };
    };
    $scope.submitIndex = () => {
        if ($scope.validationResult[0] === true) {
            $scope.indexOfWords = $scope.newIndex.createIndex($scope.indexToBeCreated,
                JSON.parse($scope.allValidatedBooks[$scope.indexToBeCreated]));
            $scope.titles[$scope.indexToBeCreated] = titlesList($scope.newIndex.books.length);
            $scope.arrayLength[$scope.indexToBeCreated] = indexCount($scope.newIndex.books.length);
            $scope.showIndex = true;
            $scope.showSearch = false;
        }
        $scope.allTitles = $scope.titles;
        $scope.allArrayLength = $scope.arrayLength;
        console.log($scope.indexToBeSearched);
    };


    $scope.searchJson = () => {
        // let file = $scope.indexToBeSearched || null,
        if ($scope.searchTerms === undefined) {
            $scope.showError = 'Please enter valid search terms';
        } else if ($scope.indexOfWords === undefined) {
            $scope.showError = 'Please upload a Json object first before searching';
        } else {
            if ($scope.indexToBeSearched === undefined) {
                $scope.searchResult = $scope.newIndex.searchIndex($scope.searchTerms);
            } else {
                $scope.searchResult = $scope.newIndex.searchIndex($scope.indexToBeSearched, $scope.searchTerms);
            }
            $scope.showIndex = false;
            $scope.showSearch = true;
        }
    };
});<commit_msg>fixed controllers<commit_after>/* eslint no-undef:0*/

const app = angular.module('InvertedIndexApp', []);

app.controller('InvertedIndexController', ($scope) => {
    $scope.allValidatedBooks = {};
    $scope.titles = {};
    $scope.arrayLength = {};
    $scope.newIndex = new InvertedIndexClass();

    const indexCount = (n) => {
        const arr = [];
        for (let i = 0; i < n; i += 1) {
            arr.push(i);
        }
        return arr;
    };
    const titlesList = () => { // eslint-no constant
        const arr = [];
        const book = $scope.newIndex.books;
        book.forEach((bookTitle) => {
            arr.push(bookTitle.title);
        });
        // console.log(arr);
        return arr;
    };

    $scope.uploader = () => {
        const fileDoc = document.getElementById('myJsonFile').files[0];
        $scope.fileDocName = fileDoc.name;
        if (typeof(fileDoc !== 'Blob')) {
            $scope.uploaderError = 'select and upload a json object and then create index'; // eslint-no constant condition
        }
        // $scope.newIndex = new InvertedIndexClass();
        const reader = new FileReader();
        reader.readAsText(fileDoc);
        reader.onload = (event) => {
            $scope.readybooks = event.target.result;
            $scope.validationResult = $scope.newIndex.validFiles($scope.readybooks);

            $scope.$apply(() => {
                if ($scope.validationResult[0]) {
                    $scope.allValidatedBooks[$scope.fileDocName] = $scope.readybooks;
                }
            });
            alert($scope.validationResult[1]); // eslint-disable-line no-alert
        };
    };
    $scope.submitIndex = () => {
        if ($scope.validationResult[0] === true) {
            $scope.indexOfWords = $scope.newIndex.createIndex($scope.indexToBeCreated,
                JSON.parse($scope.allValidatedBooks[$scope.indexToBeCreated]));
            $scope.titles[$scope.indexToBeCreated] = titlesList($scope.newIndex.books.length);
            $scope.arrayLength[$scope.indexToBeCreated] = indexCount($scope.newIndex.books.length);
            $scope.showIndex = true;
            $scope.showSearch = false;
        }
        $scope.allTitles = $scope.titles;
        $scope.allArrayLength = $scope.arrayLength;
        console.log($scope.indexToBeSearched);
    };


    $scope.searchJson = () => {
        // let file = $scope.indexToBeSearched || null,
        if ($scope.searchTerms === undefined) {
            $scope.showError = 'Please enter valid search terms';
        } else if ($scope.indexOfWords === undefined) {
            $scope.showError = 'Please upload a Json object first before searching';
        } else {
            if ($scope.indexToBeSearched === undefined) {
                $scope.searchResult = $scope.newIndex.searchIndex($scope.searchTerms);
            } else {
                $scope.searchResult = $scope.newIndex.searchIndex($scope.searchTerms, $scope.indexToBeSearched);
            }
            $scope.showIndex = false;
            $scope.showSearch = true;
        }
    };
});
{'fraction_non_alphanumeric': 0.14419961114711602, 'fraction_numerical': 0.002268308489954634, 'mean_word_length': 2.1145307769929365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '1156293', 'n_tokens_mistral': 1777, 'n_tokens_neox': 1739, 'n_words': 301}