Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add filters.genie for Chinese #11

Merged
merged 4 commits into from
Mar 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions languages/zh-tw/filters.genie
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// -*- 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, National Taiwan University
//
// Author: Giovanni Campagna <gcampagn@cs.stanford.edu>, Johnny Hsu <johnny.chhsu01@gmail.com>
//
// 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');
}

atom_filter = {
t1:constant_Time '之前' => C.timeGetPredicate($options, null, t1);
t2:constant_Time '之後' => C.timeGetPredicate($options, t2, null);
t1:constant_Time '和' t2:constant_Time '之間' => C.timeGetPredicate($options, t1, t2);
johnnychhsu marked this conversation as resolved.
Show resolved Hide resolved
'從' t1:constant_Time '到' t2:constant_Time => C.timeGetPredicate($options, t1, t2);
'從' t1:constant_Time '到' t2:constant_Time '之間' => C.timeGetPredicate($options, t1, t2);
'從' t1:constant_Time '開始 到' t2:constant_Time '結束' => C.timeGetPredicate($options, t1, t2);

'我 在' loc:constant_Location => C.locationGetPredicate($options, loc);
'我 不 在' loc:constant_Location => C.locationGetPredicate($options, loc, true);

// What is projection here?
// proj:projection_Any ('is' | 'is exactly' | 'is equal to') x:constant_Any => C.makeGetPredicate(proj, '==', x);
// proj:projection_Any ('is not' | 'is n\'t' | 'is different than') x:constant_Any => C.makeGetPredicate(proj, '==', x, true);

p:out_param_Any ('是' | '為') x:constant_Any => C.makeFilter($options, p, '==', x);
p:out_param_Any ('和' | '跟') x:constant_Any ('一樣' | '相同') => C.makeFilter($options, p, '==', x);
p:out_param_Any ('不是' | '不為') x:constant_Any => C.makeFilter($options, p, '==', x, true);
p:out_param_Any ('和' | '跟') x:constant_Any ('不一樣' | '不 相同') => C.makeFilter($options, p, '==', x, true);

p:the_out_param_Numeric '比' x:constant_Numeric ('大' | '多') => C.makeFilter($options, p, '>=', x);
p:the_out_param_Numeric '大於' x:constant_Numeric => C.makeFilter($options, p, '>=', x);
p:the_out_param_Numeric '比' x:constant_Numeric ('小' | '少') => C.makeFilter($options, p, '<=', x);
p:the_out_param_Numeric '小於' x:constant_Numeric => C.makeFilter($options, p, '<=', x);

!turking {
p:the_out_param_Date '在' x:constant_Date '之後' => C.makeFilter($options, p, '>=', x);
p:the_out_param_Date '在' x:constant_Date '之前' => C.makeFilter($options, p, '<=', x);
}

p:the_out_param_Array__Any ('有' | '包含' | '擁有' | '含有') x:constant_Any => C.makeFilter($options, p, 'contains', x);
x:constant_Any ('存在' | '在' | '存在 於') p:the_out_param_Array__Any ('之中' | '裡面') => C.makeFilter($options, p, 'contains', x);
p:the_out_param_Array__Any ('沒有' | '不 包含' | '沒 擁有' | '不 含有') x:constant_Any => C.makeFilter($options, p, 'contains', x, true);
x:constant_Any ('不 存在' | '不在' | '不 存在 於') p:the_out_param_Array__Any ('之中' | '裡面') => C.makeFilter($options, p, 'contains', x, true);

!turking range_filter;
//!turking f:either_filter => f;
}

edge_filter = {
!turking '當' p:out_param_Any ('跟' | '和') x:constant_Any ('一樣' | '相同') ('時' | '的 時候') => C.makeFilter($options, p, '==', x);
!turking '當' p:out_param_Any ('變得' | '變成') ('和' | '跟') x:constant_Any ('一樣' | '相同') ('時' | '的 時候') => C.makeFilter($options, p, '==', x);
'當' p:the_out_param_Numeric ('比' | '變得 比') x:constant_Numeric ('大' | '多') ('時' | '的 時候') => C.makeFilter($options, p, '>=', x);
'當' p:the_out_param_Numeric ('比' | '變得 比') x:constant_Numeric ('小' | '少') ('時' | '的 時候') => C.makeFilter($options, p, '<=', x);
}

either_filter = {
param:out_param_Any ('等於' | '相等於' | '是') v1:constant_Any ('或' | '或是' | '或者是') v2:constant_Any => {
// param is a Value.VarRef
//console.log('param: ' + param.name);
if (!v1.getType().equals(v2.getType()))
return null;
if (v1.equals(v2)) // can happen with constants (now, 0, 1, etc.)
return null;
if (v1.isVarRef && v1.constNumber !== undefined && v2.isVarRef && v2.constNumber !== undefined &&
v1.constNumber + 1 !== v2.constNumber) // optimization: avoid CONST_X CONST_Y with X + 1 != Y earlier (before the NN catches it)
return null;
let vtype = v1.getType();
if (vtype.isBoolean) // "is equal to true or false" does not make sense
return null;
if (!$options.allOutParams.has(param.name + '+' + vtype))
return null;
return new Ast.BooleanExpression.Atom(param.name, 'in_array', Ast.Value.Array([v1, v2]));
};
param:out_param_Any '不是' v1:constant_Any '也不是' v2:constant_Any => {
// param is a Value.VarRef
//console.log('param: ' + param.name);
if (!v1.getType().equals(v2.getType()))
return null;
if (v1.equals(v2)) // can happen with constants (now, 0, 1, etc.)
return null;
if (v1.isVarRef && v1.constNumber !== undefined && v2.isVarRef && v2.constNumber !== undefined &&
v1.constNumber + 1 !== v2.constNumber) // optimization: avoid CONST_X CONST_Y with X + 1 != Y earlier (before the NN catches it)
return null;
let vtype = v1.getType();
if (vtype.isBoolean) // "is neither true nor false" does not make sense
return null;
if (!$options.allOutParams.has(param.name + '+' + vtype))
return null;
return new Ast.BooleanExpression.Not(new Ast.BooleanExpression.Atom(param.name, 'in_array', Ast.Value.Array([v1, v2])));
};
}

range = {
v1:constant_Numeric ('和' | '跟' | '到') v2:constant_Numeric '之間'=> {
if (!v1.getType().equals(v2.getType()))
return null;
if (v1.equals(v2)) // can happen with constants (now, 0, 1, etc.)
return null;
if (v1.isVarRef && v1.constNumber !== undefined && v2.isVarRef && v2.constNumber !== undefined &&
v1.constNumber + 1 !== v2.constNumber) // optimization: avoid CONST_X CONST_Y with X + 1 != Y earlier (before the NN catches it)
return null;
return [v1, v2];
};
}

range_filter = {
param:the_out_param_Numeric '在' range:range => {
const [v1, v2] = range;
return new Ast.BooleanExpression.And([
Ast.BooleanExpression.Atom(param.name, '>=', v1),
Ast.BooleanExpression.Atom(param.name, '<=', v2)
]);
};
}