1 | static Triple<S> ai_tripelize(S s) { |
2 | T3<S> t = ai_parseTriple(s); |
3 | if (t != null) ret t; |
4 | |
5 | S x = ""; |
6 | if (endsWith(s, "?")) x = " (?)"; // statement with question mark, e.g. "Al Gore invented the Internet?" |
7 | t = ai_tripelize_impl(dropCertainPunctuationAtEnd(s, ":;,?!.")); |
8 | if (t == null) null; |
9 | ai_fixTriple(t); |
10 | //print("After fix: " + t); |
11 | if (nempty(x) && t != null && !endsWith(t.a, "?") && !endsWith(t.b, "?") && !endsWith(t.c, "?")) t.b += x; |
12 | if (endsWith(s, "!") && eq(t.b, ".")) t.b = "!"; |
13 | ret t; |
14 | } |
15 | |
16 | static Triple<S> ai_tripelize_impl(S s) { |
17 | L<S> original = ai_tripelize_prepare(s); |
18 | if (l(original) <= 1) null; // no tokens |
19 | original = simpleSpaces(original); |
20 | L<S> tok = original; |
21 | S a = get(tok, 1); |
22 | |
23 | T3<S> triple; |
24 | ret optional triple = ai_tripelize_dash(s, original); |
25 | ret optional triple = ai_tripelize_exclamCommand(s, original); |
26 | ret optional triple = ai_tripelize_howLongEtc(s, original); |
27 | |
28 | if (ai_questionWord_1(a)) { tok = subList(tok, 2); a = get(tok, 1); } |
29 | S questionWord = trimJoinSubList(original, 0, indexOfSubList(original, tok)); |
30 | |
31 | if (ai_yesNoQuestionWord_1(a) && neqicOneOf(a, "am", "are", "is")) { |
32 | L<S> tok2 = subList(tok, 2); |
33 | int i = indexOfFirstVerb(tok2); |
34 | S v = get(tok2, i); |
35 | if (v != null) { |
36 | S middle = trimJoinSubList(tok2, 0, i); |
37 | S rest = trimJoinSubList(tok2, i+1); |
38 | v = ai_tripelize_helperVerb(a, v); |
39 | ret triple(joinWithSpace2(questionWord, middle), v, rest); |
40 | } |
41 | } |
42 | |
43 | // sentence starting with verb - instruction or question? |
44 | if (isVerb(a)) { |
45 | if (ai_yesNoQuestionWord_1(a)) { |
46 | // question |
47 | tok = subList(tok, 2); |
48 | int i = ai_splitTwoNounPhrases(tok); |
49 | //int i = ai_endOfNounPhrase(tok); |
50 | ret triple( |
51 | joinWithSpace2(questionWord, trimJoinSubList(tok, 0, i)), |
52 | a + "?", |
53 | trimJoinSubList(tok, i)); |
54 | } else { |
55 | // instruction |
56 | ret triple(a, ".", join(subList(tok, 2))); |
57 | } |
58 | } |
59 | |
60 | int i = ai_endOfNounPhrase(tok); |
61 | int j = indexOfFirstVerb(tok, i); |
62 | if (j < 0) ret triple(s, ".", "."); |
63 | ret triple( |
64 | joinWithSpace2(questionWord, trimJoinSubList(tok, 0, j)), |
65 | tok.get(j), |
66 | trimJoinSubList(tok, j+2)); |
67 | } |
Began life as a copy of #1011058
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, ppjhyzlbdabe, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1011074 |
Snippet name: | ai_tripelize [getting better] |
Eternal ID of this version: | #1011074/41 |
Text MD5: | 49dc2b7937602c412488dfee07e711f2 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-12-30 18:23:18 |
Source code size: | 2265 bytes / 67 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 580 / 657 |
Version history: | 40 change(s) |
Referenced in: | [show references] |