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

51
LINES

< > BotCompany Repo | #1008579 // Find multi-word verbs in sentence [WORKS]

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

Libraryless. Click here for Pure Java version (3599L/24K/79K).

!7

static L<S> verbs = toLinesFullTrim([[
  kow towed
  made
  started
  want
]]);

static new StringTree1 tree;

p {
  tree = multiWordMap_lower(verbs);
  testAnswerFunction([[
    he kow towed before them
    i want stuff
    kow
    towed
    I WANT YOU
  ]]);
  botSleep();
}

static L<S> parse(S s) {
  ret codeTokens(nlTok4(lower(s)));
}

static StringTree1 multiWordMap_lower(L<S> items) {
  new StringTree1 tree;
  for (S s : items) {
    L<S> tok = parse(s);
    addToStringTree(tree, tok);
  }
  ret tree;
}

sS answer(S s) {
  L<S> tok = parse(s);
  new L<S> verbs;
  for i over tok: {
    StringTree1 tree = main.tree;
    int j = i;
    while (tree != null && j < l(tok)) {
      if (tree.leaf)
        verbs.add(joinWithSpace(subList(tok, i, j)));
      tree = tree.children.get(tok.get(j));
      ++j;
    }
  }
  ret join(", ", verbs);
}

Author comment

Began life as a copy of #1008567

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, nbgitpuheiab, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

-
Snippet ID: #1008579
Snippet name: Find multi-word verbs in sentence [WORKS]
Eternal ID of this version: #1008579/9
Text MD5: 6ebdf78cfd011ef36f00e9c53a67ed86
Transpilation MD5: 7075f63e83b7d3725b251fb4473ac3b2
Author: stefan
Category: javax / a.i.
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-26 19:28:56
Source code size: 904 bytes / 51 lines
Pitched / IR pitched: No / No
Views / Downloads: 425 / 559
Version history: 8 change(s)
Referenced in: