1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package test.wsmo4j.validator;
19
20 import java.util.List;
21 import java.util.Vector;
22
23 import org.deri.wsmo4j.validator.WsmlValidatorImpl;
24 import org.omwg.logicalexpression.LogicalExpression;
25 import org.wsmo.common.WSML;
26 import org.wsmo.validator.ValidationError;
27 import org.wsmo.validator.ValidationWarning;
28 import org.wsmo.validator.WsmlValidator;
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class ValidateLogicalExpressionTests extends ValidatorTestCase {
43
44 LogicalExpression logExpr = null;
45
46 List <ValidationError> errors = new Vector <ValidationError> ();
47
48 List <ValidationWarning> warnings = new Vector <ValidationWarning> ();
49
50 WsmlValidator validator = new WsmlValidatorImpl();
51
52 public void testValidCoreLogExpr() throws Exception {
53 logExpr = leFactory.createLogicalExpression(
54 "?x[_\"http://ex.org#ageOfHuman\" hasValue ?y] impliedBy " +
55 "?x[_\"http://ex.org#ageOfHuman\" hasValue ?z] and " +
56 "?z[_\"http://ex.org#ageOfHuman\" hasValue ?y].");
57 boolean valid = validator.isValid(logExpr, WSML.WSML_CORE, errors, warnings);
58 printError(errors);
59 assertTrue(valid);
60 }
61
62 public void testInValidCoreLogExpr() throws Exception {
63 logExpr = leFactory.createLogicalExpression(
64 "_\"http://ex.org#Man\" subConceptOf _integer.");
65 boolean valid = validator.isValid(logExpr, WSML.WSML_CORE, errors, warnings);
66 assertFalse(valid);
67 }
68
69 public void testValidDLLogExpr() throws Exception {
70 logExpr = leFactory.createLogicalExpression(
71 "?x memberOf _\"http://ex.org#BigDogOwner\" implies " +
72 "((?x memberOf _\"http://ex.org#Human\") and (forall ?y " +
73 "(?x[_\"http://ex.org#hasDog\" hasValue ?y] implies " +
74 "(?y memberOf _\"http://ex.org#BigDog\")))).");
75 boolean valid = validator.isValid(logExpr, WSML.WSML_DL, errors, warnings);
76 assertTrue(valid);
77 }
78
79 public void testInValidDLLogExpr1() throws Exception {
80 logExpr = leFactory.createLogicalExpression(
81 "?x memberOf A implies (?x[from hasValue ?from] " +
82 "implies ?from memberOf PlaceInInnsbruck).", ontology);
83 boolean valid = validator.isValid(logExpr, WSML.WSML_DL, errors, warnings);
84 assertFalse(valid);
85 }
86
87 public void testInValidDLLogExpr2() throws Exception {
88 logExpr = leFactory.createLogicalExpression(
89 "?x memberOf _\"http://ex.org#BigDogOwner\" and " +
90 "?x memberOf _\"http://ex.org#SmallDogOwner\".");
91 boolean valid = validator.isValid(logExpr, WSML.WSML_DL, errors, warnings);
92 assertFalse(valid);
93 }
94
95 public void testValidFlightLogExpr() throws Exception {
96 logExpr = leFactory.createLogicalExpression(
97 "_\"http://ex.org#p\"(?x) equivalent _\"http://ex.org#p\"(?x) " +
98 ":- _\"http://ex.org#p\"(?x).");
99 boolean valid = validator.isValid(logExpr, WSML.WSML_FLIGHT, errors, warnings);
100 assertTrue(valid);
101 }
102
103 public void testInValidFlightLogExpr() throws Exception {
104 logExpr = leFactory.createLogicalExpression(
105 "_\"http://ex.org#a\"[_\"http://ex.org#b\" hasValue ?x] :- ?x > 25.");
106 boolean valid = validator.isValid(logExpr, WSML.WSML_FLIGHT, errors, warnings);
107 assertFalse(valid);
108 }
109
110 public void testValidRuleLogExpr() throws Exception {
111 logExpr = leFactory.createLogicalExpression(
112 "?x[_\"http://ex.org#isAlive\" hasValue _boolean(\"false\")] " +
113 "impliedBy ?x[_\"http://ex.org#hasObit\" hasValue ?obit] " +
114 "memberOf _\"http://ex.org#Human\".");
115 boolean valid = validator.isValid(logExpr, WSML.WSML_RULE, errors, warnings);
116 assertTrue(valid);
117 }
118
119 public void testInValidRuleLogExpr() throws Exception {
120 logExpr = leFactory.createLogicalExpression(
121 "?x[_\"http://ex.org#isAlive\" hasValue _boolean(\"true\")] " +
122 ":- ?x memberOf _\"http://ex.org#Human\" and neg " +
123 "?x[_\"http://ex.org#hasObit\" hasValue ?obit].");
124 boolean valid = validator.isValid(logExpr, WSML.WSML_RULE, errors, warnings);
125 assertFalse(valid);
126 }
127
128 public void testDetermineCoreVariantOfLogExpr() throws Exception {
129 logExpr = leFactory.createLogicalExpression(
130 "?x[_\"http://ex.org#hasHolder\" hasValue ?y] implies " +
131 "?y[_\"http://ex.org#hasPet\" hasValue ?x].");
132 String variant = validator.determineVariant(logExpr, errors, warnings);
133 assertEquals(variant, WSML.WSML_CORE);
134 }
135
136 public void testDetermineFlightVariantOfLogExpr() throws Exception {
137 logExpr = leFactory.createLogicalExpression(
138 "?x[_\"http://ex.org#isAlive\" hasValue _boolean(\"true\")] " +
139 ":- ?x memberOf _\"http://ex.org#Human\" and naf " +
140 "?x[_\"http://ex.org#hasObit\" hasValue ?obit].");
141 String variant = validator.determineVariant(logExpr, errors, warnings);
142 assertEquals(variant, WSML.WSML_FLIGHT);
143 }
144
145 }
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161