-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshrdlite-offline.js
67 lines (66 loc) · 2.9 KB
/
shrdlite-offline.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
///<reference path="lib/node.d.ts"/>
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "./TextWorld", "./ExampleWorlds", "./Shrdlite"], factory);
}
})(function (require, exports) {
"use strict";
exports.__esModule = true;
var TextWorld_1 = require("./TextWorld");
var ExampleWorlds_1 = require("./ExampleWorlds");
var Shrdlite_1 = require("./Shrdlite");
/********************************************************************************
** shrdlite-offline
This is the main file for the command-line version.
You don't have to edit this file.
********************************************************************************/
// Extract command line arguments.
var nodename = process.argv[0];
var jsfile = process.argv[1].replace(/^.*\//, "");
var worldname = process.argv[2];
var utterances = process.argv.slice(3);
// Print command usage and exit if necessary.
var usage = "Usage: " + nodename + " " + jsfile +
" (" + Object.keys(ExampleWorlds_1.ExampleWorlds).join(" | ") + ")" +
" (utterance | example no. | plan)*";
if (utterances.length == 0 || !ExampleWorlds_1.ExampleWorlds[worldname]) {
console.error(usage);
process.exit(1);
}
// Loop through all example utterances, updating the world state
var world = new TextWorld_1.TextWorld(ExampleWorlds_1.ExampleWorlds[worldname]);
world.printWorld();
for (var _i = 0, utterances_1 = utterances; _i < utterances_1.length; _i++) {
var utter = utterances_1[_i];
var example = parseInt(utter);
if (!isNaN(example)) {
utter = world.currentState.examples[example];
if (!utter) {
console.error("ERROR: Cannot find example no. " + example);
process.exit(1);
}
}
console.log();
console.log("############################################################" +
"############################################################");
console.log("#####", utter);
console.log("############################################################" +
"############################################################");
console.log();
var theplan = Shrdlite_1.splitStringIntoPlan(utter);
if (!theplan) {
theplan = Shrdlite_1.parseUtteranceIntoPlan(world, utter);
}
if (!theplan) {
console.error("ERROR: Couldn't find a plan for utterance '" + utter + "'");
process.exit(1);
}
console.log();
world.performPlan(theplan);
world.printWorld();
}
});