1 | bool smartParser1_verbose; |
2 | |
3 | void smartParser1(S program) {
|
4 | // split into paragraphs and unindent |
5 | |
6 | LS paragraphs = map(s -> withoutLeadingLinesEmptyAfterTrim_autoUnindent(rtrim(s)), tok_splitAtEmptyLines(program)); |
7 | if (smartParser1_verbose) print("Got " + n2(paragraphs, "parapraph"));
|
8 | |
9 | // print the parapraphs |
10 | if (smartParser1_verbose) print(joinWithEmptyLines(map(s -> indentx("> ", s), paragraphs)));
|
11 | |
12 | // throw away comment-only and quoted paragraphs (assume it's a title) |
13 | LS paragraphs2 = antiFilter(paragraphs, s -> |
14 | isSingleLine(trim(s)) && isQuoted(trim(s)) || countJavaTokens(s) == 0 |
15 | || endsWith(rtrim(s), "----")); |
16 | if (smartParser1_verbose) print("Got " + n2(paragraphs2, "filtered paragraph"));
|
17 | if (smartParser1_verbose) print(joinWithEmptyLines(map(s -> indentx("> ", s), paragraphs2)));
|
18 | |
19 | // find fact paragraphs |
20 | |
21 | if (smartParser1_verbose) print(map allLinesAreUnindented(paragraphs2)); |
22 | Pair<LS> p1 = filterAntiFilter(s -> |
23 | !isSingleLine(trim(s)) && allLinesAreUnindented(s), paragraphs2); |
24 | LS multiFactParagraphs = p1.a, paragraphs3 = p1.b; |
25 | |
26 | for (S para : multiFactParagraphs) |
27 | for (S s : tlft(para)) |
28 | addFactFromProgram(s); |
29 | |
30 | // find logic rules |
31 | |
32 | new LS paragraphs4; |
33 | for (S para : paragraphs3) {
|
34 | PairS p = splitAtFirstDoubleArrow(javaTokWithBrackets(para)); |
35 | if (p == null) continue with paragraphs4.add(para); |
36 | addLogicRule(new LogicRule(splitAtAmpersand2(p.a), p.b), para); |
37 | } |
38 | |
39 | if (smartParser1_verbose) pnlStruct("Unparsed - assuming facts", paragraphs4);
|
40 | |
41 | // assume the unparsed stuff consists of facts |
42 | for (S para : paragraphs4) |
43 | addFactFromProgram(para); |
44 | } |
download show line numbers debug dex old transpilations
Travelled to 10 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1025615 |
| Snippet name: | smartParser1 [Include] |
| Eternal ID of this version: | #1025615/11 |
| Text MD5: | 43e575a62dec9c59e45537f66b888139 |
| Author: | stefan |
| Category: | javax / a.i. |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-02-24 21:23:06 |
| Source code size: | 1690 bytes / 44 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 503 / 1624 |
| Version history: | 10 change(s) |
| Referenced in: | [show references] |