-
Notifications
You must be signed in to change notification settings - Fork 77
/
shrdlite-offline.ts
66 lines (54 loc) · 2.13 KB
/
shrdlite-offline.ts
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
///<reference path="lib/node.d.ts"/>
import {TextWorld} from "./TextWorld";
import {ExampleWorlds} from "./ExampleWorlds";
import {parseUtteranceIntoPlan, splitStringIntoPlan} from "./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).join(" | ") + ")" +
" (utterance | example no. | plan)*";
if (utterances.length == 0 || !ExampleWorlds[worldname]) {
console.error(usage);
process.exit(1);
}
// Loop through all example utterances, updating the world state
var world = new TextWorld(ExampleWorlds[worldname]);
world.printWorld();
for (var utter of utterances) {
var example : number = 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 : string[] | null = splitStringIntoPlan(utter);
if (!theplan) {
theplan = parseUtteranceIntoPlan(world, utter);
}
if (!theplan) {
console.error("ERROR: Couldn't find a plan for utterance '" + utter + "'")
process.exit(1);
} else {
console.log();
world.performPlan(theplan);
world.printWorld();
}
}