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

23
LINES

< > BotCompany Repo | #1022303 // FullPhraseCache - as tree over words

JavaX fragment (include)

sclass FullPhraseCache {
  L<LS> phrases; // different spellings of full phrase
  Map<S, FullPhraseCache> byFirstWord;
  
  Map<S, FullPhraseCache> byFirstWord_init() {
    if (byFirstWord == null)
      byFirstWord = ciMap();
    ret byFirstWord;
  }

  void add(S phrase) {
    LS tok = javaTokNPunctuation_cached(phrase);
    if (l(tok) == 1) ret;
    add(tok, 1);
  }
  
  void add(LS tok, int idx) {
    if (idx >= l(tok)-1)
      ret with phrases = createOrAddToList(phrases, tok);
    FullPhraseCache subCache = getOrCreate(byFirstWord_init(), tok.get(idx), FullPhraseCache);
    subCache.add(tok, idx+2);
  }
}

Author comment

Began life as a copy of #1022266

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: #1022303
Snippet name: FullPhraseCache - as tree over words
Eternal ID of this version: #1022303/7
Text MD5: 6bbcb3934a581292adcaf198b4703d87
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-13 05:31:30
Source code size: 640 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 308 / 768
Version history: 6 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)