Source Code Cross Referenced for TestOntClass.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » ontology » impl » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.ontology.impl.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*****************************************************************************
002:         * Source code information
003:         * -----------------------
004:         * Original author    Ian Dickinson, HP Labs Bristol
005:         * Author email       ian.dickinson@hp.com
006:         * Package            Jena2
007:         * Web site           http://jena.sourceforge.net
008:         * Created            07-Dec-2004
009:         * Filename           $RCSfile: TestOntClass.java,v $
010:         * Revision           $Revision: 1.10 $
011:         * Release status     $State: Exp $
012:         *
013:         * Last modified on   $Date: 2008/01/02 12:08:41 $
014:         *               by   $Author: andy_seaborne $
015:         *
016:         * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017:         * (see footer for full conditions)
018:         *****************************************************************************/package com.hp.hpl.jena.ontology.impl.test;
019:
020:        // Imports
021:        ///////////////
022:        import com.hp.hpl.jena.ontology.*;
023:        import com.hp.hpl.jena.rdf.model.ModelFactory;
024:        import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
025:        import com.hp.hpl.jena.reasoner.test.TestUtil;
026:        import com.hp.hpl.jena.vocabulary.*;
027:
028:        /**
029:         * <p>
030:         * Misc. tests for OntClass, over and above those in
031:         * {@link TestClassExpression}
032:         * </p>
033:         *
034:         * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
035:         * @version CVS $Id: TestOntClass.java,v 1.10 2008/01/02 12:08:41 andy_seaborne Exp $
036:         */
037:        public class TestOntClass extends ModelTestBase {
038:            // Constants
039:            //////////////////////////////////
040:
041:            // Static variables
042:            //////////////////////////////////
043:
044:            private static final String NS = "http://example.com/test#";
045:
046:            // Instance variables
047:            //////////////////////////////////
048:
049:            // Constructors
050:            //////////////////////////////////
051:
052:            public TestOntClass(String name) {
053:                super (name);
054:            }
055:
056:            // External signature methods
057:            //////////////////////////////////
058:
059:            public void testSuperClassNE() {
060:                OntModel m = ModelFactory
061:                        .createOntologyModel(OntModelSpec.OWL_MEM);
062:                OntClass a = m.createClass(NS + "A");
063:
064:                assertNull(a.getSuperClass());
065:                assertFalse(a.hasSuperClass());
066:            }
067:
068:            public void testSubClassNE() {
069:                OntModel m = ModelFactory
070:                        .createOntologyModel(OntModelSpec.OWL_MEM);
071:                OntClass a = m.createClass(NS + "A");
072:
073:                assertNull(a.getSubClass());
074:                assertFalse(a.hasSubClass());
075:            }
076:
077:            public void testCreateIndividual() {
078:                OntModel m = ModelFactory
079:                        .createOntologyModel(OntModelSpec.OWL_MEM);
080:                OntClass a = m.createClass(NS + "A");
081:                Individual i = a.createIndividual(NS + "i");
082:                assertTrue(i.hasRDFType(a));
083:
084:                Individual j = a.createIndividual();
085:                assertTrue(j.hasRDFType(a));
086:            }
087:
088:            public void testIsHierarchyRoot0() {
089:                OntModel m = ModelFactory
090:                        .createOntologyModel(OntModelSpec.OWL_MEM);
091:                OntClass a = m.createClass(NS + "A");
092:                OntClass b = m.createClass(NS + "B");
093:                a.addSubClass(b);
094:                assertTrue(a.isHierarchyRoot());
095:                assertFalse(b.isHierarchyRoot());
096:            }
097:
098:            public void testIsHierarchyRoot1() {
099:                OntModel m = ModelFactory
100:                        .createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF);
101:                OntClass a = m.createClass(NS + "A");
102:                OntClass b = m.createClass(NS + "B");
103:                a.addSubClass(b);
104:                assertTrue(a.isHierarchyRoot());
105:                assertFalse(b.isHierarchyRoot());
106:            }
107:
108:            public void testIsHierarchyRoot2() {
109:                OntModel m = ModelFactory
110:                        .createOntologyModel(OntModelSpec.OWL_MEM_RDFS_INF);
111:                OntClass a = m.createClass(NS + "A");
112:                OntClass b = m.createClass(NS + "B");
113:                a.addSubClass(b);
114:                assertTrue(a.isHierarchyRoot());
115:                assertFalse(b.isHierarchyRoot());
116:            }
117:
118:            public void testIsHierarchyRoot3() {
119:                OntModel m = ModelFactory
120:                        .createOntologyModel(OntModelSpec.OWL_MEM_TRANS_INF);
121:                OntClass a = m.createClass(NS + "A");
122:                OntClass b = m.createClass(NS + "B");
123:                a.addSubClass(b);
124:                assertTrue(a.isHierarchyRoot());
125:                assertFalse(b.isHierarchyRoot());
126:            }
127:
128:            public void testIsHierarchyRoot4() {
129:                OntModel m = ModelFactory
130:                        .createOntologyModel(OntModelSpec.OWL_DL_MEM);
131:                OntClass a = m.createClass(NS + "A");
132:                OntClass b = m.createClass(NS + "B");
133:                a.addSubClass(b);
134:                assertTrue(a.isHierarchyRoot());
135:                assertFalse(b.isHierarchyRoot());
136:            }
137:
138:            public void testIsHierarchyRoot5() {
139:                OntModel m = ModelFactory
140:                        .createOntologyModel(OntModelSpec.OWL_LITE_MEM);
141:                OntClass a = m.createClass(NS + "A");
142:                OntClass b = m.createClass(NS + "B");
143:                a.addSubClass(b);
144:                assertTrue(a.isHierarchyRoot());
145:                assertFalse(b.isHierarchyRoot());
146:            }
147:
148:            public void testIsHierarchyRoot6() {
149:                OntModel m = ModelFactory
150:                        .createOntologyModel(OntModelSpec.DAML_MEM);
151:                OntClass a = m.createClass(NS + "A");
152:                OntClass b = m.createClass(NS + "B");
153:                a.addSubClass(b);
154:                assertTrue(a.isHierarchyRoot());
155:                assertFalse(b.isHierarchyRoot());
156:            }
157:
158:            public void testIsHierarchyRoot7() {
159:                OntModel m = ModelFactory
160:                        .createOntologyModel(OntModelSpec.DAML_MEM_RULE_INF);
161:                OntClass a = m.createClass(NS + "A");
162:                OntClass b = m.createClass(NS + "B");
163:                a.addSubClass(b);
164:                assertTrue(a.isHierarchyRoot());
165:                assertFalse(b.isHierarchyRoot());
166:            }
167:
168:            public void testIsHierarchyRoot8() {
169:                OntModel m = ModelFactory
170:                        .createOntologyModel(OntModelSpec.RDFS_MEM);
171:                OntClass a = m.createClass(NS + "A");
172:                OntClass b = m.createClass(NS + "B");
173:                a.addSubClass(b);
174:                assertTrue(a.isHierarchyRoot());
175:                assertFalse(b.isHierarchyRoot());
176:            }
177:
178:            public void testIsHierarchyRoot9() {
179:                OntModel m = ModelFactory
180:                        .createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF);
181:                OntClass a = m.createClass(NS + "A");
182:                OntClass b = m.createClass(NS + "B");
183:                a.addSubClass(b);
184:                assertTrue(a.isHierarchyRoot());
185:                assertFalse(b.isHierarchyRoot());
186:            }
187:
188:            public void testListSubClasses0() {
189:                // no inference
190:                OntModel m = createABCDEFModel(OntModelSpec.OWL_MEM);
191:                OntClass a = m.getOntClass(NS + "A");
192:                OntClass b = m.getOntClass(NS + "B");
193:                OntClass c = m.getOntClass(NS + "C");
194:                OntClass d = m.getOntClass(NS + "D");
195:                OntClass e = m.getOntClass(NS + "E");
196:
197:                TestUtil.assertIteratorValues(this , a.listSubClasses(),
198:                        new Object[] { b, c });
199:                TestUtil.assertIteratorValues(this , a.listSubClasses(false),
200:                        new Object[] { b, c });
201:                TestUtil.assertIteratorValues(this , a.listSubClasses(true),
202:                        new Object[] { b, c });
203:                TestUtil.assertIteratorValues(this , b.listSubClasses(true),
204:                        new Object[] { d, e });
205:            }
206:
207:            public void testListSubClasses1() {
208:                // rule inference
209:                OntModel m = createABCDEFModel(OntModelSpec.OWL_MEM_RULE_INF);
210:                OntClass a = m.getOntClass(NS + "A");
211:                OntClass b = m.getOntClass(NS + "B");
212:                OntClass c = m.getOntClass(NS + "C");
213:                OntClass d = m.getOntClass(NS + "D");
214:                OntClass e = m.getOntClass(NS + "E");
215:                OntClass f = m.getOntClass(NS + "F");
216:
217:                TestUtil.assertIteratorValues(this , a.listSubClasses(),
218:                        new Object[] { b, c, d, e, f });
219:                TestUtil.assertIteratorValues(this , a.listSubClasses(false),
220:                        new Object[] { b, c, d, e, f });
221:                TestUtil.assertIteratorValues(this , a.listSubClasses(true),
222:                        new Object[] { b, c });
223:                TestUtil.assertIteratorValues(this , b.listSubClasses(true),
224:                        new Object[] { d, e });
225:            }
226:
227:            public void testListSubClasses2() {
228:                // micro rule inference
229:                OntModel m = createABCDEFModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
230:                OntClass a = m.getOntClass(NS + "A");
231:                OntClass b = m.getOntClass(NS + "B");
232:                OntClass c = m.getOntClass(NS + "C");
233:                OntClass d = m.getOntClass(NS + "D");
234:                OntClass e = m.getOntClass(NS + "E");
235:                OntClass f = m.getOntClass(NS + "F");
236:
237:                TestUtil.assertIteratorValues(this , a.listSubClasses(),
238:                        new Object[] { b, c, d, e, f, OWL.Nothing });
239:                TestUtil.assertIteratorValues(this , a.listSubClasses(false),
240:                        new Object[] { b, c, d, e, f, OWL.Nothing });
241:                TestUtil.assertIteratorValues(this , a.listSubClasses(true),
242:                        new Object[] { b, c });
243:                TestUtil.assertIteratorValues(this , b.listSubClasses(true),
244:                        new Object[] { d, e });
245:            }
246:
247:            public void testListSuperClasses0() {
248:                // no inference
249:                OntModel m = createABCDEFModel(OntModelSpec.OWL_MEM);
250:                OntClass a = m.getOntClass(NS + "A");
251:                OntClass b = m.getOntClass(NS + "B");
252:                OntClass c = m.getOntClass(NS + "C");
253:                OntClass e = m.getOntClass(NS + "E");
254:
255:                TestUtil.assertIteratorValues(this , e.listSuperClasses(),
256:                        new Object[] { b, c });
257:                TestUtil.assertIteratorValues(this , e.listSuperClasses(false),
258:                        new Object[] { b, c });
259:                TestUtil.assertIteratorValues(this , e.listSuperClasses(true),
260:                        new Object[] { b, c });
261:                TestUtil.assertIteratorValues(this , b.listSuperClasses(true),
262:                        new Object[] { a });
263:            }
264:
265:            public void testListSuperClasses1() {
266:                // rule inference
267:                OntModel m = createABCDEFModel(OntModelSpec.OWL_MEM_RULE_INF);
268:                OntClass a = m.getOntClass(NS + "A");
269:                OntClass b = m.getOntClass(NS + "B");
270:                OntClass c = m.getOntClass(NS + "C");
271:                OntClass e = m.getOntClass(NS + "E");
272:
273:                TestUtil.assertIteratorValues(this , e.listSuperClasses(),
274:                        new Object[] { b, c, a, RDFS.Resource, OWL.Thing });
275:                TestUtil.assertIteratorValues(this , e.listSuperClasses(false),
276:                        new Object[] { b, c, a, RDFS.Resource, OWL.Thing });
277:                TestUtil.assertIteratorValues(this , e.listSuperClasses(true),
278:                        new Object[] { b, c });
279:                TestUtil.assertIteratorValues(this , b.listSuperClasses(true),
280:                        new Object[] { a });
281:            }
282:
283:            public void testListSuperClasses2() {
284:                // micro rule inference
285:                OntModel m = createABCDEFModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
286:                OntClass a = m.getOntClass(NS + "A");
287:                OntClass b = m.getOntClass(NS + "B");
288:                OntClass c = m.getOntClass(NS + "C");
289:                OntClass e = m.getOntClass(NS + "E");
290:
291:                TestUtil.assertIteratorValues(this , e.listSuperClasses(),
292:                        new Object[] { b, c, a, OWL.Thing });
293:                TestUtil.assertIteratorValues(this , e.listSuperClasses(false),
294:                        new Object[] { b, c, a, OWL.Thing });
295:                TestUtil.assertIteratorValues(this , e.listSuperClasses(true),
296:                        new Object[] { b, c });
297:                TestUtil.assertIteratorValues(this , b.listSuperClasses(true),
298:                        new Object[] { a });
299:            }
300:
301:            public void testListInstances0() {
302:                // no inference
303:                OntModel m = createABCDEFModel(OntModelSpec.OWL_MEM);
304:                OntClass a = m.getOntClass(NS + "A");
305:                OntClass b = m.getOntClass(NS + "B");
306:
307:                Individual ia = a.createIndividual();
308:                Individual ib = b.createIndividual();
309:
310:                TestUtil.assertIteratorValues(this , a.listInstances(),
311:                        new Object[] { ia });
312:                TestUtil.assertIteratorValues(this , b.listInstances(),
313:                        new Object[] { ib });
314:
315:                TestUtil.assertIteratorValues(this , a.listInstances(true),
316:                        new Object[] { ia });
317:                TestUtil.assertIteratorValues(this , b.listInstances(true),
318:                        new Object[] { ib });
319:            }
320:
321:            public void testListInstances1() {
322:                // no inference
323:                OntModel m = createABCDEFModel(OntModelSpec.OWL_MEM_RULE_INF);
324:                OntClass a = m.getOntClass(NS + "A");
325:                OntClass b = m.getOntClass(NS + "B");
326:                OntClass c = m.getOntClass(NS + "C");
327:                OntClass d = m.getOntClass(NS + "D");
328:                OntClass e = m.getOntClass(NS + "E");
329:
330:                Individual ia = a.createIndividual(NS + "iA");
331:                Individual ib = b.createIndividual(NS + "iB");
332:                Individual ic = c.createIndividual(NS + "iC");
333:                Individual id = d.createIndividual(NS + "iD");
334:                Individual ie = e.createIndividual(NS + "iE");
335:
336:                TestUtil.assertIteratorValues(this , a.listInstances(),
337:                        new Object[] { ia, ib, ic, id, ie });
338:                TestUtil.assertIteratorValues(this , b.listInstances(),
339:                        new Object[] { ib, id, ie });
340:
341:                TestUtil.assertIteratorValues(this , a.listInstances(true),
342:                        new Object[] { ia });
343:                TestUtil.assertIteratorValues(this , b.listInstances(true),
344:                        new Object[] { ib });
345:            }
346:
347:            public void testListInstances2() {
348:                // no inference
349:                OntModel m = createABCDEFModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
350:                OntClass a = m.getOntClass(NS + "A");
351:                OntClass b = m.getOntClass(NS + "B");
352:                OntClass c = m.getOntClass(NS + "C");
353:                OntClass d = m.getOntClass(NS + "D");
354:                OntClass e = m.getOntClass(NS + "E");
355:
356:                Individual ia = a.createIndividual(NS + "iA");
357:                Individual ib = b.createIndividual(NS + "iB");
358:                Individual ic = c.createIndividual(NS + "iC");
359:                Individual id = d.createIndividual(NS + "iD");
360:                Individual ie = e.createIndividual(NS + "iE");
361:
362:                TestUtil.assertIteratorValues(this , a.listInstances(),
363:                        new Object[] { ia, ib, ic, id, ie });
364:                TestUtil.assertIteratorValues(this , b.listInstances(),
365:                        new Object[] { ib, id, ie });
366:
367:                TestUtil.assertIteratorValues(this , a.listInstances(true),
368:                        new Object[] { ia });
369:                TestUtil.assertIteratorValues(this , b.listInstances(true),
370:                        new Object[] { ib });
371:            }
372:
373:            public void testDropIndividual() {
374:                OntModel m = createABCDEFModel(OntModelSpec.OWL_MEM);
375:                OntClass a = m.getOntClass(NS + "A");
376:                OntClass b = m.getOntClass(NS + "B");
377:                Individual ia = a.createIndividual(NS + "iA");
378:                ia.addOntClass(b);
379:
380:                assertTrue(ia.hasOntClass(a));
381:                assertTrue(ia.hasOntClass(b));
382:
383:                // drop ia from the extension of A
384:                a.dropIndividual(ia);
385:
386:                assertFalse(ia.hasOntClass(a));
387:                assertTrue(ia.hasOntClass(b));
388:
389:                // do it again - should be a no-op
390:                a.dropIndividual(ia);
391:
392:                assertFalse(ia.hasOntClass(a));
393:                assertTrue(ia.hasOntClass(b));
394:
395:                // drop ia from the extension of b
396:                b.dropIndividual(ia);
397:
398:                assertFalse(ia.hasOntClass(a));
399:                assertFalse(ia.hasOntClass(b));
400:            }
401:
402:            // Internal implementation methods
403:            //////////////////////////////////
404:
405:            protected OntModel createABCDEFModel(OntModelSpec spec) {
406:                OntModel m = ModelFactory.createOntologyModel(spec);
407:                OntClass a = m.createClass(NS + "A");
408:                OntClass b = m.createClass(NS + "B");
409:                OntClass c = m.createClass(NS + "C");
410:                OntClass d = m.createClass(NS + "D");
411:                OntClass e = m.createClass(NS + "E");
412:                OntClass f = m.createClass(NS + "F");
413:
414:                //      A
415:                //     / \
416:                //    B   C
417:                //   / \ / \
418:                //  D   E   F
419:
420:                a.addSubClass(b);
421:                a.addSubClass(c);
422:                b.addSubClass(d);
423:                b.addSubClass(e);
424:                c.addSubClass(e);
425:                c.addSubClass(f);
426:                return m;
427:            }
428:
429:            //==============================================================================
430:            // Inner class definitions
431:            //==============================================================================
432:
433:        }
434:
435:        /*
436:         (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
437:         All rights reserved.
438:
439:         Redistribution and use in source and binary forms, with or without
440:         modification, are permitted provided that the following conditions
441:         are met:
442:
443:         1. Redistributions of source code must retain the above copyright
444:         notice, this list of conditions and the following disclaimer.
445:
446:         2. Redistributions in binary form must reproduce the above copyright
447:         notice, this list of conditions and the following disclaimer in the
448:         documentation and/or other materials provided with the distribution.
449:
450:         3. The name of the author may not be used to endorse or promote products
451:         derived from this software without specific prior written permission.
452:
453:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
454:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
455:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
456:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
457:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
458:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
459:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
460:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
461:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
462:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
463:         */
w___w__w__.__ja___v__a___2_s_._c__o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.