1 | sbool englishToConceptLanguage_xyz_debug, englishToConceptLanguage_useBrackets = true; |
2 | |
3 | static new ThreadLocal<Int> englishToConceptLanguage_xyz_level; |
4 | |
5 | sS englishToConceptLanguage_xyz(S s, O preprocess) {
|
6 | assertNotNull("Input", s);
|
7 | /*int level = englishToConceptLanguage_xyz_level.get(); |
8 | if (level >= englishToConceptLanguage_xyz_maxLevel) fail("max level");
|
9 | englishToConceptLanguage_xyz_level.set(level+1); |
10 | try {*/
|
11 | s = postProcess(preprocess, s); |
12 | |
13 | // pattern matching all concepts against full string |
14 | for (AIConcept c : englishToConceptLanguage_concepts()) {
|
15 | if (empty(c.name)) {
|
16 | print("Warning, empty name: " + c.globalID);
|
17 | continue; |
18 | } |
19 | S name = postProcess(preprocess, c.name); |
20 | try answer englishToConceptLanguage_xyz_with(c.globalID, name, s); |
21 | } |
22 | |
23 | // no full string match. go word by word |
24 | L<S> tok = javaTok(s); |
25 | if (l(tok) <= 3) null; |
26 | for (int i = 1; i < l(tok); i += 2) {
|
27 | S x = englishToConceptLanguage(unquote(tok.get(i))); |
28 | if (nempty(x)) tok.set(i, conceptQuote(x)); |
29 | } |
30 | S x = join(tok); |
31 | ret eq(x, s) ? null : x; |
32 | } |
33 | |
34 | sS englishToConceptLanguage_xyz_sub(S name, S original, S s) {
|
35 | if (l(s) >= l(original)) fail("Bad sub: " + quote(name) + " " + quote(s));
|
36 | S s2 = or2(englishToConceptLanguage(s), s); |
37 | if (englishToConceptLanguage_xyz_debug) |
38 | print("xyz_sub " + quote(s) + " => " + quote(s2));
|
39 | if (englishToConceptLanguage_useBrackets) |
40 | ret isIdentifier(s2) || isInteger(s2) || isProperlyQuoted(s2) ? s2 : "(" + s2 + ")";
|
41 | ret conceptQuote(s2); |
42 | } |
43 | |
44 | sS englishToConceptLanguage_xyz_with(S id, S s) {
|
45 | ret englishToConceptLanguage_xyz_with(getAIConcept(id), s); |
46 | } |
47 | |
48 | sS englishToConceptLanguage_xyz_with(AIConcept c, S s) {
|
49 | if (c == null) null; |
50 | ret englishToConceptLanguage_xyz_with(c.globalID, c.name, s); |
51 | } |
52 | |
53 | sS englishToConceptLanguage_xyz_with(S id, S name, S s) {
|
54 | new Matches m; |
55 | L<S> originalTok = javaTok(name), tok = cloneList(originalTok); |
56 | if (l(tok) < 5) null; // need 2 code tokens |
57 | /*if (englishToConceptLanguage_xyz_debug) |
58 | print("xyz name " + name + " originalTok1 " + struct(originalTok));*/
|
59 | bool stars = tok.contains("*");
|
60 | if (stars) |
61 | tok = replace(tok, "*", "**"); |
62 | /*if (englishToConceptLanguage_xyz_debug) |
63 | print("xyz name " + name + " originalTok2 " + struct(originalTok));*/
|
64 | int n = numberOfXYZVars(tok); |
65 | if (n == 0) null; |
66 | tok = formatXYZ(tok, rep(n, "*")); |
67 | L<S> toks = javaTok_cached(s); |
68 | if (stars) |
69 | toks = replace(cloneList(toks), "*", "**"); |
70 | bool yes = flexMatchIC2(tok, toks, m, false); |
71 | if (englishToConceptLanguage_xyz_debug && yes) |
72 | print("xyz: " + n + " " + struct(tok) + " - " + struct(toks) + " => " + (yes ? struct(m) : "-"));
|
73 | if (!yes) null; |
74 | if (n != l(m.m)) null; |
75 | new TreeMap<Int, S> map; |
76 | if (englishToConceptLanguage_xyz_debug) |
77 | print("xyz originalTok " + struct(originalTok));
|
78 | for (int i = 1; i < l(originalTok); i += 2) {
|
79 | S t = originalTok.get(i); |
80 | int x = xyzVarToIndex(t); |
81 | if (englishToConceptLanguage_xyz_debug) |
82 | print("xyz " + t + " => " + x);
|
83 | if (x != 0) {
|
84 | S sub = englishToConceptLanguage_xyz_sub(name, s, m.m[x-1]); |
85 | if (englishToConceptLanguage_xyz_debug) |
86 | print("xyz sub " + t + ": " + sub);
|
87 | map.put(i, sub); |
88 | } |
89 | } |
90 | ret aiUsing(id) + " " + join(" ", values(map));
|
91 | } |
Began life as a copy of #1007880
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1007960 |
| Snippet name: | englishToConceptLanguage_xyz [enabling "*"] |
| Eternal ID of this version: | #1007960/15 |
| Text MD5: | b7d7534f940c4943c9606e2319d92022 |
| Author: | stefan |
| Category: | javax / a.i. |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-04-17 21:45:31 |
| Source code size: | 3388 bytes / 91 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 789 / 1510 |
| Version history: | 14 change(s) |
| Referenced in: | [show references] |