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

36
LINES

< > BotCompany Repo | #1017310 // ai_parser1 - top-down parser with assumptions

JavaX fragment (include)

1  
static L<ParseResult1> ai_parser1(S input, S category) {
2  
  L<S> tokInput = javaTokWithAngleBracketsC(input);
3  
  new L<ParseResult1> results;
4  
  
5  
  // TODO
6  
  // Collection<S> literalExamples = combinedMechSetsCI(ai_mechListNamesForAngleBracketCategory(p));
7  
8  
  Collection<S> patterns = combinedMechSetsCI(ai_mechPatternListNamesForAngleBracketCategory(category));
9  
    
10  
  // Try matching pattern & input word-by-word
11  
  for (S pat : patterns)
12  
    ai_matchAngleBracketPattern_toParseResults(javaTokWithAngleBracketsC_addNumbers(pat), tokInput, results);
13  
    
14  
  // Try expanding patterns
15  
  for (S pat : patterns)
16  
    ai_matchAngleBracketPattern_spread_toParseResults(javaTokWithAngleBracketsC_addNumbers(pat), tokInput, results);
17  
18  
  // Go through sorted results, try to solve assumptions using subsolve
19  
  for (ParseResult1 p : parseResultsByNumberOfAssumptions(results)) {
20  
    new L<PairS> verified;
21  
    for (PairS assumption : p.assumptions) {
22  
      S cat = assumption.a, phrase = assumption.b;
23  
      if (eq(cat, "<noun>"))
24  
        for (S pat : mL("Noun phrase patterns")) {
25  
          LPairS match = ai_matchAngleBracketPattern(javaTokWithAngleBracketsC_addNumbers(pat), javaTokWithAngleBracketsC(phrase));
26  
          if (match != null && empty(match)) {
27  
            //print("Verified: " + assumption);
28  
            verified.add(assumption);
29  
          }
30  
        }
31  
    }
32  
    addIfNotNull(results, parseResultWithVerifiedAssumptions(p, verified));
33  
  }
34  
35  
  ret parseResults_setCategory(category, takeFirst(10, parseResultsByNumberOfAssumptions(results)));
36  
}

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: #1017310
Snippet name: ai_parser1 - top-down parser with assumptions
Eternal ID of this version: #1017310/7
Text MD5: a4d59e6b61b02b2b4dba2f26bad89439
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-11 12:52:16
Source code size: 1579 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 376 / 421
Version history: 6 change(s)
Referenced in: [show references]