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

27
LINES

< > BotCompany Repo | #1028865 // ai_pronounResolvedToNLA

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (13119L/91K).

// e.g."if a snippet contains token X, it also contains token Y";
// returns an iterator of NLA blocks (one for each possible mapping)
static ItIt<S> ai_pronounResolvedToNLA(S s) {
  AI_PronounResolver1 resolver = new(s);
  resolver.run();
  print("nounPhrases", resolver.nounPhrases);
  print("pronouns", resolver.pronouns);
  
  // mapping: pronoun -> noun phrase
  ret mapI(resolver.allMappings(), mapping -> {
    L<ParsedWithTokens> pwt = replaceElementsUsingMap(resolver.pwt, (Map) mapping);
    pnl(pwt);
    CountingVarMaker varMaker = new("entity");
    new LS lines;
    new Map<ParsedWithTokens, S> entityNames;
    for (ParsedWithTokens p : values(mapping)) {
      S name = varMaker!;
      entityNames.put(p, name);
      //lines.add("there is " + getVar_rec(p) + " " + name);
      lines.add("there is " + name);
      lines.add(name + " is " + getVar_rec(p));
    }
    S prop = joinMap(pwt, p -> str(or(entityNames.get(p), getVar_rec(p))));
    lines.add(prop);
    ret lines(lines);
  });
}

Author comment

Began life as a copy of #1028862

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028865
Snippet name: ai_pronounResolvedToNLA
Eternal ID of this version: #1028865/10
Text MD5: cc8fde8f7fdf4f26f020877c8c5ade75
Transpilation MD5: 415d1317deabdc00a584d41cefb042ef
Author: stefan
Category: javax / nla
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-10 18:36:23
Source code size: 1034 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 161 / 246
Version history: 9 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1028867 - test_ai_pronounResolvedToNLA