rain1024 commited on
Commit
092c3e4
·
1 Parent(s): 3629965

Regenerate UDD-WS v1.1 dataset and update annotation tooling

Browse files
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 | 16 | 482 | 16 | 0 |
10
- | udd-ws-v1.1-dev.txt | 2 | 61 | 2 | 0 |
11
- | udd-ws-v1.1-test.txt | 1 | 54 | 1 | 0 |
12
- | **TOTAL** | **19** | **597** | **19** | **0** |
13
 
14
  ## Merge Frequency by Term
15
 
16
  | Term | Count |
17
  |:-----|------:|
18
- | làm chủ | 18 |
19
- | phiên tòa | 1 |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  ## Cross-Boundary Split Examples
22
 
23
  ### udd-ws-v1.1-train.txt
24
 
25
- - [uvw-19943] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
26
- - [uvw-6826] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
27
- - [uvb-n-16752] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
28
- - [uvw-11371] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
29
- - [uvw-14568] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
30
- - [uvw-8787] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
31
- - [uvb-n-17467] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
32
- - [vlc-9870] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
33
- - [uvw-18776] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
34
- - [uvw-19267] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
35
- - [uvw-18775] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
36
- - [uvw-12623] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
37
- - [uvw-3529] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
38
- - [uvw-18747] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
39
- - [uvw-8782] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
40
- - [uvw-16412] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
 
 
 
 
 
41
 
42
  ### udd-ws-v1.1-dev.txt
43
 
44
- - [uvw-18777] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
45
- - [uvb-n-3314] split "phiên Tòa" → 'phiên' + 'Tòa'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  ### udd-ws-v1.1-test.txt
48
 
49
- - [uvw-18702] split "làm Chủ tịch" → 'làm' + 'Chủ tịch'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  ## Long Token Split Examples
52
 
53
  ### udd-ws-v1.1-train.txt
54
 
55
- - [uvw-6448] split "chủ nghĩa biểu hiện tại" → 'chủ nghĩa' + 'biểu hiện' + 'tại'
56
- - [uvw-13917] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
57
- - [vlc-19916] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
58
- - [vlc-15] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
59
- - [vlc-16255] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận' + 'Tổ quốc' + 'Việt Nam'
60
- - [vlc-12686] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
61
- - [uvn-18201] split "chiêm ngưỡng nguyệt thực toàn" → 'chiêm ngưỡng' + 'nguyệt thực' + 'toàn'
62
- - [uvw-17503] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
63
- - [uvw-17503] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
64
- - [vlc-10039] split "Tòa án nhân dân tối cao" → 'Tòa án nhân dân' + 'tối cao'
65
- - [vlc-624] split "quyền sở hữu toàn dân" → 'quyền sở hữu' + 'toàn' + 'dân'
66
- - [vlc-353] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
67
- - [vlc-6987] split "phương tiện thông tin đại chúng" → 'phương tiện' + 'thông tin đại chúng'
68
- - [uvw-4874] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
69
- - [vlc-3583] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
70
- - [uvn-12997] split "quyền sở hữu trí tuệ" → 'quyền sở hữu' + 'trí tuệ'
71
- - [vlc-19715] split "Luật Bảo hiểm hội" → 'Luật' + 'Bảo hiểm hội'
72
- - [uvn-5062] split "Trần Lưu Tường Minh giữ" → 'Trần Lưu Tường Minh' + 'giữ'
73
- - [vlc-14777] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận' + 'Tổ quốc' + 'Việt Nam'
74
- - [uvw-10341] split "phóng vệ tinh nhân tạo" → 'phóng vệ tinh' + 'nhân tạo'
75
- - [uvw-13920] split "Đảng Cộng sản Việt Nam" → 'Đảng' + 'Cộng sản' + 'Việt Nam'
76
- - [vlc-16398] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận' + 'Tổ quốc' + 'Việt Nam'
77
- - [vlc-13141] split "quyền sở hữu trí tuệ" → 'quyền sở hữu' + 'trí tuệ'
78
- - [vlc-7920] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
79
- - [vlc-18475] split "Luật Bảo hiểm hội" → 'Luật' + 'Bảo hiểm xã hội'
80
- - [vlc-17502] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
81
- - [vlc-19572] split "Luật Bảo hiểm hội" → 'Luật' + 'Bảo hiểm hội'
82
- - [vlc-6986] split "phương tiện thông tin đại chúng" → 'phương tiện' + 'thông tin đại chúng'
83
- - [vlc-15371] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận' + 'Tổ quốc' + 'Việt Nam'
84
- - [vlc-13776] split "quyền sở hữu trí tuệ" → 'quyền sở hữu' + 'trí tuệ'
85
- - ... and 452 more
86
 
