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

33
LINES

< > BotCompany Repo | #1029043 // Snippets Deep Word Pair Index [dev.]

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

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

!7

cprint SnippetsDeepWordPairIndex {
  transient DeepWordPairIndex<S> wordIndex; // string = snippet ID
  switchable S regexp = "\\w+|\\S"; // a word or a non-space

  start-thread {
    dm_reloadOnFieldChange regexp();
    time "Make double word index" {
      print("Making index");
      new DeepWordPairIndex<S> wordIndex;
      wordIndex.regexp = regexp;
      wordIndex.useHashMaps(); // faster
      for (virtual CSnippet sn : dm_allSnippets()) {
        S snippetID = (S) rcall snippetID(sn);
        S text = cast rcall text(sn);
        wordIndex.add(snippetID, text);
      }
      setField(+wordIndex);
    }
    infoBox("Indexed " + nPairs(wordIndex.numPairs()));
  }
  
  // API
  
  Iterable<Pair<S, Cl<Int>>> snippetPreSearch_withPositions(S query, O... _) {
    Iterable<Pair<S, Cl<Int>>> l;
    //time "lookup" {
      l = wordIndex == null ? null : wordIndex.lookupString_withPositions(query, _);
    //}
    ret l;
  }
}

Author comment

Began life as a copy of #1029025

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: #1029043
Snippet name: Snippets Deep Word Pair Index [dev.]
Eternal ID of this version: #1029043/3
Text MD5: 89d5a1b22d0768b4d197c71040aba4d6
Transpilation MD5: 22c6aa8c3d182702230f4f886de5a9e9
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-17 16:25:37
Source code size: 976 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 189 / 383
Version history: 2 change(s)
Referenced in: [show references]