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

20
LINES

< > BotCompany Repo | #1021421 // ai_applyWordSplitPattern1 - match "$Redakteur{}in" with "Gärtnerin"

JavaX fragment (include)

1  
static LS ai_applyWordSplitPattern1(LS tokP, LS tokI) {
2  
  L<Int> indices = indicesOfSubList(tokP, ll("", "{}", ""));
3  
  if (empty(indices)) ret tokI;
4  
  LS tokI_original = tokI;
5  
  tokI = cloneList(tokI);
6  
  for (int i : indices) {
7  
    //if (l(tokI) < i+2) ret tokI_original;
8  
    S l = get(tokP, i-1), r = get(tokP, i+3);
9  
    if (startsWith(l, "$") && isIdentifier(l) && isIdentifier(r)) {
10  
      S x = get(tokI, i-1);
11  
      if (!ewic(x, r)) ret tokI_original; // fail
12  
      tokI.set(i-1, dropLast(x, l(r)));
13  
      tokI.add(i, "");
14  
      tokI.add(i+1, "{}");
15  
      tokI.add(i+2, "");
16  
      tokI.add(i+3, takeLast(x, l(r)));
17  
    }
18  
  }
19  
  ret tokI;
20  
}

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: #1021421
Snippet name: ai_applyWordSplitPattern1 - match "$Redakteur{}in" with "Gärtnerin"
Eternal ID of this version: #1021421/4
Text MD5: 2a1105ed0adc07f9777d9f3894564e78
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-02-13 23:01:32
Source code size: 661 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 318 / 368
Version history: 3 change(s)
Referenced in: [show references]