// -*- 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 // Refinement templates: the search is NOT complete (0, or more than 1 result), and the // agent doesn't want to show results // // These include proposals, and empty search errors. // A proposal is when the agent proposed a refined search; the user answers: // - some form of "yes" // - some form of "no" followed by another search refinement import * as $runtime from "../../sentence-generator/runtime"; import type $SentenceGenerator from "../../sentence-generator/generator"; import * as $SentenceGeneratorTypes from "../../sentence-generator/types"; import * as $I18n from "../../i18n/index"; 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'; export const search_result_preamble : $SentenceGeneratorTypes.NonTerminal = "search_result_preamble"; export const system_generic_proposal : $SentenceGeneratorTypes.NonTerminal = "system_generic_proposal"; export const negative_proposal_request : $SentenceGeneratorTypes.NonTerminal = "negative_proposal_request"; export const negative_proposal_answer_preamble : $SentenceGeneratorTypes.NonTerminal = "negative_proposal_answer_preamble"; export const negative_proposal_reply : $SentenceGeneratorTypes.NonTerminal = "negative_proposal_reply"; /** * Load the templates in this file. * * This is an autogenerated method that will be called by the {@link SentenceGenerator} * when the templates are imported. */ export async function $load($options : $SentenceGeneratorTypes.GrammarOptions, $locale : $I18n.LanguagePack, $grammar : $SentenceGenerator, $loader : ThingpediaLoader) : Promise { $grammar.declareSymbol("search_result_preamble"); $grammar.addRule("search_result_preamble", [new $runtime.NonTerminal("ctx_search_command", "ctx", undefined), new $runtime.NonTerminal("base_noun_phrase", "base", ["functionName" as ("functionName" extends keyof ReturnType ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType ? string : void)])], $locale._("{there are|i can see|i have found|i can recommend} {many|several} ${base[plural=other]} {matching your request|matching your constraints|with those characteristics|like that|}."), ((ctx : S.ContextInfo, base : Ast.FunctionDef) : (S.ContextInfo)|null => D.checkSearchResultPreamble(ctx, base, null, false)), S.contextKeyFn, { }); $grammar.addRule("search_result_preamble", [new $runtime.NonTerminal("ctx_search_command", "ctx", undefined), new $runtime.NonTerminal("base_noun_phrase", "base", ["functionName" as ("functionName" extends keyof ReturnType ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType ? string : void)])], $locale._("{there are|i can see|i have found|i have} ${ctx.resultLength} ${ctx.resultLength:plural:one{${base[plural=one]}}other{${base[plural=other]}}} {in my database|like that|}."), ((ctx : S.ContextInfo, base : Ast.FunctionDef) : (S.ContextInfo)|null => D.checkSearchResultPreamble(ctx, base, null, false)), S.contextKeyFn, { }); $grammar.declareSymbol("system_generic_proposal"); $grammar.addRule("system_generic_proposal", [new $runtime.NonTerminal("ctx_search_command", "ctx", undefined), new $runtime.NonTerminal("answer_noun_phrase", "proposal", ["functionName" as ("functionName" extends keyof ReturnType ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType ? string : void)])], $locale._("{are you looking for a|how about a|how about the} ${proposal[plural=one]}"), ((ctx : S.ContextInfo, proposal : Ast.Expression) : (S.AgentReplyRecord)|null => D.makeRefinementProposal(ctx, proposal)), undefined, { }); $grammar.addRule("system_generic_proposal", [new $runtime.NonTerminal("ctx_search_command", "ctx", undefined), new $runtime.NonTerminal("anything_phrase", "proposal", ["functionName" as ("functionName" extends keyof ReturnType ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType ? string : void)])], $locale._("{are you looking for|how about|how about} ${proposal}"), ((ctx : S.ContextInfo, proposal : Ast.Expression) : (S.AgentReplyRecord)|null => D.makeRefinementProposal(ctx, proposal)), undefined, { }); $grammar.addRule("system_generic_proposal", [new $runtime.NonTerminal("search_result_preamble", "preamble", undefined), new $runtime.NonTerminal("answer_noun_phrase", "proposal", ["functionName" as ("functionName" extends keyof ReturnType ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType ? string : void)])], $locale._("${preamble} {are you looking for a|how about a|how about the} ${proposal[plural=one]}"), ((preamble : S.ContextInfo, proposal : Ast.Expression) : (S.AgentReplyRecord)|null => D.makeRefinementProposal(preamble, proposal)), undefined, { }); $grammar.addRule("system_generic_proposal", [new $runtime.NonTerminal("search_result_preamble", "preamble", undefined), new $runtime.NonTerminal("anything_phrase", "proposal", ["functionName" as ("functionName" extends keyof ReturnType ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType ? string : void)])], $locale._("${preamble} {are you looking for|how about|how about} ${proposal}"), ((preamble : S.ContextInfo, proposal : Ast.Expression) : (S.AgentReplyRecord)|null => D.makeRefinementProposal(preamble, proposal)), undefined, { }); $grammar.declareSymbol("negative_proposal_request"); if ($options.flags.multiwoz) { $grammar.addRule("negative_proposal_request", [new $runtime.NonTerminal("counterproposal_preamble", undefined, undefined), new $runtime.NonTerminal("answer_noun_phrase", "request", undefined)], $locale._("${counterproposal_preamble} {a|any} ${request} ."), (($0 : string, request : Ast.Expression) : (Ast.Expression)|null => request), C.expressionKeyFn, { }); } $grammar.addRule("negative_proposal_request", [new $runtime.NonTerminal("counterproposal_preamble", undefined, undefined), new $runtime.NonTerminal("anything_phrase", "request", undefined)], $locale._("${counterproposal_preamble} ${request} ."), (($0 : string, request : Ast.Expression) : (Ast.Expression)|null => request), C.expressionKeyFn, { }); $grammar.declareSymbol("negative_proposal_answer_preamble"); $grammar.addRule("negative_proposal_answer_preamble", [new $runtime.NonTerminal("answer_noun_phrase", "phrase", undefined)], $locale._("{no ,|no|} {i am not in the mood for a|i do not like|i do not want} ${phrase}"), ((phrase : Ast.Expression) : (Ast.Expression)|null => phrase), C.expressionKeyFn, { }); $grammar.addRule("negative_proposal_answer_preamble", [new $runtime.NonTerminal("anything_phrase", "phrase", undefined)], $locale._("{no ,|no|} {i am not in the mood for a|i do not like|i do not want} ${phrase}"), ((phrase : Ast.Expression) : (Ast.Expression)|null => phrase), C.expressionKeyFn, { }); $grammar.declareSymbol("negative_proposal_reply"); $grammar.addRule("negative_proposal_reply", [new $runtime.NonTerminal("negative_proposal_request", "request", undefined)], $locale._("{no ,|no|} ${request}"), ((request : Ast.Expression) : (D.NegativeProposalReply)|null => [null, request]), D.negativeProposalReplyKeyFn, { }); if ($options.flags.multiwoz) { $grammar.addRule("negative_proposal_reply", [new $runtime.NonTerminal("negative_proposal_answer_preamble", "preamble", undefined)], "${preamble}", ((preamble : Ast.Expression) : (D.NegativeProposalReply)|null => [preamble, null]), D.negativeProposalReplyKeyFn, { }); $grammar.addRule("negative_proposal_reply", [new $runtime.NonTerminal("negative_proposal_answer_preamble", "preamble", undefined), new $runtime.NonTerminal("negative_proposal_request", "request", ["functionName" as ("functionName" extends keyof ReturnType ? string : void), 0, "functionName" as ("functionName" extends keyof ReturnType ? string : void)])], $locale._("${preamble} ${request}"), ((preamble : Ast.Expression, request : Ast.Expression) : (D.NegativeProposalReply)|null => [preamble, request]), D.negativeProposalReplyKeyFn, { }); } };