blob: 0f670e7a42319d33b4c8f1b578b5654504c9ea4a [file] [log] [blame]
Marc Kupietzb43a5182024-02-03 18:09:10 +01001const { execSync } = require('child_process');
2const exp = require('constants');
3
4describe('conllu2cmc', () => {
5 test('Test sparse mode', (done) => {
6 // Modify the command based on your script's location and options
7 const command = 'node src/index.js -s < test/data/ndy.conllu';
8 const stdout = execSync(command).toString();
Marc Kupietz187bcdc2025-12-18 11:43:26 +01009 expect(stdout).toContain('😂\t😂\t_\tEMOIMG');
Marc Kupietzb43a5182024-02-03 18:09:10 +010010 var emoimg_count = (stdout.match(/EMOIMG/g) || []).length;
Marc Kupietz187bcdc2025-12-18 11:43:26 +010011 expect(emoimg_count).toBe(191);
Marc Kupietzb43a5182024-02-03 18:09:10 +010012 var ascimg_count = (stdout.match(/EMOASC/g) || []).length;
Marc Kupietz76007d62025-12-11 17:13:05 +010013 expect(ascimg_count).toBe(30);
Marc Kupietzc2875332026-04-10 14:21:06 +020014 var hst_count = (stdout.match(/\tHST\t/g) || []).length;
15 expect(hst_count).toBe(14);
Marc Kupietz76007d62025-12-11 17:13:05 +010016 var url_count = (stdout.match(/\tURL\t/g) || []).length;
17 expect(url_count).toBe(4);
18 var adr_count = (stdout.match(/\tADR\t/g) || []).length;
19 expect(adr_count).toBe(1);
Marc Kupietzfd92b1d2024-03-13 10:51:29 +010020 var eot_count = (stdout.match(/\n# eot/g) || []).length;
21 expect(eot_count).toBe(1);
22 var eof_count = (stdout.match(/\n# eof/g) || []).length;
23 expect(eof_count).toBe(1);
Marc Kupietzb43a5182024-02-03 18:09:10 +010024 var lines_count = (stdout.split("\n")).length;
Marc Kupietzc2875332026-04-10 14:21:06 +020025 expect(lines_count).toBe(810);
Marc Kupietzb43a5182024-02-03 18:09:10 +010026 done();
27 });
28
29 test('Test full mode', (done) => {
30 const command = 'node src/index.js < test/data/ndy.conllu';
31 const stdout = execSync(command).toString();
Marc Kupietzc2875332026-04-10 14:21:06 +020032 expect(stdout).toContain('😂\t😂\t_\tEMOIMG');
33 var emoimg_count = (stdout.match(/EMOIMG/g) || []).length;
34 expect(emoimg_count).toBe(191);
35 var ascimg_count = (stdout.match(/EMOASC/g) || []).length;
36 expect(ascimg_count).toBe(30);
37 var hst_count = (stdout.match(/\tHST\t/g) || []).length;
38 expect(hst_count).toBe(14);
39 var url_count = (stdout.match(/\tURL\t/g) || []).length;
40 expect(url_count).toBe(4);
41 var adr_count = (stdout.match(/\tADR\t/g) || []).length;
42 expect(adr_count).toBe(1);
43 var lines_count = (stdout.split("\n")).length;
44 expect(lines_count).toBe(6202);
45 done();
46 });
47
48 test('Regression test for hashtags: emit HST', (done) => {
49 const testInput = [
50 '# foundry = base',
51 '# text_id = test-hashtag',
52 '# text = #KorAP #10',
53 ['1', '#KorAP', '_', '_', '_', '_', '_', '_', '_', '_'].join('\t'),
54 ['2', '#10', '_', '_', '_', '_', '_', '_', '_', '_'].join('\t'),
55 ''
56 ].join('\n');
57 const stdout = execSync('node src/index.js', { input: testInput }).toString();
58
59 expect(stdout).toContain('#KorAP\t_\t_\tHST');
60 expect(stdout).toContain('#10\t_\t_\tHST');
61
62 var hst_count = (stdout.match(/\tHST\t/g) || []).length;
63 expect(hst_count).toBe(2);
64 done();
Marc Kupietzb43a5182024-02-03 18:09:10 +010065 });
Marc Kupietzb5d80b32025-12-11 15:48:09 +010066
67 test('Regression test for issue #113: emoji modifiers and ZWJ', (done) => {
68 // Test that compound emojis with modifiers and ZWJ are recognized as single EMOIMG tokens
69 const testInput = `# foundry = base
70# text_id = test-113
71# text = ✊🏿 and 👨‍👨‍👦
721 ✊🏿 _ _ _ _ _ _ _ _
732 and _ CCONJ _ _ _ _ _ _
743 👨‍👨‍👦 _ _ _ _ _ _ _ _
75
76`;
77 const { execSync } = require('child_process');
78 const stdout = execSync('node src/index.js', { input: testInput }).toString();
Marc Kupietzc2875332026-04-10 14:21:06 +020079
Marc Kupietza7934e02025-12-18 07:25:53 +010080 // Check that compound emojis are tagged as EMOIMG and lemma has base emoji
Marc Kupietz187bcdc2025-12-18 11:43:26 +010081 expect(stdout).toContain('✊🏿\t✊\t_\tEMOIMG');
82 expect(stdout).toContain('👨‍👨‍👦\t👨\t_\tEMOIMG');
Marc Kupietzc2875332026-04-10 14:21:06 +020083
Marc Kupietz76007d62025-12-11 17:13:05 +010084 // Count EMOIMG occurrences (should be 1 per emoji - only in XPOS column)
Marc Kupietzb5d80b32025-12-11 15:48:09 +010085 var emoimg_count = (stdout.match(/EMOIMG/g) || []).length;
Marc Kupietz187bcdc2025-12-18 11:43:26 +010086 expect(emoimg_count).toBe(2); // 2 emojis × 1 column = 2
Marc Kupietzb5d80b32025-12-11 15:48:09 +010087 done();
88 });
89
Marc Kupietz7497fc42025-12-11 15:47:34 +010090 test('Regression test for issue #114: Wikipedia emoji templates', (done) => {
91 // Test that Wikipedia emoji templates are recognized as EMOWIKI tokens
92 const testInput = `# foundry = base
93# text_id = test-114
94# text = [_EMOJI:{{S|;)}}_] and [_EMOJI:{{cool}}_]
951 [_EMOJI:{{S|;)}}_] _ _ _ _ _ _ _ _
962 and _ CCONJ _ _ _ _ _ _
973 [_EMOJI:{{cool}}_] _ _ _ _ _ _ _ _
98
99`;
100 const { execSync } = require('child_process');
101 const stdout = execSync('node src/index.js', { input: testInput }).toString();
Marc Kupietzc2875332026-04-10 14:21:06 +0200102
Marc Kupietz76007d62025-12-11 17:13:05 +0100103 // Check that Wikipedia emoji templates are tagged as EMOWIKI in XPOS column only
104 expect(stdout).toContain('[_EMOJI:{{S|;)}}_]\t_\t_\tEMOWIKI');
105 expect(stdout).toContain('[_EMOJI:{{cool}}_]\t_\t_\tEMOWIKI');
Marc Kupietzc2875332026-04-10 14:21:06 +0200106
Marc Kupietz76007d62025-12-11 17:13:05 +0100107 // Count EMOWIKI occurrences (should be 1 per template - only in XPOS column)
Marc Kupietz7497fc42025-12-11 15:47:34 +0100108 var emowiki_count = (stdout.match(/EMOWIKI/g) || []).length;
Marc Kupietz76007d62025-12-11 17:13:05 +0100109 expect(emowiki_count).toBe(2); // 2 templates × 1 column = 2
Marc Kupietz7497fc42025-12-11 15:47:34 +0100110 done();
111 });
Marc Kupietz30634ff2025-12-18 11:39:03 +0100112
113 test('Test emoji metadata in FEATS column', (done) => {
114 // Test that EMOIMG tokens have populated FEATS column
115 const testInput = `# foundry = base
116# text_id = test-feats
117# text = 😇
1181 😇 _ _ _ _ _ _ _ _
119
120`;
121 const { execSync } = require('child_process');
122 const stdout = execSync('node src/index.js', { input: testInput }).toString();
Marc Kupietzc2875332026-04-10 14:21:06 +0200123
Marc Kupietz30634ff2025-12-18 11:39:03 +0100124 // Check that 😇 has correct metadata
125 // g=smileys_and_emotion|s=face_smiling|q=fully_qualified|v=E1.0|n=smiling_face_with_halo
126 // Note: spaces in data are replaced by _ in our script
127 expect(stdout).toContain('g=smileys_&_emotion|s=face_smiling|q=fully_qualified|v=E1.0|n=smiling_face_with_halo');
Marc Kupietzc2875332026-04-10 14:21:06 +0200128
Marc Kupietz30634ff2025-12-18 11:39:03 +0100129 // Also check for the base emoji lemma and tags
Marc Kupietz187bcdc2025-12-18 11:43:26 +0100130 expect(stdout).toContain('😇\t😇\t_\tEMOIMG');
Marc Kupietzc2875332026-04-10 14:21:06 +0200131
Marc Kupietz30634ff2025-12-18 11:39:03 +0100132 done();
133 });
Marc Kupietzb43a5182024-02-03 18:09:10 +0100134});