Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/hp/hpl/jena/ontology/impl/test/TestFrameView.java


1   /*****************************************************************************
2    * Source code information
3    * -----------------------
4    * Original author    Ian Dickinson, HP Labs Bristol
5    * Author email       Ian.Dickinson@hp.com
6    * Package            Jena 2
7    * Web                http://sourceforge.net/projects/jena/
8    * Created            04-Apr-2005
9    * Filename           $RCSfile: TestFrameView.java,v $
10   * Revision           $Revision: 1.6 $
11   * Release status     $State: Exp $
12   *
13   * Last modified on   $Date: 2005/04/12 10:57:18 $
14   *               by   $Author: ian_dickinson $
15   *
16   * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17   * (see footer for full conditions)
18   *****************************************************************************/
19  
20  // Package
21  ///////////////
22  package com.hp.hpl.jena.ontology.impl.test;
23  
24  // Imports
25  ///////////////
26  import junit.framework.TestCase;
27  
28  import com.hp.hpl.jena.ontology.*;
29  import com.hp.hpl.jena.rdf.model.*;
30  import com.hp.hpl.jena.reasoner.test.TestUtil;
31  
32  
33  
34  
35  /**
36   * <p>
37   * Unit-tests for frame-like views of OWL and RDFS-classes, especially listDeclaredProperties
38   * </p>
39   *
40   * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
41   * @version Release @release@ ($Id: TestFrameView.java,v 1.6 2005/04/12 10:57:18 ian_dickinson Exp $)
42   */
43  public class TestFrameView
44      extends TestCase
45  {
46      // Constants
47      //////////////////////////////////
48  
49      public static final String BASE = "http://jena.hpl.hp.com/testing/ontology";
50      public static final String NS = BASE + "#";
51  
52      // Static variables
53      //////////////////////////////////
54  
55      // Instance variables
56      //////////////////////////////////
57  
58      OntModel mInf;
59      OntModel mNoInf;
60  
61      OntClass infA;
62      OntClass infB;
63      OntClass infC;
64  
65      OntClass noinfA;
66      OntClass noinfB;
67      OntClass noinfC;
68  
69      ObjectProperty noinfG;
70      ObjectProperty infG;
71  
72      ObjectProperty noinfPa;
73      ObjectProperty noinfPb;
74      ObjectProperty noinfPc;
75  
76      ObjectProperty infPa;
77      ObjectProperty infPb;
78      ObjectProperty infPc;
79  
80      ObjectProperty noinfQa;
81      ObjectProperty noinfQb;
82  
83      ObjectProperty infQa;
84      ObjectProperty infQb;
85  
86      OntClass infAnn;
87      OntClass noinfAnn;
88      AnnotationProperty infPann;
89      AnnotationProperty noinfPann;
90  
91      OntClass infUnion1;
92      OntClass infUnion2;
93      OntClass noinfUnion1;
94      OntClass noinfUnion2;
95      ObjectProperty infPunion;
96      ObjectProperty noinfPunion;
97  
98      OntClass infIntersect1;
99      OntClass infIntersect2;
100     OntClass noinfIntersect1;
101     OntClass noinfIntersect2;
102     ObjectProperty infPintersect;
103     ObjectProperty noinfPintersect;
104 
105     // Constructors
106     //////////////////////////////////
107 
108     // External signature methods
109     //////////////////////////////////
110 
111     public void setUp() {
112         OntDocumentManager.getInstance().reset();
113         OntDocumentManager.getInstance().clearCache();
114         mNoInf = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
115         mNoInf.read( "file:testing/ontology/owl/list-syntax/test-ldp.rdf" );
116         //mInf = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RULE_INF );
117         mInf = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF);
118         mInf.read( "file:testing/ontology/owl/list-syntax/test-ldp.rdf" );
119 
120         infA = mInf.getOntClass( NS + "A" );
121         infB = mInf.getOntClass( NS + "B" );
122         infC = mInf.getOntClass( NS + "C" );
123 
124 
125         noinfA = mNoInf.getOntClass( NS + "A" );
126         noinfB = mNoInf.getOntClass( NS + "B" );
127         noinfC = mNoInf.getOntClass( NS + "C" );
128 
129         noinfG = mNoInf.getObjectProperty( NS + "global" );
130         infG = mInf.getObjectProperty( NS + "global" );
131 
132         noinfPa = mNoInf.getObjectProperty( NS + "pA" );
133         noinfPb = mNoInf.getObjectProperty( NS + "pB" );
134         noinfPc = mNoInf.getObjectProperty( NS + "pC" );
135 
136         infPa = mInf.getObjectProperty( NS + "pA" );
137         infPb = mInf.getObjectProperty( NS + "pB" );
138         infPc = mInf.getObjectProperty( NS + "pC" );
139 
140         noinfQa = mNoInf.getObjectProperty( NS + "qA" );
141         noinfQb = mNoInf.getObjectProperty( NS + "qB" );
142 
143         infQa = mInf.getObjectProperty( NS + "qA" );
144         infQb = mInf.getObjectProperty( NS + "qB" );
145 
146         infAnn = mInf.getOntClass( NS + "HasAnn" );
147         noinfAnn = mNoInf.getOntClass( NS + "HasAnn" );
148         infPann = mInf.getAnnotationProperty( NS + "ann" );
149         noinfPann = mNoInf.getAnnotationProperty( NS + "ann" );
150 
151         infUnion1 = mInf.getOntClass( NS + "Union1" );
152         infUnion2 = mInf.getOntClass( NS + "Union2" );
153         noinfUnion1 = mNoInf.getOntClass( NS + "Union1" );
154         noinfUnion2 = mNoInf.getOntClass( NS + "Union2" );
155         infPunion = mInf.getObjectProperty( NS + "unionP" );
156         noinfPunion = mNoInf.getObjectProperty( NS + "unionP" );
157 
158         infIntersect1 = mInf.getOntClass( NS + "Intersect1" );
159         infIntersect2 = mInf.getOntClass( NS + "Intersect2" );
160         noinfIntersect1 = mNoInf.getOntClass( NS + "Intersect1" );
161         noinfIntersect2 = mNoInf.getOntClass( NS + "Intersect2" );
162         infPintersect = mInf.getObjectProperty( NS + "intersectP" );
163         noinfPintersect = mNoInf.getObjectProperty( NS + "intersectP" );
164     }
165 
166     public void tearDown() {
167         /* assistance with monitoring space leak
168         System.gc();
169         System.gc();
170         Runtime r = Runtime.getRuntime();
171         System.out.println( getName() + 
172                             " memory = " + r.freeMemory() + 
173                             ", alloc = " + r.totalMemory() + 
174                             ", % = " + Math.round( 100.0 * (double) r.freeMemory() / (double) r.totalMemory() ));
175         */
176         mInf.close();
177         mInf = null;
178         mNoInf.close();
179         mNoInf = null;
180     }
181     
182     // OntClass.listDeclaredProperties() tests ...
183 
184     public void testLDP_noinfA_nodirect() {
185         TestUtil.assertIteratorValues( this, noinfA.listDeclaredProperties( false ),
186                                        new Object[] {noinfPa, noinfQa, noinfG, noinfQb} );
187     }
188 
189     public void testHasDP_noinfA_nodirect() {
190         // we only need a small number of tests on hasDP because it's the
191         // main componenet of listDP
192         assertTrue( noinfA.hasDeclaredProperty( noinfPa, false ) );
193         assertFalse( noinfA.hasDeclaredProperty( noinfPb, false ) );
194     }
195 
196     public void testLDP_noinfA_direct() {
197         TestUtil.assertIteratorValues( this, noinfA.listDeclaredProperties( true ),
198                                        new Object[] {noinfPa, noinfQa, noinfG, noinfQb} );
199     }
200 
201     public void testLDP_infA_nodirect() {
202         TestUtil.assertIteratorValues( this, infA.listDeclaredProperties( false ),
203                                        new Object[] {infPa, infQa, infQb, noinfG} );
204     }
205 
206     public void testLDP_infA_direct() {
207         TestUtil.assertIteratorValues( this, infA.listDeclaredProperties( true ),
208                                        new Object[] {infPa, infQa, infQb, noinfG} );
209     }
210 
211     public void testLDP_noinfB_nodirect() {
212         TestUtil.assertIteratorValues( this, noinfB.listDeclaredProperties( false ),
213                                        new Object[] {noinfPa, noinfPb, noinfQa, noinfG, noinfQb} );
214     }
215 
216     public void testLDP_noinfB_direct() {
217         TestUtil.assertIteratorValues( this, noinfB.listDeclaredProperties( true ),
218                                        new Object[] {noinfPb} );
219     }
220 
221     public void testLDP_infB_nodirect() {
222         TestUtil.assertIteratorValues( this, infB.listDeclaredProperties( false ),
223                                        new Object[] {infPa, infPb, infQa, infQb, infG} );
224     }
225 
226     public void testLDP_infB_direct() {
227         TestUtil.assertIteratorValues( this, infB.listDeclaredProperties( true ),
228                                        new Object[] {infPb} );
229     }
230 
231     public void testLDP_noinfC_nodirect() {
232         // note that qB appears in the results because without inference it looks like a global
233         TestUtil.assertIteratorValues( this, noinfC.listDeclaredProperties( false ),
234                                        new Object[] {noinfPa, noinfPb, noinfPc, noinfQa, noinfG, noinfQb} );
235     }
236 
237     public void testLDP_noinfC_direct() {
238         TestUtil.assertIteratorValues( this, noinfC.listDeclaredProperties( true ),
239                                        new Object[] {noinfPc} );
240     }
241 
242     public void testLDP_infC_nodirect() {
243         TestUtil.assertIteratorValues( this, infC.listDeclaredProperties( false ),
244                                        new Object[] {infPa, infPb, infPc, infQa, infQb, infG} );
245     }
246 
247     public void testLDP_infC_direct() {
248         TestUtil.assertIteratorValues( this, infC.listDeclaredProperties( true ),
249                                        new Object[] {infPc} );
250     }
251 
252 
253     public void testLDP_noinfAnn_nodirect() {
254         // note that qB appears in the results because without inference it looks like a global
255         TestUtil.assertIteratorValues( this, noinfAnn.listDeclaredProperties( false ),
256                                        new Object[] {noinfPann, noinfG, noinfQb} );
257     }
258 
259     public void testLDP_noinfAnn_direct() {
260         TestUtil.assertIteratorValues( this, noinfAnn.listDeclaredProperties( true ),
261                                        new Object[] {noinfPann, noinfG, noinfQb} );
262     }
263 
264     public void testLDP_infAnn_nodirect() {
265         TestUtil.assertIteratorValues( this, infAnn.listDeclaredProperties( false ),
266                                        new Object[] {noinfPann, noinfG} );
267     }
268 
269     public void testLDP_infAnn_direct() {
270         TestUtil.assertIteratorValues( this, infAnn.listDeclaredProperties( true ),
271                                        new Object[] {noinfPann, noinfG} );
272     }
273 
274 
275     public void testLDP_noinfUnion_nodirect() {
276         TestUtil.assertIteratorValues( this, noinfUnion1.listDeclaredProperties( false ),
277                 new Object[] {noinfG, noinfQb} );
278         TestUtil.assertIteratorValues( this, noinfUnion2.listDeclaredProperties( false ),
279                 new Object[] {noinfG, noinfQb} );
280     }
281 
282     public void testLDP_infUnion_nodirect() {
283         TestUtil.assertIteratorValues( this, infUnion1.listDeclaredProperties( false ),
284                 new Object[] {infPunion, infG} );
285         TestUtil.assertIteratorValues( this, infUnion2.listDeclaredProperties( false ),
286                 new Object[] {infPunion, infG} );
287     }
288 
289     public void testLDP_noinfIntersect_nodirect() {
290         TestUtil.assertIteratorValues( this, noinfIntersect1.listDeclaredProperties( false ),
291                 new Object[] {noinfG, noinfQb} );
292         TestUtil.assertIteratorValues( this, noinfIntersect2.listDeclaredProperties( false ),
293                 new Object[] {noinfG, noinfQb} );
294     }
295 
296     public void testLDP_infIntersect_nodirect() {
297         TestUtil.assertIteratorValues( this, infIntersect1.listDeclaredProperties( false ),
298                 new Object[] {infG} );
299         TestUtil.assertIteratorValues( this, infIntersect2.listDeclaredProperties( false ),
300                 new Object[] {infG} );
301     }
302 
303     // OntProperty.listDeclaringProperties() tests ...
304 
305     public void testLDC_noinfPa_nodirect() {
306         TestUtil.assertIteratorValues( this, noinfPa.listDeclaringClasses( false ),
307                 new Object[] {noinfA, noinfB, noinfC} );
308     }
309 
310     public void testLDC_infPa_nodirect() {
311         TestUtil.assertIteratorValues( this, infPa.listDeclaringClasses( false ),
312                 new Object[] {infA, infB, infC} );
313     }
314 
315     public void testLDC_noinfPb_nodirect() {
316         TestUtil.assertIteratorValues( this, noinfPb.listDeclaringClasses( false ),
317                 new Object[] {noinfB, noinfC} );
318     }
319 
320     public void testLDC_infPb_nodirect() {
321         TestUtil.assertIteratorValues( this, infPb.listDeclaringClasses( false ),
322                 new Object[] {infC, infB} );
323     }
324 
325     public void testLDC_noinfPc_nodirect() {
326         TestUtil.assertIteratorValues( this, noinfPc.listDeclaringClasses( false ),
327                 new Object[] {noinfC} );
328     }
329 
330     public void testLDC_infPc_nodirect() {
331         TestUtil.assertIteratorValues( this, infPc.listDeclaringClasses( false ),
332                 new Object[] {infC} );
333     }
334 
335     public void testLDC_noinfPa_direct() {
336         TestUtil.assertIteratorValues( this, noinfPa.listDeclaringClasses( true ),
337                 new Object[] {noinfA} );
338     }
339 
340     public void testLDC_infPa_direct() {
341         TestUtil.assertIteratorValues( this, infPa.listDeclaringClasses( true ),
342                 new Object[] {infA} );
343     }
344 
345     public void testLDC_noinfPb_direct() {
346         TestUtil.assertIteratorValues( this, noinfPb.listDeclaringClasses( true ),
347                 new Object[] {noinfB} );
348     }
349 
350     public void testLDC_infPb_direct() {
351         TestUtil.assertIteratorValues( this, infPb.listDeclaringClasses( true ),
352                 new Object[] {infB} );
353     }
354 
355     public void testLDC_noinfPc_direct() {
356         TestUtil.assertIteratorValues( this, noinfPc.listDeclaringClasses( true ),
357                 new Object[] {noinfC} );
358     }
359 
360     public void testLDC_infPc_direct() {
361         TestUtil.assertIteratorValues( this, infPc.listDeclaringClasses( true ),
362                 new Object[] {infC} );
363     }
364 
365     public void testLDC_noinfG_direct() {
366         TestUtil.assertIteratorValues( this, noinfG.listDeclaringClasses( true ),
367                 new Object[] {noinfA, noinfAnn, noinfUnion1, noinfUnion2, mNoInf.getOntClass(NS+"Joint"),noinfIntersect1,noinfIntersect2}, 2 );
368     }
369 
370     public void testLDC_infG_direct() {
371         TestUtil.assertIteratorValues( this, infG.listDeclaringClasses( true ),
372                 new Object[] {infA, infAnn, mNoInf.getOntClass(NS+"Joint"),noinfIntersect1,noinfIntersect2}, 1 );
373     }
374 
375     public void testLDC_noinfG_nodirect() {
376         TestUtil.assertIteratorValues( this, noinfG.listDeclaringClasses( false ),
377                 new Object[] {noinfA, noinfB, noinfC, noinfUnion1, noinfUnion2, noinfAnn, mNoInf.getOntClass(NS+"Joint"),noinfIntersect1,noinfIntersect2}, 2 );
378     }
379 
380     public void testLDC_infG_nodirect() {
381         TestUtil.assertIteratorValues( this, infG.listDeclaringClasses( false ),
382                 new Object[] {infA, infB, infC, infAnn, noinfUnion1, noinfUnion2, mNoInf.getOntClass(NS+"Joint"),noinfIntersect1,noinfIntersect2}, 2 );
383     }
384 
385 
386     // Internal implementation methods
387     //////////////////////////////////
388 
389     //==============================================================================
390     // Inner class definitions
391     //==============================================================================
392 
393 }
394 
395 
396 /*
397 (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
398 All rights reserved.
399 
400 Redistribution and use in source and binary forms, with or without
401 modification, are permitted provided that the following conditions
402 are met:
403 
404 1. Redistributions of source code must retain the above copyright
405    notice, this list of conditions and the following disclaimer.
406 
407 2. Redistributions in binary form must reproduce the above copyright
408    notice, this list of conditions and the following disclaimer in the
409    documentation and/or other materials provided with the distribution.
410 
411 3. The name of the author may not be used to endorse or promote products
412    derived from this software without specific prior written permission.
413 
414 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
415 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
416 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
417 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
418 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
419 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
420 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
421 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
422 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
423 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
424 */
425