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

22
LINES

< > BotCompany Repo | #1018134 // ai_findInfixPhrases - O(nWords^2)

JavaX fragment (include)

sbool ai_findInfixPhrases_debug;

static ItIt<T3<S>> ai_findInfixPhrases(S s, Collection<S> phrases) {
  final Set<S> set = asCISet(phrases);
  L<S> tok = javaTokNPunctuation(s);
  ret notNulls_iterator(
    // first, split on the left
    nestedIterator(allTokSplits_nOnRight_iterator(tok),
      func(final Pair<LS> p) -> ItIt<T3<S>> {
        // now split the right part
        if (ai_findInfixPhrases_debug)
          print("Looking at " + join(p.b));
        L<S> tok2 = javaTokNPunctuation(join(p.b));
        ret mapI(allTokSplits_nOnLeft_iterator(tok2),
          func(Pair<LS> p2) -> T3<S> {
            if (ai_findInfixPhrases_debug)
              print("  Looking at " + p2.a);
            ret set.contains(trimJoin(simpleSpaces(p2.a)))
              ? t3(join(p.a), join(p2.a), join(p2.b)) : null;
          });
      }));
}

Author comment

Began life as a copy of #1018126

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1018134
Snippet name: ai_findInfixPhrases - O(nWords^2)
Eternal ID of this version: #1018134/5
Text MD5: 93a0e1f8c7940351bbc99505229a0914
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-02 17:33:17
Source code size: 858 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 334 / 371
Version history: 4 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)