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).

1  
!7
2  
3  
sclass MatchInput > DynPrintLogWithInput {
4  
  start { dm_useLocallyCopiedMechLists(); }
5  
  
6  
  void update(S s) {
7  
    print("\n> " + s);
8  
    L<S> tokInput = printStruct(javaTokWithAngleBracketsC(s));
9  
    PlanInMotion<S> plan = new(mech_englishSentencePatterns());
10  
    L<Pair<S, L<PairS>>> results = new L; // pattern + match
11  
    
12  
    // Try matching pattern & input word-by-word
13  
    for (S pat : plan.master())
14  
      ai_matchAngleBracketPattern_toResults(pat, tokInput, results);
15  
      
16  
    // Try expanding patterns
17  
    for (S pat : mech_englishSentencePatterns()) {
18  
      LS tokPat = javaTokWithAngleBracketsC(pat);
19  
      for (LS spreadInput : ai_spreadAllAngleVars(tokPat, tokInput))
20  
        ai_matchAngleBracketPattern_toResults(pat, spreadInput, results);
21  
    }
22  
23  
    // Go through sorted results, try to solve assumptions
24  
    for (Pair<S, L<PairS>> p : sortedByLengthOfPairBList(results)) {
25  
      new L<PairS> verified;
26  
      for (PairS assumption : p.b) {
27  
        S category = assumption.a, phrase = assumption.b;
28  
        if (eq(category, "<noun>"))
29  
          for (S pat : mL("Noun phrase patterns")) {
30  
            LPairS match = ai_matchAngleBracketPattern(javaTokWithAngleBracketsC(pat), javaTokWithAngleBracketsC(phrase));
31  
            if (match != null && empty(match)) {
32  
              print("Verified: " + assumption);
33  
              verified.add(assumption);
34  
            }
35  
          }
36  
      }
37  
      if (nempty(verified))
38  
        addPair(results, p.a, listMinusList(p.b, verified));
39  
    }
40  
41  
    for (Pair<S, L<PairS>> p : sortedByLengthOfPairBList(results))
42  
      print("  [" + l(p.b) + "] " + ai_renderMatchWithQuestionMarks(p.b) + " | pattern " + quote(p.a) + " for input "  + quote(s));
43  
  }
44  
}

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: 435 / 579
Version history: 8 change(s)
Referenced in: [show references]