Skip to content

Commit

Permalink
Merge 6f44817 into ddf28bb
Browse files Browse the repository at this point in the history
  • Loading branch information
Silei Xu committed Jul 25, 2019
2 parents ddf28bb + 6f44817 commit 3c842fe
Show file tree
Hide file tree
Showing 9 changed files with 575 additions and 207 deletions.
157 changes: 157 additions & 0 deletions languages/en/filters.genie
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const { clean } = require('../../lib/utils');
const C = require('../../lib/sentence-generator/ast_manip');
}

// generic filters (npp)
get_predicate_filter = {
'before' t1:constant_Time => C.timeGetPredicate($options, null, t1);
'after' t2:constant_Time => C.timeGetPredicate($options, t2, null);
Expand Down Expand Up @@ -180,3 +181,159 @@ range_with_filter = {
]);
};
}

// filters on npp parameters
// nnp: Noun-Phrase parameter for Property of the subject
// e.g.: "name", "date of birth"
npp_filter = {
p:out_param_npp x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};

p:out_param_npp x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};
}

// filters on npi parameters
// npi: Noun-phrase parameter for Identity of the subejct
// e.g.: "owner of <company>", "student in <university>"
npi_filter = {
p:out_param_npi x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};

p:out_param_npi x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};
}

// filters on pvp parameters
// pvp: Passive-Verb Phrase parameter
// e.g.: "called <nickname>", "born on <date>"
pvp_filter = {
p:out_param_pvp x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};

p:out_param_pvp x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};
}

// filters on avp parameters
// avp: Active-Verb Phrase parameter
// e.g.: "owns <company>", "studied in <university>"
avp_filter = {
p:out_param_avp x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};

p:out_param_avp x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};
}

// filters on npv parameters
// npv: implicit parameter with Noun-Phrase Value, i.e., the parameter itself will not appear in the sentence
// e.g.: "Bob is a PhD", the parameter `academic_degree` is implicit, and should be inferred by the value "PhD"
npv_filter = {
p:out_param_npv x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};

p:out_param_npv x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};
}

// filters on apv parameter
// apv: implicit parameter with Adjective-Phrase Value (similar to npv, but in adjective form)
// e.g.: "Bob is left-handed"
apv_filter = {
p:out_param_apv x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};

p:out_param_apv x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};
}

// filters on npp parameter for "whose" question
// e.g.: whose nickname is boogie?
whose_npp_filter = {
p:out_param_npp 'is' x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};

p:out_param_npp 'is' x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};
}

// generic filters on parameters in all 6 grammar categories for "who" questions
who_generic_filter = {
!turking ('has' | 'got' | 'has got') p:out_param_npp x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};
!turking ('has' | 'got' | 'has got') p:out_param_npp x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};

?turking 'has' p:out_param_npp x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};
?turking 'has' p:out_param_npp x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};

'is the' p:out_param_npi x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};
'is the' p:out_param_npi x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};

p:out_param_avp x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};
p:out_param_apv x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};

'is' p:out_param_pvp x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};
'is' p:out_param_pvp x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};

'is a' p:out_param_npv x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};
'is a' p:out_param_npv x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};

'is' p:out_param_apv x:constant_Any => {
const op = x.getType().isString ? '=~' : '==';
return C.makeFilter($options, p, op, x);
};
'is' p:out_param_apv x:constant_Any => {
return C.makeFilter($options, p, 'contains', x);
};
}
46 changes: 46 additions & 0 deletions languages/en/stream_tables.genie
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,52 @@ two_with_filter_table = {
}


npi_filtered_table = {
!nofilter table:complete_table ('that' | 'which') 'is the' filter:npi_filter => {
if (!C.checkFilter(table, filter))
return null;
return C.addFilter(table, filter, $options);
};
}

pvp_filtered_table = {
!nofilter table:complete_table filter:pvp_filter => {
if (!C.checkFilter(table, filter))
return null;
return C.addFilter(table, filter, $options);
};
}

