"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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const C = __importStar(require("../../ast_manip"));
const D = __importStar(require("../../dialogue_acts"));
async function default_1($runtime, $ttUtils, $options, $locale, $grammar, $loader) {
    $grammar.declareSymbol("question_system_recommendation_short");
    $grammar.addRule("question_system_recommendation_short", [new $runtime.NonTerminal("ctx_with_result_and_action", undefined), "how about", new $runtime.NonTerminal("constant_name", ["value", 0, "id0"])], ((ctx, $0, proposal) => D.makeRecommendation(ctx, proposal)), D.recommendationKeyFn, {});
    $grammar.declareSymbol("action_recommendation");
    $grammar.addRule("action_recommendation", [new $runtime.NonTerminal("ctx_with_result_and_action", undefined), new $runtime.Choice(["would you like to", "would you like me to"]), new $runtime.NonTerminal("contextual_action_phrase", ["functionName", 0, "nextFunction"])], ((ctx, $0, action) => D.makeActionRecommendation(ctx, action)), D.recommendationKeyFn, { weight: (0.1) });
    $grammar.declareSymbol("actionable_system_recommendation_short");
    if ($options.flags.inference) {
        $grammar.addRule("actionable_system_recommendation_short", [new $runtime.NonTerminal("ctx_with_result_noquestion", undefined), new $runtime.NonTerminal("ctx_thingpedia_result", undefined)], ((ctx, proposal) => D.makeThingpediaRecommendation(ctx, proposal)), D.recommendationKeyFn, { priority: (2) });
        $grammar.addRule("actionable_system_recommendation_short", [new $runtime.NonTerminal("ctx_with_result_noquestion", undefined), new $runtime.NonTerminal("ctx_thingpedia_result", undefined)], ((ctx, proposal) => D.makeThingpediaRecommendation(ctx, proposal)), D.recommendationKeyFn, { priority: (2) });
    }
    if (!$options.flags.inference) {
        $grammar.addRule("actionable_system_recommendation_short", [new $runtime.NonTerminal("ctx_with_result_noquestion", undefined), new $runtime.NonTerminal("thingpedia_result", ["functionName", 0, "currentFunction"])], ((ctx, proposal) => D.makeThingpediaRecommendation(ctx, proposal)), D.recommendationKeyFn, { priority: (2) });
        $grammar.addRule("actionable_system_recommendation_short", [new $runtime.NonTerminal("ctx_with_result_noquestion", undefined), new $runtime.NonTerminal("thingpedia_result", ["functionName", 0, "currentFunction"])], ((ctx, proposal) => D.makeThingpediaRecommendation(ctx, proposal)), D.recommendationKeyFn, { priority: (2) });
    }
    $grammar.addRule("actionable_system_recommendation_short", [new $runtime.NonTerminal("ctx_with_result_and_action", undefined), "i", new $runtime.Choice(["recommend", "suggest"]), new $runtime.NonTerminal("constant_name", ["value", 0, "id0"])], ((ctx, $0, $1, proposal) => D.makeRecommendation(ctx, proposal)), D.recommendationKeyFn, {});
    $grammar.addRule("actionable_system_recommendation_short", [new $runtime.NonTerminal("ctx_with_result_noquestion", undefined), new $runtime.Choice(["i see", "i have", "i have found", "i have one , it is"]), new $runtime.NonTerminal("constant_name", ["value", 0, "id0"])], ((ctx, $0, proposal) => D.makeRecommendation(ctx, proposal)), D.recommendationKeyFn, {});
    $grammar.addRule("actionable_system_recommendation_short", [new $runtime.NonTerminal("ctx_with_result_argminmax", undefined), "the answer is", new $runtime.NonTerminal("constant_name", ["value", 0, "id0"])], ((ctx, $0, proposal) => D.makeRecommendation(ctx, proposal)), D.recommendationKeyFn, {});
    $grammar.addRule("actionable_system_recommendation_short", [new $runtime.NonTerminal("ctx_with_result_argminmax", undefined), "the", new $runtime.NonTerminal("base_table", ["functionName", 0, "currentFunction"]), "with the highest", new $runtime.NonTerminal("out_param_Any", ["functionName", 0, "currentFunction"]), "is", new $runtime.NonTerminal("constant_name", ["value", 0, "id0"])], ((ctx, $0, base, $1, param, $2, proposal) => D.makeArgMinMaxRecommendation(ctx, proposal, base, param, 'desc')), D.recommendationKeyFn, { priority: (1) });
    $grammar.addRule("actionable_system_recommendation_short", [new $runtime.NonTerminal("ctx_with_result_argminmax", undefined), "the", new $runtime.NonTerminal("base_table", ["functionName", 0, "currentFunction"]), "with the lowest", new $runtime.NonTerminal("out_param_Any", undefined), "is", new $runtime.NonTerminal("constant_name", ["value", 0, "id0"])], ((ctx, $0, base, $1, param, $2, proposal) => D.makeArgMinMaxRecommendation(ctx, proposal, base, param, 'asc')), D.recommendationKeyFn, { priority: (1) });
    $grammar.addRule("actionable_system_recommendation_short", [new $runtime.NonTerminal("ctx_with_result_argminmax", undefined), "the", new $runtime.NonTerminal("apv_argminmax", ["functionName", 0, "currentFunction"]), new $runtime.NonTerminal("base_table", ["functionName", 0, "currentFunction"]), "is", new $runtime.NonTerminal("constant_name", ["value", 0, "id0"])], ((ctx, $0, argminmax, base, $1, proposal) => D.makeArgMinMaxRecommendation(ctx, proposal, base, argminmax[0], argminmax[1])), D.recommendationKeyFn, { priority: (2) });
    $grammar.declareSymbol("recommendation_info_action_pair");
    $grammar.addRule("recommendation_info_action_pair", ["is a", new $runtime.NonTerminal("result_info_phrase", undefined), ".", new $runtime.NonTerminal("action_coref_recommendation", undefined)], (($0, res, $1, action) => {
        const resultType = res.info.schema.getArgType('id');
        if (!resultType || !C.hasArgumentOfType(action, resultType))
            return null;
        return [res, action];
    }), undefined, { weight: (0.8) });
    $grammar.addRule("recommendation_info_action_pair", ["is a", new $runtime.NonTerminal("result_info_phrase", undefined), ".", new $runtime.NonTerminal("learn_more_offer", undefined)], (($0, res, $1, $2) => {
        return [res, null];
    }), undefined, { weight: (0.2) });
    $grammar.declareSymbol("user_question_answer_begin");
    $grammar.addRule("user_question_answer_begin", [new $runtime.NonTerminal("ctx_with_result_question", undefined), new $runtime.NonTerminal("constant_name", ["value", 0, "id0"])], ((ctx, proposal) => D.makeRecommendation(ctx, proposal)), D.recommendationKeyFn, {});
    if ($options.flags.inference) {
        $grammar.addRule("user_question_answer_begin", [new $runtime.NonTerminal("ctx_with_result_question", undefined), new $runtime.NonTerminal("constant_Any", undefined)], ((ctx, proposal) => D.makeRecommendation(ctx, proposal)), D.recommendationKeyFn, {});
    }
    $grammar.declareSymbol("direct_user_question_answer");
    $grammar.addRule("direct_user_question_answer", [new $runtime.NonTerminal("direct_result_info_phrase", undefined)], ((res) => D.makeThingpediaRecommendation(res.ctx, res.info)), D.recommendationKeyFn, {});
    $grammar.declareSymbol("proposal_info_action_pair");
    $grammar.addRule("proposal_info_action_pair", ["is a", new $runtime.NonTerminal("result_info_phrase", undefined), ".", new $runtime.NonTerminal("action_coref_recommendation", undefined)], (($0, res, $1, action) => {
        const resultType = res.info.schema.getArgType('id');
        if (!resultType || !C.hasArgumentOfType(action, resultType))
            return null;
        return [res, action];
    }), undefined, { weight: (0.8) });
    if (!$options.flags.inference) {
        $grammar.addRule("proposal_info_action_pair", ["is a", new $runtime.NonTerminal("result_info_phrase", undefined), ".", new $runtime.NonTerminal("learn_more_offer", undefined)], (($0, res, $1, $2) => {
            return [res, null];
        }), undefined, { weight: (0.2) });
    }
    $grammar.declareSymbol("actionable_system_display_result_short");
    if ($options.flags.inference) {
        $grammar.addRule("actionable_system_display_result_short", [new $runtime.NonTerminal("ctx_with_result", undefined), new $runtime.NonTerminal("ctx_thingpedia_result", undefined), "."], ((ctx, info, $0) => D.makeDisplayResult(ctx, info)), D.recommendationKeyFn, { priority: (5) });
    }
    if (!$options.flags.inference) {
        $grammar.addRule("actionable_system_display_result_short", [new $runtime.NonTerminal("ctx_with_result", undefined), new $runtime.NonTerminal("thingpedia_result", ["functionName", 0, "currentFunction"]), "."], ((ctx, info, $0) => D.makeDisplayResult(ctx, info)), D.recommendationKeyFn, { priority: (5) });
    }
    $grammar.declareSymbol("system_nonlist_result");
    $grammar.addRule("system_nonlist_result", [new $runtime.NonTerminal("actionable_system_display_result_short", undefined)], (($0) => { return $0; }), D.recommendationKeyFn, { identity: (true) });
    $grammar.addRule("system_nonlist_result", [new $runtime.NonTerminal("ctx_with_result_noquestion", undefined), new $runtime.NonTerminal("direct_result_info_phrase", undefined)], ((ctx, res) => D.makeDisplayResult(ctx, res.info)), D.recommendationKeyFn, {});
    $grammar.addRule("system_nonlist_result", [new $runtime.NonTerminal("ctx_with_result_question", undefined), new $runtime.NonTerminal("direct_result_info_phrase", undefined)], ((ctx, res) => D.makeDisplayResult(ctx, res.info)), D.recommendationKeyFn, { priority: (10) });
    $grammar.addRule("system_nonlist_result", [new $runtime.NonTerminal("actionable_system_display_result_short", undefined), new $runtime.NonTerminal("direct_result_info_phrase", undefined)], ((phrase, extra) => D.combineDisplayResult(phrase, extra.info)), D.recommendationKeyFn, {});
    if ($options.flags.anything_else) {
        $grammar.addRule("system_nonlist_result", [new $runtime.NonTerminal("actionable_system_display_result_short", undefined), new $runtime.NonTerminal("anything_else_phrase", undefined)], ((proposal, $0) => {
            const clone = {};
            Object.assign(clone, proposal);
            clone.hasAnythingElse = true;
            return clone;
        }), D.recommendationKeyFn, {});
    }
    $grammar.declareSymbol("system_recommendation");
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("ctx_with_action", undefined), new $runtime.NonTerminal("question_system_recommendation_short", undefined), "."], (($0, proposal, $1) => proposal), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("ctx_with_action", undefined), new $runtime.NonTerminal("actionable_system_recommendation_short", undefined), "."], (($0, proposal, $1) => proposal), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("ctx_with_action", undefined), new $runtime.NonTerminal("actionable_system_recommendation_short", undefined), ".", new $runtime.NonTerminal("learn_more_offer", undefined)], (($0, proposal, $1, $2) => D.recommendationSetLearnMore(proposal)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("ctx_without_projection", undefined), new $runtime.NonTerminal("action_recommendation", undefined)], (($0, proposal) => proposal), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("ctx_without_projection", undefined), new $runtime.NonTerminal("actionable_system_recommendation_short", undefined), new $runtime.NonTerminal("action_coref_recommendation", undefined)], (($0, proposal, action) => D.checkActionForRecommendation(proposal, action)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("question_system_recommendation_short", undefined), "?", "it is a", new $runtime.NonTerminal("result_info_phrase", undefined), "."], ((proposal, $0, $1, res, $2) => D.checkRecommendation(proposal, res.info)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("action_recommendation", undefined), "?", "it is a", new $runtime.NonTerminal("result_info_phrase", undefined), "."], ((proposal, $0, $1, res, $2) => D.checkRecommendation(proposal, res.info)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("actionable_system_recommendation_short", undefined), ".", "it is a", new $runtime.NonTerminal("result_info_phrase", undefined), "."], ((proposal, $0, $1, res, $2) => D.checkRecommendation(proposal, res.info)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("question_system_recommendation_short", undefined), ", which is a", new $runtime.NonTerminal("result_info_phrase", undefined), "?"], ((proposal, $0, res, $1) => D.checkRecommendation(proposal, res.info)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("action_recommendation", undefined), ", which is a", new $runtime.NonTerminal("result_info_phrase", undefined), "?"], ((proposal, $0, res, $1) => D.checkRecommendation(proposal, res.info)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("actionable_system_recommendation_short", undefined), ", which is a", new $runtime.NonTerminal("result_info_phrase", undefined), "."], ((proposal, $0, res, $1) => D.checkRecommendation(proposal, res.info)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("question_system_recommendation_short", undefined), "?"], ((proposal, $0) => proposal), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("action_recommendation", undefined), "?"], ((proposal, $0) => proposal), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("actionable_system_recommendation_short", undefined), "."], ((proposal, $0) => proposal), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("user_question_answer_begin", undefined), "is a", new $runtime.NonTerminal("result_info_phrase", undefined), "."], ((proposal, $0, res, $1) => D.checkRecommendation(proposal, res.info)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("user_question_answer_begin", undefined), new $runtime.NonTerminal("avp_filter", ["functionName", 0, "functionName"]), "."], ((proposal, filter, $0) => D.makeAnswerStyleRecommendation(proposal, filter)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("user_question_answer_begin", undefined), "is", new $runtime.NonTerminal("pvp_filter", ["functionName", 0, "functionName"]), "."], ((proposal, $0, filter, $1) => D.makeAnswerStyleRecommendation(proposal, filter)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("user_question_answer_begin", undefined), "is", new $runtime.NonTerminal("apv_filter", ["functionName", 0, "functionName"]), "."], ((proposal, $0, filter, $1) => D.makeAnswerStyleRecommendation(proposal, filter)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("user_question_answer_begin", undefined), "has", new $runtime.NonTerminal("npp_filter", ["functionName", 0, "functionName"]), "."], ((proposal, $0, filter, $1) => D.makeAnswerStyleRecommendation(proposal, filter)), D.recommendationKeyFn, {});
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("direct_user_question_answer", undefined)], (($0) => { return $0; }), D.recommendationKeyFn, { identity: (true) });
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("actionable_system_recommendation_short", undefined), ". it", new $runtime.NonTerminal("proposal_info_action_pair", undefined)], ((proposal, $0, pair) => {
        const [res, action] = pair;
        const maybeProposal = D.checkRecommendation(proposal, res.info);
        if (maybeProposal === null)
            return null;
        if (action === null)
            return D.recommendationSetLearnMore(maybeProposal);
        return D.checkActionForRecommendation(maybeProposal, action);
    }), D.recommendationKeyFn, { weight: (2) });
    $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("user_question_answer_begin", undefined), new $runtime.NonTerminal("proposal_info_action_pair", undefined)], ((proposal, pair) => {
        const [res, action] = pair;
        const maybeProposal = D.checkRecommendation(proposal, res.info);
        if (maybeProposal === null)
            return null;
        if (action === null)
            return D.recommendationSetLearnMore(maybeProposal);
        return D.checkActionForRecommendation(maybeProposal, action);
    }), D.recommendationKeyFn, { weight: (2) });
    $grammar.declareSymbol("recommendation_accept_phrase_with_action");
    $grammar.addRule("recommendation_accept_phrase_with_action", [new $runtime.NonTerminal("accept_phrase", undefined), new $runtime.NonTerminal("generic_preamble_for_action", undefined), new $runtime.NonTerminal("coref_action_command", undefined)], (($0, $1, action) => action), C.invocationKeyFn, {});
    $grammar.declareSymbol("recommendation_accept_phrase_by_name");
    $grammar.addRule("recommendation_accept_phrase_by_name", [new $runtime.NonTerminal("generic_list_proposal_accept_phrase", undefined)], ((name) => [name, null]), undefined, {});
    $grammar.addRule("recommendation_accept_phrase_by_name", [new $runtime.NonTerminal("list_proposal_accept_phrase_must_have_action", undefined)], ((name) => [name, null]), undefined, {});
    $grammar.addRule("recommendation_accept_phrase_by_name", [new $runtime.NonTerminal("list_proposal_accept_phrase_with_action", undefined)], ((accept) => [accept[0], accept[1]]), undefined, {});
}
exports.default = default_1;
;
//# sourceMappingURL=recommendation.genie.js.map