Uses 911K of libraries. Click here for Pure Java version (12262L/63K).
1 | !7 |
2 | |
3 | concept DetectorEntry { |
4 | S task; // e.g. "English vs German n=1000" |
5 | S expression; // posNgram|posNgram|...^negNgram|negNgram|... |
6 | S result; // double (0..1) |
7 | } |
8 | |
9 | cmodule LanguageDetectionNGramScorers > DynCRUD<DetectorEntry> { |
10 | start { |
11 | indexConceptFieldsCI(DetectorEntry, 'task, DetectorEntry, 'expression); |
12 | crud.sorter = func(Cl<DetectorEntry> l) -> L<DetectorEntry> { |
13 | sortByCalculatedFieldDesc(l, e -> pair(parseDoubleOpt(e.result), -l(e.expression))) |
14 | }; |
15 | crud.renderer = func(DetectorEntry e) -> Map { |
16 | litorderedmap( |
17 | "Expression" := e.expression, |
18 | "Result / Length" := e.result + " / " + l(e.expression), |
19 | "Task" := e.task) |
20 | }; |
21 | } |
22 | |
23 | // API |
24 | |
25 | void saveResult(S task, S expression, S result) { |
26 | cset(uniqCI DetectorEntry(+expression, +task), +result); |
27 | } |
28 | |
29 | // pairs of expression + result |
30 | LPairS expressionsForTask(S task) { |
31 | ret map(conceptsWhereCI DetectorEntry(+task), |
32 | e -> pair(e.expression, e.result)); |
33 | } |
34 | |
35 | LS expressionsForTaskByScore(S task) { |
36 | ret pairsA(sortedByCalculatedFieldDesc(expressionsForTask(task), |
37 | p -> parseDoubleOpt(p.b))); |
38 | } |
39 | } |
Began life as a copy of #1027460
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1027488 |
Snippet name: | Language Detection N-Gram-Scorer CRUD |
Eternal ID of this version: | #1027488/13 |
Text MD5: | f5f249afce2a1d2c046cbecae5ce3ce3 |
Transpilation MD5: | 4850148dd8ee92f76e99319ef167d591 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-03-22 16:52:28 |
Source code size: | 1187 bytes / 39 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 224 / 565 |
Version history: | 12 change(s) |
Referenced in: | [show references] |