1 | sbool englishToLisp_multi_debug; |
2 | sbool englishToLisp_multi_left = true; |
3 | |
4 | static new ThreadLocal<Int> englishToLisp_multi_level; |
5 | |
6 | static L<Lisp> englishToLisp_multi(S s) { |
7 | ret englishToLisp_multi(s, null); |
8 | } |
9 | |
10 | static L<Lisp> englishToLisp_multi(S s, O preprocess) { |
11 | new L<Lisp> c; |
12 | englishToLisp_multi(listCollector(c), s, preprocess); |
13 | ret c; |
14 | } |
15 | |
16 | static void englishToLisp_multi(Collector<Lisp> out, S s, O preprocess) { |
17 | assertNotNull("Input", s); |
18 | /*int level = englishToLisp_multi_level.get(); |
19 | if (level >= englishToLisp_multi_maxLevel) fail("max level"); |
20 | englishToLisp_multi_level.set(level+1); |
21 | try {*/ |
22 | s = postProcess(preprocess, s); |
23 | |
24 | // pattern matching all concepts against full string |
25 | for (AIConcept c : englishToConceptLanguage_concepts()) { |
26 | if (empty(c.name)) { |
27 | print("Warning, empty name: " + c.globalID); |
28 | continue; |
29 | } |
30 | S name = postProcess(preprocess, c.name); |
31 | englishToLisp_multi_with(out, c.globalID, name, s); |
32 | if (out.full()) ret; |
33 | } |
34 | |
35 | // no full string match. go word by word |
36 | /* |
37 | L<S> tok = javaTok(s); |
38 | if (l(tok) <= 3) ret; |
39 | for (int i = 1; i < l(tok); i += 2) { |
40 | S x = englishToLisp(unquote(tok.get(i))); |
41 | if (nempty(x)) tok.set(i, conceptQuote(x)); |
42 | } |
43 | S x = join(tok); |
44 | if (neq(x, s)) out.add(x); |
45 | */ |
46 | } |
47 | |
48 | static void englishToLisp_multi_with(Collector<Lisp> out, S id, S name, S s) { |
49 | new Matches m; |
50 | L<S> originalTok = javaTok(name), tok = cloneList(originalTok); |
51 | if (l(tok) < 5) ret; // need 2 code tokens |
52 | /*if (englishToLisp_multi_debug) |
53 | print("xyz name " + name + " originalTok1 " + struct(originalTok));*/ |
54 | bool stars = tok.contains("*"); |
55 | if (stars) |
56 | tok = replace(tok, "*", "**"); |
57 | /*if (englishToLisp_multi_debug) |
58 | print("xyz name " + name + " originalTok2 " + struct(originalTok));*/ |
59 | int n = numberOfXYZVars(tok); |
60 | if (n == 0) ret; |
61 | tok = formatXYZ(tok, rep(n, "*")); |
62 | L<S> toks = javaTok_cached(s); |
63 | if (stars) |
64 | toks = replace(cloneList(toks), "*", "**"); |
65 | bool yes = englishToLisp_multi_left |
66 | ? flexMatchIC2_left(tok, toks, m, false) |
67 | : flexMatchIC2(tok, toks, m, false); |
68 | if (englishToLisp_multi_debug && yes) |
69 | print("xyz: " + n + " " + struct(tok) + " - " + struct(toks) + " => " + (yes ? struct(m) : "-")); |
70 | if (!yes) ret; |
71 | if (n != l(m.m)) ret; |
72 | new TreeMap<Int, S> map; |
73 | if (englishToLisp_multi_debug) |
74 | print("xyz originalTok " + struct(originalTok)); |
75 | for (int i = 1; i < l(originalTok); i += 2) { |
76 | S t = originalTok.get(i); |
77 | int x = xyzVarToIndex(t); |
78 | if (englishToLisp_multi_debug) |
79 | print("xyz " + t + " => " + x); |
80 | if (x != 0) { |
81 | //S sub = english+ToConceptLanguage_multi_sub(name, s, m.m[x-1]); |
82 | S sub = m.m[x-1]; |
83 | map.put(i, sub); |
84 | } |
85 | } |
86 | out.add(aiUsing(lisp(id, values(map)))); |
87 | } |
Began life as a copy of #1007966
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: | #1007969 |
Snippet name: | englishToLisp_multi [multiple outs, old] |
Eternal ID of this version: | #1007969/9 |
Text MD5: | 7cc6c07989e5e5ea84e29a69a8a8bd5c |
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-18 03:15:23 |
Source code size: | 2861 bytes / 87 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 492 / 486 |
Version history: | 8 change(s) |
Referenced in: | [show references] |