1   /*
2   wsmo4j - a WSMO API and Reference Implementation
3   
4   Copyright (c) 2005, University of Innsbruck, Austria
5   
6   This library is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the Free
8   Software Foundation; either version 2.1 of the License, or (at your option)
9   any later version.
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13  details.
14  You should have received a copy of the GNU Lesser General Public License along
15  with this library; if not, write to the Free Software Foundation, Inc.,
16  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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   * Checks if logical expressions are validated correctly. 
32   * 
33   * <pre>
34   * Created on Sep 19, 2006
35   * Committed by $Author: morcen $
36   * $Source$,
37   * </pre>
38   * 
39   * @author nathalie.steinmetz@deri.org
40   * @version $Revision: 1946 $ $Date: 2007-04-02 15:13:28 +0300 (Mon, 02 Apr 2007) $
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  * $Log$
148  * Revision 1.4  2007/04/02 12:13:22  morcen
149  * Generics support added to wsmo-api, wsmo4j and wsmo-test
150  *
151  * Revision 1.3  2006/10/13 17:27:14  nathaliest
152  * fixed bug in wsml-dl validation
153  *
154  * Revision 1.2  2006/09/20 09:22:55  nathaliest
155  * *** empty log message ***
156  *
157  * Revision 1.1  2006/09/20 09:13:33  nathaliest
158  * added tests for logical expression validation
159  *
160  * 
161  */