Transpiled version (928L) is out of date.
1 | !752 |
2 | |
3 | static L<S> statements = toLinesFullTrim([[ |
4 | "arnold" is a "good guy". |
5 | a "good guy" is not a "bad guy". |
6 | a "bad guy" is not a "good guy". |
7 | ]]); |
8 | |
9 | p {
|
10 | checkIs("arnold", "good guy");
|
11 | checkIs("arnold", "bad guy");
|
12 | } |
13 | |
14 | static void checkIs(S a, S b) {
|
15 | printF("Checking if * is a *", a, b);
|
16 | pcall {
|
17 | S answer = checkIs_impl(a, b); |
18 | print(" " + answer);
|
19 | } |
20 | } |
21 | |
22 | static S checkIs_impl(S a, S b) {
|
23 | // find direct statements |
24 | |
25 | L<Matches> l = findStatements(format("* is a *", a, b));
|
26 | if (nempty(l)) |
27 | ret "yes"; |
28 | |
29 | l = findStatements(format("* is not a *", a, b));
|
30 | if (nempty(l)) |
31 | ret "no"; |
32 | |
33 | // derived stuff (find all classes of a) |
34 | l = findStatements(quote(a) + "is a *"); |
35 | new TreeSet<S> classes; |
36 | for (Matches m : l) |
37 | classes.add(m.unq(0)); |
38 | |
39 | print("Classes found: " + structure(classes));
|
40 | for (S c : classes) {
|
41 | if (nempty(findStatements(format("a * is a *", c, b))))
|
42 | ret "yes"; |
43 | |
44 | if (nempty(findStatements(format("a * is not a *", c, b))))
|
45 | ret "no"; |
46 | } |
47 | |
48 | ret "unknown"; |
49 | } |
50 | |
51 | static L<Matches> findStatements(S pat) {
|
52 | new L<Matches> l; |
53 | for (S s : statements) {
|
54 | new Matches m; |
55 | if (match(pat, s, m)) // todo: match quoted and identifier (arnold vs "arnold") |
56 | l.add(m); |
57 | } |
58 | ret l; |
59 | } |
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: | #1002366 |
| Snippet name: | Arnold Logic Test (works) |
| Eternal ID of this version: | #1002366/1 |
| Text MD5: | e8c918478f4cc7fefacfc764d260a39b |
| Author: | stefan |
| Category: | eleu |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-01-09 21:21:47 |
| Source code size: | 1327 bytes / 59 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 936 / 1046 |
| Referenced in: | [show references] |