Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

74
LINES

## < > BotCompanyRepo | #1001694 - Points (developing)

### JavaX source code [tags: use-pretranspiled] - run with: x30.jar

```!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<S, O> 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<S, O> concepts = litmap("point", Point.class);

p {
for (S line : toLinesFullTrim(input))
}

L<S> 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<S, O> 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<S> tok) {
for (int i = 1; i < l(tok); )
if (equalsIgnoreCase(tok.get(i), "usually")) {
removeToken(tok, i);
} else
i += 2;
}
}```

#### Author comment

`Began life as a copy of #1001685`

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz