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> tok = javaTokC(name); |
56 | //replace(tok, "*", "\\*"); |
57 | if (tok.contains("*")) null; |
58 | int iX = tok.indexOf("X"); |
59 | if (iX >= 0) { |
60 | int iY = tok.indexOf("Y"); |
61 | if (iY >= 0) { |
62 | int iZ = tok.indexOf("Z"); |
63 | if (iZ >= 0) { |
64 | int iAA = tok.indexOf("AA"); |
65 | if (iAA >= 0) { |
66 | // X, Y, Z and AA |
67 | S pat = formatXYZ(name, "*", "*", "*", "*"); |
68 | bool yes = flexMatchIC2(pat, s, m, false); |
69 | if (englishToConceptLanguage_xyz_debug && yes) |
70 | print("xyz: " + pat + " - " + s + " => " + (yes ? struct(m) : "-")); |
71 | if (yes) { |
72 | assertEquals(name, 4, l(m.m)); |
73 | new TreeMap<Int, S> map; |
74 | map.put(iX, englishToConceptLanguage_xyz_sub(name, s, m.m[0])); |
75 | map.put(iY, englishToConceptLanguage_xyz_sub(name, s, m.m[1])); |
76 | map.put(iZ, englishToConceptLanguage_xyz_sub(name, s, m.m[2])); |
77 | map.put(iAA, englishToConceptLanguage_xyz_sub(name, s, m.m[3])); |
78 | ret aiUsing(id) + " " + join(" ", values(map)); |
79 | } |
80 | } else { |
81 | // X and Y and Z |
82 | S pat = formatXYZ(name, "*", "*", "*"); |
83 | bool yes = flexMatchIC2(pat, s, m, false); |
84 | if (englishToConceptLanguage_xyz_debug && yes) |
85 | print("xyz: " + pat + " - " + s + " => " + (yes ? struct(m) : "-")); |
86 | if (yes) { |
87 | assertEquals(name, 3, l(m.m)); |
88 | new TreeMap<Int, S> map; |
89 | map.put(iX, englishToConceptLanguage_xyz_sub(name, s, m.m[0])); |
90 | map.put(iY, englishToConceptLanguage_xyz_sub(name, s, m.m[1])); |
91 | map.put(iZ, englishToConceptLanguage_xyz_sub(name, s, m.m[2])); |
92 | ret aiUsing(id) + " " + join(" ", values(map)); |
93 | } |
94 | } |
95 | } else { |
96 | // X and Y |
97 | S pat = formatXYZ(name, "*", "*"); |
98 | bool complicated = containsSubList(tok, "X", "Y"); |
99 | bool yes = complicated ? jmatch(pat, s, m) : flexMatchIC2(pat, s, m, false); |
100 | if (englishToConceptLanguage_xyz_debug && yes) |
101 | print("xyz: " + pat + " - " + s + " => " + (yes ? struct(m) : "-")); |
102 | if (yes) { |
103 | assertEquals(name, 2, l(m.m)); |
104 | S a = englishToConceptLanguage_xyz_sub(name, s, m.m[0]); |
105 | S b = englishToConceptLanguage_xyz_sub(name, s, m.m[1]); |
106 | ret aiUsing(id) + " " + |
107 | (iX < iY ? a + " " + b : b + " " + a); |
108 | } |
109 | } |
110 | } else if (l(tok) > 1) { |
111 | // X only |
112 | S pat = formatXYZ(name, "*"); |
113 | if (flexMatchIC2(pat, s, m, false)) { |
114 | assertEquals(name, 1, l(m.m)); |
115 | S a = englishToConceptLanguage_xyz_sub(name, s, m.m[0]); |
116 | ret aiUsing(id) + " " + a; |
117 | } |
118 | } |
119 | } |
120 | null; |
121 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): cfunsshuasjs, mqqgnosmbjvj, tvejysmllsmz
No comments. add comment
Snippet ID: | #1007424 |
Snippet name: | englishToConceptLanguage_xyz (old) |
Eternal ID of this version: | #1007424/51 |
Text MD5: | ac6046a8c073d01c9e3ebd63bde25704 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | Yes |
Created/modified: | 2017-04-13 17:31:55 |
Source code size: | 4684 bytes / 121 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 531 / 418 |
Version history: | 50 change(s) |
Referenced in: | [show references] |