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.

1  
!752
2  
3  
static S rule = "If A likes B then A will greet B.";
4  
static S ifThenPattern = "If A then B.";
5  
static S fact = "John likes Paul.";
6  
static S toCheck = "John will greet Paul.";
7  
8  
p {
9  
  MultiMap ruleVars = singleCharacterVars(rule);
10  
  assertEquals(2, l(ruleVars.keySet()));
11  
  printStructure(ruleVars);
12  
  match(ifThenPattern, rule);
13  
}
14  
15  
static match(S pattern, S input) {
16  
  MultiMap<Range, ... singleCharacterVars(pattern)
17  
  Map<Int, Pair<O, Range>> vars = );
18  
  matchImpl(pattern, vars, 0, input, 0);
19  
}
20  
21  
static void matchImpl(S pattern, Map<Int, Pair<O, Range>> vars,
22  
  int iPattern, S input, int iInput, Map<O, S> values) {
23  
  if (iPattern >= l(pattern)) {
24  
    print("Match!");
25  
    ret;
26  
  }
27  
  vars
28  
}
29  
30  
// a range of characters in a string
31  
sclass Range {
32  
  int i, j; // i = from, j = to
33  
  
34  
  *() {}
35  
  *(int *i, int *j) {}
36  
}
37  
38  
static MultiMap<O, Range> singleCharacterVars(S s) {
39  
  L<S> tok = nlTok(s);
40  
  int pos = 0;
41  
  new MultiMap<S, Range> vars;
42  
  for i over tok: {
43  
    S t = tok.get(i);
44  
    int nextPos = pos+l(t);
45  
    if (l(t) == 1 && isUpperCaseLetter(t.charAt(0)))
46  
      vars.put(t, new Range(pos, nextPos));
47  
    pos = nextPos;
48  
  }
49  
  ret (MultiMap) vars;
50  
}

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