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

44
LINES

< > BotCompany Repo | #1017290 // Match Input With Pattern v5 (works with "is your father your mother")

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (18525L/132K).

!7

sclass MatchInput > DynPrintLogWithInput {
  start { dm_useLocallyCopiedMechLists(); }
  
  void update(S s) {
    print("\n> " + s);
    L<S> tokInput = printStruct(javaTokWithAngleBracketsC(s));
    PlanInMotion<S> plan = new(mech_englishSentencePatterns());
    L<Pair<S, L<PairS>>> results = new L; // pattern + match
    
    // Try matching pattern & input word-by-word
    for (S pat : plan.master())
      ai_matchAngleBracketPattern_toResults(pat, tokInput, results);
      
    // Try expanding patterns
    for (S pat : mech_englishSentencePatterns()) {
      LS tokPat = javaTokWithAngleBracketsC(pat);
      for (LS spreadInput : ai_spreadAllAngleVars(tokPat, tokInput))
        ai_matchAngleBracketPattern_toResults(pat, spreadInput, results);
    }

    // Go through sorted results, try to solve assumptions
    for (Pair<S, L<PairS>> p : sortedByLengthOfPairBList(results)) {
      new L<PairS> verified;
      for (PairS assumption : p.b) {
        S category = assumption.a, phrase = assumption.b;
        if (eq(category, "<noun>"))
          for (S pat : mL("Noun phrase patterns")) {
            LPairS match = ai_matchAngleBracketPattern(javaTokWithAngleBracketsC(pat), javaTokWithAngleBracketsC(phrase));
            if (match != null && empty(match)) {
              print("Verified: " + assumption);
              verified.add(assumption);
            }
          }
      }
      if (nempty(verified))
        addPair(results, p.a, listMinusList(p.b, verified));
    }

    for (Pair<S, L<PairS>> p : sortedByLengthOfPairBList(results))
      print("  [" + l(p.b) + "] " + ai_renderMatchWithQuestionMarks(p.b) + " | pattern " + quote(p.a) + " for input "  + quote(s));
  }
}

Author comment

Began life as a copy of #1017207

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1017290
Snippet name: Match Input With Pattern v5 (works with "is your father your mother")
Eternal ID of this version: #1017290/9
Text MD5: 733ebc0fe2791cd4d5f23f8a202068da
Transpilation MD5: c94da27c916321541310b5a9e44df2c0
Author: stefan
Category: javax / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-16 14:54:43
Source code size: 1747 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 434 / 576
Version history: 8 change(s)
Referenced in: #1017297 - Match Input With Pattern v6 (with ParseResult1, OK)