-
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.
Merge pull request #4 from Stanford-Mobisocial-IoT-Lab/add_chinese_co…
…nstant constant.genie for zh-tw
- Loading branch information
Showing
1 changed file
with
133 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,133 @@ | ||
// -*- 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'); | ||
} | ||
|
||
constant_Number = { | ||
// `turking` is a flags that controls a group of grammar rules | ||
// syntax is ?flag to enable the rule (or group of rules) only if the flag is set, !flag to disable the | ||
// rule if the flag is set | ||
|
||
!turking { | ||
'0' => new Ast.Value.Number(0); | ||
'零' => new Ast.Value.Number(0); | ||
'1' => new Ast.Value.Number(1); | ||
'一' => new Ast.Value.Number(1); | ||
} | ||
} | ||
|
||
constant_date_point = { | ||
'現在' => new Ast.Value.Date(null, '+', null); | ||
'今天' => new Ast.Value.Date(Ast.DateEdge('start_of', 'day'), '+', null); | ||
'昨天' => new Ast.Value.Date(Ast.DateEdge('start_of', 'day'), '-', Ast.Value.Measure(1, 'day')); | ||
'這 星期' => new Ast.Value.Date(Ast.DateEdge('start_of', 'week'), '+', null); | ||
'這週' => new Ast.Value.Date(Ast.DateEdge('start_of', 'week'), '+', null); | ||
'這 禮拜' => new Ast.Value.Date(Ast.DateEdge('start_of', 'week'), '+', null); | ||
|
||
!turking { | ||
'明天' => new Ast.Value.Date(Ast.DateEdge('end_of', 'day'), '+', null); | ||
'今天 以前' => new Ast.Value.Date(Ast.DateEdge('end_of', 'day'), '+', null); | ||
'這 星期 以前' => new Ast.Value.Date(Ast.DateEdge('end_of', 'week'), '+', null); | ||
'這週 以前' => new Ast.Value.Date(Ast.DateEdge('end_of', 'week'), '+', null); | ||
'這 禮拜 以前' => new Ast.Value.Date(Ast.DateEdge('end_of', 'week'), '+', null); | ||
'上 星期' => new Ast.Value.Date(Ast.DateEdge('start_of', 'week'), '-', Ast.Value.Measure(1, 'week')); | ||
'上週' => new Ast.Value.Date(Ast.DateEdge('start_of', 'week'), '-', Ast.Value.Measure(1, 'week')); | ||
'上 禮拜' => new Ast.Value.Date(Ast.DateEdge('start_of', 'week'), '-', Ast.Value.Measure(1, 'week')); | ||
'這個 月' => new Ast.Value.Date(Ast.DateEdge('start_of', 'mon'), '+', null); | ||
'今年' => new Ast.Value.Date(Ast.DateEdge('start_of', 'year'), '+', null); | ||
'下個 月' => new Ast.Value.Date(Ast.DateEdge('end_of', 'mon'), '+', null); | ||
'明年' => new Ast.Value.Date(Ast.DateEdge('end_of', 'year'), '+', null); | ||
'上個 月' => new Ast.Value.Date(Ast.DateEdge('end_of', 'mon'), '-', Ast.Value.Measure(1, 'mon')); | ||
'去年' => new Ast.Value.Date(Ast.DateEdge('end_of', 'year'), '-', Ast.Value.Measure(1, 'year')); | ||
} | ||
} | ||
|
||
constant_Date = { | ||
!turking { | ||
duration:constant_Measure_ms '以內' => new Ast.Value.Date(null, '+', duration); | ||
duration:constant_Measure_ms '之內' => new Ast.Value.Date(null, '+', duration); | ||
duration:constant_Measure_ms '以前' => new Ast.Value.Date(null, '-', duration); | ||
duration:constant_Measure_ms '之前' => new Ast.Value.Date(null, '-', duration); | ||
duration:constant_Measure_ms pt:constant_date_point '以後' => new Ast.Value.Date(pt.value, '+', duration); | ||
duration:constant_Measure_ms pt:constant_date_point '之後' => new Ast.Value.Date(pt.value, '+', duration); | ||
duration:constant_Measure_ms pt:constant_date_point '以前' => new Ast.Value.Date(pt.value, '-', duration); | ||
duration:constant_Measure_ms pt:constant_date_point '之前' => new Ast.Value.Date(pt.value, '-', duration); | ||
} | ||
} | ||
|
||
constant_Measure_byte = { | ||
!turking num:constant_Number 'byte' => C.addUnit('byte', num); | ||
num:constant_Number 'kb' => C.addUnit('KB', num); | ||
num:constant_Number 'mb' => C.addUnit('MB', num); | ||
num:constant_Number 'gb' => C.addUnit('GB', num); | ||
num:constant_Number 'tb' => C.addUnit('TB', num); | ||
num:constant_Number 'kilobytes' => C.addUnit('KB', num); | ||
num:constant_Number 'megabytes' => C.addUnit('MB', num); | ||
num:constant_Number 'gigabytes' => C.addUnit('GB', num); | ||
num:constant_Number 'terabytes' => C.addUnit('TB', num); | ||
} | ||
|
||
constant_Measure_kg = { | ||
!turking num:constant_Number '公克' => C.addUnit('g', num); | ||
num:constant_Number '公斤' => C.addUnit('kg', num); | ||
num:constant_Number '磅' => C.addUnit('lb', num); | ||
num:constant_Number '盎司' => C.addUnit('oz', num); | ||
} | ||
|
||
constant_Measure_C = { | ||
!turking { | ||
num:constant_Number 'c' => C.addUnit('C', num); | ||
num:constant_Number '攝氏' => C.addUnit('C', num); | ||
} | ||
num:constant_Number 'f' => C.addUnit('F', num); | ||
num:constant_Number '華氏' => C.addUnit('F', num); | ||
} | ||
|
||
constant_Measure_m = { | ||
!turking num:constant_Number '米' => C.addUnit('m', num); | ||
num:constant_Number '公尺' => C.addUnit('m', num); | ||
num:constant_Number '公里' => C.addUnit('km', num); | ||
num:constant_Number '公里' => C.addUnit('km', num); | ||
num:constant_Number '英里' => C.addUnit('mi', num); | ||
num:constant_Number '英里' => C.addUnit('mi', num); | ||
num:constant_Number '英尺' => C.addUnit('ft', num); | ||
num:constant_Number '英寸' => C.addUnit('in', num); | ||
num:constant_Number '英寸' => C.addUnit('in', num); | ||
num:constant_Number '公分' => C.addUnit('cm', num); | ||
num:constant_Number '厘米' => C.addUnit('cm', num); | ||
} | ||
} | ||
|
||
constant_Measure_mps = { | ||
num:constant_Number 'mph' => C.addUnit('mph', num); | ||
!turking num:constant_Number 'm/s' => C.addUnit('mps', num); | ||
num:constant_Number 'kph' => C.addUnit('kmph', num); | ||
num:constant_Number 'miles per hour' => C.addUnit('mph', num); | ||
num:constant_Number 'kilometers per hour' => C.addUnit('kmph', num); | ||
num:constant_Number 'km/h' => C.addUnit('kmph', num); | ||
} | ||
|
||
constant_Location = { | ||
'這裡' => new Ast.Value.Location(Ast.Location.Relative('current_location')); | ||
!turking '我 在 哪裡' => new Ast.Value.Location(Ast.Location.Relative('current_location')); | ||
'家裡' => new Ast.Value.Location(Ast.Location.Relative('home')); | ||
'辦公室' => new Ast.Value.Location(Ast.Location.Relative('work')); | ||
} | ||
|