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)

static L<ParseResult1> ai_parser1(S input, S category) {
  L<S> tokInput = javaTokWithAngleBracketsC(input);
  new L<ParseResult1> results;
  
  // TODO
  // Collection<S> literalExamples = combinedMechSetsCI(ai_mechListNamesForAngleBracketCategory(p));

  Collection<S> patterns = combinedMechSetsCI(ai_mechPatternListNamesForAngleBracketCategory(category));
    
  // Try matching pattern & input word-by-word
  for (S pat : patterns)
    ai_matchAngleBracketPattern_toParseResults(javaTokWithAngleBracketsC_addNumbers(pat), tokInput, results);
    
  // Try expanding patterns
  for (S pat : patterns)
    ai_matchAngleBracketPattern_spread_toParseResults(javaTokWithAngleBracketsC_addNumbers(pat), tokInput, results);

  // Go through sorted results, try to solve assumptions using subsolve
  for (ParseResult1 p : parseResultsByNumberOfAssumptions(results)) {
    new L<PairS> verified;
    for (PairS assumption : p.assumptions) {
      S cat = assumption.a, phrase = assumption.b;
      if (eq(cat, "<noun>"))
        for (S pat : mL("Noun phrase patterns")) {
          LPairS match = ai_matchAngleBracketPattern(javaTokWithAngleBracketsC_addNumbers(pat), javaTokWithAngleBracketsC(phrase));
          if (match != null && empty(match)) {
            //print("Verified: " + assumption);
            verified.add(assumption);
          }
        }
    }
    addIfNotNull(results, parseResultWithVerifiedAssumptions(p, verified));
  }

  ret parseResults_setCategory(category, takeFirst(10, parseResultsByNumberOfAssumptions(results)));
}

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: 375 / 419
Version history: 6 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)