Source Code Cross Referenced for TestOntModel.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) 


0001:        /*****************************************************************************
0002:         * Source code information
0003:         * -----------------------
0004:         * Original author    Ian Dickinson, HP Labs Bristol
0005:         * Author email       Ian.Dickinson@hp.com
0006:         * Package            Jena 2
0007:         * Web                http://sourceforge.net/projects/jena/
0008:         * Created            21-Jun-2003
0009:         * Filename           $RCSfile: TestOntModel.java,v $
0010:         * Revision           $Revision: 1.31 $
0011:         * Release status     $State: Exp $
0012:         *
0013:         * Last modified on   $Date: 2008/02/06 11:28:43 $
0014:         *               by   $Author: ian_dickinson $
0015:         *
0016:         * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
0017:         * (see footer for full conditions)
0018:         *****************************************************************************/package com.hp.hpl.jena.ontology.impl.test;
0019:
0020:        // Imports
0021:        ///////////////
0022:        import java.io.*;
0023:        import java.util.*;
0024:
0025:        import com.hp.hpl.jena.graph.Graph;
0026:        import com.hp.hpl.jena.ontology.*;
0027:        import com.hp.hpl.jena.ontology.impl.*;
0028:        import com.hp.hpl.jena.rdf.model.*;
0029:        import com.hp.hpl.jena.rdf.model.test.*;
0030:        import com.hp.hpl.jena.reasoner.rulesys.test.TestBugs;
0031:        import com.hp.hpl.jena.reasoner.test.TestUtil;
0032:        import com.hp.hpl.jena.shared.PrefixMapping;
0033:        import com.hp.hpl.jena.vocabulary.*;
0034:
0035:        /**
0036:         * <p>
0037:         * Unit tests on OntModel capabilities.  Many of OntModel's methods are tested by the other
0038:         * abstractions' unit tests.
0039:         * </p>
0040:         *
0041:         * @author Ian Dickinson, HP Labs
0042:         *         (<a  href="mailto:Ian.Dickinson@hp.com" >email</a>)
0043:         * @version CVS $Id: TestOntModel.java,v 1.31 2008/02/06 11:28:43 ian_dickinson Exp $
0044:         */
0045:        public class TestOntModel extends ModelTestBase {
0046:            // Constants
0047:            //////////////////////////////////
0048:
0049:            // Static variables
0050:            //////////////////////////////////
0051:
0052:            public static final String BASE = "http://www.hp.com/test";
0053:            public static final String NS = BASE + "#";
0054:
0055:            public static final String DOC = "<rdf:RDF"
0056:                    + "   xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""
0057:                    + "   xmlns:owl=\"http://www.w3.org/2002/07/owl#\""
0058:                    + "   xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\">"
0059:                    + "  <owl:Class rdf:about=\"http://www.hp.com/test#D\">"
0060:                    + "    <rdfs:subClassOf>"
0061:                    + "      <owl:Class rdf:about=\"http://www.hp.com/test#B\"/>"
0062:                    + "    </rdfs:subClassOf>"
0063:                    + "  </owl:Class>"
0064:                    + "  <owl:Class rdf:about=\"http://www.hp.com/test#B\">"
0065:                    + "    <rdfs:subClassOf rdf:resource=\"http://www.hp.com/test#A\""
0066:                    + "       rdf:type=\"http://www.w3.org/2002/07/owl#Class\"/>"
0067:                    + "  </owl:Class>"
0068:                    + "  <owl:Class rdf:about=\"http://www.hp.com/test#C\">"
0069:                    + "    <rdfs:subClassOf rdf:resource=\"http://www.hp.com/test#B\"/>"
0070:                    + "  </owl:Class>"
0071:                    + "  <owl:ObjectProperty rdf:about=\"http://www.hp.com/test#p\">"
0072:                    + "    <rdfs:domain rdf:resource=\"http://www.hp.com/test#A\"/>"
0073:                    + "    <rdfs:range rdf:resource=\"http://www.hp.com/test#B\"/>"
0074:                    + "    <rdfs:range rdf:resource=\"http://www.hp.com/test#C\"/>"
0075:                    + "  </owl:ObjectProperty>" + "</rdf:RDF>";
0076:
0077:            // Instance variables
0078:            //////////////////////////////////
0079:
0080:            // Constructors
0081:            //////////////////////////////////
0082:
0083:            public TestOntModel(String name) {
0084:                super (name);
0085:            }
0086:
0087:            // External signature methods
0088:            //////////////////////////////////
0089:
0090:            public void setUp() {
0091:                // ensure the ont doc manager is in a consistent state
0092:                OntDocumentManager.getInstance().reset(true);
0093:            }
0094:
0095:            /** Test writing the base model to an output stream */
0096:            public void testWriteOutputStream() {
0097:                OntModel m = ModelFactory.createOntologyModel();
0098:
0099:                // set up the model
0100:                OntClass A = m.createClass(NS + "A");
0101:                OntClass B = m.createClass(NS + "B");
0102:                OntClass C = m.createClass(NS + "C");
0103:                OntClass D = m.createClass(NS + "D");
0104:
0105:                A.addSubClass(B);
0106:                B.addSubClass(C);
0107:                B.addSubClass(D);
0108:
0109:                ObjectProperty p = m.createObjectProperty(NS + "p");
0110:
0111:                p.addDomain(A);
0112:                p.addRange(B);
0113:                p.addRange(C);
0114:
0115:                // write to a stream
0116:                ByteArrayOutputStream out = new ByteArrayOutputStream();
0117:                m.write(out);
0118:
0119:                String s = out.toString();
0120:                ByteArrayInputStream in = new ByteArrayInputStream(s.getBytes());
0121:
0122:                // read it back again
0123:                Model mIn1 = ModelFactory.createDefaultModel();
0124:                mIn1.read(in, BASE);
0125:
0126:                Model mIn2 = ModelFactory.createDefaultModel();
0127:                mIn2.read(new ByteArrayInputStream(DOC.getBytes()), BASE);
0128:
0129:                // should be the same
0130:                assertTrue("InputStream write/read cycle failed (1)", mIn1
0131:                        .isIsomorphicWith(m.getBaseModel()));
0132:                assertTrue("InputStream write/read cycle failed (2)", mIn2
0133:                        .isIsomorphicWith(m.getBaseModel()));
0134:            }
0135:
0136:            public void testGetBaseModelPrefixes() {
0137:                OntModel om = ModelFactory.createOntologyModel();
0138:                om.setNsPrefix("bill", "http://bill.and.ben/flowerpot#");
0139:                om.setNsPrefix("grue", "ftp://grue.and.bleen/2000#");
0140:                assertEquals(om.getNsPrefixMap(), om.getBaseModel()
0141:                        .getNsPrefixMap());
0142:            }
0143:
0144:            /**
0145:                 The prefixes of an OntModel should be the prefixes of its base model,
0146:                 plus any non-clashing ones from the document manager's prefix mapping.
0147:                 (which this test assume includes rdfs and daml).
0148:             */
0149:            public void testPrefixDefaulting() {
0150:                Model base = ModelFactory.createDefaultModel();
0151:                base.setNsPrefix("hedgehog", "http://hedgehog.hog/");
0152:                base.setNsPrefix("daml", "not:the-DAML-URI/");
0153:                base.setNsPrefix("mine", RDF.getURI());
0154:                OntModel m = new OntModelImpl(OntModelSpec.RDFS_MEM, base);
0155:                PrefixMapping given = m.getDocumentManager()
0156:                        .getDeclaredPrefixMapping();
0157:                assertEquals("http://hedgehog.hog/", m
0158:                        .getNsPrefixURI("hedgehog"));
0159:                assertEquals("not:the-DAML-URI/", m.getNsPrefixURI("daml"));
0160:                assertEquals(RDF.getURI(), m.getNsPrefixURI("mine"));
0161:                assertEquals(null, m.getNsPrefixURI("rdf"));
0162:                assertEquals(given.getNsPrefixURI("rdfs"), m
0163:                        .getNsPrefixURI("rdfs"));
0164:            }
0165:
0166:            public void testWritesPrefixes() {
0167:                OntModel om = ModelFactory.createOntologyModel();
0168:                om.setNsPrefix("spoo", "http://spoo.spoo.com/spoo#");
0169:                om.add(statement(om,
0170:                        "ping http://spoo.spoo.com/spoo#pang pilly"));
0171:                om.add(statement(om, "gg " + OWL.getURI() + "hh ii"));
0172:                StringWriter sw = new StringWriter();
0173:                om.write(sw);
0174:                String s = sw.getBuffer().toString();
0175:                assertTrue(s
0176:                        .indexOf("xmlns:spoo=\"http://spoo.spoo.com/spoo#\"") > 0);
0177:                assertTrue(s.indexOf("xmlns:owl=\"" + OWL.getURI() + "\"") > 0);
0178:            }
0179:
0180:            /** Test writing the base model to an output stream */
0181:            public void testWriteWriter() {
0182:                OntModel m = ModelFactory.createOntologyModel();
0183:
0184:                // set up the model
0185:                OntClass A = m.createClass(NS + "A");
0186:                OntClass B = m.createClass(NS + "B");
0187:                OntClass C = m.createClass(NS + "C");
0188:                OntClass D = m.createClass(NS + "D");
0189:
0190:                A.addSubClass(B);
0191:                B.addSubClass(C);
0192:                B.addSubClass(D);
0193:
0194:                ObjectProperty p = m.createObjectProperty(NS + "p");
0195:
0196:                p.addDomain(A);
0197:                p.addRange(B);
0198:                p.addRange(C);
0199:
0200:                // write to a stream
0201:                StringWriter out = new StringWriter();
0202:                m.write(out);
0203:
0204:                String s = out.toString();
0205:
0206:                // read it back again
0207:                Model mIn1 = ModelFactory.createDefaultModel();
0208:                mIn1.read(new StringReader(s), BASE);
0209:
0210:                Model mIn2 = ModelFactory.createDefaultModel();
0211:                mIn2.read(new StringReader(DOC), BASE);
0212:
0213:                // should be the same
0214:                assertTrue("Writer write/read cycle failed (1)", mIn1
0215:                        .isIsomorphicWith(m.getBaseModel()));
0216:                assertTrue("Writer write/read cycle failed (2)", mIn2
0217:                        .isIsomorphicWith(m.getBaseModel()));
0218:            }
0219:
0220:            public void testGetOntology() {
0221:                OntModel m = ModelFactory.createOntologyModel();
0222:                Resource r = m.getResource(NS + "r");
0223:                m.add(r, RDF.type, r);
0224:                Resource s = m.createOntology(NS + "s");
0225:                assertEquals("Result of get s", s, m.getOntology(NS + "s"));
0226:                assertNull("result of get q", m.getOntology(NS + "q"));
0227:                assertNull("result of get r", m.getOntology(NS + "r"));
0228:            }
0229:
0230:            public void testGetIndividual() {
0231:                OntModel m = ModelFactory.createOntologyModel();
0232:                OntClass c = m.createClass(NS + "c");
0233:                Resource r = m.getResource(NS + "r");
0234:                m.add(r, RDF.type, r);
0235:                Resource s = m.createIndividual(NS + "s", c);
0236:                assertEquals("Result of get s", s, m.getIndividual(NS + "s"));
0237:                assertNull("result of get q", m.getIndividual(NS + "q"));
0238:            }
0239:
0240:            /** User requested: allow null arguments when creating individuals */
0241:            public void testCreateIndividual() {
0242:                OntModel m = ModelFactory
0243:                        .createOntologyModel(OntModelSpec.OWL_MEM);
0244:                Resource i0 = m.createIndividual(OWL.Thing);
0245:                Resource i1 = m.createIndividual(null);
0246:                Resource i2 = m.createIndividual(NS + "i2", OWL.Thing);
0247:                Resource i3 = m.createIndividual(NS + "i3", null);
0248:                Resource i4 = m.createIndividual(null, OWL.Thing);
0249:                Resource i5 = m.createIndividual(null, null);
0250:
0251:                assertNotNull(i0);
0252:                assertNotNull(i1);
0253:                assertNotNull(i2);
0254:                assertNotNull(i3);
0255:                assertNotNull(i4);
0256:                assertNotNull(i5);
0257:            }
0258:
0259:            public void testGetOntProperty() {
0260:                OntModel m = ModelFactory.createOntologyModel();
0261:                Resource r = m.getResource(NS + "r");
0262:                m.add(r, RDF.type, r);
0263:                Resource s = m.createOntProperty(NS + "s");
0264:                assertEquals("Result of get s", s, m.getOntProperty(NS + "s"));
0265:                assertNull("result of get q", m.getOntProperty(NS + "q"));
0266:                assertNull("result of get r", m.getOntProperty(NS + "r"));
0267:            }
0268:
0269:            public void testGetObjectProperty() {
0270:                OntModel m = ModelFactory.createOntologyModel();
0271:                Resource r = m.getResource(NS + "r");
0272:                m.add(r, RDF.type, r);
0273:                Resource s = m.createObjectProperty(NS + "s");
0274:                assertEquals("Result of get s", s, m
0275:                        .getObjectProperty(NS + "s"));
0276:                assertNull("result of get q", m.getObjectProperty(NS + "q"));
0277:                assertNull("result of get r", m.getObjectProperty(NS + "r"));
0278:            }
0279:
0280:            public void testGetTransitiveProperty() {
0281:                OntModel m = ModelFactory.createOntologyModel();
0282:                Resource r = m.getResource(NS + "r");
0283:                m.add(r, RDF.type, r);
0284:                Resource s = m.createTransitiveProperty(NS + "s");
0285:                assertEquals("Result of get s", s, m.getTransitiveProperty(NS
0286:                        + "s"));
0287:                assertNull("result of get q", m.getTransitiveProperty(NS + "q"));
0288:                assertNull("result of get r", m.getTransitiveProperty(NS + "r"));
0289:            }
0290:
0291:            public void testGetSymmetricProperty() {
0292:                OntModel m = ModelFactory.createOntologyModel();
0293:                Resource r = m.getResource(NS + "r");
0294:                m.add(r, RDF.type, r);
0295:                Resource s = m.createSymmetricProperty(NS + "s");
0296:                assertEquals("Result of get s", s, m.getSymmetricProperty(NS
0297:                        + "s"));
0298:                assertNull("result of get q", m.getSymmetricProperty(NS + "q"));
0299:                assertNull("result of get r", m.getSymmetricProperty(NS + "r"));
0300:            }
0301:
0302:            public void testGetInverseFunctionalProperty() {
0303:                OntModel m = ModelFactory.createOntologyModel();
0304:                Resource r = m.getResource(NS + "r");
0305:                m.add(r, RDF.type, r);
0306:                Resource s = m.createInverseFunctionalProperty(NS + "s");
0307:                assertEquals("Result of get s", s, m
0308:                        .getInverseFunctionalProperty(NS + "s"));
0309:                assertNull("result of get q", m.getInverseFunctionalProperty(NS
0310:                        + "q"));
0311:                assertNull("result of get r", m.getInverseFunctionalProperty(NS
0312:                        + "r"));
0313:            }
0314:
0315:            public void testGetDatatypeProperty() {
0316:                OntModel m = ModelFactory.createOntologyModel();
0317:                Resource r = m.getResource(NS + "r");
0318:                m.add(r, RDF.type, r);
0319:                Resource s = m.createDatatypeProperty(NS + "s");
0320:                assertEquals("Result of get s", s, m.getDatatypeProperty(NS
0321:                        + "s"));
0322:                assertNull("result of get q", m.getDatatypeProperty(NS + "q"));
0323:                assertNull("result of get r", m.getDatatypeProperty(NS + "r"));
0324:            }
0325:
0326:            public void testGetAnnotationProperty() {
0327:                OntModel m = ModelFactory.createOntologyModel();
0328:                Resource r = m.getResource(NS + "r");
0329:                m.add(r, RDF.type, r);
0330:                Resource s = m.createAnnotationProperty(NS + "s");
0331:                assertEquals("Result of get s", s, m.getAnnotationProperty(NS
0332:                        + "s"));
0333:                assertNull("result of get q", m.getAnnotationProperty(NS + "q"));
0334:                assertNull("result of get r", m.getAnnotationProperty(NS + "r"));
0335:            }
0336:
0337:            public void testGetOntResource() {
0338:                OntModel m = ModelFactory.createOntologyModel();
0339:                OntResource r0 = m.getOntResource(NS + "a");
0340:                assertNull(r0);
0341:                OntResource r1 = m.createOntResource(NS + "aaa");
0342:                assertInstanceOf(OntResource.class, r1);
0343:                Resource r2a = m.getResource(NS + "a");
0344:                Resource r2b = m.getResource(NS + "b");
0345:                Property p = m.getProperty(NS + "p");
0346:                m.add(r2a, p, r2b);
0347:                r0 = m.getOntResource(NS + "a");
0348:                assertInstanceOf(OntResource.class, r0);
0349:                OntResource r3 = m.getOntResource(r2b);
0350:                assertInstanceOf(OntResource.class, r3);
0351:            }
0352:
0353:            public void testGetOntClass() {
0354:                OntModel m = ModelFactory.createOntologyModel();
0355:                Resource r = m.getResource(NS + "r");
0356:                Resource r0 = m.getResource(NS + "r0");
0357:                m.add(r, RDF.type, r0);
0358:                Resource s = m.createClass(NS + "s");
0359:                assertEquals("Result of get s", s, m.getOntClass(NS + "s"));
0360:                assertNull("result of get q", m.getOntClass(NS + "q"));
0361:                assertNull("result of get r", m.getOntClass(NS + "r"));
0362:            }
0363:
0364:            public void testGetComplementClass() {
0365:                OntModel m = ModelFactory.createOntologyModel();
0366:                OntClass c = m.createClass(NS + "c");
0367:                Resource r = m.getResource(NS + "r");
0368:                m.add(r, RDF.type, r);
0369:                Resource s = m.createComplementClass(NS + "s", c);
0370:                assertEquals("Result of get s", s, m.getComplementClass(NS
0371:                        + "s"));
0372:                assertNull("result of get q", m.getComplementClass(NS + "q"));
0373:                assertNull("result of get r", m.getComplementClass(NS + "r"));
0374:            }
0375:
0376:            public void testGetEnumeratedClass() {
0377:                OntModel m = ModelFactory.createOntologyModel();
0378:                RDFList l = m.createList();
0379:                Resource r = m.getResource(NS + "r");
0380:                m.add(r, RDF.type, r);
0381:                Resource s = m.createEnumeratedClass(NS + "s", l);
0382:                assertEquals("Result of get s", s, m.getEnumeratedClass(NS
0383:                        + "s"));
0384:                assertNull("result of get q", m.getEnumeratedClass(NS + "q"));
0385:                assertNull("result of get r", m.getEnumeratedClass(NS + "r"));
0386:            }
0387:
0388:            public void testGetUnionClass() {
0389:                OntModel m = ModelFactory.createOntologyModel();
0390:                RDFList l = m.createList();
0391:                Resource r = m.getResource(NS + "r");
0392:                m.add(r, RDF.type, r);
0393:                Resource s = m.createUnionClass(NS + "s", l);
0394:                assertEquals("Result of get s", s, m.getUnionClass(NS + "s"));
0395:                assertNull("result of get q", m.getUnionClass(NS + "q"));
0396:                assertNull("result of get r", m.getUnionClass(NS + "r"));
0397:            }
0398:
0399:            public void testGetIntersectionClass() {
0400:                OntModel m = ModelFactory.createOntologyModel();
0401:                RDFList l = m.createList();
0402:                Resource r = m.getResource(NS + "r");
0403:                m.add(r, RDF.type, r);
0404:                Resource s = m.createIntersectionClass(NS + "s", l);
0405:                assertEquals("Result of get s", s, m.getIntersectionClass(NS
0406:                        + "s"));
0407:                assertNull("result of get q", m.getIntersectionClass(NS + "q"));
0408:                assertNull("result of get r", m.getIntersectionClass(NS + "r"));
0409:            }
0410:
0411:            public void testGetRestriction() {
0412:                OntModel m = ModelFactory.createOntologyModel();
0413:                Property p = m.createProperty(NS + "p");
0414:                Resource r = m.getResource(NS + "r");
0415:                m.add(r, RDF.type, r);
0416:                Resource s = m.createRestriction(NS + "s", p);
0417:                assertEquals("Result of get s", s, m.getRestriction(NS + "s"));
0418:                assertNull("result of get q", m.getRestriction(NS + "q"));
0419:                assertNull("result of get r", m.getRestriction(NS + "r"));
0420:            }
0421:
0422:            public void testGetHasValueRestriction() {
0423:                OntModel m = ModelFactory.createOntologyModel();
0424:                Property p = m.createProperty(NS + "p");
0425:                OntClass c = m.createClass(NS + "c");
0426:                Resource r = m.getResource(NS + "r");
0427:                m.add(r, RDF.type, r);
0428:                Resource s = m.createHasValueRestriction(NS + "s", p, c);
0429:                assertEquals("Result of get s", s, m.getHasValueRestriction(NS
0430:                        + "s"));
0431:                assertNull("result of get q", m
0432:                        .getHasValueRestriction(NS + "q"));
0433:                assertNull("result of get r", m
0434:                        .getHasValueRestriction(NS + "r"));
0435:            }
0436:
0437:            public void testGetSomeValuesFromRestriction() {
0438:                OntModel m = ModelFactory.createOntologyModel();
0439:                Property p = m.createProperty(NS + "p");
0440:                OntClass c = m.createClass(NS + "c");
0441:                Resource r = m.getResource(NS + "r");
0442:                m.add(r, RDF.type, r);
0443:                Resource s = m.createSomeValuesFromRestriction(NS + "s", p, c);
0444:                assertEquals("Result of get s", s, m
0445:                        .getSomeValuesFromRestriction(NS + "s"));
0446:                assertNull("result of get q", m.getSomeValuesFromRestriction(NS
0447:                        + "q"));
0448:                assertNull("result of get r", m.getSomeValuesFromRestriction(NS
0449:                        + "r"));
0450:            }
0451:
0452:            public void testGetAllValuesFromRestriction() {
0453:                OntModel m = ModelFactory.createOntologyModel();
0454:                Property p = m.createProperty(NS + "p");
0455:                OntClass c = m.createClass(NS + "c");
0456:                Resource r = m.getResource(NS + "r");
0457:                m.add(r, RDF.type, r);
0458:                Resource s = m.createAllValuesFromRestriction(NS + "s", p, c);
0459:                assertEquals("Result of get s", s, m
0460:                        .getAllValuesFromRestriction(NS + "s"));
0461:                assertNull("result of get q", m.getAllValuesFromRestriction(NS
0462:                        + "q"));
0463:                assertNull("result of get r", m.getAllValuesFromRestriction(NS
0464:                        + "r"));
0465:            }
0466:
0467:            public void testGetCardinalityRestriction() {
0468:                OntModel m = ModelFactory.createOntologyModel();
0469:                Property p = m.createProperty(NS + "p");
0470:                Resource r = m.getResource(NS + "r");
0471:                m.add(r, RDF.type, r);
0472:                Resource s = m.createCardinalityRestriction(NS + "s", p, 1);
0473:                assertEquals("Result of get s", s, m
0474:                        .getCardinalityRestriction(NS + "s"));
0475:                assertNull("result of get q", m.getCardinalityRestriction(NS
0476:                        + "q"));
0477:                assertNull("result of get r", m.getCardinalityRestriction(NS
0478:                        + "r"));
0479:            }
0480:
0481:            public void testGetMinCardinalityRestriction() {
0482:                OntModel m = ModelFactory.createOntologyModel();
0483:                Property p = m.createProperty(NS + "p");
0484:                Resource r = m.getResource(NS + "r");
0485:                m.add(r, RDF.type, r);
0486:                Resource s = m.createMinCardinalityRestriction(NS + "s", p, 1);
0487:                assertEquals("Result of get s", s, m
0488:                        .getMinCardinalityRestriction(NS + "s"));
0489:                assertNull("result of get q", m.getMinCardinalityRestriction(NS
0490:                        + "q"));
0491:                assertNull("result of get r", m.getMinCardinalityRestriction(NS
0492:                        + "r"));
0493:            }
0494:
0495:            public void testGetMaxCardinalityRestriction() {
0496:                OntModel m = ModelFactory.createOntologyModel();
0497:                Property p = m.createProperty(NS + "p");
0498:                Resource r = m.getResource(NS + "r");
0499:                m.add(r, RDF.type, r);
0500:                Resource s = m.createMaxCardinalityRestriction(NS + "s", p, 1);
0501:                assertEquals("Result of get s", s, m
0502:                        .getMaxCardinalityRestriction(NS + "s"));
0503:                assertNull("result of get q", m.getMaxCardinalityRestriction(NS
0504:                        + "q"));
0505:                assertNull("result of get r", m.getMaxCardinalityRestriction(NS
0506:                        + "r"));
0507:            }
0508:
0509:            public void testGetSubgraphs() {
0510:                OntModel m = ModelFactory.createOntologyModel();
0511:                m.read("file:testing/ontology/testImport6/a.owl");
0512:                assertEquals("Marker count not correct", 4,
0513:                        TestOntDocumentManager.countMarkers(m));
0514:
0515:                List subs = m.getSubGraphs();
0516:
0517:                assertEquals("n subgraphs should be ", 3, subs.size());
0518:
0519:                boolean isGraph = true;
0520:                for (Iterator i = subs.iterator(); i.hasNext();) {
0521:                    Object x = i.next();
0522:                    if (!(x instanceof  Graph)) {
0523:                        isGraph = false;
0524:                    }
0525:                }
0526:                assertTrue("All sub-graphs should be graphs", isGraph);
0527:
0528:            }
0529:
0530:            public void testListImportURIs() {
0531:                OntModel m = ModelFactory.createOntologyModel();
0532:                m.read("file:testing/ontology/testImport6/a.owl");
0533:                Collection c = m.listImportedOntologyURIs();
0534:
0535:                assertEquals("Should be two non-closed import URI's", 2, c
0536:                        .size());
0537:                assertTrue("b should be imported ", c
0538:                        .contains("file:testing/ontology/testImport6/b.owl"));
0539:                assertFalse("c should not be imported ", c
0540:                        .contains("file:testing/ontology/testImport6/c.owl"));
0541:                assertTrue("d should be imported ", c
0542:                        .contains("file:testing/ontology/testImport6/d.owl"));
0543:
0544:                c = m.listImportedOntologyURIs(true);
0545:
0546:                assertEquals("Should be two non-closed import URI's", 3, c
0547:                        .size());
0548:                assertTrue("b should be imported ", c
0549:                        .contains("file:testing/ontology/testImport6/b.owl"));
0550:                assertTrue("c should be imported ", c
0551:                        .contains("file:testing/ontology/testImport6/c.owl"));
0552:                assertTrue("d should be imported ", c
0553:                        .contains("file:testing/ontology/testImport6/d.owl"));
0554:            }
0555:
0556:            /* Test removed: superseded by testListSubmodelsN (below)
0557:            //    public void testListImportedModels() {
0558:             *
0559:             */
0560:
0561:            /** Some tests for listing properties. See also {@link TestListSyntaxCategories} */
0562:
0563:            public void testListOntProperties0() {
0564:                OntModel m = ModelFactory
0565:                        .createOntologyModel(OntModelSpec.OWL_MEM);
0566:                ObjectProperty op = m.createObjectProperty(NS + "op");
0567:                DatatypeProperty dp = m.createDatatypeProperty(NS + "dp");
0568:                AnnotationProperty ap = m.createAnnotationProperty(NS + "ap");
0569:                OntProperty ontp = m.createOntProperty(NS + "ontp");
0570:                Property rdfp = m.createProperty(NS + "rdfp");
0571:                rdfp.addProperty(RDF.type, RDF.Property);
0572:
0573:                // no rdf:type entailment, so we don't find most properties ...
0574:
0575:                assertFalse(iteratorContains(m.listOntProperties(), op));
0576:                assertFalse(iteratorContains(m.listOntProperties(), dp));
0577:                assertFalse(iteratorContains(m.listOntProperties(), ap));
0578:                assertTrue(iteratorContains(m.listOntProperties(), ontp));
0579:                assertTrue(iteratorContains(m.listOntProperties(), rdfp));
0580:            }
0581:
0582:            public void testListOntProperties1() {
0583:                OntModel m = ModelFactory
0584:                        .createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
0585:                ObjectProperty op = m.createObjectProperty(NS + "op");
0586:                DatatypeProperty dp = m.createDatatypeProperty(NS + "dp");
0587:                AnnotationProperty ap = m.createAnnotationProperty(NS + "ap");
0588:                OntProperty ontp = m.createOntProperty(NS + "ontp");
0589:                Property rdfp = m.createProperty(NS + "rdfp");
0590:                rdfp.addProperty(RDF.type, RDF.Property);
0591:
0592:                assertTrue(iteratorContains(m.listOntProperties(), op));
0593:                assertTrue(iteratorContains(m.listOntProperties(), dp));
0594:
0595:                // note that owl:AnnotationProperty is an rdf:Property in OWL Full
0596:                assertTrue(iteratorContains(m.listOntProperties(), ap));
0597:                assertTrue(iteratorContains(m.listOntProperties(), ontp));
0598:                assertTrue(iteratorContains(m.listOntProperties(), rdfp));
0599:            }
0600:
0601:            public void testListOntProperties2() {
0602:                OntModelSpec owlDLReasoner = new OntModelSpec(
0603:                        OntModelSpec.OWL_DL_MEM);
0604:                owlDLReasoner.setReasoner(OntModelSpec.OWL_MEM_MICRO_RULE_INF
0605:                        .getReasoner());
0606:                OntModel m = ModelFactory.createOntologyModel(owlDLReasoner);
0607:                ObjectProperty op = m.createObjectProperty(NS + "op");
0608:                DatatypeProperty dp = m.createDatatypeProperty(NS + "dp");
0609:                AnnotationProperty ap = m.createAnnotationProperty(NS + "ap");
0610:                OntProperty ontp = m.createOntProperty(NS + "ontp");
0611:                Property rdfp = m.createProperty(NS + "rdfp");
0612:                rdfp.addProperty(RDF.type, RDF.Property);
0613:
0614:                assertTrue(iteratorContains(m.listOntProperties(), op));
0615:                assertTrue(iteratorContains(m.listOntProperties(), dp));
0616:
0617:                // note that owl:AnnotationProperty not an rdf:Property in OWL DL
0618:                assertFalse(iteratorContains(m.listOntProperties(), ap));
0619:                assertTrue(iteratorContains(m.listOntProperties(), ontp));
0620:                assertTrue(iteratorContains(m.listOntProperties(), rdfp));
0621:            }
0622:
0623:            public void testListAllOntProperties0() {
0624:                OntModel m = ModelFactory
0625:                        .createOntologyModel(OntModelSpec.OWL_MEM);
0626:                ObjectProperty op = m.createObjectProperty(NS + "op");
0627:                DatatypeProperty dp = m.createDatatypeProperty(NS + "dp");
0628:                AnnotationProperty ap = m.createAnnotationProperty(NS + "ap");
0629:                OntProperty ontp = m.createOntProperty(NS + "ontp");
0630:                Property rdfp = m.createProperty(NS + "rdfp");
0631:                rdfp.addProperty(RDF.type, RDF.Property);
0632:
0633:                // no rdf:type entailment, so we don't find most properties ...
0634:
0635:                assertTrue(iteratorContains(m.listAllOntProperties(), op));
0636:                assertTrue(iteratorContains(m.listAllOntProperties(), dp));
0637:                assertTrue(iteratorContains(m.listAllOntProperties(), ap));
0638:                assertTrue(iteratorContains(m.listAllOntProperties(), ontp));
0639:                assertTrue(iteratorContains(m.listAllOntProperties(), rdfp));
0640:            }
0641:
0642:            public void testListObjectProperties0() {
0643:                OntModel m = ModelFactory
0644:                        .createOntologyModel(OntModelSpec.OWL_MEM);
0645:                ObjectProperty op = m.createObjectProperty(NS + "op");
0646:                DatatypeProperty dp = m.createDatatypeProperty(NS + "dp");
0647:                AnnotationProperty ap = m.createAnnotationProperty(NS + "ap");
0648:                OntProperty ontp = m.createOntProperty(NS + "ontp");
0649:                Property rdfp = m.createProperty(NS + "rdfp");
0650:                rdfp.addProperty(RDF.type, RDF.Property);
0651:
0652:                // no rdf:type entailment, so we don't find most properties ...
0653:
0654:                assertTrue(iteratorContains(m.listObjectProperties(), op));
0655:                assertFalse(iteratorContains(m.listObjectProperties(), dp));
0656:                assertFalse(iteratorContains(m.listObjectProperties(), ap));
0657:                assertFalse(iteratorContains(m.listObjectProperties(), ontp));
0658:                assertFalse(iteratorContains(m.listObjectProperties(), rdfp));
0659:            }
0660:
0661:            public void testListDatatypeProperties0() {
0662:                OntModel m = ModelFactory
0663:                        .createOntologyModel(OntModelSpec.OWL_MEM);
0664:                ObjectProperty op = m.createObjectProperty(NS + "op");
0665:                DatatypeProperty dp = m.createDatatypeProperty(NS + "dp");
0666:                AnnotationProperty ap = m.createAnnotationProperty(NS + "ap");
0667:                OntProperty ontp = m.createOntProperty(NS + "ontp");
0668:                Property rdfp = m.createProperty(NS + "rdfp");
0669:                rdfp.addProperty(RDF.type, RDF.Property);
0670:
0671:                // no rdf:type entailment, so we don't find most properties ...
0672:
0673:                assertFalse(iteratorContains(m.listDatatypeProperties(), op));
0674:                assertTrue(iteratorContains(m.listDatatypeProperties(), dp));
0675:                assertFalse(iteratorContains(m.listDatatypeProperties(), ap));
0676:                assertFalse(iteratorContains(m.listDatatypeProperties(), ontp));
0677:                assertFalse(iteratorContains(m.listDatatypeProperties(), rdfp));
0678:            }
0679:
0680:            public void testListAnnotationProperties0() {
0681:                OntModel m = ModelFactory
0682:                        .createOntologyModel(OntModelSpec.OWL_MEM);
0683:                ObjectProperty op = m.createObjectProperty(NS + "op");
0684:                DatatypeProperty dp = m.createDatatypeProperty(NS + "dp");
0685:                AnnotationProperty ap = m.createAnnotationProperty(NS + "ap");
0686:                OntProperty ontp = m.createOntProperty(NS + "ontp");
0687:                Property rdfp = m.createProperty(NS + "rdfp");
0688:                rdfp.addProperty(RDF.type, RDF.Property);
0689:
0690:                // no rdf:type entailment, so we don't find most properties ...
0691:
0692:                assertFalse(iteratorContains(m.listAnnotationProperties(), op));
0693:                assertFalse(iteratorContains(m.listAnnotationProperties(), dp));
0694:                assertTrue(iteratorContains(m.listAnnotationProperties(), ap));
0695:                assertFalse(iteratorContains(m.listAnnotationProperties(), ontp));
0696:                assertFalse(iteratorContains(m.listAnnotationProperties(), rdfp));
0697:            }
0698:
0699:            public void testListSubModels0() {
0700:                OntModel m = ModelFactory.createOntologyModel();
0701:                m.read("file:testing/ontology/testImport6/a.owl");
0702:                assertEquals("Marker count not correct", 4,
0703:                        TestOntDocumentManager.countMarkers(m));
0704:
0705:                List importModels = new ArrayList();
0706:                for (Iterator j = m.listSubModels(); j.hasNext();) {
0707:                    importModels.add(j.next());
0708:                }
0709:
0710:                assertEquals("n import models should be ", 3, importModels
0711:                        .size());
0712:
0713:                boolean isOntModel = true;
0714:                int nImports = 0;
0715:
0716:                for (Iterator i = importModels.iterator(); i.hasNext();) {
0717:                    Object x = i.next();
0718:                    if (!(x instanceof  OntModel)) {
0719:                        isOntModel = false;
0720:                    } else {
0721:                        // count the number of imports of each sub-model
0722:                        nImports += ((OntModel) x).countSubModels();
0723:                    }
0724:                }
0725:
0726:                assertTrue("All import models should be OntModels", isOntModel);
0727:
0728:                // listSubModels' default behaviour is *not* to include imports of sub-models
0729:                assertEquals("Wrong number of sub-model imports", 0, nImports);
0730:            }
0731:
0732:            public void testListSubModels1() {
0733:                OntModel m = ModelFactory.createOntologyModel();
0734:                m.read("file:testing/ontology/testImport6/a.owl");
0735:                assertEquals("Marker count not correct", 4,
0736:                        TestOntDocumentManager.countMarkers(m));
0737:
0738:                List importModels = new ArrayList();
0739:                for (Iterator j = m.listSubModels(true); j.hasNext();) {
0740:                    importModels.add(j.next());
0741:                }
0742:
0743:                assertEquals("n import models should be ", 3, importModels
0744:                        .size());
0745:
0746:                boolean isOntModel = true;
0747:                int nImports = 0;
0748:
0749:                for (Iterator i = importModels.iterator(); i.hasNext();) {
0750:                    Object x = i.next();
0751:                    if (!(x instanceof  OntModel)) {
0752:                        isOntModel = false;
0753:                    } else {
0754:                        // count the number of imports of each sub-model
0755:                        nImports += ((OntModel) x).countSubModels();
0756:                    }
0757:                }
0758:
0759:                assertTrue("All import models should be OntModels", isOntModel);
0760:                assertEquals("Wrong number of sub-model imports", 2, nImports);
0761:            }
0762:
0763:            public void testGetImportedModel() {
0764:                OntModel m = ModelFactory.createOntologyModel();
0765:                m.read("file:testing/ontology/testImport6/a.owl");
0766:
0767:                OntModel m0 = m
0768:                        .getImportedModel("file:testing/ontology/testImport6/b.owl");
0769:                OntModel m1 = m
0770:                        .getImportedModel("file:testing/ontology/testImport6/c.owl");
0771:                OntModel m2 = m
0772:                        .getImportedModel("file:testing/ontology/testImport6/d.owl");
0773:                OntModel m3 = m.getImportedModel(
0774:                        "file:testing/ontology/testImport6/b.owl")
0775:                        .getImportedModel(
0776:                                "file:testing/ontology/testImport6/c.owl");
0777:                OntModel m4 = m
0778:                        .getImportedModel("file:testing/ontology/testImport6/a.owl");
0779:
0780:                assertNotNull("Import model b should not be null", m0);
0781:                assertNotNull("Import model c should not be null", m1);
0782:                assertNotNull("Import model d should not be null", m2);
0783:                assertNotNull("Import model b-c should not be null", m3);
0784:                assertNull("Import model a should be null", m4);
0785:            }
0786:
0787:            /**
0788:             * Test that the supports checks that are defined in the OWL full profile are not
0789:             * missing in the DL and Lite profiles, unless by design.
0790:             * Not strictly a model test, but it has to go somewhere */
0791:            public void testProfiles() {
0792:                List notInDL = Arrays.asList(new Class[] {});
0793:                List notInLite = Arrays.asList(new Class[] { DataRange.class,
0794:                        HasValueRestriction.class });
0795:
0796:                Map fullProfileMap = new OWLProfileExt().getSupportsMap();
0797:                Map dlProfileMap = new OWLDLProfileExt().getSupportsMap();
0798:                Map liteProfileMap = new OWLLiteProfileExt().getSupportsMap();
0799:
0800:                for (Iterator i = fullProfileMap.entrySet().iterator(); i
0801:                        .hasNext();) {
0802:                    Map.Entry kv = (Map.Entry) i.next();
0803:                    Class c = (Class) kv.getKey();
0804:                    assertTrue("Key in OWL DL profile: " + c.getName(),
0805:                            dlProfileMap.containsKey(c) || notInDL.contains(c));
0806:                    assertTrue("Key in OWL lite profile: " + c.getName(),
0807:                            liteProfileMap.containsKey(c)
0808:                                    || notInLite.contains(c));
0809:                }
0810:            }
0811:
0812:            /**
0813:                Added by kers to ensure that bulk update works; should really be a test
0814:                of the ontology Graph using AbstractTestGraph, but that fails because there
0815:                are too many things that don't pass those tests.
0816:            <p>
0817:                <b>Yet</b>.
0818:             */
0819:            public void testBulkAddWorks() {
0820:                OntModel om1 = ModelFactory.createOntologyModel();
0821:                OntModel om2 = ModelFactory.createOntologyModel();
0822:                om1.add(om2);
0823:            }
0824:
0825:            public void testRead() {
0826:                String base0 = "http://example.com/test0";
0827:                String ns0 = base0 + "#";
0828:                String base1 = "http://example.com/test1";
0829:                String ns1 = base1 + "#";
0830:
0831:                OntModel m = ModelFactory
0832:                        .createOntologyModel(OntModelSpec.OWL_MEM);
0833:                m.getDocumentManager().reset();
0834:                m.getDocumentManager().addAltEntry(base0,
0835:                        "file:testing/ontology/relativenames.rdf");
0836:                m.read(base0, "RDF/XML");
0837:                assertNotNull("Should be a class ns0:A", m.getOntClass(ns0
0838:                        + "A"));
0839:                assertNull("Should not be a class ns1:A", m.getOntClass(ns1
0840:                        + "A"));
0841:
0842:                m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
0843:                m.getDocumentManager().reset();
0844:                m.getDocumentManager().addAltEntry(base0,
0845:                        "file:testing/ontology/relativenames.rdf");
0846:                m.read(base0, base1, "RDF/XML");
0847:                assertNull("Should not be a class ns0:A", m.getOntClass(ns0
0848:                        + "A"));
0849:                assertNotNull("Should be a class ns1:A", m.getOntClass(ns1
0850:                        + "A"));
0851:            }
0852:
0853:            public void testListDataRange() {
0854:                String base = "http://jena.hpl.hp.com/test#";
0855:                String doc = "<?xml version='1.0'?>"
0856:                        + "<!DOCTYPE owl ["
0857:                        + "      <!ENTITY rdf  'http://www.w3.org/1999/02/22-rdf-syntax-ns#' >"
0858:                        + "      <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#' >"
0859:                        + "      <!ENTITY xsd  'http://www.w3.org/2001/XMLSchema#' >"
0860:                        + "      <!ENTITY owl  'http://www.w3.org/2002/07/owl#' >"
0861:                        + "      <!ENTITY dc   'http://purl.org/dc/elements/1.1/' >"
0862:                        + "      <!ENTITY base  'http://jena.hpl.hp.com/test' >"
0863:                        + "    ]>"
0864:                        + "<rdf:RDF"
0865:                        + "   xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
0866:                        + "   xmlns:owl='http://www.w3.org/2002/07/owl#'>"
0867:                        + "  <owl:DataRange>"
0868:                        + "    <owl:oneOf>"
0869:                        + "      <rdf:List>"
0870:                        + "        <rdf:first rdf:datatype='&xsd;integer'>0</rdf:first>"
0871:                        + "        <rdf:rest rdf:resource='&rdf;nil' />"
0872:                        + "      </rdf:List>" + "    </owl:oneOf>"
0873:                        + "  </owl:DataRange>" + "</rdf:RDF>";
0874:
0875:                OntModel m = ModelFactory.createOntologyModel(
0876:                        OntModelSpec.OWL_MEM, null);
0877:                m.read(new StringReader(doc), base);
0878:
0879:                Iterator i = m.listDataRanges();
0880:                assertTrue("Should be at least one DataRange", i.hasNext());
0881:                Object dr = i.next();
0882:                assertInstanceOf(DataRange.class, dr);
0883:                assertFalse("Should no more DataRange", i.hasNext());
0884:            }
0885:
0886:            public void testListHierarchyRoots0() {
0887:                OntModel m = ModelFactory
0888:                        .createOntologyModel(OntModelSpec.OWL_MEM);
0889:                assertFalse(m.listHierarchyRootClasses().hasNext());
0890:                m = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
0891:                assertFalse(m.listHierarchyRootClasses().hasNext());
0892:            }
0893:
0894:            public void testListHierarchyRoots1() {
0895:                String doc = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. "
0896:                        + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. "
0897:                        + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. "
0898:                        + "@prefix owl: <http://www.w3.org/2002/07/owl#>. "
0899:                        + "@prefix : <" + NS + ">. " + ":A a owl:Class. ";
0900:
0901:                OntModel m = ModelFactory.createOntologyModel(
0902:                        OntModelSpec.OWL_MEM, null);
0903:                m.read(new StringReader(doc), NS, "N3");
0904:
0905:                OntClass a = m.getOntClass(NS + "A");
0906:                TestUtil.assertIteratorValues(this , m
0907:                        .listHierarchyRootClasses(), new Object[] { a });
0908:            }
0909:
0910:            public void testListHierarchyRoots2() {
0911:                String doc = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. "
0912:                        + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. "
0913:                        + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. "
0914:                        + "@prefix owl: <http://www.w3.org/2002/07/owl#>. "
0915:                        + "@prefix : <" + NS + ">. " + ":A a owl:Class. ";
0916:
0917:                OntModel m = ModelFactory.createOntologyModel(
0918:                        OntModelSpec.OWL_MEM_RULE_INF, null);
0919:                m.read(new StringReader(doc), NS, "N3");
0920:
0921:                OntClass a = m.getOntClass(NS + "A");
0922:                TestUtil.assertIteratorValues(this , m
0923:                        .listHierarchyRootClasses(), new Object[] { a });
0924:            }
0925:
0926:            public void testListHierarchyRoots3() {
0927:                String doc = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. "
0928:                        + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. "
0929:                        + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. "
0930:                        + "@prefix owl: <http://www.w3.org/2002/07/owl#>. "
0931:                        + "@prefix : <"
0932:                        + NS
0933:                        + ">. "
0934:                        + ":A a owl:Class. "
0935:                        + ":B a owl:Class ; rdfs:subClassOf :A . ";
0936:
0937:                OntModel m = ModelFactory.createOntologyModel(
0938:                        OntModelSpec.OWL_MEM_MINI_RULE_INF, null);
0939:                m.read(new StringReader(doc), NS, "N3");
0940:
0941:                OntClass a = m.getOntClass(NS + "A");
0942:                TestUtil.assertIteratorValues(this , m
0943:                        .listHierarchyRootClasses(), new Object[] { a });
0944:            }
0945:
0946:            public void testListHierarchyRoots4() {
0947:                String doc = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. "
0948:                        + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. "
0949:                        + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. "
0950:                        + "@prefix owl: <http://www.w3.org/2002/07/owl#>. "
0951:                        + "@prefix : <"
0952:                        + NS
0953:                        + ">. "
0954:                        + ":A a rdfs:Class. "
0955:                        + ":C a rdfs:Class. "
0956:                        + ":B a rdfs:Class ; rdfs:subClassOf :A . ";
0957:
0958:                OntModel m = ModelFactory.createOntologyModel(
0959:                        OntModelSpec.RDFS_MEM_RDFS_INF, null);
0960:                m.read(new StringReader(doc), NS, "N3");
0961:
0962:                OntClass a = m.getOntClass(NS + "A");
0963:                OntClass c = m.getOntClass(NS + "C");
0964:                TestUtil.assertIteratorValues(this , m
0965:                        .listHierarchyRootClasses(), new Object[] { a, c });
0966:            }
0967:
0968:            /* Auto-loading of imports is off by default */
0969:            public void testLoadImports0() {
0970:                OntModel m = ModelFactory
0971:                        .createOntologyModel(OntModelSpec.OWL_MEM);
0972:                Resource a = m
0973:                        .getResource("file:testing/ontology/testImport3/a.owl");
0974:                Resource b = m
0975:                        .getResource("file:testing/ontology/testImport3/b.owl");
0976:                m.add(a, m.getProfile().IMPORTS(), b);
0977:
0978:                // not dymamically imported by default
0979:                assertEquals("Marker count not correct", 0,
0980:                        TestOntDocumentManager.countMarkers(m));
0981:
0982:                assertFalse(
0983:                        "c should not be imported",
0984:                        m
0985:                                .hasLoadedImport("file:testing/ontology/testImport3/c.owl"));
0986:                assertFalse(
0987:                        "b should not be imported",
0988:                        m
0989:                                .hasLoadedImport("file:testing/ontology/testImport3/b.owl"));
0990:
0991:                m.loadImports();
0992:
0993:                assertEquals("Marker count not correct", 2,
0994:                        TestOntDocumentManager.countMarkers(m));
0995:
0996:                assertTrue(
0997:                        "c should be imported",
0998:                        m
0999:                                .hasLoadedImport("file:testing/ontology/testImport3/c.owl"));
1000:                assertTrue(
1001:                        "b should be imported",
1002:                        m
1003:                                .hasLoadedImport("file:testing/ontology/testImport3/b.owl"));
1004:            }
1005:
1006:            /* Auto-loading of imports = on */
1007:            public void testLoadImports1() {
1008:                OntModel m = ModelFactory
1009:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1010:                Resource a = m
1011:                        .getResource("file:testing/ontology/testImport3/a.owl");
1012:                Resource b = m
1013:                        .getResource("file:testing/ontology/testImport3/b.owl");
1014:
1015:                m.setDynamicImports(true);
1016:                m.add(a, m.getProfile().IMPORTS(), b);
1017:
1018:                assertEquals("Marker count not correct", 2,
1019:                        TestOntDocumentManager.countMarkers(m));
1020:
1021:                assertTrue(
1022:                        "c should be imported",
1023:                        m
1024:                                .hasLoadedImport("file:testing/ontology/testImport3/c.owl"));
1025:                assertTrue(
1026:                        "b should be imported",
1027:                        m
1028:                                .hasLoadedImport("file:testing/ontology/testImport3/b.owl"));
1029:
1030:                // this should have no effect
1031:                m.loadImports();
1032:
1033:                assertEquals("Marker count not correct", 2,
1034:                        TestOntDocumentManager.countMarkers(m));
1035:
1036:                assertTrue(
1037:                        "c should be imported",
1038:                        m
1039:                                .hasLoadedImport("file:testing/ontology/testImport3/c.owl"));
1040:                assertTrue(
1041:                        "b should be imported",
1042:                        m
1043:                                .hasLoadedImport("file:testing/ontology/testImport3/b.owl"));
1044:            }
1045:
1046:            /** Test getting conclusions after loading imports */
1047:            public void testAddImports0() {
1048:                OntModel base = ModelFactory
1049:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1050:
1051:                base.createClass(NS + "A");
1052:                base.createClass(NS + "B");
1053:
1054:                OntModel m = ModelFactory.createOntologyModel(
1055:                        OntModelSpec.OWL_MEM_MICRO_RULE_INF, base);
1056:
1057:                OntClass a = m.getOntClass(NS + "A");
1058:                OntClass b = m.getOntClass(NS + "B");
1059:
1060:                // nothing is known about a and b yet
1061:                assertFalse(a.hasSubClass(b));
1062:
1063:                // add some ontology data
1064:                OntModel imp = ModelFactory
1065:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1066:                imp.add(b, RDFS.subClassOf, a);
1067:
1068:                m.addSubModel(imp, true);
1069:                assertTrue(a.hasSubClass(b));
1070:            }
1071:
1072:            public void testAddImports1() {
1073:                String ns = "http://jena.hpl.hp.com/2003/03/testont";
1074:                OntModel base = ModelFactory
1075:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1076:
1077:                OntDocumentManager odm = OntDocumentManager.getInstance();
1078:                odm.addAltEntry(ns + "#a",
1079:                        "file:testing/ontology/testImport7/a.owl");
1080:
1081:                OntModel m = ModelFactory.createOntologyModel(
1082:                        OntModelSpec.OWL_MEM_MICRO_RULE_INF, base);
1083:
1084:                Ontology oo = base.createOntology(ns);
1085:                oo.addImport(base.createResource(ns + "#a"));
1086:
1087:                // nothing is known about a and b yet
1088:                Resource a = m.getResource(ns + "#A");
1089:                Resource c = m.getResource(ns + "#C");
1090:                assertFalse(m.contains(c, RDFS.subClassOf, a));
1091:
1092:                // when we load the imports, the odm must kick the reasoner with a rebind()
1093:                m.getDocumentManager().loadImports(m);
1094:                assertTrue(m.contains(c, RDFS.subClassOf, a));
1095:            }
1096:
1097:            /** Getting the deductions model of an OntModel
1098:             * see also {@link TestBugs#testOntModelGetDeductions()}
1099:             * <p>ijd: Feb 6th, 2008 - this test has been disabled for
1100:             * the time being, since it is not correct as written. However,
1101:             * I'm not removing or changing it just yet, since it is showing up
1102:             * an infelicity in the rule engine that Dave will investigate
1103:             * at some future date.</p>
1104:             * */
1105:            public void xxtestGetDeductionsModel0() {
1106:                OntModel m = ModelFactory
1107:                        .createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
1108:                OntClass a = m.createClass(NS + "A");
1109:                OntClass b = m.createClass(NS + "B");
1110:                OntClass c = m.createClass(NS + "C");
1111:
1112:                b.addSubClass(c);
1113:
1114:                // we see the entailments only in the deductions model
1115:                Model dm = m.getDeductionsModel();
1116:                assertTrue(dm.contains(OWL.Nothing, RDFS.subClassOf, a));
1117:                assertTrue(dm.contains(OWL.Nothing, RDFS.subClassOf, c));
1118:
1119:                a.addSubClass(b);
1120:
1121:                assertTrue(a.hasSubClass(c));
1122:
1123:                dm = m.getDeductionsModel();
1124:
1125:                assertFalse(dm.contains(OWL.Nothing, RDFS.subClassOf, a));
1126:                assertTrue(dm.contains(OWL.Nothing, RDFS.subClassOf, c));
1127:            }
1128:
1129:            // Internal implementation methods
1130:            //////////////////////////////////
1131:
1132:            /**
1133:             * Answer true iff an iterator contains a given value.
1134:             */
1135:            private boolean iteratorContains(Iterator i, Object x) {
1136:                boolean found = false;
1137:                while (i.hasNext()) {
1138:                    found = i.next().equals(x) || found;
1139:                }
1140:                return found;
1141:            }
1142:
1143:            //==============================================================================
1144:            // Inner class definitions
1145:            //==============================================================================
1146:
1147:            protected class OWLProfileExt extends OWLProfile {
1148:                public Map getSupportsMap() {
1149:                    return getCheckTable();
1150:                }
1151:            }
1152:
1153:            protected class OWLDLProfileExt extends OWLDLProfile {
1154:                public Map getSupportsMap() {
1155:                    return getCheckTable();
1156:                }
1157:            }
1158:
1159:            protected class OWLLiteProfileExt extends OWLLiteProfile {
1160:                public Map getSupportsMap() {
1161:                    return getCheckTable();
1162:                }
1163:            }
1164:        }
1165:
1166:        /*
1167:         (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
1168:         All rights reserved.
1169:
1170:         Redistribution and use in source and binary forms, with or without
1171:         modification, are permitted provided that the following conditions
1172:         are met:
1173:
1174:         1. Redistributions of source code must retain the above copyright
1175:         notice, this list of conditions and the following disclaimer.
1176:
1177:         2. Redistributions in binary form must reproduce the above copyright
1178:         notice, this list of conditions and the following disclaimer in the
1179:         documentation and/or other materials provided with the distribution.
1180:
1181:         3. The name of the author may not be used to endorse or promote products
1182:         derived from this software without specific prior written permission.
1183:
1184:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1185:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1186:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1187:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1188:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1189:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1190:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1191:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1192:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1193:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1194:         */
w_w_w__.___j__av__a___2___s__._co__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.