// returns func(S) -> S or fails // returnFullText = false: return only answer static O ai_relateTwoTokens(S text1, S text2, L functionsToTry, bool returnFullText) { L<S> t1 = javaTok(text1), t2 = javaTok(text2); if (l(t1) != l(t2)) quickFail(); L<Triple<S, S, Int>> diffs = differencesElementByElement_codeTokensOnly(t1, t2); if (l(diffs) != 2) quickFail(); Triple<S, S, Int> d1 = first(diffs), d2 = second(diffs); for (O f : functionsToUse) { if (checkFunctionOnPairs(f, ll(pair(d1.a, d2.a), pair(d1.b, d2.b)))) ret ai_relateTwoTokens_solver(t1, d1.c, d2.c, f, returnFullText); if (checkFunctionOnPairs(f, ll(pair(d2.a, d1.a), pair(d2.b, d1.b)))) ret ai_relateTwoTokens_solver(t1, d2.c, d1.c, f, returnFullText); } throw quickFail("No function found"); } static O ai_relateTwoTokens_solver(final L<S> answerTmpl, final int i, final int j, fO f, final bool returnFullText) { ret func(S s) { L<S> tok = javaTok(s); int l = l(tok); tok.addAll(subList(answerTmpl, l)); tok.set(j, (S) callF(f, tok.get(i))); ret returnFullText ? join(tok) : join(subList(tok, l-1)); }; }
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1009494 |
Snippet name: | ai_relateTwoTokens |
Eternal ID of this version: | #1009494/4 |
Text MD5: | c2e277327999adc7123426dce83c57db |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-08-04 18:08:28 |
Source code size: | 1153 bytes / 26 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 486 / 519 |
Version history: | 3 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |