Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

72
LINES

< > BotCompany Repo | #1024174 // Chat Line Annotation Guesser [dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (5029L/26K).

1  
!7
2  
3  
srecord Guesser(S regexp, S annotation) {}
4  
5  
cmodule CLAG > DynPrintLogAndEnabled {
6  
  new Map<S, LS> entries; // text -> annotations
7  
  L<Guesser> guessers = litsynclist(Guesser("eval", "eval command"));
8  
  
9  
  sclass ByCategory {
10  
    Guesser bestGuesser;
11  
  }
12  
  
13  
  start {
14  
    doEveryAndNow(5.0, r step);
15  
  }
16  
  
17  
  void step enter {
18  
    if (!enabled) ret;
19  
    
20  
    temp tempPrintTime();
21  
    dm_clearModulePrintLog();
22  
    
23  
    // find annotator module
24  
    S mod = annotator();
25  
    if (empty(mod)) ret;
26  
    
27  
    // get visible rows
28  
    IntRange vis = cast quickImport(dm_rcall visibleRows(mod));
29  
    if (vis == null) ret;
30  
    L<virtual Entry> allData = (L) dm_rcall data(mod);
31  
    L visibleData = subList(allData, vis);
32  
    
33  
    // get all annotations (without "!")
34  
    Set<S> allClasses = asCISet(dropPrefixAll("!", (Collection<S>) dm_rcall allAnnotations(mod)));
35  
    print(+allClasses);
36  
    
37  
    // update entry map
38  
    
39  
    fOr (virtual Entry e : allData) {
40  
      S text = getString text(e);
41  
      LS annotations = cast rcall annotations(e);
42  
      entries.put(text, annotations);
43  
    }
44  
    
45  
    // go through classes
46  
    
47  
    for (S c : allClasses) {
48  
      LS plusExamples = keysWhereValueContains(c, entries);
49  
      LS minusExamples = keysWhereValueContains("!" + c, entries);
50  
      print(c + ": " + l(plusExamples) + "/" + l(minusExamples));
51  
    }
52  
    
53  
    // guess visible rows
54  
    
55  
    bool change;
56  
    fOr (virtual Entry e : visibleData) {
57  
      S text = getString text(e);
58  
      LS annotations = cast rcall annotations(e);
59  
      Set<S> guesses = ciSet();
60  
      for (Guesser guesser : guessers)
61  
        if (regexpFindIC(guesser.regexp, text))
62  
          guesses.add(guesser.annotation);
63  
      S guess = joinWithComma(guesses);
64  
      if (set_trueIfChanged(e, +guess)) set change;
65  
    }
66  
    if (change) dm_rcall fireDataChanged(mod);
67  
  }
68  
  
69  
  S annotator() {
70  
    ret dm_moduleWithSnippetID(#1024172);
71  
  }
72  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1024174
Snippet name: Chat Line Annotation Guesser [dev.]
Eternal ID of this version: #1024174/20
Text MD5: 046fe6296c06567176ec6cf740cc8f69
Transpilation MD5: 789b8dc42beea758717978ed3bb0c5cc
Author: stefan
Category: javax / stefan's os / a.i
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-24 19:29:34
Source code size: 1979 bytes / 72 lines
Pitched / IR pitched: No / No
Views / Downloads: 213 / 589
Version history: 19 change(s)
Referenced in: [show references]