Libraryless. Click here for Pure Java version (3593L/24K/79K).
!7 p { callAnswerFunctionVerbose("tell me what time it is"); callAnswerFunctionVerbose("Can you tell me what time it is?"); botSleep(); } sclass TokConsumer { L<S> l; int i; *(L<S> *l) {} S peek() { ret get(l, i); } S next() { ret get(l, i++); } L<S> remainingTokens() { ret subList(l, i); } } sS answer(S s) { ret group(s); } sS group(S s) { s = groupStep(s); L<S> tok = joinBrackets(javaTok(s)); for (int i = 1; i < l(tok); i += 2) { S t = tok.get(i); if (isRoundBracketed(t)) tok.set(i, "(" + group(dropFirstAndLast(t)) + ")"); } ret join(tok); } sS groupStep(S s) { L<S> tok = codeTokens(dropPunctuation(javaTok(s))); TokConsumer c = new(tok); S verb = consumeVerb(c); if (verb != null) { S noun = consumeNoun(c); if (noun != null) ret group(verb, noun, rest(c)); } ret joinWithSpace(tok); } static Set<S> verbs = asSet(splitAtSpace("can does will tell would were do")); static Set<S> nouns = asSet(splitAtSpace("i you he she it we someone me")); static S consumeVerb(TokConsumer c) { ret consumeFromList(verbs, c); } static S consumeNoun(TokConsumer c) { ret consumeFromList(nouns, c); } static S consumeFromList(Set<S> set, TokConsumer c) { if (set.contains(toLower(c.peek()))) ret c.next(); null; } sS group(S... parts) { new L<S> l; for (S part : parts) { L<S> tok = javaTokC(part); if (l(tok) > 1) l.add("(" + joinWithSpace(tok) + ")"); else l.addAll(tok); } ret joinWithSpace(l); } sS rest(TokConsumer c) { ret joinWithSpace(c.remainingTokens()); }
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: | #1008567 |
Snippet name: | Group sentence parts v1 |
Eternal ID of this version: | #1008567/15 |
Text MD5: | 9c7c3895ec48425f1262a282fef224c0 |
Transpilation MD5: | b94c23b1bc35e6e8ac7dbe16e75c4aad |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-05-24 00:00:11 |
Source code size: | 1672 bytes / 79 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 423 / 513 |
Version history: | 14 change(s) |
Referenced in: | [show references] |