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

81
LINES

< > BotCompany Repo | #1022180 // Interpretables Test v3 [repeated search, OK]

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

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

1  
!7
2  
3  
sclass Interpretable {
4  
  S text;
5  
  S ruleID;
6  
  
7  
  *() {}
8  
  *(S *text, S *ruleID) {}
9  
}
10  
11  
sclass Entry {
12  
  long msgID;
13  
  S originalLine;
14  
  S interpretableText;
15  
  S ruleID;
16  
  //S matchedRuleStruct;
17  
  
18  
  sS _fieldOrder = "msgID originalLine interpretableText";
19  
}
20  
21  
set flag DynModule.
22  
23  
cmodule InterpretableTest > DynObjectTable<Entry> {
24  
  transient int maxInterpretablesPerLine = 20;
25  
  
26  
  start {
27  
    addCountToName();
28  
    thread { scan(); }
29  
  }
30  
  
31  
  visualize {
32  
    ret withCenteredButtons(super.visualize(), "Scan", rThread scan);
33  
  }
34  
  
35  
  void scan enter {
36  
    new L<Entry> list;
37  
    new Flag interrupted;
38  
    temp AutoCloseable action = dm_currentAction("Scanning chat", rRaiseFlag(interrupted));
39  
    F0<GazelleEvalContext> contextMaker = new GazelleContextCache_v2().fill();
40  
    L<GazelleLine> lines = dm_discord_allLines();
41  
    int i = 0;
42  
    for (GazelleLine line : reversed(lines)) {
43  
      ++i;
44  
      if (!licensed() || interrupted!) break;
45  
      Collection<Interpretable> l = getInterpretables(line, +contextMaker);
46  
      for (Interpretable intp : l)
47  
        list.add(nu Entry(originalLine := line.text, msgID := line.msgID, interpretableText := intp.text, ruleID := intp.ruleID));
48  
      call(action, 'setText, "Found " + n2(list, "interpretable") + ", scanned " + i + "/" + n2(lines, "line"));
49  
    }
50  
    setList(list);
51  
  }
52  
  
53  
  Collection<Interpretable> getInterpretables(GazelleLine line, O... _) {
54  
    Set<S> texts = litCISet(line.text);
55  
    new L<Interpretable> interpretables;
56  
    Collector<Interpretable> collector = limitedCollector(interpretables, maxInterpretablesPerLine);
57  
    RuleEngine2 engine = ((F0<GazelleEvalContext>) optPar contextMaker(_)).get().engine;
58  
59  
    int nInterpreted = -1;
60  
    
61  
    bigLoop: while (!collector.full() && nInterpreted < l(interpretables)) {
62  
      Interpretable workingOn = get(interpretables, nInterpreted);
63  
      S input = nInterpreted < 0 ? line.text : workingOn.text;
64  
      S ruleBase = workingOn == null ? "" : workingOn.ruleID + "+";
65  
      ++nInterpreted;
66  
      
67  
      for (RuleEngine2.SimplifyWithRule rule : engine.splitterRules()) pcall {
68  
        for (S out : gazelle_executeSplitterRule(engine, rule, input))
69  
          if (texts.add(out))
70  
            if (collector.add(new Interpretable(out, ruleBase + rule.globalID))) break bigLoop;
71  
      }
72  
      
73  
      for (GazelleTree t : dm_gazelle_reasonAboutChatInput_v2(null, input, 
74  
        paramsPlus(_, skipSplitters := true, acceptablePurposes := litset('preprocess))))
75  
          if (texts.add(t.line))
76  
            if (collector.add(new Interpretable(t.line, ruleBase + t.ruleID()))) break bigLoop;
77  
    }
78  
        
79  
    ret interpretables;
80  
  }
81  
}

Author comment

Began life as a copy of #1022179

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: #1022180
Snippet name: Interpretables Test v3 [repeated search, OK]
Eternal ID of this version: #1022180/6
Text MD5: 15b88b735d2bf854237626cfbcbb3e8e
Transpilation MD5: 50611e4e1478349f89cf35b50f1dda2a
Author: stefan
Category: javax / gazelle
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-10 15:23:15
Source code size: 2727 bytes / 81 lines
Pitched / IR pitched: No / No
Views / Downloads: 247 / 354
Version history: 5 change(s)
Referenced in: [show references]