-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnorm-doc.js
executable file
·50 lines (41 loc) · 1.64 KB
/
norm-doc.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
#!/usr/bin/env node
var fs = require('fs');
var $ = require('jquery');
var prog = process.argv.shift();
if (prog.indexOf('node') >= 0)
{
prog = process.argv.shift();
}
function processFile(data, hOut)
{
var $body = $('body');
$(data).appendTo($body);
var $doc = $body.find('document');
var $sect = $body.find('section');
var $p = $body.find('p');
var $s = $body.find('[data-type=sentence]');
var $tokens = $body.find( [ '[data-type=word]',
'[data-type=ws]',
'[data-type=punc]'].join(','));
//var $w = $body.find('[data-type=word]');
//var $ws = $body.find('[data-type=ws]');
//var $punc = $body.find('[data-type=punc]');
// Assign unique identifiers for each level
$sect.each(function(idex) { $(this).attr('data-id', 'sect'+ idex); });
$p.each(function(idex) { $(this).attr('data-id', 'p'+ idex); });
$s.each(function(idex) { $(this).attr('data-id', 's'+ idex); });
$tokens.each(function(idex){ $(this).attr('data-id', 't'+ idex); });
/*
$w.each(function(idex) { $(this).attr('data-id', 'w'+ idex); });
$ws.each(function(idex) { $(this).attr('data-id', 'ws'+ idex); });
$punc.each(function(idex) { $(this).attr('data-id', 'punc'+ idex); });
// */
fs.writeSync(hOut, $body.html(), 0);
}
process.argv.forEach(function(fileIn, idex, ar) {
console.log("Input file[ %s ]\n", fileIn);
var data = fs.readFileSync(fileIn, 'utf8');
var hOut = fs.openSync(fileIn +'.out', 'w');
processFile(data, hOut);
fs.closeSync(hOut);
});