"use strict";
// -*- mode: typescript; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of Genie
//
// Copyright 2020 The Board of Trustees of the Leland Stanford Junior University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Giovanni Campagna <gcampagn@cs.stanford.edu>
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const stream_1 = __importDefault(require("stream"));
const replace_parameters_1 = __importDefault(require("./replace_parameters"));
const single_device_augmenter_1 = __importDefault(require("./single_device_augmenter"));
class DatasetAugmenter extends stream_1.default.Transform {
    constructor(schemaRetriever, constProvider, thingpediaClient, options) {
        super({
            readableObjectMode: true,
            writableObjectMode: true,
        });
        this._options = options;
        this._rng = options.rng;
        this._includeQuotedExample = options.includeQuotedExample;
        this._singledevice = new single_device_augmenter_1.default(options.locale, thingpediaClient, options.singleDeviceExpandFactor, this._rng);
        this._paramReplacer = new replace_parameters_1.default({
            thingpediaClient: thingpediaClient,
            schemaRetriever: schemaRetriever,
            constProvider: constProvider,
            paramLocale: options.paramLocale,
            rng: this._rng,
            addFlag: true,
            quotedProbability: this._options.quotedProbability,
            untypedStringProbability: this._options.untypedStringProbability,
            maxSpanLength: this._options.maxSpanLength,
            syntheticExpandFactor: this._options.syntheticExpandFactor,
            noQuoteExpandFactor: this._options.noQuoteExpandFactor,
            paraphrasingExpandFactor: this._options.paraphrasingExpandFactor,
            replaceLocations: this._options.replaceLocations,
            replaceNumbers: this._options.replaceNumbers,
            cleanParameters: this._options.cleanParameters,
            requotable: this._options.requotable,
            samplingType: this._options.samplingType,
            subsetParamSet: this._options.subsetParamSet,
            numAttempts: this._options.numAttempts,
            debug: this._options.debug
        });
    }
    async _process(ex) {
        if (ex.flags.eval)
            return [ex];
        const output = await this._paramReplacer.process(ex);
        if (this._includeQuotedExample)
            output.push(ex);
        const singledeviceexs = await this._singledevice.process(ex);
        if (this._includeQuotedExample)
            output.push(...singledeviceexs);
        for (const singledeviceex of singledeviceexs)
            output.push(...await this._paramReplacer.process(singledeviceex));
        return output;
    }
    _flush(callback) {
        process.nextTick(callback);
    }
    _transform(inex, encoding, callback) {
        this._process(inex).then((output) => {
            for (const ex of output)
                this.push(ex);
            callback();
        }, (err) => {
            callback(err);
        });
    }
}
exports.default = DatasetAugmenter;
//# sourceMappingURL=index.js.map