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

!752

m {
  // subject, predicate, object
  static class SPO {
    S s, p, o;
    int value; // 1 = asserted as true, -1 = asserted as false
  
    *(S *s, S *p, S *o, int *value) {}
    *(S *s, S *p, S *o) {}
    *() {}
    
    public boolean equals(O _o) {
      if (!(_o instanceof SPO)) ret false;
      SPO x = cast _o;
      ret eq(s, x.s) && eq(p, x.p) && eq(o, x.o);
    }
  }
  
  static new L<SPO> data;
  
  static void store(S s, S p, S o, int value) {
    data.add(new SPO(s, p, o, value));
  }
  
  static int query(S s, S p, S o) {
    int i = data.indexOf(new SPO(s, p, o));
    ret i >= 0 ? data.get(i).value : 0;
  }
  
  static S answer(S s) {
    new Matches m;
    if (match("query * * *", s, m))
      ret string(query(m.unq(0), m.unq(1), m.unq(2)));
    if (match("assert * * *", s, m)) {
      store(m.unq(0), m.unq(1), m.unq(2), 1);
      ret "OK.";
    }
    if (match("assertnot * * *", s, m)) {
      store(m.unq(0), m.unq(1), m.unq(2), -1);
      ret "OK.";
    }
    ret null;
  }
  
  p {
    store("2000", "is a", "year", 1);
    assertEq("2000", 1, query("2000", "is a", "year"));
    assertEq("2004", 0, query("2004", "is a", "year"));
    print("OK!");
  }
}

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