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

50
LINES

< > BotCompany Repo | #1005169 // Rule Matching Test [abandoned]

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

Transpiled version (1363L) is out of date.

!752

static S rule = "If A likes B then A will greet B.";
static S ifThenPattern = "If A then B.";
static S fact = "John likes Paul.";
static S toCheck = "John will greet Paul.";

p {
  MultiMap ruleVars = singleCharacterVars(rule);
  assertEquals(2, l(ruleVars.keySet()));
  printStructure(ruleVars);
  match(ifThenPattern, rule);
}

static match(S pattern, S input) {
  MultiMap<Range, ... singleCharacterVars(pattern)
  Map<Int, Pair<O, Range>> vars = );
  matchImpl(pattern, vars, 0, input, 0);
}

static void matchImpl(S pattern, Map<Int, Pair<O, Range>> vars,
  int iPattern, S input, int iInput, Map<O, S> values) {
  if (iPattern >= l(pattern)) {
    print("Match!");
    ret;
  }
  vars
}

// a range of characters in a string
sclass Range {
  int i, j; // i = from, j = to
  
  *() {}
  *(int *i, int *j) {}
}

static MultiMap<O, Range> singleCharacterVars(S s) {
  L<S> tok = nlTok(s);
  int pos = 0;
  new MultiMap<S, Range> vars;
  for i over tok: {
    S t = tok.get(i);
    int nextPos = pos+l(t);
    if (l(t) == 1 && isUpperCaseLetter(t.charAt(0)))
      vars.put(t, new Range(pos, nextPos));
    pos = nextPos;
  }
  ret (MultiMap) vars;
}

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: #1005169
Snippet name: Rule Matching Test [abandoned]
Eternal ID of this version: #1005169/1
Text MD5: 07939e37ac42d20e9af68ee10abbc35e
Author: stefan
Category: javax / a.i.
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-10-18 19:47:29
Source code size: 1207 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 450 / 507
Referenced in: [show references]