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

86
LINES

< > BotCompany Repo | #1002372 // New Parser Bot (parse/jparse)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (2977L/20K/64K).

!759

static Class parser;

static S javaRulesID = "#1002329";

p {
  print("parser bot loading");
  parser = hotwire_overBot("#1002472");
  print("parser bot loaded");
}

answer {
  if (startsWithIgnoreCase(s, "parse ")) try {
    fillNLParser(parser);
    S text = s.substring(5).trim();
    boolean debug = text.startsWith("debug ");
    if (debug) text = text.substring(5).trim();
    boolean explain = text.startsWith("explain ");
    S explainClass = null;
    if (explain) {
      text = text.substring("explain ".length()).trim();
      int i = text.indexOf(' ');
      explainClass = text.substring(0, i).trim();
      text = text.substring(i).trim();
    }
    
    O result;
    time {
      result = call(parser, "parse", text);
    }
    
    if (debug)
      ret structure(get(parser, "recog"));
    else if (explain)
      ret structure(call(result, "explain", explainClass));
    else {
      L<S> classes = cast call(result, "fullMatchClasses");
      ret (empty(classes) ? "not parsed" : "parsed as " + structure(classes)) + " [" + getLastTiming() + " ms, " + getOpt(parser, "timing") + " ms actual]";
    }
  } catch (Throwable e) {
    ret exceptionToUser(e);
  }
  
  if (startsWithIgnoreCase(s, "jparse ")) try {
    S text = s.substring(6).trim();
    
    // make a separate parser for Java
    O parser = hotwire_overBot("#1002472");
   
    boolean debug = text.startsWith("debug ");
    if (debug) text = text.substring(5).trim();
    boolean explain = text.startsWith("explain ");
    S explainClass = null;
    if (explain) {
      text = text.substring("explain ".length()).trim();
      int i = text.indexOf(' ');
      explainClass = text.substring(0, i).trim();
      text = text.substring(i).trim();
    }
    
    O result;
    time {
      result = call(parser, "parse", text, javaRulesID);
    }
    
    if (debug)
      ret "```" + call(result, "prettierAnalysis") + "```";
    else if (explain)
      ret structure(call(result, "explain", explainClass));
    else {
      L<S> classes = cast call(result, "fullMatchClasses");
      ret (empty(classes) ? "not parsed" : "parsed as " + structure(classes)) + " [" + getLastTiming() + " ms, " + getOpt(parser, "timing") + " ms actual]";
    }
  } catch (Throwable e) {
    ret exceptionToUser(e);
  }
}

static void fillNLParser(O parser) {
  callOpt(parser, "addDict", "adjective", makeEleuSet("adjective"));

  O bot = getBot("#1002342"); // nouns bot
  if (bot != null)
    callOpt(parser, "addDict", "noun", get(bot, "nouns"));
}

Author comment

Began life as a copy of #1002308

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002372
Snippet name: New Parser Bot (parse/jparse)
Eternal ID of this version: #1002372/1
Text MD5: 61300e08f4333bc3f99089d5d7fdf44b
Transpilation MD5: 22e34baa7a7e5ac885341764f1a3c3e5
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-01 19:57:32
Source code size: 2604 bytes / 86 lines
Pitched / IR pitched: No / No
Views / Downloads: 680 / 1632
Referenced in: #1002391 - Slack Analyzer (parses slack lines)
#1002475 - Very New Parser Bot
#3000169 - Answer for stefanreich
#3000174 - Answer for stefanreich
#3000175 - Answer for stefanreich
#3000176 - Answer for stefanreich
#3000177 - Answer for stefanreich
#3000179 - Answer for stefanreich
#3000180 - Answer for stefanreich
#3000181 - Answer for stefanreich
#3000182 - Answer for stefanreich
#3000185 - Answer for stefanreich
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000203 - Answer for stefanreich (>> timing hello bot)
#3000208 - Answer for bgrgndz (>> list sub bots)
#3000209 - Answer for bgrgndz (>> list sub bots)
#3000238 - Answer for stefanreich (>> t power bot)
#3000369 - Answer for Stefan (>> list sub bots)
#3000376 - Answer for stefanreich (>> list sub bots)
#3000380 - Answer for stefanreich (>> list sub bots)
#3000381 - Answer for speedforce (>> list sub bots)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)