// -*- mode: js; 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>

// Slot fill templates: the agent asks a question, and the user replies
//
// There are two types slot-fill templates:
// - for searches: the agent is trying to add a filter
// - for actions/queries w/ parameters: the agent is trying to add a parameter

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 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("one_param_direct_search_question");
   $grammar.addRule("one_param_direct_search_question", ["what", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), new $runtime.NonTerminal("prefer_question_phrase", undefined), "?"], (($0 : undefined, p : C.ParamSlot, $1 : string, $2 : undefined) : (C.ParamSlot[])|null => {
        if (p.name === 'id')
            return null;
        if (!p.filterable)
            return null;
        return [p];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("one_param_direct_search_question", [new $runtime.NonTerminal("thingpedia_search_question", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "?"], ((p : C.ParamSlot, $0 : undefined) : (C.ParamSlot[])|null => {
        if (p.name === 'id')
            return null;
        if (!p.filterable)
            return null;
        return [p];
    }), C.paramArrayKeyFn, {  });
   $grammar.declareSymbol("one_param_direct_search_question_with_preamble");
   $grammar.addRule("one_param_direct_search_question_with_preamble", [new $runtime.NonTerminal("search_result_preamble", undefined), new $runtime.NonTerminal("one_param_direct_search_question", undefined)], (($0 : S.ContextInfo, question : C.ParamSlot[]) : (C.ParamSlot[])|null => question), C.paramArrayKeyFn, {  });
   $grammar.declareSymbol("two_param_direct_search_question");
   $grammar.addRule("two_param_direct_search_question", ["what", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "and", new $runtime.NonTerminal("out_param_Any", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 1, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), new $runtime.NonTerminal("prefer_question_phrase", undefined), "?"], (($0 : undefined, p1 : C.ParamSlot, $1 : undefined, p2 : C.ParamSlot, $2 : string, $3 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(p1.schema, p2.schema))
            return null;
        if (p1.name === 'id' || p2.name === 'id' || p1.name === p2.name)
            return null;
        if (!p1.filterable || !p2.filterable)
            return null;
        return [p1, p2];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("two_param_direct_search_question", [new $runtime.NonTerminal("thingpedia_search_question", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "and", "what", new $runtime.NonTerminal("out_param_Any", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 0, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), new $runtime.NonTerminal("prefer_question_phrase", undefined), "?"], ((p1 : C.ParamSlot, $0 : undefined, $1 : undefined, p2 : C.ParamSlot, $2 : string, $3 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(p1.schema, p2.schema))
            return null;
        if (p1.name === 'id' || p2.name === 'id' || p1.name === p2.name)
            return null;
        if (!p1.filterable || !p2.filterable)
            return null;
        return [p1, p2];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("two_param_direct_search_question", ["what", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), new $runtime.NonTerminal("prefer_question_phrase", undefined), "and", new $runtime.NonTerminal("thingpedia_search_question", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 1, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), "?"], (($0 : undefined, p1 : C.ParamSlot, $1 : string, $2 : undefined, p2 : C.ParamSlot, $3 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(p1.schema, p2.schema))
            return null;
        if (p1.name === 'id' || p2.name === 'id' || p1.name === p2.name)
            return null;
        if (!p1.filterable || !p2.filterable)
            return null;
        return [p1, p2];
    }), C.paramArrayKeyFn, {  });
   $grammar.declareSymbol("one_param_yesno_direct_search_question");
   $grammar.addRule("one_param_yesno_direct_search_question", ["any preference of", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "?"], (($0 : undefined, p : C.ParamSlot, $1 : undefined) : (C.ParamSlot[])|null => {
        if (p.name === 'id')
            return null;
        if (!p.filterable)
            return null;
        return [p];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("one_param_yesno_direct_search_question", ["do you have a specific", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "in mind?"], (($0 : undefined, p : C.ParamSlot, $1 : undefined) : (C.ParamSlot[])|null => {
        if (p.name === 'id')
            return null;
        if (!p.filterable)
            return null;
        return [p];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("one_param_yesno_direct_search_question", ["do you have a preference of", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "?"], (($0 : undefined, p : C.ParamSlot, $1 : undefined) : (C.ParamSlot[])|null => {
        if (p.name === 'id')
            return null;
        if (!p.filterable)
            return null;
        return [p];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("one_param_yesno_direct_search_question", ["do you have a preferred", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "?"], (($0 : undefined, p : C.ParamSlot, $1 : undefined) : (C.ParamSlot[])|null => {
        if (p.name === 'id')
            return null;
        if (!p.filterable)
            return null;
        return [p];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("one_param_yesno_direct_search_question", ["are you looking for a specific", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "?"], (($0 : undefined, p : C.ParamSlot, $1 : undefined) : (C.ParamSlot[])|null => {
        if (p.name === 'id')
            return null;
        if (!p.filterable)
            return null;
        return [p];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("one_param_yesno_direct_search_question", ["are you interested in a specific", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "?"], (($0 : undefined, p : C.ParamSlot, $1 : undefined) : (C.ParamSlot[])|null => {
        if (p.name === 'id')
            return null;
        if (!p.filterable)
            return null;
        return [p];
    }), C.paramArrayKeyFn, {  });
   $grammar.declareSymbol("one_param_yesno_direct_search_question_with_preamble");
   $grammar.addRule("one_param_yesno_direct_search_question_with_preamble", [new $runtime.NonTerminal("search_result_preamble", undefined), new $runtime.NonTerminal("one_param_yesno_direct_search_question", undefined)], (($0 : S.ContextInfo, question : C.ParamSlot[]) : (C.ParamSlot[])|null => question), C.paramArrayKeyFn, {  });
   $grammar.declareSymbol("two_param_yesno_direct_search_question");
   $grammar.addRule("two_param_yesno_direct_search_question", ["any preference of", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "or", new $runtime.NonTerminal("out_param_Any", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 1, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), "?"], (($0 : undefined, p1 : C.ParamSlot, $1 : undefined, p2 : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(p1.schema, p2.schema))
            return null;
        if (p1.name === 'id' || p2.name === 'id' || p1.name === p2.name)
            return null;
        if (!p1.filterable || !p2.filterable)
            return null;
        return [p1, p2];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("two_param_yesno_direct_search_question", ["do you have a specific", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "or", new $runtime.NonTerminal("out_param_Any", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 1, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), "in mind?"], (($0 : undefined, p1 : C.ParamSlot, $1 : undefined, p2 : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(p1.schema, p2.schema))
            return null;
        if (p1.name === 'id' || p2.name === 'id' || p1.name === p2.name)
            return null;
        if (!p1.filterable || !p2.filterable)
            return null;
        return [p1, p2];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("two_param_yesno_direct_search_question", ["do you have a preference of", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "or", new $runtime.NonTerminal("out_param_Any", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 1, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), "?"], (($0 : undefined, p1 : C.ParamSlot, $1 : undefined, p2 : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(p1.schema, p2.schema))
            return null;
        if (p1.name === 'id' || p2.name === 'id' || p1.name === p2.name)
            return null;
        if (!p1.filterable || !p2.filterable)
            return null;
        return [p1, p2];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("two_param_yesno_direct_search_question", ["do you have a preferred", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "or", new $runtime.NonTerminal("out_param_Any", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 1, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), "?"], (($0 : undefined, p1 : C.ParamSlot, $1 : undefined, p2 : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(p1.schema, p2.schema))
            return null;
        if (p1.name === 'id' || p2.name === 'id' || p1.name === p2.name)
            return null;
        if (!p1.filterable || !p2.filterable)
            return null;
        return [p1, p2];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("two_param_yesno_direct_search_question", ["are you looking for a specific", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "or", new $runtime.NonTerminal("out_param_Any", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 1, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), "?"], (($0 : undefined, p1 : C.ParamSlot, $1 : undefined, p2 : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(p1.schema, p2.schema))
            return null;
        if (p1.name === 'id' || p2.name === 'id' || p1.name === p2.name)
            return null;
        if (!p1.filterable || !p2.filterable)
            return null;
        return [p1, p2];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("two_param_yesno_direct_search_question", ["are you interested in a specific", new $runtime.NonTerminal("out_param_Any", ["filterable" as ("filterable" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), (true) as ReturnType<typeof C.paramKeyFn>["filterable"]]), "or", new $runtime.NonTerminal("out_param_Any", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 1, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), "?"], (($0 : undefined, p1 : C.ParamSlot, $1 : undefined, p2 : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(p1.schema, p2.schema))
            return null;
        if (p1.name === 'id' || p2.name === 'id' || p1.name === p2.name)
            return null;
        if (!p1.filterable || !p2.filterable)
            return null;
        return [p1, p2];
    }), C.paramArrayKeyFn, {  });
   $grammar.declareSymbol("question_npp_filter_pair");
   $grammar.addRule("question_npp_filter_pair", [new $runtime.NonTerminal("ctx_with_result_noquestion", undefined), new $runtime.NonTerminal("npp_filter", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), "or", new $runtime.NonTerminal("npp_filter", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, f1 : C.FilterSlot, $0 : undefined, f2 : C.FilterSlot) : (C.ParamSlot)|null => D.checkFilterPairForDisjunctiveQuestion(ctx, f1, f2)), C.paramKeyFn, {  });
   $grammar.addRule("question_npp_filter_pair", [new $runtime.NonTerminal("ctx_with_result_noquestion", undefined), new $runtime.NonTerminal("npp_filter", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), "or", new $runtime.NonTerminal("constant_Any", ["type" as ("type" extends keyof ReturnType<typeof C.valueKeyFn> ? string : void), 1, "type" as ("type" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void)])], ((ctx : S.ContextInfo, f1 : C.FilterSlot, $0 : undefined, c : Ast.Value) : (C.ParamSlot)|null => D.checkFilterPairForDisjunctiveQuestionWithConstant(ctx, f1, c)), C.paramKeyFn, {  });
   $grammar.declareSymbol("question_apv_filter_pair");
   $grammar.addRule("question_apv_filter_pair", [new $runtime.NonTerminal("ctx_with_result_noquestion", undefined), new $runtime.NonTerminal("apv_filter", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), "or", new $runtime.NonTerminal("apv_filter", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, f1 : C.FilterSlot, $0 : undefined, f2 : C.FilterSlot) : (C.ParamSlot)|null => D.checkFilterPairForDisjunctiveQuestion(ctx, f1, f2)), C.paramKeyFn, {  });
   $grammar.declareSymbol("question_avp_filter_pair");
   $grammar.addRule("question_avp_filter_pair", [new $runtime.NonTerminal("ctx_with_result_noquestion", undefined), new $runtime.NonTerminal("avp_filter", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), "or", new $runtime.NonTerminal("constant_Any", ["type" as ("type" extends keyof ReturnType<typeof C.valueKeyFn> ? string : void), 1, "type" as ("type" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void)])], ((ctx : S.ContextInfo, f1 : C.FilterSlot, $0 : undefined, c : Ast.Value) : (C.ParamSlot)|null => D.checkFilterPairForDisjunctiveQuestionWithConstant(ctx, f1, c)), C.paramKeyFn, {  });
   $grammar.declareSymbol("question_preposition_filter_pair");
   $grammar.addRule("question_preposition_filter_pair", [new $runtime.NonTerminal("ctx_with_result_noquestion", undefined), new $runtime.NonTerminal("preposition_filter", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), "or", new $runtime.NonTerminal("preposition_filter", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, f1 : C.FilterSlot, $0 : undefined, f2 : C.FilterSlot) : (C.ParamSlot)|null => D.checkFilterPairForDisjunctiveQuestion(ctx, f1, f2)), C.paramKeyFn, {  });
   $grammar.declareSymbol("question_pvp_filter_pair");
   $grammar.addRule("question_pvp_filter_pair", [new $runtime.NonTerminal("ctx_with_result_noquestion", undefined), new $runtime.NonTerminal("pvp_filter", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), "or", new $runtime.NonTerminal("pvp_filter", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.filterKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, f1 : C.FilterSlot, $0 : undefined, f2 : C.FilterSlot) : (C.ParamSlot)|null => D.checkFilterPairForDisjunctiveQuestion(ctx, f1, f2)), C.paramKeyFn, {  });
   $grammar.declareSymbol("disjunctive_search_question");
   $grammar.addRule("disjunctive_search_question", [new $runtime.Choice(["are you looking for", "would you like", "do you need"]), "something with", new $runtime.NonTerminal("question_npp_filter_pair", undefined), "?"], (($0 : undefined, $1 : undefined, question : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => [question]), C.paramArrayKeyFn, {  });
   $grammar.addRule("disjunctive_search_question", [new $runtime.Choice(["are you looking for", "would you like", "do you need"]), "something", new $runtime.NonTerminal("question_apv_filter_pair", undefined), "?"], (($0 : undefined, $1 : undefined, question : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => [question]), C.paramArrayKeyFn, {  });
   $grammar.addRule("disjunctive_search_question", [new $runtime.Choice(["are you looking for", "would you like", "do you need"]), "something", new $runtime.NonTerminal("question_preposition_filter_pair", undefined), "?"], (($0 : undefined, $1 : undefined, question : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => [question]), C.paramArrayKeyFn, {  });
   $grammar.addRule("disjunctive_search_question", [new $runtime.Choice(["are you looking for", "would you like", "do you need"]), "something", new $runtime.NonTerminal("question_pvp_filter_pair", undefined), "?"], (($0 : undefined, $1 : undefined, question : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => [question]), C.paramArrayKeyFn, {  });
   $grammar.addRule("disjunctive_search_question", [new $runtime.Choice(["are you looking for", "would you like", "do you need"]), "something that", new $runtime.NonTerminal("question_avp_filter_pair", undefined), "?"], (($0 : undefined, $1 : undefined, question : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => [question]), C.paramArrayKeyFn, {  });
   $grammar.addRule("disjunctive_search_question", [new $runtime.Choice(["are you looking for", "would you like", "do you need"]), "a", new $runtime.NonTerminal("base_table", undefined), new $runtime.Choice(["with", "that has"]), new $runtime.NonTerminal("question_npp_filter_pair", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 2, "functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void)]), "?"], (($0 : undefined, $1 : undefined, table : Ast.InvocationExpression, $2 : undefined, question : C.ParamSlot, $3 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(table.schema!, question.schema))
            return null;
        return [question];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("disjunctive_search_question", [new $runtime.Choice(["are you looking for", "would you like", "do you need"]), "a", new $runtime.NonTerminal("question_apv_filter_pair", undefined), new $runtime.NonTerminal("base_table", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void), 2, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), "?"], (($0 : undefined, $1 : undefined, question : C.ParamSlot, table : Ast.InvocationExpression, $2 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(table.schema!, question.schema))
            return null;
        return [question];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("disjunctive_search_question", [new $runtime.Choice(["are you looking for", "would you like", "do you need"]), "a", new $runtime.NonTerminal("base_table", undefined), new $runtime.NonTerminal("question_pvp_filter_pair", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 2, "functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void)]), "?"], (($0 : undefined, $1 : undefined, table : Ast.InvocationExpression, question : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(table.schema!, question.schema))
            return null;
        return [question];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("disjunctive_search_question", [new $runtime.Choice(["are you looking for", "would you like", "do you need"]), "a", new $runtime.NonTerminal("base_table", undefined), new $runtime.NonTerminal("question_preposition_filter_pair", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 2, "functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void)]), "?"], (($0 : undefined, $1 : undefined, table : Ast.InvocationExpression, question : C.ParamSlot, $2 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(table.schema!, question.schema))
            return null;
        return [question];
    }), C.paramArrayKeyFn, {  });
   $grammar.addRule("disjunctive_search_question", [new $runtime.Choice(["are you looking for", "would you like", "do you need"]), "a", new $runtime.NonTerminal("base_table", undefined), "that", new $runtime.NonTerminal("question_avp_filter_pair", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 2, "functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void)]), "?"], (($0 : undefined, $1 : undefined, table : Ast.InvocationExpression, $2 : undefined, question : C.ParamSlot, $3 : undefined) : (C.ParamSlot[])|null => {
        if (!C.isSameFunction(table.schema!, question.schema))
            return null;
        return [question];
    }), C.paramArrayKeyFn, {  });
   $grammar.declareSymbol("generic_question");
   $grammar.addRule("generic_question", ["which one would you like ?"], (($0 : undefined) : (never[])|null => []), undefined, {  });
   $grammar.addRule("generic_question", ["do you have a specific one in mind ?"], (($0 : undefined) : (never[])|null => []), undefined, {  });
   $grammar.addRule("generic_question", ["do you have any more information to narrow down the search ?"], (($0 : undefined) : (never[])|null => []), undefined, {  });
   $grammar.declareSymbol("simple_search_question");
   $grammar.addRule("simple_search_question", [new $runtime.NonTerminal("one_param_direct_search_question", undefined)], (($0 : C.ParamSlot[]) : (C.ParamSlot[])|null => { return $0; }), C.paramArrayKeyFn, { priority: (0.1), identity: (true) });
   $grammar.addRule("simple_search_question", [new $runtime.NonTerminal("two_param_direct_search_question", undefined)], (($0 : C.ParamSlot[]) : (C.ParamSlot[])|null => { return $0; }), C.paramArrayKeyFn, { identity: (true) });
   if ($options.flags.disjunctive_search_questions) {
       $grammar.addRule("simple_search_question", [new $runtime.NonTerminal("disjunctive_search_question", undefined)], (($0 : C.ParamSlot[]) : (C.ParamSlot[])|null => { return $0; }), C.paramArrayKeyFn, { identity: (true) });
   }
   $grammar.addRule("simple_search_question", [new $runtime.NonTerminal("one_param_yesno_direct_search_question", undefined)], (($0 : C.ParamSlot[]) : (C.ParamSlot[])|null => { return $0; }), C.paramArrayKeyFn, { priority: (0.1), identity: (true) });
   $grammar.addRule("simple_search_question", [new $runtime.NonTerminal("two_param_yesno_direct_search_question", undefined)], (($0 : C.ParamSlot[]) : (C.ParamSlot[])|null => { return $0; }), C.paramArrayKeyFn, { identity: (true) });
   $grammar.declareSymbol("search_question");
   $grammar.addRule("search_question", [new $runtime.NonTerminal("simple_search_question", undefined)], (($0 : C.ParamSlot[]) : (C.ParamSlot[])|null => { return $0; }), C.paramArrayKeyFn, { identity: (true) });
   $grammar.addRule("search_question", [new $runtime.NonTerminal("search_result_preamble", undefined), new $runtime.NonTerminal("simple_search_question", undefined)], (($0 : S.ContextInfo, question : C.ParamSlot[]) : (C.ParamSlot[])|null => question), C.paramArrayKeyFn, { weight: (0.1) });
   $grammar.declareSymbol("verbose_search_answer");
   $grammar.addRule("verbose_search_answer", [new $runtime.NonTerminal("generic_preamble_for_answer", undefined), new $runtime.Choice(["a", "the"]), new $runtime.NonTerminal("answer_noun_phrase", undefined)], (($0 : string, $1 : undefined, query : Ast.Expression) : (Ast.Expression)|null => query), C.expressionKeyFn, {  });
   $grammar.addRule("verbose_search_answer", [new $runtime.NonTerminal("generic_preamble_for_answer", undefined), new $runtime.NonTerminal("anything_phrase", undefined)], (($0 : string, query : Ast.Expression) : (Ast.Expression)|null => query), C.expressionKeyFn, {  });
   $grammar.declareSymbol("verbose_search_answer_with_action");
   $grammar.addRule("verbose_search_answer_with_action", [new $runtime.NonTerminal("verbose_search_answer", undefined), new $runtime.Choice([".", ","]), new $runtime.NonTerminal("generic_preamble_for_action", undefined), new $runtime.NonTerminal("coref_action_command", undefined)], ((query : Ast.Expression, $0 : undefined, $1 : string, action : Ast.Invocation) : ([Ast.Expression, Ast.Invocation])|null => {
        // check that one of the parameters of action has the right type to param pass into the action
        let idArg = query.schema!.getArgument('id');
        if (!idArg)
            return null;

        let found = false;
        for (let arg of action.schema!.iterateArguments()) {
            if (!arg.is_input)
                continue
            if (arg.type.equals(idArg.type)) {
                found = true;
                break;
            }
        }
        if (!found)
            return null;
        return [query, action];
    }), undefined, {  });
   $grammar.declareSymbol("precise_search_question_answer");
   $grammar.addRule("precise_search_question_answer", [new $runtime.NonTerminal("verbose_search_answer", undefined)], ((table : Ast.Expression) : (D.PreciseSearchQuestionAnswer)|null => [table, null, false]), D.preciseSearchQuestionAnswerKeyFn, {  });
   $grammar.addRule("precise_search_question_answer", [new $runtime.Choice(["yes", "yes ,", ""]), new $runtime.NonTerminal("verbose_search_answer", undefined)], (($0 : undefined, table : Ast.Expression) : (D.PreciseSearchQuestionAnswer)|null => [table, null, true]), D.preciseSearchQuestionAnswerKeyFn, {  });
   $grammar.addRule("precise_search_question_answer", [new $runtime.NonTerminal("verbose_search_answer_with_action", undefined)], ((table_action : [Ast.Expression, Ast.Invocation]) : (D.PreciseSearchQuestionAnswer)|null => [...table_action, false]), D.preciseSearchQuestionAnswerKeyFn, {  });
   $grammar.addRule("precise_search_question_answer", [new $runtime.Choice(["yes", "yes ,", ""]), new $runtime.NonTerminal("verbose_search_answer_with_action", undefined)], (($0 : undefined, table_action : [Ast.Expression, Ast.Invocation]) : (D.PreciseSearchQuestionAnswer)|null => [...table_action, true]), D.preciseSearchQuestionAnswerKeyFn, {  });
   $grammar.declareSymbol("specific_dontcare_phrase");
   $grammar.addRule("specific_dontcare_phrase", ["the", new $runtime.NonTerminal("out_param_Any", undefined), "does not matter ."], (($0 : undefined, param : C.ParamSlot, $1 : undefined) : (C.FilterSlot)|null => C.makeDontCareFilter(param)), C.filterKeyFn, {  });
   $grammar.addRule("specific_dontcare_phrase", ["the", new $runtime.NonTerminal("out_param_Any", undefined), "is not an issue ."], (($0 : undefined, param : C.ParamSlot, $1 : undefined) : (C.FilterSlot)|null => C.makeDontCareFilter(param)), C.filterKeyFn, {  });
   $grammar.addRule("specific_dontcare_phrase", ["the", new $runtime.NonTerminal("out_param_Any", undefined), "is not important ."], (($0 : undefined, param : C.ParamSlot, $1 : undefined) : (C.FilterSlot)|null => C.makeDontCareFilter(param)), C.filterKeyFn, {  });
   $grammar.addRule("specific_dontcare_phrase", ["the", new $runtime.NonTerminal("out_param_Any", undefined), "does not matter . can you suggest one ?"], (($0 : undefined, param : C.ParamSlot, $1 : undefined) : (C.FilterSlot)|null => C.makeDontCareFilter(param)), C.filterKeyFn, {  });
   $grammar.addRule("specific_dontcare_phrase", ["i", new $runtime.Choice(["do not have a", "have no"]), "preference of ", new $runtime.NonTerminal("out_param_Any", undefined), "."], (($0 : undefined, $1 : undefined, $2 : undefined, param : C.ParamSlot, $3 : undefined) : (C.FilterSlot)|null => C.makeDontCareFilter(param)), C.filterKeyFn, {  });
   $grammar.addRule("specific_dontcare_phrase", ["i", new $runtime.Choice(["do not have a", "have no"]), "preference of ", new $runtime.NonTerminal("out_param_Any", undefined), ". what do you recommend ?"], (($0 : undefined, $1 : undefined, $2 : undefined, param : C.ParamSlot, $3 : undefined) : (C.FilterSlot)|null => C.makeDontCareFilter(param)), C.filterKeyFn, {  });
   $grammar.addRule("specific_dontcare_phrase", ["i have no preference of ", new $runtime.NonTerminal("out_param_Any", undefined), ". please make a recommendation ."], (($0 : undefined, param : C.ParamSlot, $1 : undefined) : (C.FilterSlot)|null => C.makeDontCareFilter(param)), C.filterKeyFn, {  });
   $grammar.addRule("specific_dontcare_phrase", [new $runtime.Choice(["i do not care that it has", "it need not have", "i do not need"]), new $runtime.NonTerminal("npp_filter", undefined)], (($0 : undefined, param : C.FilterSlot) : (C.FilterSlot)|null => {
        if (!(param.ast instanceof Ast.AtomBooleanExpression))
            return null;
        if (!(param.ast.value instanceof Ast.BooleanValue) || param.ast.value.value !== true)
            return null;
        return C.makeDontCareFilter({ schema: param.schema, type: param.ptype, name: param.ast.name,
            filterable: param.schema.getArgument(param.ast.name)!.getImplementationAnnotation<boolean>('filterable') ?? true,
            ast: new Ast.Value.VarRef(param.ast.name) });
    }), C.filterKeyFn, {  });
   $grammar.declareSymbol("coref_constant");
   $grammar.addRule("coref_constant", [new $runtime.NonTerminal("ctx_multidomain", undefined), new $runtime.Choice(["the", "the same"]), new $runtime.NonTerminal("base_table", undefined), "'s", new $runtime.NonTerminal("out_param_Any", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 2, "functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void)]), "."], ((ctx : S.ContextInfo, $0 : undefined, base : Ast.InvocationExpression, $1 : undefined, param : C.ParamSlot, $2 : undefined) : (Ast.Value)|null => D.corefConstant(ctx, base, param)), C.valueKeyFn, {  });
   $grammar.addRule("coref_constant", [new $runtime.NonTerminal("ctx_multidomain", undefined), new $runtime.NonTerminal("generic_preamble_for_answer", undefined), new $runtime.Choice(["the", "the same"]), new $runtime.NonTerminal("base_table", undefined), "'s", new $runtime.NonTerminal("out_param_Any", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void), 3, "functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void)]), "."], ((ctx : S.ContextInfo, $0 : string, $1 : undefined, base : Ast.InvocationExpression, $2 : undefined, param : C.ParamSlot, $3 : undefined) : (Ast.Value)|null => D.corefConstant(ctx, base, param)), C.valueKeyFn, {  });
   $grammar.addRule("coref_constant", [new $runtime.NonTerminal("ctx_multidomain", undefined), "the same", new $runtime.NonTerminal("out_param_Any", undefined), "as", "the", new $runtime.NonTerminal("base_table", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void), 2, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), "."], ((ctx : S.ContextInfo, $0 : undefined, param : C.ParamSlot, $1 : undefined, $2 : undefined, base : Ast.InvocationExpression, $3 : undefined) : (Ast.Value)|null => D.corefConstant(ctx, base, param)), C.valueKeyFn, {  });
   $grammar.addRule("coref_constant", [new $runtime.NonTerminal("ctx_multidomain", undefined), new $runtime.NonTerminal("generic_preamble_for_answer", undefined), "the same", new $runtime.NonTerminal("out_param_Any", undefined), "as", "the", new $runtime.NonTerminal("base_table", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void), 3, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), "."], ((ctx : S.ContextInfo, $0 : string, $1 : undefined, param : C.ParamSlot, $2 : undefined, $3 : undefined, base : Ast.InvocationExpression, $4 : undefined) : (Ast.Value)|null => D.corefConstant(ctx, base, param)), C.valueKeyFn, {  });
   $grammar.addRule("coref_constant", [new $runtime.NonTerminal("ctx_multidomain", undefined), new $runtime.Choice(["the same as the", "the"]), new $runtime.NonTerminal("out_param_Any", undefined), "of", "the", new $runtime.NonTerminal("base_table", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void), 2, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), "."], ((ctx : S.ContextInfo, $0 : undefined, param : C.ParamSlot, $1 : undefined, $2 : undefined, base : Ast.InvocationExpression, $3 : undefined) : (Ast.Value)|null => D.corefConstant(ctx, base, param)), C.valueKeyFn, {  });
   $grammar.addRule("coref_constant", [new $runtime.NonTerminal("ctx_multidomain", undefined), new $runtime.NonTerminal("generic_preamble_for_answer", undefined), new $runtime.Choice(["the same as the", "the"]), new $runtime.NonTerminal("out_param_Any", undefined), "of", "the", new $runtime.NonTerminal("base_table", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void), 3, "functionName" as ("functionName" extends keyof ReturnType<typeof C.paramKeyFn> ? string : void)]), "."], ((ctx : S.ContextInfo, $0 : string, $1 : undefined, param : C.ParamSlot, $2 : undefined, $3 : undefined, base : Ast.InvocationExpression, $4 : undefined) : (Ast.Value)|null => D.corefConstant(ctx, base, param)), C.valueKeyFn, {  });
   $grammar.declareSymbol("imprecise_search_coref_answer");
   $grammar.addRule("imprecise_search_coref_answer", [new $runtime.NonTerminal("coref_constant", undefined)], ((slot : Ast.Value) : (Ast.Value|C.FilterSlot)|null => slot), undefined, {  });
   $grammar.addRule("imprecise_search_coref_answer", [new $runtime.NonTerminal("coref_npp_filter", undefined)], ((slot : C.FilterSlot) : (Ast.Value|C.FilterSlot)|null => slot), undefined, {  });
   $grammar.addRule("imprecise_search_coref_answer", [new $runtime.NonTerminal("coref_apv_filter", undefined)], ((slot : C.FilterSlot) : (Ast.Value|C.FilterSlot)|null => slot), undefined, {  });
   $grammar.addRule("imprecise_search_coref_answer", [new $runtime.NonTerminal("coref_pvp_filter", undefined)], ((slot : C.FilterSlot) : (Ast.Value|C.FilterSlot)|null => slot), undefined, {  });
   $grammar.addRule("imprecise_search_coref_answer", [new $runtime.NonTerminal("coref_preposition_filter", undefined)], ((slot : C.FilterSlot) : (Ast.Value|C.FilterSlot)|null => slot), undefined, {  });
   $grammar.declareSymbol("imprecise_search_answer_phrase");
   $grammar.addRule("imprecise_search_answer_phrase", [new $runtime.NonTerminal("constant_Any", undefined)], ((slot : Ast.Value) : (Ast.Value|C.FilterSlot)|null => slot), undefined, {  });
   $grammar.addRule("imprecise_search_answer_phrase", [new $runtime.NonTerminal("npp_filter", undefined)], ((slot : C.FilterSlot) : (Ast.Value|C.FilterSlot)|null => slot), undefined, {  });
   $grammar.addRule("imprecise_search_answer_phrase", [new $runtime.NonTerminal("apv_filter", undefined)], ((slot : C.FilterSlot) : (Ast.Value|C.FilterSlot)|null => slot), undefined, {  });
   $grammar.addRule("imprecise_search_answer_phrase", [new $runtime.NonTerminal("pvp_filter", undefined)], ((slot : C.FilterSlot) : (Ast.Value|C.FilterSlot)|null => slot), undefined, {  });
   $grammar.addRule("imprecise_search_answer_phrase", [new $runtime.NonTerminal("preposition_filter", undefined)], ((slot : C.FilterSlot) : (Ast.Value|C.FilterSlot)|null => slot), undefined, {  });
   $grammar.declareSymbol("imprecise_search_answer");
   $grammar.addRule("imprecise_search_answer", [new $runtime.NonTerminal("imprecise_search_answer_phrase", undefined), new $runtime.Choice(["please", ""]), "."], ((ans : Ast.Value|C.FilterSlot, $0 : undefined, $1 : undefined) : (Ast.Value|C.FilterSlot)|null => ans), undefined, {  });
   $grammar.addRule("imprecise_search_answer", [new $runtime.NonTerminal("generic_preamble_for_answer", undefined), new $runtime.NonTerminal("imprecise_search_answer_phrase", undefined), "."], (($0 : string, ans : Ast.Value|C.FilterSlot, $1 : undefined) : (Ast.Value|C.FilterSlot)|null => ans), undefined, {  });
   $grammar.declareSymbol("imprecise_search_question_answer");
   $grammar.addRule("imprecise_search_question_answer", [new $runtime.NonTerminal("imprecise_search_answer", undefined)], (($0 : Ast.Value|C.FilterSlot) : (Ast.Value|C.FilterSlot|'dontcare')|null => { return $0; }), undefined, { identity: (true) });
   $grammar.addRule("imprecise_search_question_answer", [new $runtime.NonTerminal("imprecise_search_coref_answer", undefined)], (($0 : Ast.Value|C.FilterSlot) : (Ast.Value|C.FilterSlot|'dontcare')|null => { return $0; }), undefined, { identity: (true) });
   if ($options.flags.dontcare) {
       $grammar.addRule("imprecise_search_question_answer", [new $runtime.NonTerminal("generic_dontcare_phrase", undefined)], (($0 : string) : (Ast.Value|C.FilterSlot|'dontcare')|null => 'dontcare'), undefined, { weight: (0.1) });
       $grammar.addRule("imprecise_search_question_answer", [new $runtime.NonTerminal("no_dontcare_phrase", undefined)], (($0 : string) : (Ast.Value|C.FilterSlot|'dontcare')|null => 'dontcare'), undefined, { weight: (0.1) });
       $grammar.addRule("imprecise_search_question_answer", [new $runtime.NonTerminal("specific_dontcare_phrase", undefined)], (($0 : C.FilterSlot) : (Ast.Value|C.FilterSlot|'dontcare')|null => { return $0; }), undefined, { identity: (true) });
   }
};
