"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Preprocessor = void 0;
var Preprocessor = /** @class */ (function () {
    function Preprocessor() {
    }
    Object.defineProperty(Preprocessor.prototype, "normalizer", {
        set: function (value) {
            this._normalizer = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Preprocessor.prototype, "stemmer", {
        set: function (value) {
            this._stemmer = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Preprocessor.prototype, "tokenizer", {
        set: function (value) {
            this._tokenizer = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Preprocessor.prototype, "language", {
        get: function () {
            return this._language;
        },
        set: function (value) {
            this._language = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Preprocessor.prototype, "maxSeqLen", {
        get: function () {
            return this._maxSeqLen;
        },
        set: function (value) {
            this._maxSeqLen = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Preprocessor.prototype, "vocabulary", {
        get: function () {
            return this._vocabulary;
        },
        set: function (vocabulary) {
            this._vocabulary = vocabulary;
        },
        enumerable: false,
        configurable: true
    });
    // TO DO: Maybe vocabulary should be generated with a different data set than the train or test one.
    Preprocessor.prototype.generateVocabulary = function (data) {
        var _this = this;
        this._vocabulary = {};
        var id = 1;
        data.forEach(function (sample) {
            var normalizedSentence = _this._normalizer.normalize(sample.feature);
            var stemmedSentence = _this._stemmer.stem(normalizedSentence, _this._language);
            var tokens = _this._tokenizer.tokenize(stemmedSentence);
            tokens.forEach(function (token) {
                if (!(token in _this._vocabulary)) {
                    _this._vocabulary[token] = id;
                    id++;
                }
            });
        });
    };
    Preprocessor.prototype.preprocess = function (sentence) {
        var normalizedSentence = this._normalizer.normalize(sentence);
        var stemmedSentence = this._stemmer.stem(normalizedSentence, this._language);
        var tokens = this._tokenizer.tokenize(stemmedSentence);
        var sequence = this._computeSequence(tokens);
        var truncatedSequence = this._truncate(sequence);
        var paddedSequence = this._paddSequence(truncatedSequence);
        return paddedSequence;
    };
    Preprocessor.prototype._computeSequence = function (tokens) {
        var _this = this;
        var sequence = tokens.map(function (token) {
            return token in _this._vocabulary ? _this._vocabulary[token] : 0;
        });
        return sequence;
    };
    Preprocessor.prototype._truncate = function (sequence) {
        return sequence.length > this._maxSeqLen
            ? sequence.slice(0, this._maxSeqLen)
            : sequence;
    };
    // TO DO: check differences between pre and post padding.
    Preprocessor.prototype._paddSequence = function (truncatedSequence) {
        var padd = Array(this._maxSeqLen - truncatedSequence.length).fill(0);
        var paddedSequence = padd.concat(truncatedSequence);
        return paddedSequence;
    };
    return Preprocessor;
}());
exports.Preprocessor = Preprocessor;
//# sourceMappingURL=preprocessor.js.map