/* the vocabulizer! */
if (typeof(jsArguments)=='undefined') throw ("Usage: jsdb vocab.js filename.tex|filename.html");
var fin = new Stream(jsArguments[0],'rt');
var line = 0;
var istex = jsArguments[0].match(/.tex/i);
var words = new Array;
/* word object: [name: 'foo', pos: {line, line, line}]
*/
function addWord(w, line)
{
for (var x in words)
{
if (words[x].name==w)
{
words[x].pos.push(line);
return;
}
}
words.push({name: w, pos: [line]});
}
function compare(w1,w2) {return w1.pos.length - w2.pos.length;}
while (!fin.eof)
{
line ++;
var text = fin.readLine();
if (istex )
{
if (text.charAt(0) == '%') continue;
text = text.replace(/\$.*?\$/g,' ');
text = text.replace(/\\\w*/g,' ');
text = text.replace(/{.*?}/g,' ');
}
else text = text.replace(/<[^>]*>/g,' ');
text = text.replace(/[^\w]/g,' ');
list = text.split(' ');
for (var x in list)
{
if (list[x] == '') continue;
addWord(list[x].toLowerCase(),line);
}
}
var out = new Stream('~words.html','wt');
words = words.sort(compare);
var count = 0;
for (var x in words)
{
count += words[x].pos.length;
out.writeln(words[x].pos.length,' ',words[x].name,'
');
}
//http://www.m-w.com/cgi-bin/thesaurus?va=blah
writeln(count,' words');
jsShellExec('~words.html');