| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 1 | const { execSync } = require('child_process'); |
| 2 | const exp = require('constants'); |
| 3 | |
| 4 | describe('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 Kupietz | 187bcdc | 2025-12-18 11:43:26 +0100 | [diff] [blame] | 9 | expect(stdout).toContain('😂\t😂\t_\tEMOIMG'); |
| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 10 | var emoimg_count = (stdout.match(/EMOIMG/g) || []).length; |
| Marc Kupietz | 187bcdc | 2025-12-18 11:43:26 +0100 | [diff] [blame] | 11 | expect(emoimg_count).toBe(191); |
| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 12 | var ascimg_count = (stdout.match(/EMOASC/g) || []).length; |
| Marc Kupietz | 76007d6 | 2025-12-11 17:13:05 +0100 | [diff] [blame] | 13 | expect(ascimg_count).toBe(30); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 14 | var hst_count = (stdout.match(/\tHST\t/g) || []).length; |
| Marc Kupietz | e8e40ec | 2026-04-10 15:15:59 +0200 | [diff] [blame] | 15 | expect(hst_count).toBe(12); |
| Marc Kupietz | 76007d6 | 2025-12-11 17:13:05 +0100 | [diff] [blame] | 16 | 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 Kupietz | fd92b1d | 2024-03-13 10:51:29 +0100 | [diff] [blame] | 20 | 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 Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 24 | var lines_count = (stdout.split("\n")).length; |
| Marc Kupietz | e8e40ec | 2026-04-10 15:15:59 +0200 | [diff] [blame] | 25 | expect(lines_count).toBe(803); |
| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 26 | 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 Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 32 | 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; |
| Marc Kupietz | e8e40ec | 2026-04-10 15:15:59 +0200 | [diff] [blame] | 38 | expect(hst_count).toBe(12); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 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', |
| Marc Kupietz | e8e40ec | 2026-04-10 15:15:59 +0200 | [diff] [blame] | 52 | '# text = #KorAP #3D #10', |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 53 | ['1', '#KorAP', '_', '_', '_', '_', '_', '_', '_', '_'].join('\t'), |
| Marc Kupietz | e8e40ec | 2026-04-10 15:15:59 +0200 | [diff] [blame] | 54 | ['2', '#3D', '_', '_', '_', '_', '_', '_', '_', '_'].join('\t'), |
| 55 | ['3', '#10', '_', '_', '_', '_', '_', '_', '_', '_'].join('\t'), |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 56 | '' |
| 57 | ].join('\n'); |
| 58 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| 59 | |
| 60 | expect(stdout).toContain('#KorAP\t_\t_\tHST'); |
| Marc Kupietz | e8e40ec | 2026-04-10 15:15:59 +0200 | [diff] [blame] | 61 | expect(stdout).toContain('#3D\t_\t_\tHST'); |
| 62 | expect(stdout).not.toContain('#10\t_\t_\tHST'); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 63 | |
| 64 | var hst_count = (stdout.match(/\tHST\t/g) || []).length; |
| 65 | expect(hst_count).toBe(2); |
| 66 | done(); |
| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 67 | }); |
| Marc Kupietz | b5d80b3 | 2025-12-11 15:48:09 +0100 | [diff] [blame] | 68 | |
| Marc Kupietz | 804750d | 2026-04-10 14:44:13 +0200 | [diff] [blame] | 69 | test('Regression test for addresses: emit ADR regardless of existing POS values', (done) => { |
| 70 | const testInput = [ |
| 71 | '# foundry = base', |
| 72 | '# text_id = test-address', |
| 73 | '# text = @handle @markup', |
| 74 | ['1', '@handle', '_', 'PROPN', '_', '_', '_', '_', '_', '_'].join('\t'), |
| 75 | ['2', '@markup', '_', 'NE', '_', '_', '_', '_', '_', '_'].join('\t'), |
| 76 | '' |
| 77 | ].join('\n'); |
| 78 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| 79 | |
| 80 | expect(stdout).toContain('@handle\t_\tPROPN\tADR'); |
| 81 | expect(stdout).toContain('@markup\t_\tNE\tADR'); |
| 82 | |
| 83 | var adr_count = (stdout.match(/\tADR\t/g) || []).length; |
| 84 | expect(adr_count).toBe(2); |
| 85 | done(); |
| 86 | }); |
| 87 | |
| Marc Kupietz | b5d80b3 | 2025-12-11 15:48:09 +0100 | [diff] [blame] | 88 | test('Regression test for issue #113: emoji modifiers and ZWJ', (done) => { |
| 89 | // Test that compound emojis with modifiers and ZWJ are recognized as single EMOIMG tokens |
| 90 | const testInput = `# foundry = base |
| 91 | # text_id = test-113 |
| 92 | # text = ✊🏿 and 👨👨👦 |
| 93 | 1 ✊🏿 _ _ _ _ _ _ _ _ |
| 94 | 2 and _ CCONJ _ _ _ _ _ _ |
| 95 | 3 👨👨👦 _ _ _ _ _ _ _ _ |
| 96 | |
| 97 | `; |
| 98 | const { execSync } = require('child_process'); |
| 99 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 100 | |
| Marc Kupietz | a7934e0 | 2025-12-18 07:25:53 +0100 | [diff] [blame] | 101 | // Check that compound emojis are tagged as EMOIMG and lemma has base emoji |
| Marc Kupietz | 187bcdc | 2025-12-18 11:43:26 +0100 | [diff] [blame] | 102 | expect(stdout).toContain('✊🏿\t✊\t_\tEMOIMG'); |
| 103 | expect(stdout).toContain('👨👨👦\t👨\t_\tEMOIMG'); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 104 | |
| Marc Kupietz | 76007d6 | 2025-12-11 17:13:05 +0100 | [diff] [blame] | 105 | // Count EMOIMG occurrences (should be 1 per emoji - only in XPOS column) |
| Marc Kupietz | b5d80b3 | 2025-12-11 15:48:09 +0100 | [diff] [blame] | 106 | var emoimg_count = (stdout.match(/EMOIMG/g) || []).length; |
| Marc Kupietz | 187bcdc | 2025-12-18 11:43:26 +0100 | [diff] [blame] | 107 | expect(emoimg_count).toBe(2); // 2 emojis × 1 column = 2 |
| Marc Kupietz | b5d80b3 | 2025-12-11 15:48:09 +0100 | [diff] [blame] | 108 | done(); |
| 109 | }); |
| 110 | |
| Marc Kupietz | 7497fc4 | 2025-12-11 15:47:34 +0100 | [diff] [blame] | 111 | test('Regression test for issue #114: Wikipedia emoji templates', (done) => { |
| 112 | // Test that Wikipedia emoji templates are recognized as EMOWIKI tokens |
| 113 | const testInput = `# foundry = base |
| 114 | # text_id = test-114 |
| 115 | # text = [_EMOJI:{{S|;)}}_] and [_EMOJI:{{cool}}_] |
| 116 | 1 [_EMOJI:{{S|;)}}_] _ _ _ _ _ _ _ _ |
| 117 | 2 and _ CCONJ _ _ _ _ _ _ |
| 118 | 3 [_EMOJI:{{cool}}_] _ _ _ _ _ _ _ _ |
| 119 | |
| 120 | `; |
| 121 | const { execSync } = require('child_process'); |
| 122 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 123 | |
| Marc Kupietz | 76007d6 | 2025-12-11 17:13:05 +0100 | [diff] [blame] | 124 | // Check that Wikipedia emoji templates are tagged as EMOWIKI in XPOS column only |
| 125 | expect(stdout).toContain('[_EMOJI:{{S|;)}}_]\t_\t_\tEMOWIKI'); |
| 126 | expect(stdout).toContain('[_EMOJI:{{cool}}_]\t_\t_\tEMOWIKI'); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 127 | |
| Marc Kupietz | 76007d6 | 2025-12-11 17:13:05 +0100 | [diff] [blame] | 128 | // Count EMOWIKI occurrences (should be 1 per template - only in XPOS column) |
| Marc Kupietz | 7497fc4 | 2025-12-11 15:47:34 +0100 | [diff] [blame] | 129 | var emowiki_count = (stdout.match(/EMOWIKI/g) || []).length; |
| Marc Kupietz | 76007d6 | 2025-12-11 17:13:05 +0100 | [diff] [blame] | 130 | expect(emowiki_count).toBe(2); // 2 templates × 1 column = 2 |
| Marc Kupietz | 7497fc4 | 2025-12-11 15:47:34 +0100 | [diff] [blame] | 131 | done(); |
| 132 | }); |
| Marc Kupietz | 30634ff | 2025-12-18 11:39:03 +0100 | [diff] [blame] | 133 | |
| 134 | test('Test emoji metadata in FEATS column', (done) => { |
| 135 | // Test that EMOIMG tokens have populated FEATS column |
| 136 | const testInput = `# foundry = base |
| 137 | # text_id = test-feats |
| 138 | # text = 😇 |
| 139 | 1 😇 _ _ _ _ _ _ _ _ |
| 140 | |
| 141 | `; |
| 142 | const { execSync } = require('child_process'); |
| 143 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 144 | |
| Marc Kupietz | 30634ff | 2025-12-18 11:39:03 +0100 | [diff] [blame] | 145 | // Check that 😇 has correct metadata |
| 146 | // g=smileys_and_emotion|s=face_smiling|q=fully_qualified|v=E1.0|n=smiling_face_with_halo |
| 147 | // Note: spaces in data are replaced by _ in our script |
| 148 | expect(stdout).toContain('g=smileys_&_emotion|s=face_smiling|q=fully_qualified|v=E1.0|n=smiling_face_with_halo'); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 149 | |
| Marc Kupietz | 30634ff | 2025-12-18 11:39:03 +0100 | [diff] [blame] | 150 | // Also check for the base emoji lemma and tags |
| Marc Kupietz | 187bcdc | 2025-12-18 11:43:26 +0100 | [diff] [blame] | 151 | expect(stdout).toContain('😇\t😇\t_\tEMOIMG'); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 152 | |
| Marc Kupietz | 30634ff | 2025-12-18 11:39:03 +0100 | [diff] [blame] | 153 | done(); |
| 154 | }); |
| Marc Kupietz | 2de30e2 | 2026-04-11 12:49:52 +0200 | [diff] [blame^] | 155 | |
| 156 | test('Test normalized emoji-name separators in FEATS', (done) => { |
| 157 | const testInput = `# foundry = base |
| 158 | # text_id = test-name-normalization |
| 159 | # text = 👍🏻 👨👨👦 |
| 160 | 1 👍🏻 _ _ _ _ _ _ _ _ |
| 161 | 2 👨👨👦 _ _ _ _ _ _ _ _ |
| 162 | |
| 163 | `; |
| 164 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| 165 | |
| 166 | expect(stdout).toContain('n=thumbs_up:light_skin_tone'); |
| 167 | expect(stdout).toContain('n=family:man,man,boy'); |
| 168 | expect(stdout).not.toContain('n=thumbs_up:_light_skin_tone'); |
| 169 | expect(stdout).not.toContain('n=family:_man,_man,_boy'); |
| 170 | |
| 171 | done(); |
| 172 | }); |
| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 173 | }); |