Skip to content

Commit

Permalink
Merge 2c49fd6 into 5a98644
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychhsu committed Mar 5, 2019
2 parents 5a98644 + 2c49fd6 commit 2bc32ff
Showing 1 changed file with 264 additions and 0 deletions.
264 changes: 264 additions & 0 deletions languages/zh-tw/parameters.genie
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of ThingTalk
//
// Copyright 2017-2018 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna <gcampagn@cs.stanford.edu>
//
// See COPYING for details

{
const assert = require('assert');

const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;
const { clean } = require('../../lib/utils');

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
}

import '../common-parameters';

// these are autogenerated and depends on projection_*, which is also
// autogenerated
projection_Any = {}
stream_projection_Any = {}
table_join_replace_placeholder = {}
action_replace_param_with_table = {}
action_replace_param_with_stream = {}

projection_Numeric = {
projection_Number;
projection_Currency;
projection_Measure_ms;
projection_Measure_byte;
projection_Measure_kg;
projection_Measure_C;
projection_Measure_m;
projection_Measure_mps;
projection_Measure_Pa;
projection_Measure_kcal;
}

single_projection_String = table:complete_table => {
let outParams = Object.keys(table.schema.out);
if (outParams.length === 1 && table.schema.out[outParams[0]].isString)
return new Ast.Table.Projection(table, [outParams[0]], table.schema);

for (let pname in table.schema.out) {
if (pname === 'picture_url')
return null;
let ptype = table.schema.out[pname];
if ($options.types.id.has(C.typeToStringSafe(ptype)))
return null;
}
return new Ast.Table.Projection(table, ['$event'], table.schema);
};
single_stream_projection_String = ('新的' | '新') table:complete_table => {
if (!table.schema.is_monitorable)
return null;
let outParams = Object.keys(table.schema.out);
if (outParams.length === 1 && table.schema.out[outParams[0]].isString)
return new Ast.Stream.Projection(new Ast.Stream.Monitor(table, null, table.schema), [outParams[0]], table.schema);

for (let pname in table.schema.out) {
if (pname === 'picture_url')
return null;
let ptype = table.schema.out[pname];
if ($options.types.id.has(C.typeToStringSafe(ptype)))
return null;
}
return new Ast.Stream.Projection(new Ast.Stream.Monitor(table, null, table.schema), ['$event'], table.schema);
};

single_projection_Entity__tt__picture = table:complete_table => {
if (!table.schema.out['picture_url'])
return null;
return new Ast.Table.Projection(table, ['picture_url'], table.schema);
};
single_stream_projection_Entity__tt__picture = ('新的' | '新') table:complete_table => {
if (!table.schema.out['picture_url'])
return null;
if (!table.schema.is_monitorable)
return null;
return new Ast.Stream.Projection(new Ast.Stream.Monitor(table, null, table.schema), ['picture_url'], table.schema);
};


the_out_param_Numeric = {
p:out_param_Numeric => p;
!turking {
('我' | '我的') p:out_param_Numeric => p;
}
}
the_out_param_Array__Any = {
p:out_param_Array__Any => p;
!turking {
('我' | '我的') p:out_param_Array__Any => p;
}
}

for (let [typestr, type] of $options.types.all) {
// don't access booleans or enums out arguments generically, as that rarely makes sense
// (and when it does, you probably want a macro and maybe and edge trigger)
if (!type.isEnum && !type.isBoolean) {
$('the_out_param_' + typestr) = {
p:$('out_param_' + typestr) => p;

!turking {
('我' | '我的') p:$('out_param_' + typestr) => p;
}
}

if (!$options.types.id.has(typestr)) {
$('projection_' + typestr) = table:complete_table '的' outParam:$('the_out_param_' + typestr) => {
const name = outParam.name;
if (!table.schema.out[name] || !Type.isAssignable(table.schema.out[name], type))
return null;
if (name === 'picture_url' && $options.flags.turking)
return null;
const newSchema = table.schema.filterArguments((arg) => arg.direction !== Ast.ArgDirection.OUT || arg.name === name);
return new Ast.Table.Projection(table, [name], newSchema);
};

$('stream_projection_' + typestr) = table:complete_table '的 新' outParam:$('the_out_param_' + typestr) => {
const name = outParam.name;
if (!table.schema.out[name] || !Type.isAssignable(table.schema.out[name], type))
return null;
if (!table.schema.is_monitorable)
return null;
const stream = new Ast.Stream.Monitor(table, null, table.schema);
const newSchema = stream.schema.filterArguments((arg, i) => arg.direction !== Ast.ArgDirection.OUT || arg.name === name);
return new Ast.Stream.Projection(stream, [name], newSchema);
};

projection_Any = $('projection_' + typestr);
}

if ($options.types.id.has(typestr)) {
$('single_projection_' + typestr) = table:complete_table => {
for (let pname in table.schema.out) {
if (table.schema.out[pname].equals(type))
return new Ast.Table.Projection(table, [pname], table.schema);
}
return null;
};

$('single_stream_projection_' + typestr) = ('新的' | '新') table:complete_table => {
if (!table.schema.is_monitorable)
return null;
for (let pname in table.schema.out) {
if (table.schema.out[pname].equals(type))
return new Ast.Stream.Projection(new Ast.Stream.Monitor(table, null, table.schema), [pname], table.schema);
}
return null;
};
} else if (typestr !== 'Entity__tt__picture' && typestr !== 'String') {
$('single_projection_' + typestr) = table:complete_table => {
let outParams = Object.keys(table.schema.out);
if (outParams.length !== 1 || !type.equals(table.schema.out[outParams[0]]))
return null;
return new Ast.Table.Projection(table, [outParams[0]], table.schema);
};

$('single_stream_projection_' + typestr) = ('新的' | '新') table:complete_table => {
let outParams = Object.keys(table.schema.out);
if (outParams.length !== 1 || !type.equals(table.schema.out[outParams[0]]))
return null;
if (!table.schema.is_monitorable)
return null;
return new Ast.Stream.Projection(new Ast.Stream.Monitor(table, null, table.schema), [outParams[0]], table.schema);
};
}
}
}

