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

37
LINES

< > BotCompany Repo | #1017390 // ai_buParser_parseWeightedProductions

JavaX fragment (include)

static L<WeightedProduction> ai_buParser_parseWeightedProductions() {
  ret ai_buParser_parseWeightedProductions(mL_raw(ai_language() + " bottom-up groupings"));
}

static L<WeightedProduction> ai_buParser_parseWeightedProductions(S text) {
  new L<WeightedProduction> l;
  for (S s : tlftj(text)) {
    s = trim(javaDropAllComments(s));
    L<S> meta = trimAll(tok_splitAtComma(trailingAngleBracketStuff(s)));
    s = dropTrailingAngleBracketStuff(s);
    //print("s=" + s +", meta=" + meta);
    L<S> tok = javaTokWithAngleBracketsC(s);
    WeightedProduction p = null;
    double weight = 1.0;
    S f = null;
    for (S met : meta)
      if (startsWithDigit(met))
        weight = parseDouble(met);
      else if (startsWith(met, "ai"))
        f = met;
    if (l(tok) == 5)
      p = WeightedProduction(tok.get(0), tok.get(2), tok.get(4), weight);
    else if (l(tok) == 3)
      p = WeightedProduction(tok.get(0), tok.get(2), weight);
      
    if (p != null) {
      p.plausibilityFunction = f;
      for (S met : meta)
        if (eqOneOf(met, "L", "R", "B")) {
          //print("Have simplification hint: " + met);
          p.simplificationHint = met;
        }
      l.add(p);
    }
  }
  ret l;
}

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: #1017390
Snippet name: ai_buParser_parseWeightedProductions
Eternal ID of this version: #1017390/15
Text MD5: f6d219047ded5700debd0f898bdcd34e
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-08-20 11:59:14
Source code size: 1246 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 447 / 494
Version history: 14 change(s)
Referenced in: [show references]