avp_filtered_table = {
!nofilter table:complete_table ('that' | 'which' | '') filter:avp_filter => {
if (!C.checkFilter(table, filter))
return null;
return C.addFilter(table, filter, $options);
};
}

npv_filtered_table = {
!nofilter table:complete_table ('that' | 'which') 'is a' filter:npv_filter => {
if (!C.checkFilter(table, filter))
return null;
return C.addFilter(table, filter, $options);
};
}

apv_filtered_table = {
!nofilter table:complete_table ('that' | 'which') 'is' filter:apv_filter => {
if (!C.checkFilter(table, filter))
return null;
return C.addFilter(table, filter, $options);
};

!nofilter filter:apv_filter table:complete_table => {
if (!C.checkFilter(table, filter))
return null;
return C.addFilter(table, filter, $options);
};
}

edge_stream = {
!turking ('when' | 'if') 'the' p:projection_Any ('becomes' | 'becomes equal to') x:constant_Any => {
if (x.getType().isString)
Expand Down
46 changes: 46 additions & 0 deletions languages/en/thingtalk.genie
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import './timers';
import './filters';
import './parameters';
import './aggregation';
import './who_questions';

if ($options.flags.bookkeeping)
import './bookkeeping';
Expand Down Expand Up @@ -321,13 +322,58 @@ $root = {
| ('tell me' | 'give me' | 'show me' | 'present' | 'retrieve' | 'pull up') table:complete_table
| ('hey almond' | '') ('search' | 'find' | 'i want' | 'i need') table:with_filtered_table
| ('hey almond' | '') 'what are' table:with_filtered_table ('' | '?')
| ('hey almond' | '') 'what are' table:pvp_filtered_table ('' | '?')
| ('hey almond' | '') 'what are' table:avp_filtered_table ('' | '?')
| ('hey almond' | '') 'what are' table:npi_filtered_table ('' | '?')
| ('hey almond' | '') 'what are' table:npv_filtered_table ('' | '?')
| ('hey almond' | '') 'what are' table:apv_filtered_table ('' | '?')
) => C.makeProgram(new Ast.Statement.Command(table, [C.notifyAction()]));
('hey almond' | 'please' | '') ('list' | 'enumerate') table:with_filtered_table => {
if (!table.schema.is_list)
return null;
return C.makeProgram(new Ast.Statement.Command(table, [C.notifyAction()]));
};

// now => get => notify (who questions)
!turking (
('hey almond' | '') ('who' | 'which person' | 'which individual') ('has' | 'got' | 'has got' ) table:who_npp_filtered_table ('' | '?')
| ('hey almond' | '') ('who is the person' | 'who is the one' | 'who is the individual') ('with' | 'has' | 'got' | 'has got') table:who_npp_filtered_table ('' | '?')
| ('hey almond' | '') 'whose' table:whose_npp_filtered_table ('' | '?')
| ('hey almond' | '') ('who' | 'which person' | 'which individual') 'is' table:who_pvp_filtered_table ('' | '?')
| ('hey almond' | '') ('who is the person' | 'who is the one' | 'who is the individual') table:who_pvp_filtered_table ('' | '?')
| ('hey almond' | '') ('who' | 'which person' | 'which individual' | 'who is the person' | 'who is the one' | 'who is the individual') table:who_avp_filtered_table ('' | '?')
| ('hey almond' | '') ('who' | 'which person' | 'which individual') 'is the' table:who_npi_filtered_table ('' | '?')
| ('hey almond' | '') ('who' | 'which person' | 'which individual') 'is a' table:who_npv_filtered_table ('' | '?')
| ('hey almond' | '') ('who' | 'which person' | 'which individual') 'is' table:who_apv_filtered_table ('' | '?')
| ('hey almond' | '') 'which' table:who_npi_generic_filtered_table ('' | '?')
| ('hey almond' | '') 'which' table:who_npv_generic_filtered_table ('' | '?')
| ('hey almond' | '') ('who' | 'which person' | 'which individual') 'is a' table:who_apv_npv_filtered_table ('' | '?')
| ('hey almond' | '') ('who' | 'which person' | 'which individual') 'is a' table:who_apv_npi_filtered_table ('' | '?')
| ('hey almond' | '') ('who' | 'which person' | 'which individual') ('has' | 'got' | 'has got') table:who_npp_npp_filtered_table ('' | '?')
| ('hey almond' | '') ('who is the person' | 'who is the one' | 'who is the individual') ('with' | 'has' | 'got' | 'has got') table:who_npp_npp_filtered_table ('' | '?')
| ('hey almond' | '') ('who' | 'which person' | 'which individual') 'is' table:who_npi_npi_filtered_table ('' | '?')
| ('hey almond' | '') ('who' | 'which person' | 'which individual') 'is' table:who_npi_pvp_filtered_table ('' | '?')
| ('hey almond' | '') ('who' | 'which person' | 'which individual') table:who_generic_npp_filtered_table ('' | '?')
) => C.makeProgram(new Ast.Statement.Command(table, [C.notifyAction()]));
?turking (
'who has' table:who_npp_filtered_table ('' | '?')
| ('who is the one' | 'who is the person') 'with' table:who_npp_filtered_table ('' | '?')
| 'whose' table:whose_npp_filtered_table ('' | '?')
| 'who is' table:who_pvp_filtered_table ('' | '?')
| 'who' table:who_avp_filtered_table ('' | '?')
| 'who is the' table:who_npi_filtered_table ('' | '?')
| 'who is a' table:who_npv_filtered_table ('' | '?')
| 'who is' table:who_apv_filtered_table ('' | '?')
| 'which' table:who_npi_generic_filtered_table ('' | '?')
| 'which' table:who_npv_generic_filtered_table ('' | '?')
| 'who is a' table:who_apv_npv_filtered_table ('' | '?')
| 'who is a' table:who_apv_npi_filtered_table ('' | '?')
| 'who has' table:who_npp_npp_filtered_table ('' | '?')
| 'who is' table:who_npi_npi_filtered_table ('' | '?')
| 'who is' table:who_npi_pvp_filtered_table ('' | '?')
| 'who' table:who_generic_npp_filtered_table ('' | '?')
) => C.makeProgram(new Ast.Statement.Command(table, [C.notifyAction()]));

// now => get => say(...)
// don't merge these, the output sizes are too small
(
Expand Down
4 changes: 2 additions & 2 deletions languages/en/timers.genie
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const AT_TIMER_SCHEMA = new Ast.FunctionDef('stream',
}

timer = {
'every day at' time:constant_Time => new Ast.Stream.AtTimer(time, AT_TIMER_SCHEMA);
'every day at' time:constant_Time => new Ast.Stream.AtTimer([time], null, AT_TIMER_SCHEMA);

!turking {
'every' interval:constant_Measure_ms => new Ast.Stream.Timer(Ast.Value.Date.now(), interval, TIMER_SCHEMA);
Expand All @@ -50,6 +50,6 @@ timer = {
'once a month' => new Ast.Stream.Timer(Ast.Value.Date.now(), new Ast.Value.Measure(1, 'mon'), TIMER_SCHEMA);
'once a week' => new Ast.Stream.Timer(Ast.Value.Date.now(), new Ast.Value.Measure(1, 'week'), TIMER_SCHEMA);
'once an hour' => new Ast.Stream.Timer(Ast.Value.Date.now(), new Ast.Value.Measure(1, 'h'), TIMER_SCHEMA);
'daily at' time:constant_Time => new Ast.Stream.AtTimer(time, AT_TIMER_SCHEMA);
'daily at' time:constant_Time => new Ast.Stream.AtTimer([time], null, AT_TIMER_SCHEMA);
}
}
Loading

0 comments on commit 3c842fe

Please sign in to comment.