// -*- 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>

// Recommendation templates: the agent reads out or describe the top result from the search,
// optionally proposing an action to do on it

// A recommendation from the system is followed by:
// - yes (= "positive_recommendation_reply_pair")
// - some form of search refinement (= "negative_recommendation_reply_pair")
// - a question (= "recommendation_search_question_pair")
// - closing the dialogue (= "recommendation_cancel_pair")

import { Ast, } from 'thingtalk';
import * as C from '../../ast_manip';
import * as D from '../../dialogue_acts';
import * as S from '../../state_manip';
import ThingpediaLoader from '../../load-thingpedia';
import { SlotBag } from '../../slot_bag';
import type * as $Genie from "genie-toolkit";
export default async function($runtime : typeof $Genie.SentenceGeneratorRuntime, $ttUtils : typeof $Genie.ThingTalkUtils, $options : $Genie.SentenceGeneratorTypes.GrammarOptions, $locale : $Genie.I18n.LanguagePack, $grammar : $Genie.SentenceGenerator<any, any>, $loader : ThingpediaLoader) : Promise<void> {
   $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" as ("value" extends keyof ReturnType<typeof C.entityOrNumberValueKeyFn> ? string : void), 0, "id0" as ("id0" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, $0 : undefined, proposal : Ast.EntityValue|Ast.NumberValue) : (D.Recommendation)|null => 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" as ("functionName" extends keyof ReturnType<typeof C.invocationKeyFn> ? string : void), 0, "nextFunction" as ("nextFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, $0 : undefined, action : Ast.Invocation) : (D.Recommendation)|null => 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 : S.ContextInfo, proposal : SlotBag) : (D.Recommendation)|null => 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 : S.ContextInfo, proposal : SlotBag) : (D.Recommendation)|null => 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" as ("functionName" extends keyof ReturnType<typeof C.slotBagKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, proposal : SlotBag) : (D.Recommendation)|null => 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" as ("functionName" extends keyof ReturnType<typeof C.slotBagKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, proposal : SlotBag) : (D.Recommendation)|null => 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" as ("value" extends keyof ReturnType<typeof C.entityOrNumberValueKeyFn> ? string : void), 0, "id0" as ("id0" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, $0 : undefined, $1 : undefined, proposal : Ast.EntityValue|Ast.NumberValue) : (D.Recommendation)|null => 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" as ("value" extends keyof ReturnType<typeof C.entityOrNumberValueKeyFn> ? string : void), 0, "id0" as ("id0" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, $0 : undefined, proposal : Ast.EntityValue|Ast.NumberValue) : (D.Recommendation)|null => 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" as ("value" extends keyof ReturnType<typeof C.entityOrNumberValueKeyFn> ? string : void), 0, "id0" as ("id0" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, $0 : undefined, proposal : Ast.EntityValue|Ast.NumberValue) : (D.Recommendation)|null => 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" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), "with the highest", new $runtime.NonTerminal("out_param_Any", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), "is", new $runtime.NonTerminal("constant_name", ["value" as ("value" extends keyof ReturnType<typeof C.entityOrNumberValueKeyFn> ? string : void), 0, "id0" as ("id0" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, $0 : undefined, base : Ast.InvocationExpression, $1 : undefined, param : C.ParamSlot, $2 : undefined, proposal : Ast.EntityValue|Ast.NumberValue) : (D.Recommendation)|null => 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" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), "with the lowest", new $runtime.NonTerminal("out_param_Any", undefined), "is", new $runtime.NonTerminal("constant_name", ["value" as ("value" extends keyof ReturnType<typeof C.entityOrNumberValueKeyFn> ? string : void), 0, "id0" as ("id0" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, $0 : undefined, base : Ast.InvocationExpression, $1 : undefined, param : C.ParamSlot, $2 : undefined, proposal : Ast.EntityValue|Ast.NumberValue) : (D.Recommendation)|null => 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" as ("functionName" extends keyof ReturnType<typeof C.argMinMaxKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), new $runtime.NonTerminal("base_table", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), "is", new $runtime.NonTerminal("constant_name", ["value" as ("value" extends keyof ReturnType<typeof C.entityOrNumberValueKeyFn> ? string : void), 0, "id0" as ("id0" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, $0 : undefined, argminmax : C.ArgMinMax, base : Ast.InvocationExpression, $1 : undefined, proposal : Ast.EntityValue|Ast.NumberValue) : (D.Recommendation)|null => 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 : undefined, res : D.ResultPhrase, $1 : undefined, action : Ast.Invocation) : ([D.ResultPhrase, Ast.Invocation|null])|null => {
        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 : undefined, res : D.ResultPhrase, $1 : undefined, $2 : string) : ([D.ResultPhrase, Ast.Invocation|null])|null => {
        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" as ("value" extends keyof ReturnType<typeof C.entityOrNumberValueKeyFn> ? string : void), 0, "id0" as ("id0" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, proposal : Ast.EntityValue|Ast.NumberValue) : (D.Recommendation)|null => 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 : S.ContextInfo, proposal : Ast.Value) : (D.Recommendation)|null => 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.ResultPhrase) : (D.Recommendation)|null => 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 : undefined, res : D.ResultPhrase, $1 : undefined, action : Ast.Invocation) : ([D.ResultPhrase, Ast.Invocation|null])|null => {
        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 : undefined, res : D.ResultPhrase, $1 : undefined, $2 : string) : ([D.ResultPhrase, Ast.Invocation|null])|null => {
            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 : S.ContextInfo, info : SlotBag, $0 : undefined) : (D.Recommendation)|null => 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" as ("functionName" extends keyof ReturnType<typeof C.slotBagKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), "."], ((ctx : S.ContextInfo, info : SlotBag, $0 : undefined) : (D.Recommendation)|null => 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 : D.Recommendation) : (D.Recommendation)|null => { 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 : S.ContextInfo, res : D.ResultPhrase) : (D.Recommendation)|null => 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 : S.ContextInfo, res : D.ResultPhrase) : (D.Recommendation)|null => 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 : D.Recommendation, extra : D.ResultPhrase) : (D.Recommendation)|null => 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 : D.Recommendation, $0 : string) : (D.Recommendation)|null => {
        const clone : any = {};
        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 : S.ContextInfo, proposal : D.Recommendation, $1 : undefined) : (D.Recommendation)|null => proposal), D.recommendationKeyFn, {  });
   $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("ctx_with_action", undefined), new $runtime.NonTerminal("actionable_system_recommendation_short", undefined), "."], (($0 : S.ContextInfo, proposal : D.Recommendation, $1 : undefined) : (D.Recommendation)|null => 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 : S.ContextInfo, proposal : D.Recommendation, $1 : undefined, $2 : string) : (D.Recommendation)|null => D.recommendationSetLearnMore(proposal)), D.recommendationKeyFn, {  });
   $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("ctx_without_projection", undefined), new $runtime.NonTerminal("action_recommendation", undefined)], (($0 : S.ContextInfo, proposal : D.Recommendation) : (D.Recommendation)|null => 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 : S.ContextInfo, proposal : D.Recommendation, action : Ast.Invocation) : (D.Recommendation)|null => 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 : D.Recommendation, $0 : undefined, $1 : undefined, res : D.ResultPhrase, $2 : undefined) : (D.Recommendation)|null => 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 : D.Recommendation, $0 : undefined, $1 : undefined, res : D.ResultPhrase, $2 : undefined) : (D.Recommendation)|null => 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 : D.Recommendation, $0 : undefined, $1 : undefined, res : D.ResultPhrase, $2 : undefined) : (D.Recommendation)|null => 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 : D.Recommendation, $0 : undefined, res : D.ResultPhrase, $1 : undefined) : (D.Recommendation)|null => 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 : D.Recommendation, $0 : undefined, res : D.ResultPhrase, $1 : undefined) : (D.Recommendation)|null => 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 : D.Recommendation, $0 : undefined, res : D.ResultPhrase, $1 : undefined) : (D.Recommendation)|null => D.checkRecommendation(proposal, res.info)), D.recommendationKeyFn, {  });
   $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("question_system_recommendation_short", undefined), "?"], ((proposal : D.Recommendation, $0 : undefined) : (D.Recommendation)|null => proposal), D.recommendationKeyFn, {  });
   $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("action_recommendation", undefined), "?"], ((proposal : D.Recommendation, $0 : undefined) : (D.Recommendation)|null => proposal), D.recommendationKeyFn, {  });
   $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("actionable_system_recommendation_short", undefined), "."], ((proposal : D.Recommendation, $0 : undefined) : (D.Recommendation)|null => 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 : D.Recommendation, $0 : undefined, res : D.ResultPhrase, $1 : undefined) : (D.Recommendation)|null => 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" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "functionName" as ("functionName" extends keyof ReturnType<typeof D.recommendationKeyFn> ? string : void)]), "."], ((proposal : D.Recommendation, filter : C.FilterSlot, $0 : undefined) : (D.Recommendation)|null => 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" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "functionName" as ("functionName" extends keyof ReturnType<typeof D.recommendationKeyFn> ? string : void)]), "."], ((proposal : D.Recommendation, $0 : undefined, filter : C.FilterSlot, $1 : undefined) : (D.Recommendation)|null => 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" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "functionName" as ("functionName" extends keyof ReturnType<typeof D.recommendationKeyFn> ? string : void)]), "."], ((proposal : D.Recommendation, $0 : undefined, filter : C.FilterSlot, $1 : undefined) : (D.Recommendation)|null => 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" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "functionName" as ("functionName" extends keyof ReturnType<typeof D.recommendationKeyFn> ? string : void)]), "."], ((proposal : D.Recommendation, $0 : undefined, filter : C.FilterSlot, $1 : undefined) : (D.Recommendation)|null => D.makeAnswerStyleRecommendation(proposal, filter)), D.recommendationKeyFn, {  });
   $grammar.addRule("system_recommendation", [new $runtime.NonTerminal("direct_user_question_answer", undefined)], (($0 : D.Recommendation) : (D.Recommendation)|null => { 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 : D.Recommendation, $0 : undefined, pair : [D.ResultPhrase, Ast.Invocation|null]) : (D.Recommendation)|null => {
        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 : D.Recommendation, pair : [D.ResultPhrase, Ast.Invocation|null]) : (D.Recommendation)|null => {
        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 : string, $1 : string, action : Ast.Invocation) : (Ast.Invocation)|null => 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 : Ast.EntityValue|Ast.NumberValue) : ([Ast.EntityValue|Ast.NumberValue, Ast.Invocation|null])|null => [name, null]), undefined, {  });
   $grammar.addRule("recommendation_accept_phrase_by_name", [new $runtime.NonTerminal("list_proposal_accept_phrase_must_have_action", undefined)], ((name : Ast.EntityValue|Ast.NumberValue) : ([Ast.EntityValue|Ast.NumberValue, Ast.Invocation|null])|null => [name, null]), undefined, {  });
   $grammar.addRule("recommendation_accept_phrase_by_name", [new $runtime.NonTerminal("list_proposal_accept_phrase_with_action", undefined)], ((accept : [Ast.EntityValue|Ast.NumberValue, Ast.Invocation, boolean]) : ([Ast.EntityValue|Ast.NumberValue, Ast.Invocation|null])|null => [accept[0], accept[1]]), undefined, {  });
};
