-
Notifications
You must be signed in to change notification settings - Fork 21
/
test_sentence_generator_manual.js
71 lines (62 loc) · 2.04 KB
/
test_sentence_generator_manual.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env node
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of ThingEngine
//
// Copyright 2017 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna <gcampagn@cs.stanford.edu>
//
// See COPYING for details
"use strict";
process.on('unhandledRejection', (up) => { throw up; });
const fs = require('fs');
const stream = require('stream');
const seedrandom = require('seedrandom');
const argparse = require('argparse');
const SentenceGenerator = require('../lib/sentence-generator');
const _tpClient = require('./mock_schema_delegate');
function main() {
const parser = new argparse.ArgumentParser({
addHelp: true,
description: 'Update Thingpedia Dataset'
});
parser.addArgument(['-o', '--output'], {
required: true,
type: fs.createWriteStream
});
parser.addArgument('--maxdepth', {
type: Number,
defaultValue: 6,
help: 'Maximum depth of synthetic sentence generation',
});
parser.addArgument('--turking', {
nargs: 0,
action: 'storeTrue',
help: 'Restrict grammar rules to MTurk-friendly ones.',
defaultValue: false
});
const args = parser.parseArgs();
const options = {
rng: seedrandom.alea('almond is awesome'),
language: 'en',
targetLanguage: 'thingtalk',
thingpediaClient: _tpClient,
turkingMode: args.turking,
maxDepth: args.maxdepth,
debug: true
};
const generator = new SentenceGenerator(options);
const transform = new stream.Transform({
writableObjectMode: true,
transform(ex, encoding, callback) {
callback(null, ex.id + '\t' + ex.utterance + '\t' + ex.target_code + '\n');
},
flush(callback) {
process.nextTick(callback);
}
});
generator.pipe(transform).pipe(args.output);
args.output.on('finish', () => process.exit());
}
return main();