Warning: session_start(): open(/var/lib/php/sessions/sess_cjgqpcabpjt7o75ks9qq755elg, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!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> vars = );
matchImpl(pattern, vars, 0, input, 0);
}
static void matchImpl(S pattern, Map> vars,
int iPattern, S input, int iInput, Map 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 singleCharacterVars(S s) {
L tok = nlTok(s);
int pos = 0;
new MultiMap 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;
}