Libraryless. Click here for Pure Java version (3496L/24K/77K).
1 | !7 |
2 | |
3 | sS text1 = [[ |
4 | Player A rolled a 5. |
5 | The second player rolled a 3. |
6 | Player A won. |
7 | The second player cried a lot. |
8 | ]]; |
9 | |
10 | static L<Pair<S>> actions1 = ll( |
11 | pair("Player A", "rolled a 5"), |
12 | pair("The second player", "rolled a 3"), |
13 | pair("Player A", "won"), |
14 | pair("The second player", "cried a lot")); |
15 | |
16 | p { |
17 | L<Pair<S>> actions = ai_findActionsInText(text1); |
18 | print("Actions found:\n" + indentx(structureLines(actions))); |
19 | assertContainsAll(actions, actions1); |
20 | print("Yo!"); |
21 | } |
22 | |
23 | static L<Pair<S>> ai_findActionsInText(S text) { |
24 | L<S> sentences = map(f dropPunctuationAtEnd, splitIntoSentences_v3(text)); |
25 | new L<Pair<S>> actions; |
26 | new Matches m; |
27 | Set<S> verbs = knownVerbs(); |
28 | for (S s : sentences) { |
29 | L<S> tok = javaTok(s); |
30 | int i = indexOfAny(allToLower(tok), verbs); |
31 | if (i >= 0) |
32 | actions.add(pair(trimJoinSubList(tok, 0, i), trimJoinSubList(tok, i))); |
33 | } |
34 | ret actions; |
35 | } |
Began life as a copy of #1009501
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: | #1009503 |
Snippet name: | Find actions in text [OK] |
Eternal ID of this version: | #1009503/7 |
Text MD5: | 36d6d49596b790557fce98b61c142c65 |
Transpilation MD5: | 6e41664e3e481e0698f44d210390fbf2 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-08-05 02:48:33 |
Source code size: | 930 bytes / 35 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 520 / 673 |
Version history: | 6 change(s) |
Referenced in: | [show references] |