87
  ### udd-ws-v1.1-dev.txt
88
 
89
- - [vlc-2196] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
90
- - [uvn-5219] split "The Harmony Đồng Minh Anh" → 'The Harmony' + 'Đồng Minh' + 'Anh'
91
- - [uvn-19577] split "mạch quang tử tích hợp" → 'mạch' + 'quang' + 'tử' + 'tích hợp'
92
- - [uvn-15947] split "Bùi Hoàng Phương kỳ vọng" → 'Bùi Hoàng Phương' + 'kỳ vọng'
93
- - [vlc-17841] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
94
- - [vlc-13138] split "quyền sở hữu trí tuệ" → 'quyền sở hữu' + 'trí tuệ'
95
- - [uvn-99] split "Khánh Hoàng Phước Tuấn Ảnh" → 'Khánh' + 'Hoàng' + 'Phước' + 'Tuấn' + 'Ảnh'
96
- - [vlc-7955] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
97
- - [vlc-2090] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
98
- - [vlc-16511] split "Luật Bảo hiểm hội" → 'Luật' + 'Bảo hiểm xã hội'
99
- - [uvw-5886] split " hội Chủ nghĩa Việt Nam" → ' hội Chủ nghĩa' + 'Việt Nam'
100
- - [vlc-10450] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
101
- - [uvw-19491] split "Giải địch bóng đá châu" → 'Giải địch' + 'bóng đá' + 'châu'
102
- - [uvw-19491] split "Giải địch bóng đá châu" → 'Giải địch' + 'bóng đá' + 'châu'
103
- - [uvw-16453] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận' + 'Tổ quốc' + 'Việt Nam'
104
- - [vlc-8188] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
105
- - [vlc-3804] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
106
- - [vlc-13775] split "quyền sở hữu trí tuệ" → 'quyền sở hữu' + 'trí tuệ'
107
- - [vlc-13775] split "luật tố tụng dân sự" → 'luật' + 'tố tụng dân sự'
108
- - [vlc-19295] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận' + 'Tổ quốc' + 'Việt Nam'
109
- - [uvn-15092] split "kính hiển vi sinh học" → 'kính' + 'hiển' + 'vi' + 'sinh học'
110
- - [vlc-7484] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
111
- - [vlc-19947] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận' + 'Tổ quốc' + 'Việt Nam'
112
- - [vlc-19927] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
113
- - [vlc-16896] split "Luật Bảo hiểm hội" → 'Luật' + 'Bảo hiểm xã hội'
114
- - [vlc-621] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
115
- - [uvw-7796] split " hội Chủ nghĩa Việt Nam" → ' hội Chủ nghĩa' + 'Việt Nam'
116
- - [vlc-6731] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
117
- - [vlc-17800] split "phương tiện thông tin đại chúng" → 'phương tiện' + 'thông tin đại chúng'
118
- - [vlc-7950] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
119
- - ... and 31 more
120
 
121
  ### udd-ws-v1.1-test.txt
122
 
