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

52
LINES

< > BotCompany Repo | #1001841 // SPO (developing)

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

Libraryless. Click here for Pure Java version (852L/6K/19K).

1  
!752
2  
3  
m {
4  
  // subject, predicate, object
5  
  static class SPO {
6  
    S s, p, o;
7  
    int value; // 1 = asserted as true, -1 = asserted as false
8  
  
9  
    *(S *s, S *p, S *o, int *value) {}
10  
    *(S *s, S *p, S *o) {}
11  
    *() {}
12  
    
13  
    public boolean equals(O _o) {
14  
      if (!(_o instanceof SPO)) ret false;
15  
      SPO x = cast _o;
16  
      ret eq(s, x.s) && eq(p, x.p) && eq(o, x.o);
17  
    }
18  
  }
19  
  
20  
  static new L<SPO> data;
21  
  
22  
  static void store(S s, S p, S o, int value) {
23  
    data.add(new SPO(s, p, o, value));
24  
  }
25  
  
26  
  static int query(S s, S p, S o) {
27  
    int i = data.indexOf(new SPO(s, p, o));
28  
    ret i >= 0 ? data.get(i).value : 0;
29  
  }
30  
  
31  
  static S answer(S s) {
32  
    new Matches m;
33  
    if (match("query * * *", s, m))
34  
      ret string(query(m.unq(0), m.unq(1), m.unq(2)));
35  
    if (match("assert * * *", s, m)) {
36  
      store(m.unq(0), m.unq(1), m.unq(2), 1);
37  
      ret "OK.";
38  
    }
39  
    if (match("assertnot * * *", s, m)) {
40  
      store(m.unq(0), m.unq(1), m.unq(2), -1);
41  
      ret "OK.";
42  
    }
43  
    ret null;
44  
  }
45  
  
46  
  p {
47  
    store("2000", "is a", "year", 1);
48  
    assertEq("2000", 1, query("2000", "is a", "year"));
49  
    assertEq("2004", 0, query("2004", "is a", "year"));
50  
    print("OK!");
51  
  }
52  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001841
Snippet name: SPO (developing)
Eternal ID of this version: #1001841/1
Text MD5: e653a9b5cf13e63e6e756fb049b16b49
Transpilation MD5: ebe44a3dc7d396994ec40fe8dd7a7430
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-11-24 21:15:43
Source code size: 1245 bytes / 52 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 642 / 929
Referenced in: [show references]