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

25
LINES

< > BotCompany Repo | #1022307 // fullPhraseCache_longestPhraseLength - returns C index after longest match

JavaX fragment (include)

1  
static int fullPhraseCache_longestPhraseLength(FullPhraseCache cache, LS tok) {
2  
  ret fullPhraseCache_longestPhraseLength(cache, tok, 1);
3  
}
4  
5  
// returns index of C token in tok after longest match
6  
static int fullPhraseCache_longestPhraseLength(FullPhraseCache cache, LS tok, int idx) {
7  
  if (cache == null || tok == null) ret -1;
8  
  int longest = -1;
9  
  if (nempty(cache.phrases)) longest = idx;
10  
  while (idx < l(tok)-1) {
11  
    ifdef fullPhraseCache_longestPhraseLength_debug
12  
      print("longest=" + longest + ", idx=" + idx + ", phrases=" + cache.phrases + ", next token= " + quote(tok.get(idx)));
13  
    endifdef
14  
    cache = mapGet(cache.byFirstWord, tok.get(idx));
15  
    if (cache == null) break;
16  
    idx += 2;
17  
    if (nempty(cache.phrases)) longest = idx;
18  
  }
19  
  ret longest;
20  
}
21  
22  
static int fullPhraseCache_longestPhraseLength(FullPhraseCache cache, S s) {
23  
  if (cache == null || s == null) ret -1;
24  
  ret fullPhraseCache_longestPhraseLength(cache, javaTokNPunctuation_cached(s));
25  
}

Author comment

Began life as a copy of #1022306

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: #1022307
Snippet name: fullPhraseCache_longestPhraseLength - returns C index after longest match
Eternal ID of this version: #1022307/12
Text MD5: 13ef1d5f5f10fa7004490f78a5ef416c
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-02 13:54:19
Source code size: 999 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 329 / 352
Version history: 11 change(s)
Referenced in: [show references]