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).

!7

sclass Interpretable {
  S text;
  S ruleID;
  
  *() {}
  *(S *text, S *ruleID) {}
}

sclass Entry {
  long msgID;
  S originalLine;
  S interpretableText;
  S ruleID;
  //S matchedRuleStruct;
  
  sS _fieldOrder = "msgID originalLine interpretableText";
}

set flag DynModule.

cmodule InterpretableTest > DynObjectTable<Entry> {
  transient int maxInterpretablesPerLine = 20;
  
  start {
    addCountToName();
    thread { scan(); }
  }
  
  visualize {
    ret withCenteredButtons(super.visualize(), "Scan", rThread scan);
  }
  
  void scan enter {
    new L<Entry> list;
    new Flag interrupted;
    temp AutoCloseable action = dm_currentAction("Scanning chat", rRaiseFlag(interrupted));
    F0<GazelleEvalContext> contextMaker = new GazelleContextCache_v2().fill();
    L<GazelleLine> lines = dm_discord_allLines();
    int i = 0;
    for (GazelleLine line : reversed(lines)) {
      ++i;
      if (!licensed() || interrupted!) break;
      Collection<Interpretable> l = getInterpretables(line, +contextMaker);
      for (Interpretable intp : l)
        list.add(nu Entry(originalLine := line.text, msgID := line.msgID, interpretableText := intp.text, ruleID := intp.ruleID));
      call(action, 'setText, "Found " + n2(list, "interpretable") + ", scanned " + i + "/" + n2(lines, "line"));
    }
    setList(list);
  }
  
  Collection<Interpretable> getInterpretables(GazelleLine line, O... _) {
    Set<S> texts = litCISet(line.text);
    new L<Interpretable> interpretables;
    Collector<Interpretable> collector = limitedCollector(interpretables, maxInterpretablesPerLine);
    RuleEngine2 engine = ((F0<GazelleEvalContext>) optPar contextMaker(_)).get().engine;

    int nInterpreted = -1;
    
    bigLoop: while (!collector.full() && nInterpreted < l(interpretables)) {
      Interpretable workingOn = get(interpretables, nInterpreted);
      S input = nInterpreted < 0 ? line.text : workingOn.text;
      S ruleBase = workingOn == null ? "" : workingOn.ruleID + "+";
      ++nInterpreted;
      
      for (RuleEngine2.SimplifyWithRule rule : engine.splitterRules()) pcall {
        for (S out : gazelle_executeSplitterRule(engine, rule, input))
          if (texts.add(out))
            if (collector.add(new Interpretable(out, ruleBase + rule.globalID))) break bigLoop;
      }
      
      for (GazelleTree t : dm_gazelle_reasonAboutChatInput_v2(null, input, 
        paramsPlus(_, skipSplitters := true, acceptablePurposes := litset('preprocess))))
          if (texts.add(t.line))
            if (collector.add(new Interpretable(t.line, ruleBase + t.ruleID()))) break bigLoop;
    }
        
    ret interpretables;
  }
}

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: 319 / 444
Version history: 5 change(s)
Referenced in: [show references]