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

42
LINES

< > BotCompany Repo | #1004284 // Simple Logic

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

Libraryless. Click here for Pure Java version (2402L/16K/54K).

!759

p {
  L<S> log = scanEventLogForText("#1004032", "wallpaper");
  psl(log);
  genLog_set(log);
  
  for (Matches m : gJMatch("if * and * then *")) {
    //print("if then: " + struct(m));
    Iterator<SS> sat = satisfyStatements(ll(m.unq(0), m.unq(1)));
    while (sat.hasNext())
      print("Inferred statement: " + replaceVars(m.unq(2), sat.next()));
  }
}

// null = no satisfaction
// otherwise return var map
static Iterator<SS> satisfyStatements(L<S> statements) {
  if (l(statements) == 1)
    ret satisfyStatement(first(statements));
  
  if (l(statements) == 2) {
    new L<SS> l;
    for (SS map : satisfyStatement(first(statements)))
      for (SS map2 : satisfyStatement(get(statements, 1)))
        addIfNotEmpty(l, mergeMappings(map, map2));
    ret l.iterator();
  }
      
  fail("too complicated for now :)");
}

static IterableIterator<SS> satisfyStatement(S statement) {
  final new L<S> vars;
  S pat = upperCaseVarsToStars(statement, vars);
  ret mapI(func(Matches m) {
    new SS map;
    for (int i = 0; i < l(m.m); i++)
      map.put(vars.get(i), m.unq(i));
    ret map;
  }, gJMatch(pat));
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1004284
Snippet name: Simple Logic
Eternal ID of this version: #1004284/1
Text MD5: ad64f00936e33feb3d951e3597ee7a48
Transpilation MD5: dfd4002bf46cc049f897110b43341425
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-13 00:47:17
Source code size: 1163 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 771 / 1022
Referenced in: [show references]