-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
} |