-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
58 lines (45 loc) · 1.15 KB
/
index.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
var BurstTrie = require("../Burst/BurstTrie.js");
var OptionsFromBSTNode = require("./OptionsFromBSTNode.js");
var LinePrefix = require("../Burst/LinePrefix.js");
var myTrie = new BurstTrie();
var myOptions = new OptionsFromBSTNode();
var loadedTerms = loadDict(myTrie,100);
getOptions(loadedTerms[0], myOptions);
function addTerm(term,trie)
{
trie.add(term);
console.log("adding " + term);
}
function getOptions(term,options)
{
var results = myTrie.get(term);
options.node = results.node;
console.log("options for " + term);
console.dir(options.getOptions(results.prefix));
console.log(options.node.getType());
console.log(options.node.asString(new LinePrefix("")));
}
function loadDict(trie,maxWords)
{
var fs = require("fs");
var data = fs.readFileSync( "dict/string.txt", "utf8");
var words = data.split(" ");
var numWords = Math.min(words.length,maxWords);
var terms = [];
var word;
for (var i=0; i < numWords; i++)
{
terms.push(words[i]);
}
terms.sort(randOrd);
for (var i=0; i < numWords; i++)
{
trie.add(terms[i]);
}
console.log(trie.toString());
return terms;
}
function randOrd()
{
return (Math.round(Math.random())-0.5);
}