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

19
LINES

< > BotCompany Repo | #1021553 - tok_groupPhrase

JavaX fragment (include)

// TODO: ignore N tokens
static LS tok_groupPhrase(LS tok, S phrase) {
  LS tokPhrase = dropFirstAndLast(javaTok_cached(phrase));
  L<Int> l = indicesOfSubListIC(tok, tokPhrase);
  for (int i : l) {
    int j = i+l(tokPhrase)-1;
    if (i == 1 && j == l(tok)-2) continue;
    S pre = get(tok, i-1), post = get(tok, j+1);
    if (endsWith(pre, "{") && startsWith(post, "}"))
      continue;
    tokPrepend(tok, i, "{");
    tokAppend(tok, j, "}");
  }
  ret tok;
}

sS tok_groupPhrase(S s, S phrase) {
  ret join(tok_groupPhrase(javaTok(s), phrase));
}

Author comment

Began life as a copy of #1018199

download  show line numbers  debug dex   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1021553
Snippet name: tok_groupPhrase
Eternal ID of this version: #1021553/13
Text MD5: 15f4035b1d9fc730f960c126f389e62c
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-09 14:24:07
Source code size: 569 bytes / 19 lines
Pitched / IR pitched: No / No
Views / Downloads: 142 / 175
Version history: 12 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1021553 & http://1021553.tinybrain.de