for (let [pname, typestr] of $options.params.in.values()) {
// don't parameter pass booleans or enums, as that rarely makes sense
if (typestr !== 'Boolean' && !typestr.startsWith('Enum__')) {
table_join_replace_placeholder = q:thingpedia_query p:$('single_projection_' + typestr) [-> pname] => C.tableJoinReplacePlaceholder(q, pname, p);
action_replace_param_with_table = a:thingpedia_action p:$('single_projection_' + typestr) [-> pname] => C.actionReplaceParamWithTable(a, pname, p);
action_replace_param_with_stream = a:thingpedia_action p:$('single_stream_projection_' + typestr) [-> pname] => C.actionReplaceParamWithStream(a, pname, p);

if ($options.types.id.has(typestr)) {
forward_get_do_command = command:forward_get_do_command [-> pname] => {
for (let joinArg in command.table.schema.out) {
if (typestr === C.typeToStringSafe(command.table.schema.out[joinArg]))
return C.getDoCommand(command, pname, new Ast.Value.VarRef(joinArg));
}
return null;
};

forward_when_do_rule = rule:forward_when_do_rule [-> pname] => {
for (let joinArg in rule.stream.schema.out) {
if (typestr === C.typeToStringSafe(rule.stream.schema.out[joinArg]))
return C.whenDoRule(rule, pname, new Ast.Value.VarRef(joinArg));
}
return null;
};

when_get_stream = stream:when_get_stream [-> pname] => {
for (let joinArg in stream.stream.schema.out) {
if (typestr === C.typeToStringSafe(stream.stream.schema.out[joinArg]))
return C.whenGetStream(stream, pname, new Ast.Value.VarRef(joinArg));
}
return null;
};
} else {
table_join_replace_placeholder = q:thingpedia_query p:$('projection_' + typestr) [-> pname] => C.tableJoinReplacePlaceholder(q, pname, p);
action_replace_param_with_table = a:thingpedia_action p:$('projection_' + typestr) [-> pname] => C.actionReplaceParamWithTable(a, pname, p);
action_replace_param_with_stream = a:thingpedia_action p:$('stream_projection_' + typestr) [-> pname] => C.actionReplaceParamWithStream(a, pname, p);

forward_get_do_command = !turking command:forward_get_do_command p:$('the_out_param_' + typestr) [-> pname] => C.getDoCommand(command, pname, p);
backward_get_do_command = !turking command:backward_get_do_command p:$('the_out_param_' + typestr) [-> pname] => C.getDoCommand(command, pname, p);
forward_when_do_rule = !turking rule:forward_when_do_rule p:$('the_out_param_' + typestr) [-> pname] => C.whenDoRule(rule, pname, p);
backward_when_do_rule = !turking rule:backward_when_do_rule p:$('the_out_param_' + typestr) [-> pname] => C.whenDoRule(rule, pname, p);
when_get_stream = !turking stream:when_get_stream p:$('the_out_param_' + typestr) [-> pname] => C.whenGetStream(stream, pname, p);
}

if (pname === 'p_picture_url') {
forward_get_do_command = command:forward_get_do_command [-> pname] => C.getDoCommand(command, pname, new Ast.Value.VarRef('picture_url'));
forward_when_do_rule = rule:forward_when_do_rule [-> pname] => C.whenDoRule(rule, pname, new Ast.Value.VarRef('picture_url'));
when_get_stream = stream:when_get_stream [-> pname] => C.whenGetStream(stream, pname, new Ast.Value.VarRef('picture_url'));
}

if (typestr === 'String' && ['p_body', 'p_message', 'p_caption', 'p_status', 'p_text'].indexOf(pname) >= 0) {
forward_get_do_command = command:forward_get_do_command [-> pname] => {
for (let pname in command.table.schema.out) {
if (pname === 'picture_url')
return null;
let ptype = command.table.schema.out[pname];
if ($options.types.id.has(C.typeToStringSafe(ptype)))
return null;
}
return C.getDoCommand(command, pname, new Ast.Value.Event(null));
};

forward_when_do_rule = rule:forward_when_do_rule [-> pname] => {
for (let pname in rule.stream.schema.out) {
if (pname === 'picture_url')
return null;
let ptype = rule.stream.schema.out[pname];
if ($options.types.id.has(C.typeToStringSafe(ptype)))
return null;
}
return C.whenDoRule(rule, pname, new Ast.Value.Event(null));
};

when_get_stream = stream:when_get_stream [-> pname] => {
for (let pname in stream.stream.schema.out) {
if (pname === 'picture_url')
return null;
let ptype = stream.stream.schema.out[pname];
if ($options.types.id.has(C.typeToStringSafe(ptype)))
return null;
}
return C.whenGetStream(stream, pname, new Ast.Value.Event(null));
};
}
}
}

0 comments on commit 2bc32ff

Please sign in to comment.