1 | static new ThreadLocal<Int> ai_tokenizationToTextPane_charsWritten; |
2 | |
3 | static JTextPane ai_tokenizationToTextPane(LS tok) { |
4 | ret ai_tokenizationToTextPane(fontSizePlus(7, jtextpane()), tok); |
5 | } |
6 | |
7 | static JTextPane ai_tokenizationToTextPane(JTextPane tp, LS tok) { |
8 | bool spaced = true; |
9 | int chars = 0; |
10 | for i over tok: { |
11 | if (!spaced) { |
12 | appendToTextPane(tp, " "); |
13 | ++chars; |
14 | spaced = true; |
15 | } |
16 | S t = tok.get(i); |
17 | if (empty(t)) continue; |
18 | SimpleAttributeSet style; |
19 | if (odd(i)) // C token |
20 | style = style_background(Color.yellow, style_foreground(Color.black)); |
21 | else // N token (whitespace) |
22 | style = style_foreground(Color.gray, style_background(colorFromHex("#E0E0E0"))); |
23 | appendToTextPane(tp, t, style); |
24 | chars += l(t); |
25 | spaced = false; |
26 | } |
27 | setTL(ai_tokenizationToTextPane_charsWritten, chars); |
28 | ret tp; |
29 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1022890 |
Snippet name: | ai_tokenizationToTextPane - visualize C and N tokens differently |
Eternal ID of this version: | #1022890/10 |
Text MD5: | 38e806367dfe6ee9982713e0a035d262 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-04-14 18:27:42 |
Source code size: | 891 bytes / 29 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 300 / 330 |
Version history: | 9 change(s) |
Referenced in: | [show references] |