Skip to content

Commit

Permalink
Merge b58bef8 into b1bef64
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychhsu committed Mar 6, 2019
2 parents b1bef64 + b58bef8 commit d0835b1
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions languages/zh-tw/aggregation.genie
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// -*- 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 Generate = ThingTalk.Generate;
const { clean } = require('../../lib/utils');

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

projection_Number = {
t:complete_table '的' ('數量' | '數目' | '筆數') => {
if (!t.schema.is_list)
return null;
const newSchema = t.schema.filterArguments((arg, i) => arg.direction !== Ast.ArgDirection.OUT)
.addArguments([new Ast.ArgumentDef(Ast.ArgDirection.OUT, 'count', Type.Number)]);
const agg = new Ast.Table.Aggregation(t, '*', 'count', null, newSchema);
return new Ast.Table.Projection(agg, ['count'], newSchema);
};
}

projection_Any = {
t:complete_table p:out_param_Numeric '的' ('和' | '總和') => {
if (!t.schema.out[p.name] || !t.schema.out[p.name].isNumeric())
return null;
if (!t.schema.is_list)
return null;

const newSchema = t.schema.filterArguments((arg, i) => arg.direction !== Ast.ArgDirection.OUT || arg.name === p.name);
const agg = new Ast.Table.Aggregation(t, p.name, 'sum', null, newSchema);
return new Ast.Table.Projection(agg, [p.name], newSchema);
};

t:complete_table '的' p:out_param_Numeric '的' ('和' | '總和') => {
if (!t.schema.out[p.name] || !t.schema.out[p.name].isNumeric())
return null;
if (!t.schema.is_list)
return null;

const newSchema = t.schema.filterArguments((arg, i) => arg.direction !== Ast.ArgDirection.OUT || arg.name === p.name);
const agg = new Ast.Table.Aggregation(t, p.name, 'sum', null, newSchema);
return new Ast.Table.Projection(agg, [p.name], newSchema);
};

t:complete_table '的' p:out_param_Numeric '加 起來' => {
if (!t.schema.out[p.name] || !t.schema.out[p.name].isNumeric())
return null;
if (!t.schema.is_list)
return null;

const newSchema = t.schema.filterArguments((arg, i) => arg.direction !== Ast.ArgDirection.OUT || arg.name === p.name);
const agg = new Ast.Table.Aggregation(t, p.name, 'sum', null, newSchema);
return new Ast.Table.Projection(agg, [p.name], newSchema);
};

!turking t:complete_table '的' p:out_param_Numeric ('平均') => {
if (!t.schema.out[p.name] || !t.schema.out[p.name].isNumeric())
return null;
if (!t.schema.is_list)
return null;

const newSchema = t.schema.filterArguments((arg, i) => arg.direction !== Ast.ArgDirection.OUT || arg.name === p.name);
const agg = new Ast.Table.Aggregation(t, p.name, 'avg', null, newSchema);
return new Ast.Table.Projection(agg, [p.name], newSchema);
};
t:complete_table p:out_param_Numeric '的 平均'=> {
if (!t.schema.out[p.name] || !t.schema.out[p.name].isNumeric())
return null;
if (!t.schema.is_list)
return null;

const newSchema = t.schema.filterArguments((arg, i) => arg.direction !== Ast.ArgDirection.OUT || arg.name === p.name);
const agg = new Ast.Table.Aggregation(t, p.name, 'avg', null, newSchema);
return new Ast.Table.Projection(agg, [p.name], newSchema);
};

!turking t:complete_table '的' p:out_param_Numeric '的 平均'=> {
if (!t.schema.out[p.name] || !t.schema.out[p.name].isNumeric())
return null;
if (!t.schema.is_list)
return null;

const newSchema = t.schema.filterArguments((arg, i) => arg.direction !== Ast.ArgDirection.OUT || arg.name === p.name);
const agg = new Ast.Table.Aggregation(t, p.name, 'avg', null, newSchema);
return new Ast.Table.Projection(agg, [p.name], newSchema);
};

t:complete_table ('中' | '裡' | '裡面') ('最低' | '最少' | '最小') '的' p:out_param_Numeric => {
if (!t.schema.out[p.name] || !t.schema.out[p.name].isNumeric())
return null;
if (!t.schema.is_list)
return null;

const newSchema = t.schema.filterArguments((arg, i) => arg.direction !== Ast.ArgDirection.OUT || arg.name === p.name);
const agg = new Ast.Table.Aggregation(t, p.name, 'min', null, newSchema);
return new Ast.Table.Projection(agg, [p.name], newSchema);
};

t:complete_table ('中' | '裡' | '裡面') ('最高' | '最大' | '最多') '的' p:out_param_Numeric => {
if (!t.schema.out[p.name] || !t.schema.out[p.name].isNumeric())
return null;
if (!t.schema.is_list)
return null;

const newSchema = t.schema.filterArguments((arg, i) => arg.direction !== Ast.ArgDirection.OUT || arg.name === p.name);
const agg = new Ast.Table.Aggregation(t, p.name, 'max', null, newSchema);
return new Ast.Table.Projection(agg, [p.name], newSchema);
};
}

0 comments on commit d0835b1

Please sign in to comment.