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).

1  
!759
2  
3  
p {
4  
  L<S> log = scanEventLogForText("#1004032", "wallpaper");
5  
  psl(log);
6  
  genLog_set(log);
7  
  
8  
  for (Matches m : gJMatch("if * and * then *")) {
9  
    //print("if then: " + struct(m));
10  
    Iterator<SS> sat = satisfyStatements(ll(m.unq(0), m.unq(1)));
11  
    while (sat.hasNext())
12  
      print("Inferred statement: " + replaceVars(m.unq(2), sat.next()));
13  
  }
14  
}
15  
16  
// null = no satisfaction
17  
// otherwise return var map
18  
static Iterator<SS> satisfyStatements(L<S> statements) {
19  
  if (l(statements) == 1)
20  
    ret satisfyStatement(first(statements));
21  
  
22  
  if (l(statements) == 2) {
23  
    new L<SS> l;
24  
    for (SS map : satisfyStatement(first(statements)))
25  
      for (SS map2 : satisfyStatement(get(statements, 1)))
26  
        addIfNotEmpty(l, mergeMappings(map, map2));
27  
    ret l.iterator();
28  
  }
29  
      
30  
  fail("too complicated for now :)");
31  
}
32  
33  
static IterableIterator<SS> satisfyStatement(S statement) {
34  
  final new L<S> vars;
35  
  S pat = upperCaseVarsToStars(statement, vars);
36  
  ret mapI(func(Matches m) {
37  
    new SS map;
38  
    for (int i = 0; i < l(m.m); i++)
39  
      map.put(vars.get(i), m.unq(i));
40  
    ret map;
41  
  }, gJMatch(pat));
42  
}

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: 714 / 948
Referenced in: [show references]