123
- - [vlc-10034] split "Viện kiểm sát nhân dân" → 'Viện kiểm sát' + 'nhân dân'
124
- - [uvb-f-461] split " Hội Chủ Nghĩa Anh" → ' Hội Chủ Nghĩa' + 'Anh'
125
- - [vlc-16618] 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'
126
- - [uvw-1380] split "Tổng thu nhập quốc dân" → 'Tổng thu' + 'nhập' + 'quốc dân'
127
- - [vlc-15228] split "Mặt trận Tổ quốc Việt Nam" → 'Mặt trận' + 'Tổ quốc' + 'Việt Nam'
128
- - [vlc-8925] split "Viện kiểm sát nhân dân" → 'Viện kiểm sát' + 'nhân dân'
129
- - [vlc-8925] 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'
130
- - [vlc-18894] split "Bộ Tài nguyên Môi trường" → 'Bộ' + 'Tài nguyên' + '' + 'Môi trường'
131
- - [vlc-13757] split "quyền sở hữu trí tuệ" → 'quyền sở hữu' + 'trí tuệ'
132
- - [vlc-11587] split "Luật ban hành văn bản" → 'Luật' + 'ban hành' + 'văn bản'
133
- - [vlc-19296] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
134
- - [vlc-16198] split "Bộ Tài nguyên Môi trường" → 'Bộ' + 'Tài nguyên' + 'và' + 'Môi trường'
135
- - [vlc-18868] split "Bộ Tài nguyên Môi trường" → 'Bộ' + 'Tài nguyên' + 'và' + 'Môi trường'
136
- - [vlc-13097] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
137
- - [vlc-8917] split "Viện kiểm sát nhân dân" → 'Viện kiểm sát' + 'nhân dân'
138
- - [vlc-16751] split "Tòa án nhân dân tối cao" → 'Tòa án nhân dân' + 'tối cao'
139
- - [uvb-n-11178] split " thuyết vi trùng học" → ' thuyết' + 'vi' + 'trùng' + 'học'
140
- - [vlc-14758] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
141
- - [vlc-10398] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
142
- - [vlc-15065] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
143
- - [uvw-5867] split " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
144
- - [vlc-18922] split "Bộ Tài nguyên Môi trường" → 'Bộ' + 'Tài nguyên' + 'và' + 'Môi trường'
145
- - [uvw-7413] split "lực lượng trang giáo phái" → 'lực lượng trang' + 'giáo phái'
146
- - [uvw-8427] split "Bồ Đào Nha thiết lập" → 'Bồ Đào Nha' + 'thiết lập'
147
- - [vlc-3487] split "xã hội chủ nghĩa Việt Nam" → 'xã hội chủ nghĩa' + 'Việt Nam'
148
- - [uvw-10867] split "hiện thực hội chủ nghĩa" → 'hiện thực' + ' hội chủ nghĩa'
149
- - [vlc-2387] split "Bộ Tài nguyên Môi trường" → 'Bộ' + 'Tài nguyên' + 'và' + 'Môi trường'
150
- - [vlc-13758] split "quyền sở hữu trí tuệ" → 'quyền sở hữu' + 'trí tuệ'
151
- - [uvw-4525] split " hội Chủ nghĩa Việt Nam" → ' hội Chủ nghĩa' + 'Việt Nam'
152
- - [vlc-10296] split "Viện kiểm sát nhân dân" → 'Viện kiểm sát' + 'nhân dân'
153
- - ... and 24 more
 
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 trang giáo phái" → 'lực lượng trang' + 'giáo phái'
121
+ - [vlc-19939] split " hội chủ nghĩa Việt Nam" → ' 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 " hội chủ nghĩa Việt Nam" → ' 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 " hội chủ nghĩa Việt Nam" → ' 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 thể" → 'Chúng' + 'sở hữu' + 'cơ thể'
134
+ - [vlc-14193] split " hội chủ nghĩa Việt Nam" → ' 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 Môi trường" → 'Bộ' + 'Tài nguyên' + 'và' + 'Môi trường'
137
+ - [vlc-17799] split "Bộ Tài nguyên Môi trường" → 'Bộ' + 'Tài nguyên' + 'và' + 'Môi trường'
138
+ - [vlc-7359] split " hội chủ nghĩa Việt Nam" → ' 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 " hội chủ nghĩa Việt Nam" → ' 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 " hội chủ nghĩa Việt Nam" → ' 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 " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
153
+ - [vlc-14549] split " hội chủ nghĩa Việt Nam" → ' 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 " hội chủ nghĩa Việt Nam" → ' 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 " 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 " hội chủ nghĩa Việt Nam" → ' 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 " → 'nhà thiên văn' + 'nghiệp' + ''
166
+ - [uvw-5987] split "nhà thiên văn nghiệp " → '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 " hội chủ nghĩa Việt Nam" → ' 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 " 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 " hội chủ nghĩa Việt Nam" → ' hội chủ nghĩa' + 'Việt Nam'
178
+ - [uvb-n-18761] split " thuyết vi trùng học" → ' 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 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 Môi trường" → 'Bộ' + 'Tài nguyên' + 'và' + 'Môi trường'
190
+ - [vlc-12025] split " hội chủ nghĩa Việt Nam" → ' 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 " hội chủ nghĩa Việt Nam" → ' 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 " → 'nhà thiên văn' + 'vật '
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 " hội chủ nghĩa Việt Nam" → ' 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 " hội chủ nghĩa Việt Nam" → ' 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 " hội chủ nghĩa Việt Nam" → ' 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 a self-contained HTML dictionary plugin for Label Studio.
6
 
