-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClause.java
More file actions
62 lines (51 loc) · 1.38 KB
/
Copy pathClause.java
File metadata and controls
62 lines (51 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.*;
//import java.io.*;
public class Clause {
Vector ruleRefs ;
RuleVariable lhs ;
String rhs ;
Condition cond ;
Boolean consequent ; // true or false
Boolean truth; // states = null(unknown), true or false
Clause(RuleVariable Lhs, Condition Cond, String Rhs) {
lhs = Lhs ; cond = Cond ; rhs = Rhs ;
lhs.addClauseRef(this) ;
ruleRefs = new Vector() ;
truth = null ;
consequent = new Boolean(false) ;
}
void addRuleRef(Rule ref) {
ruleRefs.addElement(ref) ;
}
Boolean check() {
if (consequent.booleanValue() == true)
return null ;
if (lhs.value == null)
return truth = null ; // Var value is undefined
else
switch(cond.index) {
case 1:
truth = new Boolean(lhs.value.equals(rhs)) ;
break ;
case 2:
truth = new Boolean(lhs.value.compareTo(rhs) > 0) ;
break ;
case 3:
truth = new Boolean(lhs.value.compareTo(rhs) < 0) ;
break ;
case 4:
truth = new Boolean(lhs.value.compareTo(rhs) != 0) ;
break ;
}
return truth ;
}
void isConsequent() {
consequent = new Boolean(true);
}
Rule getRule() {
if (consequent.booleanValue() == true)
return (Rule)ruleRefs.firstElement() ;
else
return null ;
}
};