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

59
LINES

< > BotCompany Repo | #1002366 // Arnold Logic Test (works)

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

Transpiled version (928L) is out of date.

!752

static L<S> statements = toLinesFullTrim([[
  "arnold" is a "good guy".
  a "good guy" is not a "bad guy".
  a "bad guy" is not a "good guy".
]]);

p {
  checkIs("arnold", "good guy");
  checkIs("arnold", "bad guy");
}

static void checkIs(S a, S b) {
  printF("Checking if * is a *", a, b);
  pcall {
    S answer = checkIs_impl(a, b);
    print("  " + answer);
  }
}

static S checkIs_impl(S a, S b) {
  // find direct statements
  
  L<Matches> l = findStatements(format("* is a *", a, b));
  if (nempty(l))
    ret "yes";
  
  l = findStatements(format("* is not a *", a, b));
  if (nempty(l))
    ret "no";
    
  // derived stuff (find all classes of a)
  l = findStatements(quote(a) + "is a *");
  new TreeSet<S> classes;
  for (Matches m : l)
    classes.add(m.unq(0));

  print("Classes found: " + structure(classes));
  for (S c : classes) {
    if (nempty(findStatements(format("a * is a *", c, b))))
      ret "yes";
      
    if (nempty(findStatements(format("a * is not a *", c, b))))
      ret "no";
  }

  ret "unknown";
}

static L<Matches> findStatements(S pat) {
  new L<Matches> l;
  for (S s : statements) {
    new Matches m;
    if (match(pat, s, m)) // todo: match quoted and identifier (arnold vs "arnold")
      l.add(m);
  }
  ret l;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002366
Snippet name: Arnold Logic Test (works)
Eternal ID of this version: #1002366/1
Text MD5: e8c918478f4cc7fefacfc764d260a39b
Author: stefan
Category: eleu
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-01-09 21:21:47
Source code size: 1327 bytes / 59 lines
Pitched / IR pitched: No / No
Views / Downloads: 583 / 621
Referenced in: [show references]