7
- Produces dict_plugin.html that provides:
8
- 1. Highlight bar: reads sentence text and predicted spans from URL fragment,
9
- colors multi-syllable words green (in dict) or red (not in dict)
10
- 2. Search box: instant dictionary search with exact/prefix/substring matches
11
 
12
- The full 63K-entry dictionary is embedded as a JS array for client-side lookup.
13
- Per-task data is passed via URL fragment (#text=...&spans=...) so the ~900KB
14
- dictionary is loaded once and cached by the browser.
 
 
15
 
16
  Usage:
17
  uv run src/build_dict_plugin.py --dict path/to/dictionary.txt
18
- uv run src/build_dict_plugin.py # uses default path
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
- LS_STATIC_DIRS = [
32
- "/home/claude-code/.local/share/uv/tools/label-studio/"
33
- "lib/python3.12/site-packages/label_studio/core/static_build",
34
- "/home/claude-code/projects/workspace_underthesea/label-studio/.venv/"
35
- "lib/python3.12/site-packages/label_studio/core/static_build",
36
  ]
37
 
38
 
@@ -51,220 +54,274 @@ def load_dictionary(dict_path):
51
  return entries
52
 
53
 
54
- def build_html(entries):
55
- # JSON-encode the sorted list for embedding in JS
56
- dict_json = json.dumps(entries, ensure_ascii=False)
57
-
58
- return (
59
- '<!DOCTYPE html>\n'
60
- '<html lang="vi">\n'
61
- '<head>\n'
62
- '<meta charset="UTF-8">\n'
63
- '<style>\n'
64
- '* { box-sizing: border-box; margin: 0; padding: 0; }\n'
65
- 'body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }\n'
66
- '.highlights {\n'
67
- ' padding: 6px 10px;\n'
68
- ' font-size: 15px;\n'
69
- ' line-height: 1.6;\n'
70
- ' background: #fafafa;\n'
71
- ' border-bottom: 1px solid #e0e0e0;\n'
72
- ' cursor: default;\n'
73
- '}\n'
74
- '.highlights .word {\n'
75
- ' cursor: pointer;\n'
76
- '}\n'
77
- '.highlights .word:hover {\n'
78
- ' background: #e3f2fd;\n'
79
- ' border-radius: 3px;\n'
80
- '}\n'
81
- '.highlights .in-dict {\n'
82
- ' background: #c8e6c9;\n'
83
- ' padding: 1px 3px;\n'
84
- ' border-radius: 3px;\n'
85
- ' cursor: pointer;\n'
86
- '}\n'
87
- '.highlights .not-dict {\n'
88
- ' background: #ffcdd2;\n'
89
- ' padding: 1px 3px;\n'
90
- ' border-radius: 3px;\n'
91
- ' text-decoration: underline;\n'
92
- ' text-decoration-color: red;\n'
93
- ' cursor: pointer;\n'
94
- '}\n'
95
- '.search-area {\n'
96
- ' padding: 6px 10px;\n'
97
- '}\n'
98
- '.search-box {\n'
99
- ' display: flex;\n'
100
- ' gap: 6px;\n'
101
- ' align-items: center;\n'
102
- '}\n'
103
- '.search-box input {\n'
104
- ' flex: 1;\n'
105
- ' padding: 5px 10px;\n'
106
- ' font-size: 14px;\n'
107
- ' border: 1px solid #ccc;\n'
108
- ' border-radius: 4px;\n'
109
- ' outline: none;\n'
110
- '}\n'
111
- '.search-box input:focus { border-color: #4CAF50; }\n'
112
- '.search-box .count {\n'
113
- ' font-size: 12px;\n'
114
- ' color: #888;\n'
115
- ' white-space: nowrap;\n'
116
- '}\n'
117
- '#results {\n'
118
- ' max-height: 200px;\n'
119
- ' overflow-y: auto;\n'
120
- ' font-size: 14px;\n'
121
- '}\n'
122
- '.section { padding: 4px 0; }\n'
123
- '.section-title {\n'
124
- ' font-size: 11px;\n'
125
- ' font-weight: 600;\n'
126
- ' color: #888;\n'
127
- ' text-transform: uppercase;\n'
128
- ' padding: 2px 0;\n'
129
- '}\n'
130
- '.match { padding: 1px 0; }\n'
131
- '.match.exact { font-weight: 600; color: #2e7d32; }\n'
132
- '.match mark { background: #fff9c4; padding: 0 1px; border-radius: 2px; }\n'
133
- '.no-results { color: #999; padding: 4px 0; }\n'
134
- '.hidden { display: none; }\n'
135
- '</style>\n'
136
- '</head>\n'
137
- '<body>\n'
138
- '<div class="highlights" id="highlights"></div>\n'
139
- '<div class="search-area">\n'
140
- ' <div class="search-box">\n'
141
- ' <input type="text" id="q" placeholder="Search dictionary..." autocomplete="off">\n'
142
- ' <span class="count" id="dict-count"></span>\n'
143
- ' </div>\n'
144
- ' <div id="results" class="hidden"></div>\n'
145
- '</div>\n'
146
- '\n'
147
- '<script>\n'
148
- 'const DICT = ' + dict_json + ';\n'
149
- 'const DICT_LOWER = DICT.map(e => e.toLowerCase());\n'
150
- 'const DICT_SET = new Set(DICT_LOWER);\n'
151
- 'document.getElementById("dict-count").textContent = DICT.length.toLocaleString() + " entries";\n'
152
- '\n'
153
- '// --- Highlight bar: read params from URL fragment ---\n'
154
- 'function parseFragment() {\n'
155
- ' const hash = decodeURIComponent(location.hash.slice(1));\n'
156
- ' const params = {};\n'
157
- ' for (const part of hash.split("&")) {\n'
158
- ' const eq = part.indexOf("=");\n'
159
- ' if (eq > 0) params[part.slice(0, eq)] = part.slice(eq + 1);\n'
160
- ' }\n'
161
- ' return params;\n'
162
- '}\n'
163
- '\n'
164
- 'function escHtml(s) {\n'
165
- ' return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");\n'
166
- '}\n'
167
- '\n'
168
- 'function renderHighlights() {\n'
169
- ' const params = parseFragment();\n'
170
- ' const text = params.text || "";\n'
171
- ' const el = document.getElementById("highlights");\n'
172
- ' if (!text) { el.classList.add("hidden"); return; }\n'
173
- ' el.classList.remove("hidden");\n'
174
- '\n'
175
- ' let spans;\n'
176
- ' try { spans = JSON.parse(params.spans || "[]"); } catch(e) { spans = []; }\n'
177
- '\n'
178
- ' if (!spans.length) {\n'
179
- ' el.innerHTML = escHtml(text);\n'
180
- ' return;\n'
181
- ' }\n'
182
- '\n'
183
- ' let html = "";\n'
184
- ' let prev = 0;\n'
185
- ' for (const sp of spans) {\n'
186
- ' const [start, end] = sp;\n'
187
- ' if (start > prev) html += escHtml(text.slice(prev, start));\n'
188
- ' const word = text.slice(start, end);\n'
189
- ' const nSyl = word.split(" ").length;\n'
190
- ' if (nSyl === 1) {\n'
191
- ' html += \'<span class="word" onclick="fillSearch(this)">\' + escHtml(word) + "</span>";\n'
192
- ' } else {\n'
193
- ' const inDict = DICT_SET.has(word.toLowerCase());\n'
194
- ' const cls = inDict ? "in-dict" : "not-dict";\n'
195
- ' html += \'<span class="\' + cls + \'" onclick="fillSearch(this)">\' + escHtml(word) + "</span>";\n'
196
- ' }\n'
197
- ' prev = end;\n'
198
- ' }\n'
199
- ' if (prev < text.length) html += escHtml(text.slice(prev));\n'
200
- ' el.innerHTML = html;\n'
201
- '}\n'
202
- '\n'
203
- 'function fillSearch(el) {\n'
204
- ' const q = document.getElementById("q");\n'
205
- ' q.value = el.textContent;\n'
206
- ' q.focus();\n'
207
- ' doSearch();\n'
208
- '}\n'
209
- '\n'
210
- 'renderHighlights();\n'
211
- '\n'
212
- '// --- Dictionary search ---\n'
213
- 'const input = document.getElementById("q");\n'
214
- 'const resultsDiv = document.getElementById("results");\n'
215
- 'let debounceTimer;\n'
216
- 'input.addEventListener("input", () => {\n'
217
- ' clearTimeout(debounceTimer);\n'
218
- ' debounceTimer = setTimeout(doSearch, 150);\n'
219
- '});\n'
220
- '\n'
221
- 'function doSearch() {\n'
222
- ' const q = input.value.trim().toLowerCase();\n'
223
- ' if (!q) { resultsDiv.classList.add("hidden"); return; }\n'
224
- ' const exact = [], prefix = [], substring = [];\n'
225
- ' const MAX = 50;\n'
226
- ' for (let i = 0; i < DICT_LOWER.length; i++) {\n'
227
- ' const e = DICT_LOWER[i];\n'
228
- ' if (e === q) exact.push(i);\n'
229
- ' else if (e.startsWith(q)) { if (prefix.length < MAX) prefix.push(i); }\n'
230
- ' else if (e.includes(q)) { if (substring.length < MAX) substring.push(i); }\n'
231
- ' if (prefix.length >= MAX && substring.length >= MAX && exact.length > 0) break;\n'
232
- ' }\n'
233
- ' let h = "";\n'
234
- ' if (exact.length > 0) {\n'
235
- ' h += \'<div class="section"><div class="section-title">Exact</div>\';\n'
236
- ' for (const i of exact) h += \'<div class="match exact">\' + hl(DICT[i], q) + "</div>";\n'
237
- ' h += "</div>";\n'
238
- ' }\n'
239
- ' if (prefix.length > 0) {\n'
240
- ' h += \'<div class="section"><div class="section-title">Prefix (\' + prefix.length + ")</div>";\n'
241
- ' for (const i of prefix) h += \'<div class="match">\' + hl(DICT[i], q) + "</div>";\n'
242
- ' h += "</div>";\n'
243
- ' }\n'
244
- ' if (substring.length > 0) {\n'
245
- ' h += \'<div class="section"><div class="section-title">Contains (\' + substring.length + ")</div>";\n'
246
- ' for (const i of substring) h += \'<div class="match">\' + hl(DICT[i], q) + "</div>";\n'
247
- ' h += "</div>";\n'
248
- ' }\n'
249
- ' if (!h) h = \'<div class="no-results">No matches</div>\';\n'
250
- ' resultsDiv.innerHTML = h;\n'
251
- ' resultsDiv.classList.remove("hidden");\n'
252
- '}\n'
253
- '\n'
254
- 'function hl(text, query) {\n'
255
- ' const idx = text.toLowerCase().indexOf(query);\n'
256
- ' if (idx < 0) return escHtml(text);\n'
257
- ' return escHtml(text.slice(0, idx)) + "<mark>" + escHtml(text.slice(idx, idx + query.length)) + "</mark>" + escHtml(text.slice(idx + query.length));\n'
258
- '}\n'
259
- '</script>\n'
260
- '</body>\n'
261
- '</html>'
262
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
 
264
 
265
  def main():
266
  parser = argparse.ArgumentParser(
267
- description="Generate dictionary plugin HTML for Label Studio"
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/dict_plugin.html",
277
- help="Output HTML path (default: src/dict_plugin.html)",
278
  )
279
  parser.add_argument(
280
  "--deploy",
281
  action="store_true",
282
- help="Also copy to LS static_build directory",
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
- html_content = build_html(entries)
295
- output_path = Path(args.output)
296
- output_path.parent.mkdir(parents=True, exist_ok=True)
297
- output_path.write_text(html_content, encoding="utf-8")
298
 
299
- size_kb = output_path.stat().st_size / 1024
300
- print(f"Written {output_path} ({size_kb:.0f} KB)")
 
 
 
301
 
 
 
 
 
 
 
 
 
302
  if args.deploy:
303
  import shutil
304
- for static_dir in LS_STATIC_DIRS:
305
- deploy_path = Path(static_dir) / "dict_plugin.html"
306
- if deploy_path.parent.exists():
307
- shutil.copy2(output_path, deploy_path)
308
- print(f"Deployed to {deploy_path}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  else:
310
- print(f"WARNING: {deploy_path.parent} not found, skipping")
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)">&times;</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, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
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)">&times;</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, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
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
- <View style="border:1px solid #e0e0e0; border-radius:8px; overflow:hidden; margin-bottom:8px">
5
- <HyperText name="dict_view" value="$dict_iframe" inline="true"/>
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
- generates dict_html field with dictionary match highlights:
17
- green = multi-syllable span in dictionary
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 build_dict_iframe(spans, text):
219
- """Build an iframe tag pointing to the dictionary plugin page.
220
 
221
- Encodes the sentence text and span positions in the URL fragment so the
222
- plugin page can render highlights and search without a server round-trip.
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 iframe tag string for the HyperText panel
231
  """
232
- # Encode spans as compact [start, end] pairs
233
- span_pairs = [
234
- [s["value"]["start"], s["value"]["end"]] for s in spans
235
- ]
236
- spans_json = json.dumps(span_pairs, separators=(",", ":"))
237
-
238
- fragment = f"text={quote(text, safe='')}&spans={quote(spans_json, safe='')}"
239
- return (
240
- f"<iframe src='/static/dict_plugin.html#{fragment}'"
241
- f" width='100%' height='180' style='border:none'></iframe>"
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 iframe for search
449
- dict_iframe = ""
450
  if dictionary:
451
  add_dict_meta(spans, dictionary)
452
- dict_iframe = build_dict_iframe(spans, text)
453
 
454
  task = {
455
  "data": {
@@ -458,7 +484,7 @@ def main():
458
  "rank": row["rank"],
459
  "file": split,
460
  "sent_idx": sent_idx,
461
- "dict_iframe": dict_iframe,
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:46e72f621aea374546b2623fa204b61188eba0ba6294373be840f6ae17b924af
3
- size 55097167
 
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:6813dd255f69b2aab95307b857efd4aeae5f9998a66cae87891303b99df8b52d
3
- size 33868610
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f96a698acd5bc306bdfb52f79e348feb3eededaab8006e3423a0146230b2c18
3
+ size 35961491