-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest.js
More file actions
executable file
·44 lines (41 loc) · 1.66 KB
/
test.js
File metadata and controls
executable file
·44 lines (41 loc) · 1.66 KB
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
#!/usr/bin/env node
/**
* AbbrevIso v1.0 JS lib for publication title abbreviation per ISO-4 standard.
* Copyright (C) 2018 by Marcin Wrochna. MIT License, see file: LICENSE.
* @fileoverview A test script for the library.
*/
'use strict';
const fs = require('fs');
const AbbrevIso = require('./nodeBundle.js');
const ltwa = fs.readFileSync('./LTWA_2024-modified.csv', 'utf8');
const shortWords = fs.readFileSync('./shortwords.txt', 'utf8');
const abbrevIso = new AbbrevIso.AbbrevIso(ltwa, shortWords);
let t = process.argv.slice(2).join(' ').trim();
if (t.length) {
t = t.normalize('NFC');
console.log('Abbreviation using all language rules:');
console.log(abbrevIso.makeAbbreviation(t));
console.log('Matching patterns:');
const matchingPatterns = abbrevIso.getMatchingPatterns(t);
for (const pattern of matchingPatterns)
console.log(pattern.line);
console.log('Possible compound patterns:');
const compoundPatterns = abbrevIso.getMatchingPatterns(t, undefined, true);
for (const pattern of compoundPatterns)
if (!matchingPatterns.includes(pattern))
console.log(pattern.line);
} else {
let rl = require('readline').createInterface({
input: fs.createReadStream('./tests.csv', { encoding: 'utf8' })
});
rl.on('line', (line) => {
line = line.split('\t', 3);
const abbrev = abbrevIso.makeAbbreviation(line[0]);
if (abbrev !== line[1] && line[1] !== '???') {
console.log(`Mismatch:\t${line[0]}\nIs: \t${abbrev}\nShould be:\t${line[1]}`);
if (line[2])
console.log(`Known issue: ${line[2]}`);
console.log('');
}
});
}