!747 !multi-line strings m { static S input = [[ // Dogmas A point consists of a number "x" and number "y". These numbers are independent. A number might be a float. // Questions What are x and y of the point "1,2"? ]]; !include #2000515 // unquote !include #1000709 // formatSnippetID static class Point { static Map parse(S s) { new Matches m; if (match3("*,*", s, m)) ret litmap("x", parseDouble(m.unq(0)), "y", parseDouble(m.unq(1))); ret null; } } static Map concepts = litmap("point", Point.class); p { for (S line : toLinesFullTrim(input)) print(answer(line)); } static S answer(S line) { L tok = nlTok(line); if (l(tok) == 1) ret "..."; simplify(tok); S s = join(tok); print(" " + s); new Matches m; // Dogmas - We just ignore them this time // Questions if (match3("What are the * and * of the * *?", s, m) || match3("What are * and * of the * *?", s, m)) { S component1 = simplifyName(m.unq(0)); S component2 = simplifyName(m.unq(1)); S name = simplifyName(m.unq(2)); S pattern = m.unq(3); O concept = concepts.get(name); Map instance = (Map) call(concept, "parse", pattern); ret structure(instance); // TODO: filter for components } ret "huh?"; } static S simplifyName(S s) { ret join(" ", codeTokensOnly(tokensToLowerCase(nlTok(s)))); } static void simplify(L tok) { for (int i = 1; i < l(tok); ) if (equalsIgnoreCase(tok.get(i), "usually")) { removeToken(tok, i); } else i += 2; } }