1 | // returns func(S) -> S or fails |
2 | // returnFullText = false: return only answer |
3 | static O ai_relateTwoTokens(S text1, S text2, L functionsToTry, bool returnFullText) { |
4 | L<S> t1 = javaTok(text1), t2 = javaTok(text2); |
5 | if (l(t1) != l(t2)) quickFail(); |
6 | L<Triple<S, S, Int>> diffs = differencesElementByElement_codeTokensOnly(t1, t2); |
7 | if (l(diffs) != 2) quickFail(); |
8 | Triple<S, S, Int> d1 = first(diffs), d2 = second(diffs); |
9 | for (O f : functionsToUse) { |
10 | if (checkFunctionOnPairs(f, ll(pair(d1.a, d2.a), pair(d1.b, d2.b)))) |
11 | ret ai_relateTwoTokens_solver(t1, d1.c, d2.c, f, returnFullText); |
12 | if (checkFunctionOnPairs(f, ll(pair(d2.a, d1.a), pair(d2.b, d1.b)))) |
13 | ret ai_relateTwoTokens_solver(t1, d2.c, d1.c, f, returnFullText); |
14 | } |
15 | throw quickFail("No function found"); |
16 | } |
17 | |
18 | static O ai_relateTwoTokens_solver(final L<S> answerTmpl, final int i, final int j, fO f, final bool returnFullText) { |
19 | ret func(S s) { |
20 | L<S> tok = javaTok(s); |
21 | int l = l(tok); |
22 | tok.addAll(subList(answerTmpl, l)); |
23 | tok.set(j, (S) callF(f, tok.get(i))); |
24 | ret returnFullText ? join(tok) : join(subList(tok, l-1)); |
25 | }; |
26 | } |
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: | 487 / 520 |
Version history: | 3 change(s) |
Referenced in: | [show references] |