Datasets:
Regenerate UDD-WS v1.1 dataset and update annotation tooling
Browse files- WS_FIX_REPORT.md +180 -118
- ls_import_cycle1.json +0 -0
- src/build_dict_plugin.py +329 -240
- src/dict_data.json +0 -0
- src/dict_plugin.js +225 -0
- src/ls_config_ws.xml +2 -3
- src/ls_import_ws.py +52 -26
- udd-ws-v1.1-dev.conllu +0 -0
- udd-ws-v1.1-dev.txt +0 -0
- udd-ws-v1.1-test.conllu +0 -0
- udd-ws-v1.1-test.txt +0 -0
- udd-ws-v1.1-train.conllu +2 -2
- udd-ws-v1.1-train.txt +2 -2
WS_FIX_REPORT.md
CHANGED
|
@@ -6,148 +6,210 @@ Fixes applied by `src/fix_ws_errors.py` to UDD-1.1 word segmentation BIO files.
|
|
| 6 |
|
| 7 |
| File | Cross-boundary splits | Long token splits | Compound merges | Validation errors |
|
| 8 |
|------|----------------------:|------------------:|----------------:|------------------:|
|
| 9 |
-
| udd-ws-v1.1-train.txt |
|
| 10 |
-
| udd-ws-v1.1-dev.txt |
|
| 11 |
-
| udd-ws-v1.1-test.txt |
|
| 12 |
-
| **TOTAL** | **
|
| 13 |
|
| 14 |
## Merge Frequency by Term
|
| 15 |
|
| 16 |
| Term | Count |
|
| 17 |
|:-----|------:|
|
| 18 |
-
|
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
## Cross-Boundary Split Examples
|
| 22 |
|
| 23 |
### udd-ws-v1.1-train.txt
|
| 24 |
|
| 25 |
-
- [uvw-
|
| 26 |
-
- [
|
| 27 |
-
- [
|
| 28 |
-
- [uvw-
|
| 29 |
-
- [
|
| 30 |
-
- [
|
| 31 |
-
- [
|
| 32 |
-
- [
|
| 33 |
-
- [
|
| 34 |
-
- [
|
| 35 |
-
- [
|
| 36 |
-
- [
|
| 37 |
-
- [
|
| 38 |
-
- [
|
| 39 |
-
- [uvw-
|
| 40 |
-
- [uvw-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
### udd-ws-v1.1-dev.txt
|
| 43 |
|
| 44 |
-
- [
|
| 45 |
-
- [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
### udd-ws-v1.1-test.txt
|
| 48 |
|
| 49 |
-
- [uvw-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
## Long Token Split Examples
|
| 52 |
|
| 53 |
### udd-ws-v1.1-train.txt
|
| 54 |
|
| 55 |
-
- [
|
| 56 |
-
- [
|
| 57 |
-
- [vlc-
|
| 58 |
-
- [
|
| 59 |
-
- [vlc-
|
| 60 |
-
- [
|
| 61 |
-
- [
|
| 62 |
-
- [
|
| 63 |
-
- [
|
| 64 |
-
- [vlc-
|
| 65 |
-
- [vlc-
|
| 66 |
-
- [vlc-
|
| 67 |
-
- [
|
| 68 |
-
- [
|
| 69 |
-
- [vlc-
|
| 70 |
-
- [
|
| 71 |
-
- [
|
| 72 |
-
- [
|
| 73 |
-
- [vlc-
|
| 74 |
-
- [
|
| 75 |
-
- [
|
| 76 |
-
- [vlc-
|
| 77 |
-
- [
|
| 78 |
-
- [vlc-
|
| 79 |
-
- [vlc-
|
| 80 |
-
- [vlc-
|
| 81 |
-
- [vlc-
|
| 82 |
-
- [vlc-
|
| 83 |
-
- [
|
| 84 |
-
- [vlc-
|
| 85 |
-
- ... and
|
| 86 |
|
| 87 |
### udd-ws-v1.1-dev.txt
|
| 88 |
|
| 89 |
-
- [vlc-
|
| 90 |
-
- [
|
| 91 |
-
- [
|
| 92 |
-
- [
|
| 93 |
-
- [vlc-
|
| 94 |
-
- [vlc-
|
| 95 |
-
- [
|
| 96 |
-
- [vlc-
|
| 97 |
-
- [vlc-
|
| 98 |
-
- [vlc-
|
| 99 |
-
- [uvw-
|
| 100 |
-
- [vlc-
|
| 101 |
-
- [
|
| 102 |
-
- [
|
| 103 |
-
- [uvw-
|
| 104 |
-
- [
|
| 105 |
-
- [vlc-
|
| 106 |
-
- [
|
| 107 |
-
- [vlc-
|
| 108 |
-
- [vlc-
|
| 109 |
-
- [
|
| 110 |
-
- [vlc-
|
| 111 |
-
- [vlc-
|
| 112 |
-
- [vlc-
|
| 113 |
-
- [vlc-
|
| 114 |
-
- [vlc-
|
| 115 |
-
- [
|
| 116 |
-
- [
|
| 117 |
-
- [vlc-
|
| 118 |
-
- [
|
| 119 |
-
- ... and
|
| 120 |
|
| 121 |
### udd-ws-v1.1-test.txt
|
| 122 |
|
| 123 |
-
- [
|
| 124 |
-
- [
|
| 125 |
-
- [vlc-
|
| 126 |
-
- [
|
| 127 |
-
- [vlc-
|
| 128 |
-
- [vlc-
|
| 129 |
-
- [vlc-
|
| 130 |
-
- [vlc-
|
| 131 |
-
- [
|
| 132 |
-
- [vlc-
|
| 133 |
-
- [vlc-
|
| 134 |
-
- [vlc-
|
| 135 |
-
- [
|
| 136 |
-
- [vlc-
|
| 137 |
-
- [vlc-
|
| 138 |
-
- [
|
| 139 |
-
- [
|
| 140 |
-
- [vlc-
|
| 141 |
-
- [
|
| 142 |
-
- [vlc-
|
| 143 |
-
- [
|
| 144 |
-
- [vlc-
|
| 145 |
-
- [
|
| 146 |
-
- [uvw-
|
| 147 |
-
- [vlc-
|
| 148 |
-
- [
|
| 149 |
-
- [vlc-
|
| 150 |
-
- [vlc-
|
| 151 |
-
- [
|
| 152 |
-
- [vlc-
|
| 153 |
-
- ... and
|
|
|
|
| 6 |
|
| 7 |
| File | Cross-boundary splits | Long token splits | Compound merges | Validation errors |
|
| 8 |
|------|----------------------:|------------------:|----------------:|------------------:|
|
| 9 |
+
| udd-ws-v1.1-train.txt | 4,969 | 725 | 1,870 | 0 |
|
| 10 |
+
| udd-ws-v1.1-dev.txt | 598 | 87 | 222 | 0 |
|
| 11 |
+
| udd-ws-v1.1-test.txt | 611 | 79 | 233 | 0 |
|
| 12 |
+
| **TOTAL** | **6,178** | **891** | **2,325** | **0** |
|
| 13 |
|
| 14 |
## Merge Frequency by Term
|
| 15 |
|
| 16 |
| Term | Count |
|
| 17 |
|:-----|------:|
|
| 18 |
+
| hàng hóa | 759 |
|
| 19 |
+
| chữa bệnh | 326 |
|
| 20 |
+
| khám bệnh | 255 |
|
| 21 |
+
| vụ án | 209 |
|
| 22 |
+
| hòa giải | 138 |
|
| 23 |
+
| kèm theo | 107 |
|
| 24 |
+
| trả lại | 86 |
|
| 25 |
+
| làm chủ | 82 |
|
| 26 |
+
| phạt tù | 82 |
|
| 27 |
+
| hủy bỏ | 81 |
|
| 28 |
+
| phiên tòa | 44 |
|
| 29 |
+
| bị hại | 37 |
|
| 30 |
+
| ghi rõ | 35 |
|
| 31 |
+
| rút gọn | 34 |
|
| 32 |
+
| tiền công | 27 |
|
| 33 |
+
| quá hạn | 9 |
|
| 34 |
+
| chủ tọa | 7 |
|
| 35 |
+
| lời khai | 5 |
|
| 36 |
+
| thuê khoán | 1 |
|
| 37 |
+
| bốc hàng | 1 |
|
| 38 |
|
| 39 |
## Cross-Boundary Split Examples
|
| 40 |
|
| 41 |
### udd-ws-v1.1-train.txt
|
| 42 |
|
| 43 |
+
- [uvw-12640] split "nhà Minh" → 'nhà' + 'Minh'
|
| 44 |
+
- [vlc-18105] split "ban Thường vụ Quốc hội" → 'ban' + 'Thường vụ' + 'Quốc hội'
|
| 45 |
+
- [uvn-5192] split "nam MC" → 'nam' + 'MC'
|
| 46 |
+
- [uvw-13051] split "diễn văn Gettysburg" → 'diễn văn' + 'Gettysburg'
|
| 47 |
+
- [uvn-11996] split "sàn London" → 'sàn' + 'London'
|
| 48 |
+
- [uvb-f-11285] split "Tiên phong Thiên Giới" → 'Tiên phong' + 'Thiên Giới'
|
| 49 |
+
- [uvn-1652] split "giải Vietstock" → 'giải' + 'Vietstock'
|
| 50 |
+
- [uvn-1652] split "Nông nghiệp và Môi trường" → 'Nông nghiệp và' + 'Môi trường'
|
| 51 |
+
- [uvn-15129] split "chuyên Sinh" → 'chuyên' + 'Sinh'
|
| 52 |
+
- [uvb-n-18150] split "vua Kiệt" → 'vua' + 'Kiệt'
|
| 53 |
+
- [uvn-11110] split "bắc Tử" → 'bắc' + 'Tử'
|
| 54 |
+
- [uvb-n-7068] split "phái Duy Vật" → 'phái' + 'Duy Vật'
|
| 55 |
+
- [uvb-n-10940] split "quân Anh" → 'quân' + 'Anh'
|
| 56 |
+
- [uvn-3318] split "chuẩn Anh" → 'chuẩn' + 'Anh'
|
| 57 |
+
- [uvw-11565] split "nhà Thương" → 'nhà' + 'Thương'
|
| 58 |
+
- [uvw-14254] split "châu Á" → 'châu' + 'Á'
|
| 59 |
+
- [uvn-6648] split "hình X-quang" → 'hình' + 'X-quang'
|
| 60 |
+
- [uvn-3392] split "bảng G ." → 'bảng' + 'G .'
|
| 61 |
+
- [uvn-3392] split "bảng H" → 'bảng' + 'H'
|
| 62 |
+
- [uvn-8106] split "châu Âu" → 'châu' + 'Âu'
|
| 63 |
+
- ... and 4949 more
|
| 64 |
|
| 65 |
### udd-ws-v1.1-dev.txt
|
| 66 |
|
| 67 |
+
- [uvb-n-730] split "mừng Lễ" → 'mừng' + 'Lễ'
|
| 68 |
+
- [uvn-7093] split "chữ T" → 'chữ' + 'T'
|
| 69 |
+
- [uvn-3234] split "môn Văn cấp" → 'môn' + 'Văn cấp'
|
| 70 |
+
- [uvw-10521] split "of Plants" → 'of' + 'Plants'
|
| 71 |
+
- [uvb-n-5230] split "châu Âu" → 'châu' + 'Âu'
|
| 72 |
+
- [uvw-380] split "quẻ Sư 師" → 'quẻ' + 'Sư 師'
|
| 73 |
+
- [uvb-f-19862] split "bán TV" → 'bán' + 'TV'
|
| 74 |
+
- [uvn-207] split "9.0 IELTS" → '9.0' + 'IELTS'
|
| 75 |
+
- [uvw-9988] split "Đế quốc Đông" → 'Đế quốc' + 'Đông'
|
| 76 |
+
- [uvw-8703] split "phân Riemann" → 'phân' + 'Riemann'
|
| 77 |
+
- [vlc-16923] split "và Phát triển nông thôn" → 'và' + 'Phát triển nông thôn'
|
| 78 |
+
- [uvw-7715] split "châu Phi Francophone" → 'châu' + 'Phi Francophone'
|
| 79 |
+
- [vlc-19028] split "và Phát triển nông thôn" → 'và' + 'Phát triển nông thôn'
|
| 80 |
+
- [uvw-18298] split ":: Một" → '::' + 'Một'
|
| 81 |
+
- [uvn-6630] split "hành Perseverance" → 'hành' + 'Perseverance'
|
| 82 |
+
- [uvn-2592] split "da Luz" → 'da' + 'Luz'
|
| 83 |
+
- [uvn-15632] split "phi hành gia NASA" → 'phi hành gia' + 'NASA'
|
| 84 |
+
- [vlc-8981] split "thường vụ Quốc hội" → 'thường vụ' + 'Quốc hội'
|
| 85 |
+
- [uvw-7003] split "châu Âu" → 'châu' + 'Âu'
|
| 86 |
+
- [uvn-115] split "Giáo dục và Đào tạo" → 'Giáo dục và' + 'Đào tạo'
|
| 87 |
+
- ... and 578 more
|
| 88 |
|
| 89 |
### udd-ws-v1.1-test.txt
|
| 90 |
|
| 91 |
+
- [uvw-10170] split "phương Nam" → 'phương' + 'Nam'
|
| 92 |
+
- [uvw-10170] split "thời Trung Cổ" → 'thời' + 'Trung Cổ'
|
| 93 |
+
- [vlc-6223] split "thường vụ Quốc hội" → 'thường vụ' + 'Quốc hội'
|
| 94 |
+
- [vlc-6223] split "Mặt trận Tổ quốc" → 'Mặt trận' + 'Tổ quốc'
|
| 95 |
+
- [uvn-2071] split "tây Nam Cực" → 'tây' + 'Nam Cực'
|
| 96 |
+
- [uvn-19983] split "fanpage Facebook" → 'fanpage' + 'Facebook'
|
| 97 |
+
- [uvn-19983] split "nhắn SMS" → 'nhắn' + 'SMS'
|
| 98 |
+
- [uvw-4834] split "châu Phi" → 'châu' + 'Phi'
|
| 99 |
+
- [uvw-4834] split "châu Phi" → 'châu' + 'Phi'
|
| 100 |
+
- [uvb-n-1229] split "matières Le" → 'matières' + 'Le'
|
| 101 |
+
- [uvb-f-17918] split "gả Loan" → 'gả' + 'Loan'
|
| 102 |
+
- [uvb-f-17918] split "phán Lợi" → 'phán' + 'Lợi'
|
| 103 |
+
- [uvb-f-11852] split "‘ Người" → '‘' + 'Người'
|
| 104 |
+
- [uvb-f-4210] split "quân Urgals" → 'quân' + 'Urgals'
|
| 105 |
+
- [uvw-18184] split "quân H'mong" → 'quân' + "H'mong"
|
| 106 |
+
- [vlc-13904] split "thường vụ Quốc hội" → 'thường vụ' + 'Quốc hội'
|
| 107 |
+
- [uvn-17235] split "giải Jackpot" → 'giải' + 'Jackpot'
|
| 108 |
+
- [uvn-3787] split "Thế chiến Ii" → 'Thế chiến' + 'Ii'
|
| 109 |
+
- [uvw-14649] split "nhà Hồ" → 'nhà' + 'Hồ'
|
| 110 |
+
- [uvw-14649] split "quân Minh" → 'quân' + 'Minh'
|
| 111 |
+
- ... and 591 more
|
| 112 |
|
| 113 |
## Long Token Split Examples
|
| 114 |
|
| 115 |
### udd-ws-v1.1-train.txt
|
| 116 |
|
| 117 |
+
- [vlc-16418] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
|
| 118 |
+
- [vlc-366] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
|
| 119 |
+
- [vlc-18939] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 120 |
+
- [uvw-3718] split "lực lượng vũ trang giáo phái" → 'lực lượng vũ trang' + 'giáo phái'
|
| 121 |
+
- [vlc-19939] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 122 |
+
- [uvn-5647] split "phương tiện thông tin đại chúng" → 'phương tiện' + 'thông tin đại chúng'
|
| 123 |
+
- [vlc-4038] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 124 |
+
- [vlc-9598] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 125 |
+
- [vlc-121] split "luật tố tụng hình sự" → 'luật' + 'tố tụng hình sự'
|
| 126 |
+
- [vlc-121] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 127 |
+
- [vlc-2994] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
|
| 128 |
+
- [vlc-2994] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
|
| 129 |
+
- [uvw-3692] split "Thanh Tâm Tài Nhân thảo" → 'Thanh Tâm' + 'Tài Nhân' + 'thảo'
|
| 130 |
+
- [uvn-11014] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 131 |
+
- [vlc-7080] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
|
| 132 |
+
- [vlc-1414] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
|
| 133 |
+
- [uvn-15822] split "Chúng sở hữu cơ thể" → 'Chúng' + 'sở hữu' + 'cơ thể'
|
| 134 |
+
- [vlc-14193] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 135 |
+
- [vlc-15939] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 136 |
+
- [vlc-17799] split "Bộ Tài nguyên và Môi trường" → 'Bộ' + 'Tài nguyên' + 'và' + 'Môi trường'
|
| 137 |
+
- [vlc-17799] split "Bộ Tài nguyên và Môi trường" → 'Bộ' + 'Tài nguyên' + 'và' + 'Môi trường'
|
| 138 |
+
- [vlc-7359] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 139 |
+
- [uvn-12995] split "Tổng giám đốc điều hành" → 'Tổng giám đốc' + 'điều hành'
|
| 140 |
+
- [vlc-4115] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 141 |
+
- [vlc-16369] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 142 |
+
- [vlc-16369] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 143 |
+
- [vlc-7736] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
|
| 144 |
+
- [vlc-7433] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 145 |
+
- [uvn-2956] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
|
| 146 |
+
- [vlc-131] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 147 |
+
- ... and 695 more
|
| 148 |
|
| 149 |
### udd-ws-v1.1-dev.txt
|
| 150 |
|
| 151 |
+
- [vlc-18372] split "phương tiện thông tin đại chúng" → 'phương tiện' + 'thông tin đại chúng'
|
| 152 |
+
- [vlc-7298] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 153 |
+
- [vlc-14549] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 154 |
+
- [vlc-3635] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 155 |
+
- [vlc-210] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
|
| 156 |
+
- [vlc-210] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 157 |
+
- [vlc-17769] split "Tòa án nhân dân tối cao" → 'Tòa án nhân dân' + 'tối cao'
|
| 158 |
+
- [vlc-10450] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 159 |
+
- [vlc-8980] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 160 |
+
- [vlc-18762] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 161 |
+
- [uvw-13677] split "thức ăn biến đổi gen" → 'thức ăn' + 'biến đổi gen'
|
| 162 |
+
- [vlc-8382] split "Viện kiểm sát nhân dân tối cao" → 'Viện kiểm sát' + 'nhân dân' + 'tối cao'
|
| 163 |
+
- [vlc-562] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 164 |
+
- [uvn-1191] split "quyền sở hữu toàn dân" → 'quyền sở hữu' + 'toàn' + 'dân'
|
| 165 |
+
- [uvw-5987] split "nhà thiên văn nghiệp dư" → 'nhà thiên văn' + 'nghiệp' + 'dư'
|
| 166 |
+
- [uvw-5987] split "nhà thiên văn nghiệp dư" → 'nhà thiên văn' + 'nghiệp' + 'dư'
|
| 167 |
+
- [vlc-11201] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 168 |
+
- [uvb-f-16068] split "Dương dở khóc dở cười" → 'Dương' + 'dở' + 'khóc' + 'dở' + 'cười'
|
| 169 |
+
- [vlc-11811] split "Viện kiểm sát nhân dân" → 'Viện kiểm sát' + 'nhân dân'
|
| 170 |
+
- [vlc-11811] split "Viện kiểm sát nhân dân" → 'Viện kiểm sát' + 'nhân dân'
|
| 171 |
+
- [uvw-6333] split "phóng vệ tinh nhân tạo" → 'phóng vệ tinh' + 'nhân tạo'
|
| 172 |
+
- [vlc-13552] split "phương tiện thông tin đại chúng" → 'phương tiện' + 'thông tin đại chúng'
|
| 173 |
+
- [vlc-17367] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 174 |
+
- [vlc-784] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 175 |
+
- [vlc-375] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 176 |
+
- [vlc-310] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 177 |
+
- [vlc-8628] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 178 |
+
- [uvb-n-18761] split "lý thuyết vi trùng học" → 'lý thuyết' + 'vi trùng' + 'học'
|
| 179 |
+
- [vlc-12944] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 180 |
+
- [uvb-n-8034] split "phong vũ biểu tâm hồn" → 'phong' + 'vũ' + 'biểu' + 'tâm hồn'
|
| 181 |
+
- ... and 57 more
|
| 182 |
|
| 183 |
### udd-ws-v1.1-test.txt
|
| 184 |
|
| 185 |
+
- [uvb-n-19086] split "Phù duy bất khả thức" → 'Phù' + 'duy' + 'bất' + 'khả' + 'thức'
|
| 186 |
+
- [vlc-17267] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 187 |
+
- [vlc-6223] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 188 |
+
- [vlc-9785] split "Viện kiểm sát nhân dân tối cao" → 'Viện kiểm sát' + 'nhân dân' + 'tối cao'
|
| 189 |
+
- [vlc-16181] split "Bộ Tài nguyên và Môi trường" → 'Bộ' + 'Tài nguyên' + 'và' + 'Môi trường'
|
| 190 |
+
- [vlc-12025] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 191 |
+
- [vlc-3574] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
|
| 192 |
+
- [vlc-10711] split "Viện kiểm sát nhân dân tối cao" → 'Viện kiểm sát' + 'nhân dân' + 'tối cao'
|
| 193 |
+
- [uvn-11938] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
|
| 194 |
+
- [vlc-4389] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 195 |
+
- [vlc-1254] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 196 |
+
- [vlc-5002] split "luật tố tụng hình sự" → 'luật' + 'tố tụng hình sự'
|
| 197 |
+
- [uvw-14472] split "nhà thiên văn vật lý" → 'nhà thiên văn' + 'vật lý'
|
| 198 |
+
- [vlc-1994] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 199 |
+
- [vlc-8312] split "Tổng liên đoàn Lao động" → 'Tổng liên đoàn' + 'Lao động'
|
| 200 |
+
- [uvw-15118] split "Đông Hoài quốc hoàng đế" → 'Đông' + 'Hoài' + 'quốc' + 'hoàng đế'
|
| 201 |
+
- [uvw-15118] split "Hoàn Nhan A Cốt Đả" → 'Hoàn' + 'Nhan' + 'A' + 'Cốt' + 'Đả'
|
| 202 |
+
- [vlc-4206] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 203 |
+
- [uvw-19136] split "sinh vật biến đổi gen" → 'sinh vật' + 'biến đổi gen'
|
| 204 |
+
- [vlc-3581] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 205 |
+
- [vlc-1319] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
|
| 206 |
+
- [vlc-1319] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 207 |
+
- [vlc-1319] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 208 |
+
- [uvw-156] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 209 |
+
- [vlc-6908] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 210 |
+
- [vlc-2238] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 211 |
+
- [vlc-14701] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 212 |
+
- [vlc-14701] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 213 |
+
- [vlc-16929] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận Tổ quốc' + 'Việt Nam'
|
| 214 |
+
- [vlc-870] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
|
| 215 |
+
- ... and 49 more
|
ls_import_cycle1.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
src/build_dict_plugin.py
CHANGED
|
@@ -2,24 +2,27 @@
|
|
| 2 |
# requires-python = ">=3.9"
|
| 3 |
# dependencies = []
|
| 4 |
# ///
|
| 5 |
-
"""Generate
|
| 6 |
|
| 7 |
-
Produces
|
| 8 |
-
1.
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
The
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
Usage:
|
| 17 |
uv run src/build_dict_plugin.py --dict path/to/dictionary.txt
|
| 18 |
-
uv run src/build_dict_plugin.py #
|
| 19 |
"""
|
| 20 |
|
| 21 |
import argparse
|
| 22 |
import json
|
|
|
|
| 23 |
import unicodedata
|
| 24 |
from pathlib import Path
|
| 25 |
|
|
@@ -28,11 +31,11 @@ DEFAULT_DICT = (
|
|
| 28 |
"models/word_segmentation/udd_ws_v1_1-20260211_034002/dictionary.txt"
|
| 29 |
)
|
| 30 |
|
| 31 |
-
|
| 32 |
-
"/home/claude-code/.local/share/uv/tools/label-studio/"
|
| 33 |
-
|
| 34 |
-
"/home/claude-code/projects/workspace_underthesea/label-studio/.venv/"
|
| 35 |
-
|
| 36 |
]
|
| 37 |
|
| 38 |
|
|
@@ -51,220 +54,274 @@ def load_dictionary(dict_path):
|
|
| 51 |
return entries
|
| 52 |
|
| 53 |
|
| 54 |
-
def
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
'
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
|
| 265 |
def main():
|
| 266 |
parser = argparse.ArgumentParser(
|
| 267 |
-
description="Generate dictionary plugin
|
| 268 |
)
|
| 269 |
parser.add_argument(
|
| 270 |
"--dict",
|
|
@@ -272,14 +329,14 @@ def main():
|
|
| 272 |
help=f"Path to dictionary.txt (default: {DEFAULT_DICT})",
|
| 273 |
)
|
| 274 |
parser.add_argument(
|
| 275 |
-
"--output",
|
| 276 |
-
default="src
|
| 277 |
-
help="Output
|
| 278 |
)
|
| 279 |
parser.add_argument(
|
| 280 |
"--deploy",
|
| 281 |
action="store_true",
|
| 282 |
-
help="
|
| 283 |
)
|
| 284 |
args = parser.parse_args()
|
| 285 |
|
|
@@ -288,26 +345,58 @@ def main():
|
|
| 288 |
print(f"ERROR: {dict_path} not found")
|
| 289 |
return
|
| 290 |
|
|
|
|
| 291 |
entries = load_dictionary(dict_path)
|
| 292 |
print(f"Loaded {len(entries)} dictionary entries from {dict_path}")
|
| 293 |
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
output_path.write_text(html_content, encoding="utf-8")
|
| 298 |
|
| 299 |
-
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
| 301 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
if args.deploy:
|
| 303 |
import shutil
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
else:
|
| 310 |
-
print(f"WARNING: {
|
| 311 |
|
| 312 |
|
| 313 |
if __name__ == "__main__":
|
|
|
|
| 2 |
# requires-python = ">=3.9"
|
| 3 |
# dependencies = []
|
| 4 |
# ///
|
| 5 |
+
"""Generate dictionary plugin files for Label Studio frontend JS injection.
|
| 6 |
|
| 7 |
+
Produces three outputs:
|
| 8 |
+
1. dict_data.json — sorted NFC-normalized dictionary entries as a JSON array
|
| 9 |
+
2. dict_plugin.js — floating search panel + auto-lookup on region select
|
| 10 |
+
3. Patches base.html — adds <script> tag in the {% block bottomjs %} block
|
| 11 |
|
| 12 |
+
The JS plugin:
|
| 13 |
+
- Loads dictionary via fetch("/static/dict_data.json") into a Set for O(1) lookup
|
| 14 |
+
- Creates a fixed-position search panel at bottom-right (toggle with 'd' key)
|
| 15 |
+
- Auto-fills search from selected annotation region via Htx.annotationStore polling
|
| 16 |
+
- Only activates on annotation pages (checks window.APP_SETTINGS)
|
| 17 |
|
| 18 |
Usage:
|
| 19 |
uv run src/build_dict_plugin.py --dict path/to/dictionary.txt
|
| 20 |
+
uv run src/build_dict_plugin.py --deploy # also deploys to LS static/templates
|
| 21 |
"""
|
| 22 |
|
| 23 |
import argparse
|
| 24 |
import json
|
| 25 |
+
import re
|
| 26 |
import unicodedata
|
| 27 |
from pathlib import Path
|
| 28 |
|
|
|
|
| 31 |
"models/word_segmentation/udd_ws_v1_1-20260211_034002/dictionary.txt"
|
| 32 |
)
|
| 33 |
|
| 34 |
+
LS_INSTALL_DIRS = [
|
| 35 |
+
Path("/home/claude-code/.local/share/uv/tools/label-studio/"
|
| 36 |
+
"lib/python3.12/site-packages/label_studio"),
|
| 37 |
+
Path("/home/claude-code/projects/workspace_underthesea/label-studio/.venv/"
|
| 38 |
+
"lib/python3.12/site-packages/label_studio"),
|
| 39 |
]
|
| 40 |
|
| 41 |
|
|
|
|
| 54 |
return entries
|
| 55 |
|
| 56 |
|
| 57 |
+
def build_dict_data_json(entries):
|
| 58 |
+
return json.dumps(entries, ensure_ascii=False)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def build_dict_plugin_js():
|
| 62 |
+
return r"""(function() {
|
| 63 |
+
"use strict";
|
| 64 |
+
|
| 65 |
+
// Only activate on annotation pages
|
| 66 |
+
if (!window.APP_SETTINGS || !window.APP_SETTINGS.project) return;
|
| 67 |
+
|
| 68 |
+
var DICT_SET = null;
|
| 69 |
+
var DICT_LOWER = null;
|
| 70 |
+
var dictLoaded = false;
|
| 71 |
+
|
| 72 |
+
// Load dictionary
|
| 73 |
+
fetch("/static/dict_data.json")
|
| 74 |
+
.then(function(r) { return r.json(); })
|
| 75 |
+
.then(function(entries) {
|
| 76 |
+
DICT_LOWER = entries.map(function(e) { return e.toLowerCase(); });
|
| 77 |
+
DICT_SET = new Set(DICT_LOWER);
|
| 78 |
+
dictLoaded = true;
|
| 79 |
+
if (countEl) countEl.textContent = entries.length.toLocaleString() + " entries";
|
| 80 |
+
console.log("[dict-plugin] Loaded " + entries.length + " dictionary entries");
|
| 81 |
+
})
|
| 82 |
+
.catch(function(err) {
|
| 83 |
+
console.error("[dict-plugin] Failed to load dictionary:", err);
|
| 84 |
+
});
|
| 85 |
+
|
| 86 |
+
// --- Create floating panel ---
|
| 87 |
+
var panel = document.createElement("div");
|
| 88 |
+
panel.id = "dict-plugin-panel";
|
| 89 |
+
panel.innerHTML = [
|
| 90 |
+
'<div class="dp-header">',
|
| 91 |
+
' <span class="dp-title">Dictionary</span>',
|
| 92 |
+
' <span class="dp-status" id="dp-status"></span>',
|
| 93 |
+
' <span class="dp-count" id="dp-count"></span>',
|
| 94 |
+
' <button class="dp-close" id="dp-close" title="Close (d)">×</button>',
|
| 95 |
+
'</div>',
|
| 96 |
+
'<div class="dp-search">',
|
| 97 |
+
' <input type="text" id="dp-input" placeholder="Search dictionary..." autocomplete="off">',
|
| 98 |
+
'</div>',
|
| 99 |
+
'<div class="dp-results" id="dp-results"></div>'
|
| 100 |
+
].join("\n");
|
| 101 |
+
document.body.appendChild(panel);
|
| 102 |
+
|
| 103 |
+
// --- Styles ---
|
| 104 |
+
var style = document.createElement("style");
|
| 105 |
+
style.textContent = [
|
| 106 |
+
'#dict-plugin-panel {',
|
| 107 |
+
' position: fixed; bottom: 16px; right: 16px; width: 340px;',
|
| 108 |
+
' background: #fff; border: 1px solid #ccc; border-radius: 8px;',
|
| 109 |
+
' box-shadow: 0 4px 16px rgba(0,0,0,0.15); z-index: 10000;',
|
| 110 |
+
' font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;',
|
| 111 |
+
' font-size: 14px; display: flex; flex-direction: column;',
|
| 112 |
+
' max-height: 400px; overflow: hidden;',
|
| 113 |
+
'}',
|
| 114 |
+
'#dict-plugin-panel.dp-hidden { display: none; }',
|
| 115 |
+
'.dp-header {',
|
| 116 |
+
' display: flex; align-items: center; padding: 8px 12px;',
|
| 117 |
+
' border-bottom: 1px solid #eee; gap: 8px;',
|
| 118 |
+
'}',
|
| 119 |
+
'.dp-title { font-weight: 600; font-size: 13px; }',
|
| 120 |
+
'.dp-status {',
|
| 121 |
+
' font-size: 12px; padding: 1px 6px; border-radius: 3px;',
|
| 122 |
+
' white-space: nowrap;',
|
| 123 |
+
'}',
|
| 124 |
+
'.dp-status.in-dict { background: #c8e6c9; color: #2e7d32; }',
|
| 125 |
+
'.dp-status.not-dict { background: #ffcdd2; color: #c62828; }',
|
| 126 |
+
'.dp-count { font-size: 11px; color: #999; margin-left: auto; }',
|
| 127 |
+
'.dp-close {',
|
| 128 |
+
' background: none; border: none; font-size: 18px; cursor: pointer;',
|
| 129 |
+
' color: #999; padding: 0 4px; line-height: 1;',
|
| 130 |
+
'}',
|
| 131 |
+
'.dp-close:hover { color: #333; }',
|
| 132 |
+
'.dp-search { padding: 8px 12px; }',
|
| 133 |
+
'.dp-search input {',
|
| 134 |
+
' width: 100%; padding: 6px 10px; font-size: 14px;',
|
| 135 |
+
' border: 1px solid #ddd; border-radius: 4px; outline: none;',
|
| 136 |
+
' box-sizing: border-box;',
|
| 137 |
+
'}',
|
| 138 |
+
'.dp-search input:focus { border-color: #4CAF50; }',
|
| 139 |
+
'.dp-results {',
|
| 140 |
+
' padding: 4px 12px 8px; overflow-y: auto; max-height: 260px;',
|
| 141 |
+
'}',
|
| 142 |
+
'.dp-section { padding: 2px 0; }',
|
| 143 |
+
'.dp-section-title {',
|
| 144 |
+
' font-size: 11px; font-weight: 600; color: #888;',
|
| 145 |
+
' text-transform: uppercase; padding: 2px 0;',
|
| 146 |
+
'}',
|
| 147 |
+
'.dp-match { padding: 1px 0; font-size: 13px; }',
|
| 148 |
+
'.dp-match.exact { font-weight: 600; color: #2e7d32; }',
|
| 149 |
+
'.dp-match mark { background: #fff9c4; padding: 0 1px; border-radius: 2px; }',
|
| 150 |
+
'.dp-no-results { color: #999; padding: 4px 0; font-size: 13px; }'
|
| 151 |
+
].join("\n");
|
| 152 |
+
document.head.appendChild(style);
|
| 153 |
+
|
| 154 |
+
var input = document.getElementById("dp-input");
|
| 155 |
+
var resultsDiv = document.getElementById("dp-results");
|
| 156 |
+
var statusEl = document.getElementById("dp-status");
|
| 157 |
+
var countEl = document.getElementById("dp-count");
|
| 158 |
+
var closeBtn = document.getElementById("dp-close");
|
| 159 |
+
|
| 160 |
+
// --- Toggle visibility ---
|
| 161 |
+
var visible = true;
|
| 162 |
+
function togglePanel() {
|
| 163 |
+
visible = !visible;
|
| 164 |
+
panel.classList.toggle("dp-hidden", !visible);
|
| 165 |
+
if (visible) input.focus();
|
| 166 |
+
}
|
| 167 |
+
closeBtn.addEventListener("click", togglePanel);
|
| 168 |
+
|
| 169 |
+
// Keyboard shortcut: 'd' to toggle (only when not typing in an input)
|
| 170 |
+
document.addEventListener("keydown", function(e) {
|
| 171 |
+
if (e.key === "d" && !e.ctrlKey && !e.altKey && !e.metaKey) {
|
| 172 |
+
var tag = (e.target.tagName || "").toLowerCase();
|
| 173 |
+
if (tag !== "input" && tag !== "textarea" && !e.target.isContentEditable) {
|
| 174 |
+
e.preventDefault();
|
| 175 |
+
togglePanel();
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
});
|
| 179 |
+
|
| 180 |
+
// --- Search with debounce ---
|
| 181 |
+
var debounceTimer;
|
| 182 |
+
input.addEventListener("input", function() {
|
| 183 |
+
clearTimeout(debounceTimer);
|
| 184 |
+
debounceTimer = setTimeout(doSearch, 150);
|
| 185 |
+
});
|
| 186 |
+
|
| 187 |
+
function escHtml(s) {
|
| 188 |
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
function highlight(text, query) {
|
| 192 |
+
var idx = text.toLowerCase().indexOf(query);
|
| 193 |
+
if (idx < 0) return escHtml(text);
|
| 194 |
+
return escHtml(text.slice(0, idx)) + "<mark>" +
|
| 195 |
+
escHtml(text.slice(idx, idx + query.length)) + "</mark>" +
|
| 196 |
+
escHtml(text.slice(idx + query.length));
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
function doSearch() {
|
| 200 |
+
if (!dictLoaded) return;
|
| 201 |
+
var q = input.value.trim().toLowerCase();
|
| 202 |
+
if (!q) { resultsDiv.innerHTML = ""; updateStatus(q); return; }
|
| 203 |
+
|
| 204 |
+
updateStatus(q);
|
| 205 |
+
|
| 206 |
+
var exact = [], prefix = [], substring = [];
|
| 207 |
+
var MAX = 20;
|
| 208 |
+
for (var i = 0; i < DICT_LOWER.length; i++) {
|
| 209 |
+
var e = DICT_LOWER[i];
|
| 210 |
+
if (e === q) exact.push(i);
|
| 211 |
+
else if (e.startsWith(q)) { if (prefix.length < MAX) prefix.push(i); }
|
| 212 |
+
else if (e.indexOf(q) >= 0) { if (substring.length < MAX) substring.push(i); }
|
| 213 |
+
if (prefix.length >= MAX && substring.length >= MAX && exact.length > 0) break;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
var h = "";
|
| 217 |
+
if (exact.length > 0) {
|
| 218 |
+
h += '<div class="dp-section"><div class="dp-section-title">Exact</div>';
|
| 219 |
+
for (var j = 0; j < exact.length; j++)
|
| 220 |
+
h += '<div class="dp-match exact">' + highlight(DICT_LOWER[exact[j]], q) + '</div>';
|
| 221 |
+
h += '</div>';
|
| 222 |
+
}
|
| 223 |
+
if (prefix.length > 0) {
|
| 224 |
+
h += '<div class="dp-section"><div class="dp-section-title">Prefix (' + prefix.length + ')</div>';
|
| 225 |
+
for (var j = 0; j < prefix.length; j++)
|
| 226 |
+
h += '<div class="dp-match">' + highlight(DICT_LOWER[prefix[j]], q) + '</div>';
|
| 227 |
+
h += '</div>';
|
| 228 |
+
}
|
| 229 |
+
if (substring.length > 0) {
|
| 230 |
+
h += '<div class="dp-section"><div class="dp-section-title">Contains (' + substring.length + ')</div>';
|
| 231 |
+
for (var j = 0; j < substring.length; j++)
|
| 232 |
+
h += '<div class="dp-match">' + highlight(DICT_LOWER[substring[j]], q) + '</div>';
|
| 233 |
+
h += '</div>';
|
| 234 |
+
}
|
| 235 |
+
if (!h) h = '<div class="dp-no-results">No matches</div>';
|
| 236 |
+
resultsDiv.innerHTML = h;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
function updateStatus(query) {
|
| 240 |
+
if (!query || !DICT_SET) {
|
| 241 |
+
statusEl.textContent = "";
|
| 242 |
+
statusEl.className = "dp-status";
|
| 243 |
+
return;
|
| 244 |
+
}
|
| 245 |
+
if (DICT_SET.has(query)) {
|
| 246 |
+
statusEl.textContent = "\u2713 in dict";
|
| 247 |
+
statusEl.className = "dp-status in-dict";
|
| 248 |
+
} else {
|
| 249 |
+
statusEl.textContent = "\u2717 not found";
|
| 250 |
+
statusEl.className = "dp-status not-dict";
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
// --- Auto-lookup on region select ---
|
| 255 |
+
var lastRegionText = "";
|
| 256 |
+
setInterval(function() {
|
| 257 |
+
if (!dictLoaded || !visible) return;
|
| 258 |
+
try {
|
| 259 |
+
var store = window.Htx && window.Htx.annotationStore;
|
| 260 |
+
if (!store) return;
|
| 261 |
+
var sel = store.selected;
|
| 262 |
+
if (!sel) return;
|
| 263 |
+
var regions = sel.regionStore && sel.regionStore.regions;
|
| 264 |
+
if (!regions) return;
|
| 265 |
+
|
| 266 |
+
// Find selected region
|
| 267 |
+
var selectedRegion = null;
|
| 268 |
+
for (var i = 0; i < regions.length; i++) {
|
| 269 |
+
if (regions[i].selected) { selectedRegion = regions[i]; break; }
|
| 270 |
+
}
|
| 271 |
+
if (!selectedRegion) {
|
| 272 |
+
if (lastRegionText) { lastRegionText = ""; }
|
| 273 |
+
return;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
var text = selectedRegion.text || "";
|
| 277 |
+
if (text && text !== lastRegionText) {
|
| 278 |
+
lastRegionText = text;
|
| 279 |
+
input.value = text;
|
| 280 |
+
doSearch();
|
| 281 |
+
}
|
| 282 |
+
} catch(e) {
|
| 283 |
+
// Silently ignore — store structure may vary
|
| 284 |
+
}
|
| 285 |
+
}, 300);
|
| 286 |
+
})();
|
| 287 |
+
"""
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
def patch_base_html(base_html_path):
|
| 291 |
+
"""Patch base.html to include dict_plugin.js in the bottomjs block.
|
| 292 |
+
|
| 293 |
+
Adds <script src="/static/dict_plugin.js"></script> before {% endblock %}
|
| 294 |
+
in the bottomjs block. Idempotent — skips if already patched.
|
| 295 |
+
"""
|
| 296 |
+
content = base_html_path.read_text(encoding="utf-8")
|
| 297 |
+
|
| 298 |
+
script_tag = '<script src="/static/dict_plugin.js"></script>'
|
| 299 |
+
if script_tag in content:
|
| 300 |
+
print(f" Already patched: {base_html_path}")
|
| 301 |
+
return False
|
| 302 |
+
|
| 303 |
+
# Find {% endblock %} that closes {% block bottomjs %}
|
| 304 |
+
# Insert the script tag before the last {% endblock %} in the file
|
| 305 |
+
pattern = r'([ \t]*)({% endblock %})\s*$'
|
| 306 |
+
match = list(re.finditer(pattern, content, re.MULTILINE))
|
| 307 |
+
if not match:
|
| 308 |
+
print(f" WARNING: Could not find {{% endblock %}} in {base_html_path}")
|
| 309 |
+
return False
|
| 310 |
+
|
| 311 |
+
# Use the last match (the bottomjs endblock is at the end of the file)
|
| 312 |
+
m = match[-1]
|
| 313 |
+
indent = m.group(1)
|
| 314 |
+
insert_pos = m.start()
|
| 315 |
+
patched = content[:insert_pos] + indent + script_tag + "\n" + content[insert_pos:]
|
| 316 |
+
|
| 317 |
+
base_html_path.write_text(patched, encoding="utf-8")
|
| 318 |
+
print(f" Patched: {base_html_path}")
|
| 319 |
+
return True
|
| 320 |
|
| 321 |
|
| 322 |
def main():
|
| 323 |
parser = argparse.ArgumentParser(
|
| 324 |
+
description="Generate dictionary plugin for Label Studio (JS injection)"
|
| 325 |
)
|
| 326 |
parser.add_argument(
|
| 327 |
"--dict",
|
|
|
|
| 329 |
help=f"Path to dictionary.txt (default: {DEFAULT_DICT})",
|
| 330 |
)
|
| 331 |
parser.add_argument(
|
| 332 |
+
"--output-dir",
|
| 333 |
+
default="src",
|
| 334 |
+
help="Output directory for generated files (default: src)",
|
| 335 |
)
|
| 336 |
parser.add_argument(
|
| 337 |
"--deploy",
|
| 338 |
action="store_true",
|
| 339 |
+
help="Deploy to LS static_build + patch base.html",
|
| 340 |
)
|
| 341 |
args = parser.parse_args()
|
| 342 |
|
|
|
|
| 345 |
print(f"ERROR: {dict_path} not found")
|
| 346 |
return
|
| 347 |
|
| 348 |
+
# Load dictionary
|
| 349 |
entries = load_dictionary(dict_path)
|
| 350 |
print(f"Loaded {len(entries)} dictionary entries from {dict_path}")
|
| 351 |
|
| 352 |
+
# Generate dict_data.json
|
| 353 |
+
output_dir = Path(args.output_dir)
|
| 354 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 355 |
|
| 356 |
+
json_path = output_dir / "dict_data.json"
|
| 357 |
+
json_content = build_dict_data_json(entries)
|
| 358 |
+
json_path.write_text(json_content, encoding="utf-8")
|
| 359 |
+
json_kb = json_path.stat().st_size / 1024
|
| 360 |
+
print(f"Written {json_path} ({json_kb:.0f} KB, {len(entries)} entries)")
|
| 361 |
|
| 362 |
+
# Generate dict_plugin.js
|
| 363 |
+
js_path = output_dir / "dict_plugin.js"
|
| 364 |
+
js_content = build_dict_plugin_js()
|
| 365 |
+
js_path.write_text(js_content, encoding="utf-8")
|
| 366 |
+
js_kb = js_path.stat().st_size / 1024
|
| 367 |
+
print(f"Written {js_path} ({js_kb:.0f} KB)")
|
| 368 |
+
|
| 369 |
+
# Deploy
|
| 370 |
if args.deploy:
|
| 371 |
import shutil
|
| 372 |
+
print("\nDeploying to Label Studio installations:")
|
| 373 |
+
for ls_dir in LS_INSTALL_DIRS:
|
| 374 |
+
static_dir = ls_dir / "core" / "static_build"
|
| 375 |
+
templates_dir = ls_dir / "templates"
|
| 376 |
+
|
| 377 |
+
if not static_dir.exists():
|
| 378 |
+
print(f" SKIP: {static_dir} not found")
|
| 379 |
+
continue
|
| 380 |
+
|
| 381 |
+
# Copy dict_data.json and dict_plugin.js to static_build
|
| 382 |
+
shutil.copy2(json_path, static_dir / "dict_data.json")
|
| 383 |
+
print(f" Deployed dict_data.json -> {static_dir}")
|
| 384 |
+
|
| 385 |
+
shutil.copy2(js_path, static_dir / "dict_plugin.js")
|
| 386 |
+
print(f" Deployed dict_plugin.js -> {static_dir}")
|
| 387 |
+
|
| 388 |
+
# Remove old dict_plugin.html if it exists
|
| 389 |
+
old_html = static_dir / "dict_plugin.html"
|
| 390 |
+
if old_html.exists():
|
| 391 |
+
old_html.unlink()
|
| 392 |
+
print(f" Removed old dict_plugin.html")
|
| 393 |
+
|
| 394 |
+
# Patch base.html
|
| 395 |
+
base_html = templates_dir / "base.html"
|
| 396 |
+
if base_html.exists():
|
| 397 |
+
patch_base_html(base_html)
|
| 398 |
else:
|
| 399 |
+
print(f" WARNING: {base_html} not found")
|
| 400 |
|
| 401 |
|
| 402 |
if __name__ == "__main__":
|
src/dict_data.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
src/dict_plugin.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(function() {
|
| 2 |
+
"use strict";
|
| 3 |
+
|
| 4 |
+
// Only activate on annotation pages
|
| 5 |
+
if (!window.APP_SETTINGS || !window.APP_SETTINGS.project) return;
|
| 6 |
+
|
| 7 |
+
var DICT_SET = null;
|
| 8 |
+
var DICT_LOWER = null;
|
| 9 |
+
var dictLoaded = false;
|
| 10 |
+
|
| 11 |
+
// Load dictionary
|
| 12 |
+
fetch("/static/dict_data.json")
|
| 13 |
+
.then(function(r) { return r.json(); })
|
| 14 |
+
.then(function(entries) {
|
| 15 |
+
DICT_LOWER = entries.map(function(e) { return e.toLowerCase(); });
|
| 16 |
+
DICT_SET = new Set(DICT_LOWER);
|
| 17 |
+
dictLoaded = true;
|
| 18 |
+
if (countEl) countEl.textContent = entries.length.toLocaleString() + " entries";
|
| 19 |
+
console.log("[dict-plugin] Loaded " + entries.length + " dictionary entries");
|
| 20 |
+
})
|
| 21 |
+
.catch(function(err) {
|
| 22 |
+
console.error("[dict-plugin] Failed to load dictionary:", err);
|
| 23 |
+
});
|
| 24 |
+
|
| 25 |
+
// --- Create floating panel ---
|
| 26 |
+
var panel = document.createElement("div");
|
| 27 |
+
panel.id = "dict-plugin-panel";
|
| 28 |
+
panel.innerHTML = [
|
| 29 |
+
'<div class="dp-header">',
|
| 30 |
+
' <span class="dp-title">Dictionary</span>',
|
| 31 |
+
' <span class="dp-status" id="dp-status"></span>',
|
| 32 |
+
' <span class="dp-count" id="dp-count"></span>',
|
| 33 |
+
' <button class="dp-close" id="dp-close" title="Close (d)">×</button>',
|
| 34 |
+
'</div>',
|
| 35 |
+
'<div class="dp-search">',
|
| 36 |
+
' <input type="text" id="dp-input" placeholder="Search dictionary..." autocomplete="off">',
|
| 37 |
+
'</div>',
|
| 38 |
+
'<div class="dp-results" id="dp-results"></div>'
|
| 39 |
+
].join("\n");
|
| 40 |
+
document.body.appendChild(panel);
|
| 41 |
+
|
| 42 |
+
// --- Styles ---
|
| 43 |
+
var style = document.createElement("style");
|
| 44 |
+
style.textContent = [
|
| 45 |
+
'#dict-plugin-panel {',
|
| 46 |
+
' position: fixed; bottom: 16px; right: 16px; width: 340px;',
|
| 47 |
+
' background: #fff; border: 1px solid #ccc; border-radius: 8px;',
|
| 48 |
+
' box-shadow: 0 4px 16px rgba(0,0,0,0.15); z-index: 10000;',
|
| 49 |
+
' font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;',
|
| 50 |
+
' font-size: 14px; display: flex; flex-direction: column;',
|
| 51 |
+
' max-height: 400px; overflow: hidden;',
|
| 52 |
+
'}',
|
| 53 |
+
'#dict-plugin-panel.dp-hidden { display: none; }',
|
| 54 |
+
'.dp-header {',
|
| 55 |
+
' display: flex; align-items: center; padding: 8px 12px;',
|
| 56 |
+
' border-bottom: 1px solid #eee; gap: 8px;',
|
| 57 |
+
'}',
|
| 58 |
+
'.dp-title { font-weight: 600; font-size: 13px; }',
|
| 59 |
+
'.dp-status {',
|
| 60 |
+
' font-size: 12px; padding: 1px 6px; border-radius: 3px;',
|
| 61 |
+
' white-space: nowrap;',
|
| 62 |
+
'}',
|
| 63 |
+
'.dp-status.in-dict { background: #c8e6c9; color: #2e7d32; }',
|
| 64 |
+
'.dp-status.not-dict { background: #ffcdd2; color: #c62828; }',
|
| 65 |
+
'.dp-count { font-size: 11px; color: #999; margin-left: auto; }',
|
| 66 |
+
'.dp-close {',
|
| 67 |
+
' background: none; border: none; font-size: 18px; cursor: pointer;',
|
| 68 |
+
' color: #999; padding: 0 4px; line-height: 1;',
|
| 69 |
+
'}',
|
| 70 |
+
'.dp-close:hover { color: #333; }',
|
| 71 |
+
'.dp-search { padding: 8px 12px; }',
|
| 72 |
+
'.dp-search input {',
|
| 73 |
+
' width: 100%; padding: 6px 10px; font-size: 14px;',
|
| 74 |
+
' border: 1px solid #ddd; border-radius: 4px; outline: none;',
|
| 75 |
+
' box-sizing: border-box;',
|
| 76 |
+
'}',
|
| 77 |
+
'.dp-search input:focus { border-color: #4CAF50; }',
|
| 78 |
+
'.dp-results {',
|
| 79 |
+
' padding: 4px 12px 8px; overflow-y: auto; max-height: 260px;',
|
| 80 |
+
'}',
|
| 81 |
+
'.dp-section { padding: 2px 0; }',
|
| 82 |
+
'.dp-section-title {',
|
| 83 |
+
' font-size: 11px; font-weight: 600; color: #888;',
|
| 84 |
+
' text-transform: uppercase; padding: 2px 0;',
|
| 85 |
+
'}',
|
| 86 |
+
'.dp-match { padding: 1px 0; font-size: 13px; }',
|
| 87 |
+
'.dp-match.exact { font-weight: 600; color: #2e7d32; }',
|
| 88 |
+
'.dp-match mark { background: #fff9c4; padding: 0 1px; border-radius: 2px; }',
|
| 89 |
+
'.dp-no-results { color: #999; padding: 4px 0; font-size: 13px; }'
|
| 90 |
+
].join("\n");
|
| 91 |
+
document.head.appendChild(style);
|
| 92 |
+
|
| 93 |
+
var input = document.getElementById("dp-input");
|
| 94 |
+
var resultsDiv = document.getElementById("dp-results");
|
| 95 |
+
var statusEl = document.getElementById("dp-status");
|
| 96 |
+
var countEl = document.getElementById("dp-count");
|
| 97 |
+
var closeBtn = document.getElementById("dp-close");
|
| 98 |
+
|
| 99 |
+
// --- Toggle visibility ---
|
| 100 |
+
var visible = true;
|
| 101 |
+
function togglePanel() {
|
| 102 |
+
visible = !visible;
|
| 103 |
+
panel.classList.toggle("dp-hidden", !visible);
|
| 104 |
+
if (visible) input.focus();
|
| 105 |
+
}
|
| 106 |
+
closeBtn.addEventListener("click", togglePanel);
|
| 107 |
+
|
| 108 |
+
// Keyboard shortcut: 'd' to toggle (only when not typing in an input)
|
| 109 |
+
document.addEventListener("keydown", function(e) {
|
| 110 |
+
if (e.key === "d" && !e.ctrlKey && !e.altKey && !e.metaKey) {
|
| 111 |
+
var tag = (e.target.tagName || "").toLowerCase();
|
| 112 |
+
if (tag !== "input" && tag !== "textarea" && !e.target.isContentEditable) {
|
| 113 |
+
e.preventDefault();
|
| 114 |
+
togglePanel();
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
});
|
| 118 |
+
|
| 119 |
+
// --- Search with debounce ---
|
| 120 |
+
var debounceTimer;
|
| 121 |
+
input.addEventListener("input", function() {
|
| 122 |
+
clearTimeout(debounceTimer);
|
| 123 |
+
debounceTimer = setTimeout(doSearch, 150);
|
| 124 |
+
});
|
| 125 |
+
|
| 126 |
+
function escHtml(s) {
|
| 127 |
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
function highlight(text, query) {
|
| 131 |
+
var idx = text.toLowerCase().indexOf(query);
|
| 132 |
+
if (idx < 0) return escHtml(text);
|
| 133 |
+
return escHtml(text.slice(0, idx)) + "<mark>" +
|
| 134 |
+
escHtml(text.slice(idx, idx + query.length)) + "</mark>" +
|
| 135 |
+
escHtml(text.slice(idx + query.length));
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
function doSearch() {
|
| 139 |
+
if (!dictLoaded) return;
|
| 140 |
+
var q = input.value.trim().toLowerCase();
|
| 141 |
+
if (!q) { resultsDiv.innerHTML = ""; updateStatus(q); return; }
|
| 142 |
+
|
| 143 |
+
updateStatus(q);
|
| 144 |
+
|
| 145 |
+
var exact = [], prefix = [], substring = [];
|
| 146 |
+
var MAX = 20;
|
| 147 |
+
for (var i = 0; i < DICT_LOWER.length; i++) {
|
| 148 |
+
var e = DICT_LOWER[i];
|
| 149 |
+
if (e === q) exact.push(i);
|
| 150 |
+
else if (e.startsWith(q)) { if (prefix.length < MAX) prefix.push(i); }
|
| 151 |
+
else if (e.indexOf(q) >= 0) { if (substring.length < MAX) substring.push(i); }
|
| 152 |
+
if (prefix.length >= MAX && substring.length >= MAX && exact.length > 0) break;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
var h = "";
|
| 156 |
+
if (exact.length > 0) {
|
| 157 |
+
h += '<div class="dp-section"><div class="dp-section-title">Exact</div>';
|
| 158 |
+
for (var j = 0; j < exact.length; j++)
|
| 159 |
+
h += '<div class="dp-match exact">' + highlight(DICT_LOWER[exact[j]], q) + '</div>';
|
| 160 |
+
h += '</div>';
|
| 161 |
+
}
|
| 162 |
+
if (prefix.length > 0) {
|
| 163 |
+
h += '<div class="dp-section"><div class="dp-section-title">Prefix (' + prefix.length + ')</div>';
|
| 164 |
+
for (var j = 0; j < prefix.length; j++)
|
| 165 |
+
h += '<div class="dp-match">' + highlight(DICT_LOWER[prefix[j]], q) + '</div>';
|
| 166 |
+
h += '</div>';
|
| 167 |
+
}
|
| 168 |
+
if (substring.length > 0) {
|
| 169 |
+
h += '<div class="dp-section"><div class="dp-section-title">Contains (' + substring.length + ')</div>';
|
| 170 |
+
for (var j = 0; j < substring.length; j++)
|
| 171 |
+
h += '<div class="dp-match">' + highlight(DICT_LOWER[substring[j]], q) + '</div>';
|
| 172 |
+
h += '</div>';
|
| 173 |
+
}
|
| 174 |
+
if (!h) h = '<div class="dp-no-results">No matches</div>';
|
| 175 |
+
resultsDiv.innerHTML = h;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
function updateStatus(query) {
|
| 179 |
+
if (!query || !DICT_SET) {
|
| 180 |
+
statusEl.textContent = "";
|
| 181 |
+
statusEl.className = "dp-status";
|
| 182 |
+
return;
|
| 183 |
+
}
|
| 184 |
+
if (DICT_SET.has(query)) {
|
| 185 |
+
statusEl.textContent = "\u2713 in dict";
|
| 186 |
+
statusEl.className = "dp-status in-dict";
|
| 187 |
+
} else {
|
| 188 |
+
statusEl.textContent = "\u2717 not found";
|
| 189 |
+
statusEl.className = "dp-status not-dict";
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
// --- Auto-lookup on region select ---
|
| 194 |
+
var lastRegionText = "";
|
| 195 |
+
setInterval(function() {
|
| 196 |
+
if (!dictLoaded || !visible) return;
|
| 197 |
+
try {
|
| 198 |
+
var store = window.Htx && window.Htx.annotationStore;
|
| 199 |
+
if (!store) return;
|
| 200 |
+
var sel = store.selected;
|
| 201 |
+
if (!sel) return;
|
| 202 |
+
var regions = sel.regionStore && sel.regionStore.regions;
|
| 203 |
+
if (!regions) return;
|
| 204 |
+
|
| 205 |
+
// Find selected region
|
| 206 |
+
var selectedRegion = null;
|
| 207 |
+
for (var i = 0; i < regions.length; i++) {
|
| 208 |
+
if (regions[i].selected) { selectedRegion = regions[i]; break; }
|
| 209 |
+
}
|
| 210 |
+
if (!selectedRegion) {
|
| 211 |
+
if (lastRegionText) { lastRegionText = ""; }
|
| 212 |
+
return;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
var text = selectedRegion.text || "";
|
| 216 |
+
if (text && text !== lastRegionText) {
|
| 217 |
+
lastRegionText = text;
|
| 218 |
+
input.value = text;
|
| 219 |
+
doSearch();
|
| 220 |
+
}
|
| 221 |
+
} catch(e) {
|
| 222 |
+
// Silently ignore — store structure may vary
|
| 223 |
+
}
|
| 224 |
+
}, 300);
|
| 225 |
+
})();
|
src/ls_config_ws.xml
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
<View>
|
| 2 |
<Header value="Word Segmentation: Select each word as a span. Multi-syllable words = one span."/>
|
| 3 |
<Header value="Sentence: $sent_id | Rank: $rank" size="4"/>
|
| 4 |
-
<
|
| 5 |
-
|
| 6 |
-
</View>
|
| 7 |
<Labels name="label" toName="text" choice="single">
|
| 8 |
<Label value="W" background="#4CAF50" hotkey="w"/>
|
| 9 |
<Label value="WH" background="#2196F3" hotkey="h"/>
|
|
|
|
| 1 |
<View>
|
| 2 |
<Header value="Word Segmentation: Select each word as a span. Multi-syllable words = one span."/>
|
| 3 |
<Header value="Sentence: $sent_id | Rank: $rank" size="4"/>
|
| 4 |
+
<Header value="Dictionary: green = in dict, red = NOT in dict" size="5"/>
|
| 5 |
+
<HyperText name="dict_view" value="$dict_html"/>
|
|
|
|
| 6 |
<Labels name="label" toName="text" choice="single">
|
| 7 |
<Label value="W" background="#4CAF50" hotkey="w"/>
|
| 8 |
<Label value="WH" background="#2196F3" hotkey="h"/>
|
src/ls_import_ws.py
CHANGED
|
@@ -12,10 +12,9 @@ When --model is provided, computes per-span confidence scores from CRF
|
|
| 12 |
marginal probabilities. Each word span gets score = min confidence across
|
| 13 |
its syllables, so words with any uncertain boundary get a low score.
|
| 14 |
|
| 15 |
-
When --dict is provided (standalone or auto-detected from model dir)
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
pink/red = multi-syllable span NOT in dictionary
|
| 19 |
|
| 20 |
Usage:
|
| 21 |
uv run src/ls_import_ws.py [--validate]
|
|
@@ -24,11 +23,11 @@ Usage:
|
|
| 24 |
"""
|
| 25 |
|
| 26 |
import argparse
|
|
|
|
| 27 |
import json
|
| 28 |
import sys
|
| 29 |
import unicodedata
|
| 30 |
from pathlib import Path
|
| 31 |
-
from urllib.parse import quote
|
| 32 |
|
| 33 |
|
| 34 |
def parse_bio_file(filepath):
|
|
@@ -215,31 +214,58 @@ def add_dict_meta(spans, dictionary):
|
|
| 215 |
span["meta"] = meta
|
| 216 |
|
| 217 |
|
| 218 |
-
def
|
| 219 |
-
"""Build
|
| 220 |
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
The ~900KB dictionary page is loaded once and cached by the browser.
|
| 224 |
|
| 225 |
Args:
|
| 226 |
spans: list of span dicts from bio_to_spans()
|
| 227 |
text: the sentence text
|
|
|
|
| 228 |
|
| 229 |
Returns:
|
| 230 |
-
HTML
|
| 231 |
"""
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
|
| 244 |
|
| 245 |
def validate_spans(spans, text, syllables):
|
|
@@ -445,11 +471,11 @@ def main():
|
|
| 445 |
# Task-level prediction score = 1 - AL uncertainty score
|
| 446 |
pred_score = round(1.0 - row["score"], 6)
|
| 447 |
|
| 448 |
-
# Add dictionary metadata to spans + build
|
| 449 |
-
|
| 450 |
if dictionary:
|
| 451 |
add_dict_meta(spans, dictionary)
|
| 452 |
-
|
| 453 |
|
| 454 |
task = {
|
| 455 |
"data": {
|
|
@@ -458,7 +484,7 @@ def main():
|
|
| 458 |
"rank": row["rank"],
|
| 459 |
"file": split,
|
| 460 |
"sent_idx": sent_idx,
|
| 461 |
-
"
|
| 462 |
},
|
| 463 |
"predictions": [{
|
| 464 |
"model_version": "silver_crf_v1.1",
|
|
|
|
| 12 |
marginal probabilities. Each word span gets score = min confidence across
|
| 13 |
its syllables, so words with any uncertain boundary get a low score.
|
| 14 |
|
| 15 |
+
When --dict is provided (standalone or auto-detected from model dir):
|
| 16 |
+
- dict_html: inline styled spans (green = in dict, red = NOT in dict)
|
| 17 |
+
- meta.dict: dict status shown in Region Details when a span is selected
|
|
|
|
| 18 |
|
| 19 |
Usage:
|
| 20 |
uv run src/ls_import_ws.py [--validate]
|
|
|
|
| 23 |
"""
|
| 24 |
|
| 25 |
import argparse
|
| 26 |
+
import html
|
| 27 |
import json
|
| 28 |
import sys
|
| 29 |
import unicodedata
|
| 30 |
from pathlib import Path
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
def parse_bio_file(filepath):
|
|
|
|
| 214 |
span["meta"] = meta
|
| 215 |
|
| 216 |
|
| 217 |
+
def build_dict_html(spans, text, dictionary):
|
| 218 |
+
"""Build inline HTML with colored spans showing dictionary status.
|
| 219 |
|
| 220 |
+
Multi-syllable words are colored green (in dict) or red (not in dict).
|
| 221 |
+
Single-syllable words are shown without color.
|
|
|
|
| 222 |
|
| 223 |
Args:
|
| 224 |
spans: list of span dicts from bio_to_spans()
|
| 225 |
text: the sentence text
|
| 226 |
+
dictionary: set of NFC-normalized lowercase dictionary entries
|
| 227 |
|
| 228 |
Returns:
|
| 229 |
+
HTML string for the HyperText panel
|
| 230 |
"""
|
| 231 |
+
parts = []
|
| 232 |
+
prev_end = 0
|
| 233 |
+
|
| 234 |
+
for span in spans:
|
| 235 |
+
start = span["value"]["start"]
|
| 236 |
+
end = span["value"]["end"]
|
| 237 |
+
span_text = span["value"]["text"]
|
| 238 |
+
n_syllables = span_text.count(" ") + 1
|
| 239 |
+
|
| 240 |
+
# Add any gap text (spaces between spans)
|
| 241 |
+
if start > prev_end:
|
| 242 |
+
parts.append(html.escape(text[prev_end:start]))
|
| 243 |
+
|
| 244 |
+
escaped = html.escape(span_text)
|
| 245 |
+
if n_syllables > 1:
|
| 246 |
+
normalized = nfc(span_text.lower().strip())
|
| 247 |
+
in_dict = normalized in dictionary
|
| 248 |
+
if in_dict:
|
| 249 |
+
parts.append(
|
| 250 |
+
f'<span style="background:#c8e6c9;padding:1px 3px;'
|
| 251 |
+
f'border-radius:3px">{escaped}</span>'
|
| 252 |
+
)
|
| 253 |
+
else:
|
| 254 |
+
parts.append(
|
| 255 |
+
f'<span style="background:#ffcdd2;padding:1px 3px;'
|
| 256 |
+
f'border-radius:3px;text-decoration:underline;'
|
| 257 |
+
f'text-decoration-color:red">{escaped}</span>'
|
| 258 |
+
)
|
| 259 |
+
else:
|
| 260 |
+
parts.append(escaped)
|
| 261 |
+
|
| 262 |
+
prev_end = end
|
| 263 |
+
|
| 264 |
+
# Trailing text
|
| 265 |
+
if prev_end < len(text):
|
| 266 |
+
parts.append(html.escape(text[prev_end:]))
|
| 267 |
+
|
| 268 |
+
return '<div style="font-size:15px;line-height:1.8;padding:4px 0">' + " ".join(parts) + "</div>"
|
| 269 |
|
| 270 |
|
| 271 |
def validate_spans(spans, text, syllables):
|
|
|
|
| 471 |
# Task-level prediction score = 1 - AL uncertainty score
|
| 472 |
pred_score = round(1.0 - row["score"], 6)
|
| 473 |
|
| 474 |
+
# Add dictionary metadata to spans + build inline HTML
|
| 475 |
+
dict_html = ""
|
| 476 |
if dictionary:
|
| 477 |
add_dict_meta(spans, dictionary)
|
| 478 |
+
dict_html = build_dict_html(spans, text, dictionary)
|
| 479 |
|
| 480 |
task = {
|
| 481 |
"data": {
|
|
|
|
| 484 |
"rank": row["rank"],
|
| 485 |
"file": split,
|
| 486 |
"sent_idx": sent_idx,
|
| 487 |
+
"dict_html": dict_html,
|
| 488 |
},
|
| 489 |
"predictions": [{
|
| 490 |
"model_version": "silver_crf_v1.1",
|
udd-ws-v1.1-dev.conllu
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
udd-ws-v1.1-dev.txt
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
udd-ws-v1.1-test.conllu
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
udd-ws-v1.1-test.txt
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
udd-ws-v1.1-train.conllu
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b9d03e5e2b7d628c68701a4c42f71b319f69790b6c3d0f7e74adcc90a2ce41b5
|
| 3 |
+
size 58568648
|
udd-ws-v1.1-train.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5f96a698acd5bc306bdfb52f79e348feb3eededaab8006e3423a0146230b2c18
|
| 3 |
+
size 35961491
|