// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*- // // This file is part of Genie // // Copyright 2021 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: Silei Xu 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 ThingpediaLoader from './load-thingpedia'; export const pronoun_the_first : $SentenceGeneratorTypes.NonTerminal = "pronoun_the_first"; export const pronoun_the_second : $SentenceGeneratorTypes.NonTerminal = "pronoun_the_second"; export const each_other : $SentenceGeneratorTypes.NonTerminal = "each_other"; export const short_phrase_table : $SentenceGeneratorTypes.NonTerminal = "short_phrase_table"; export const self_join_table : $SentenceGeneratorTypes.NonTerminal = "self_join_table"; export const generic_join_table : $SentenceGeneratorTypes.NonTerminal = "generic_join_table"; export const complete_table : $SentenceGeneratorTypes.NonTerminal = "complete_table"; /** * 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("pronoun_the_first"); $grammar.addRule("pronoun_the_first", [], $locale._("the first"), (() : (string)|null => "the first"), undefined, { identity: (true) }); $grammar.addRule("pronoun_the_first", [], $locale._("the former"), (() : (string)|null => "the former"), undefined, { identity: (true) }); $grammar.declareSymbol("pronoun_the_second"); $grammar.addRule("pronoun_the_second", [], $locale._("the second"), (() : (string)|null => "the second"), undefined, { identity: (true) }); $grammar.addRule("pronoun_the_second", [], $locale._("the latter"), (() : (string)|null => "the latter"), undefined, { identity: (true) }); $grammar.declareSymbol("each_other"); $grammar.addRule("each_other", [], $locale._("each other"), (() : (string)|null => "each other"), undefined, { identity: (true) }); $grammar.addRule("each_other", [], $locale._("one another"), (() : (string)|null => "one another"), undefined, { identity: (true) }); $grammar.declareSymbol("short_phrase_table"); $grammar.addRule("short_phrase_table", [new $runtime.NonTerminal("complete_table", undefined, undefined)], "${complete_table}", (($0 : Ast.Expression) : (Ast.Expression)|null => { return $0; }), C.expressionKeyFn, { identity: (true) }); $grammar.addRule("short_phrase_table", [new $runtime.NonTerminal("one_clean_filter_table", undefined, undefined)], "${one_clean_filter_table}", (($0 : Ast.Expression) : (Ast.Expression)|null => { return $0; }), C.expressionKeyFn, { identity: (true) }); $grammar.declareSymbol("self_join_table"); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("pronoun_the_first", undefined, undefined), new $runtime.NonTerminal("out_param_Any", "param", undefined), new $runtime.NonTerminal("pronoun_the_second", undefined, undefined)], $locale._("pairs of ${table} {such that|that} ${pronoun_the_first} {is|are|was|were} {the|a|} ${param} of ${pronoun_the_second}"), ((table : Ast.Expression, $0 : string, param : C.ParamSlot, $1 : string) : (Ast.Expression)|null => C.makeSelfJoinFromParam($loader, table, param)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("pronoun_the_first", undefined, undefined), new $runtime.NonTerminal("pronoun_the_second", undefined, undefined), new $runtime.NonTerminal("out_param_Any", "param", undefined)], $locale._("pairs of ${table} {such that|that} ${pronoun_the_first} {has|have|had} ${pronoun_the_second} as {the|a|} ${param}"), ((table : Ast.Expression, $0 : string, $1 : string, param : C.ParamSlot) : (Ast.Expression)|null => C.makeSelfJoinFromParam($loader, table, param)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("pronoun_the_first", undefined, undefined), new $runtime.NonTerminal("npp_join_condition", "condition", undefined)], $locale._("pairs of ${table} {such that|that} ${pronoun_the_first} {has|have|had} ${condition}"), ((table : Ast.Expression, $0 : string, condition : C.FilterSlot) : (Ast.Expression)|null => C.makeSelfJoin(table, condition)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("pronoun_the_first", undefined, undefined), new $runtime.NonTerminal("npi_join_condition", "condition", undefined)], $locale._("pairs of ${table} {such that|that} ${pronoun_the_first} {is|are|was|were} {the|a|} ${condition}"), ((table : Ast.Expression, $0 : string, condition : C.FilterSlot) : (Ast.Expression)|null => C.makeSelfJoin(table, condition)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("pronoun_the_first", undefined, undefined), new $runtime.NonTerminal("pvp_join_condition", "condition", undefined)], $locale._("pairs of ${table} {such that|that} ${pronoun_the_first} {is|are|was|were} ${condition}"), ((table : Ast.Expression, $0 : string, condition : C.FilterSlot) : (Ast.Expression)|null => C.makeSelfJoin(table, condition)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("pronoun_the_first", undefined, undefined), new $runtime.NonTerminal("preposition_join_condition", "condition", undefined)], $locale._("pairs of ${table} {such that|that} ${pronoun_the_first} {is|are|was|were} ${condition}"), ((table : Ast.Expression, $0 : string, condition : C.FilterSlot) : (Ast.Expression)|null => C.makeSelfJoin(table, condition)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("pronoun_the_first", undefined, undefined), new $runtime.NonTerminal("avp_join_condition", "condition", undefined)], $locale._("pairs of ${table} {such that|that} ${pronoun_the_first} ${condition}"), ((table : Ast.Expression, $0 : string, condition : C.FilterSlot) : (Ast.Expression)|null => C.makeSelfJoin(table, condition)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("pronoun_the_first", undefined, undefined), new $runtime.NonTerminal("reverse_verb_join_condition", "condition", undefined)], $locale._("pairs of ${table} {such that|that} ${pronoun_the_first} ${condition}"), ((table : Ast.Expression, $0 : string, condition : C.FilterSlot) : (Ast.Expression)|null => C.makeSelfJoin(table, condition)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("out_param_Any", "param", ["symmetric" as ("symmetric" extends keyof ReturnType ? string : void), (true) as ReturnType["symmetric"]]), new $runtime.NonTerminal("each_other", undefined, undefined)], $locale._("${table} {pairs|} {that|which|who} {are|were} {the|} ${param} of ${each_other}"), ((table : Ast.Expression, param : C.ParamSlot, $0 : string) : (Ast.Expression)|null => C.makeSelfJoinFromParam($loader, table, param)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("npi_symmetric_join_condition", "condition", undefined)], $locale._("{pairs of|} ${table} {that|which|who} {are|were} {the|} ${condition}"), ((table : Ast.Expression, condition : C.FilterSlot) : (Ast.Expression)|null => C.makeSelfJoin(table, condition)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("pvp_symmetric_join_condition", "condition", undefined)], $locale._("{pairs of|} ${table} {that|which|who} {are|were} ${condition}"), ((table : Ast.Expression, condition : C.FilterSlot) : (Ast.Expression)|null => C.makeSelfJoin(table, condition)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("preposition_symmetric_join_condition", "condition", undefined)], $locale._("{pairs of|} ${table} {that|which|who} {are|were} ${condition}"), ((table : Ast.Expression, condition : C.FilterSlot) : (Ast.Expression)|null => C.makeSelfJoin(table, condition)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("avp_symmetric_join_condition", "condition", undefined)], $locale._("{pairs of|} ${table} {that|which|who} ${condition}"), ((table : Ast.Expression, condition : C.FilterSlot) : (Ast.Expression)|null => C.makeSelfJoin(table, condition)), C.expressionKeyFn, { }); $grammar.addRule("self_join_table", [new $runtime.NonTerminal("short_phrase_table", "table", undefined), new $runtime.NonTerminal("reverse_verb_symmetric_join_condition", "condition", undefined)], $locale._("{pairs of|} ${table} {that|which|who} ${condition}"), ((table : Ast.Expression, condition : C.FilterSlot) : (Ast.Expression)|null => C.makeSelfJoin(table, condition)), C.expressionKeyFn, { }); $grammar.declareSymbol("generic_join_table"); $grammar.addRule("generic_join_table", [new $runtime.NonTerminal("short_phrase_table", "table1", undefined), new $runtime.NonTerminal("base_table_hidden", "table2", undefined), new $runtime.NonTerminal("out_param_Any", "param2", undefined), new $runtime.NonTerminal("out_param_Any", "param1", undefined)], $locale._("${table1} {and|with} the ${table2} ${param2} of {its|their} ${param1}"), ((table1 : Ast.Expression, table2 : Ast.InvocationExpression, param2 : C.ParamSlot, param1 : C.ParamSlot) : (any)|null => C.makeGenericJoin($loader, table1, param1, table2, param2)), undefined, { }); $grammar.declareSymbol("complete_table"); if (!$options.flags.notablejoin) { $grammar.addRule("complete_table", [new $runtime.NonTerminal("self_join_table", undefined, undefined)], "${self_join_table}", (($0 : Ast.Expression) : (Ast.Expression)|null => { return $0; }), C.expressionKeyFn, { identity: (true) }); } if (!$options.flags.notablejoin) { $grammar.addRule("complete_table", [new $runtime.NonTerminal("generic_join_table", undefined, undefined)], "${generic_join_table}", (($0 : any) : (Ast.Expression)|null => { return $0; }), C.expressionKeyFn, { identity: (true) }); } };