Source Code Cross Referenced for TestBugReports.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            16-Jun-2003
0009:         * Filename           $RCSfile: TestBugReports.java,v $
0010:         * Revision           $Revision: 1.93 $
0011:         * Release status     $State: Exp $
0012:         *
0013:         * Last modified on   $Date: 2008/01/23 14:31:14 $
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 junit.framework.TestCase;
0026:
0027:        import com.hp.hpl.jena.enhanced.EnhGraph;
0028:        import com.hp.hpl.jena.graph.*;
0029:        import com.hp.hpl.jena.graph.impl.SimpleGraphMaker;
0030:        import com.hp.hpl.jena.graph.impl.SimpleTransactionHandler;
0031:        import com.hp.hpl.jena.graph.query.SimpleQueryHandler;
0032:        import com.hp.hpl.jena.mem.faster.GraphMemFasterQueryHandler;
0033:        import com.hp.hpl.jena.ontology.*;
0034:        import com.hp.hpl.jena.ontology.impl.OntClassImpl;
0035:        import com.hp.hpl.jena.rdf.model.*;
0036:        import com.hp.hpl.jena.rdf.model.impl.ModelMakerImpl;
0037:        import com.hp.hpl.jena.reasoner.Reasoner;
0038:        import com.hp.hpl.jena.reasoner.ReasonerRegistry;
0039:        import com.hp.hpl.jena.reasoner.dig.*;
0040:        import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
0041:        import com.hp.hpl.jena.reasoner.rulesys.Rule;
0042:        import com.hp.hpl.jena.reasoner.test.TestUtil;
0043:        import com.hp.hpl.jena.shared.ClosedException;
0044:        import com.hp.hpl.jena.util.FileUtils;
0045:        import com.hp.hpl.jena.util.iterator.ExtendedIterator;
0046:        import com.hp.hpl.jena.vocabulary.*;
0047:
0048:        /**
0049:         * <p>
0050:         * Unit tests that are derived from user bug reports
0051:         * </p>
0052:         *
0053:         * @author Ian Dickinson, HP Labs (<a  href="mailto:Ian.Dickinson@hp.com" >
0054:         *         email</a>)
0055:         * @version CVS $Id: TestBugReports.java,v 1.23 2003/11/20 17:53:10
0056:         *          ian_dickinson Exp $
0057:         */
0058:        public class TestBugReports extends TestCase {
0059:            // Constants
0060:            //////////////////////////////////
0061:
0062:            public static String NS = "http://example.org/test#";
0063:
0064:            // Static variables
0065:            //////////////////////////////////
0066:
0067:            // Instance variables
0068:            //////////////////////////////////
0069:
0070:            public TestBugReports(String name) {
0071:                super (name);
0072:            }
0073:
0074:            // Constructors
0075:            //////////////////////////////////
0076:
0077:            // External signature methods
0078:            //////////////////////////////////
0079:
0080:            public void setUp() {
0081:                // ensure the ont doc manager is in a consistent state
0082:                OntDocumentManager.getInstance().reset(true);
0083:                OntDocumentManager.getInstance().setMetadataSearchPath(
0084:                        "file:etc/ont-policy.rdf", false);
0085:            }
0086:
0087:            /** Bug report by Danah Nada - listIndividuals returning too many results */
0088:            public void test_dn_0() {
0089:                OntModel schema = ModelFactory.createOntologyModel(
0090:                        OntModelSpec.OWL_LITE_MEM_RULES_INF, null);
0091:
0092:                schema.read("file:doc/inference/data/owlDemoSchema.xml", null);
0093:
0094:                int count = 0;
0095:                for (Iterator i = schema.listIndividuals(); i.hasNext();) {
0096:                    //Resource r = (Resource) i.next();
0097:                    i.next();
0098:                    count++;
0099:                    /* Debugging * /
0100:                    for (StmtIterator j = r.listProperties(RDF.type); j.hasNext(); ) {
0101:                        System.out.println( "ind - " + r + " rdf:type = " + j.nextStatement().getObject() );
0102:                    }
0103:                    System.out.println("----------"); /**/
0104:                }
0105:
0106:                assertEquals("Expecting 6 individuals", 6, count);
0107:            }
0108:
0109:            /* Bug report by Danah Nada - duplicate elements in property domain */
0110:            public void test_dn_01() {
0111:                // direct reading for the model method 1
0112:                OntModel m0 = ModelFactory.createOntologyModel(
0113:                        OntModelSpec.OWL_DL_MEM_RULE_INF, null);
0114:                m0.read("file:testing/ontology/bugs/test_hk_07B.owl");
0115:
0116:                OntProperty p0 = m0
0117:                        .getOntProperty("file:testing/ontology/bugs/test_hk_07B.owl#PropB");
0118:                int count = 0;
0119:                for (Iterator i = p0.listDomain(); i.hasNext();) {
0120:                    count++;
0121:                    i.next();
0122:                }
0123:                assertEquals(3, count);
0124:
0125:                // repeat test - thus using previously cached model for import
0126:
0127:                OntModel m1 = ModelFactory.createOntologyModel(
0128:                        OntModelSpec.OWL_DL_MEM_RULE_INF, null);
0129:                m1.read("file:testing/ontology/bugs/test_hk_07B.owl");
0130:
0131:                OntProperty p1 = m1
0132:                        .getOntProperty("file:testing/ontology/bugs/test_hk_07B.owl#PropB");
0133:                count = 0;
0134:                for (Iterator i = p1.listDomain(); i.hasNext();) {
0135:                    count++;
0136:                    i.next();
0137:                }
0138:                assertEquals(3, count);
0139:            }
0140:
0141:            /** Bug report by Danah Nada - cannot remove import */
0142:            public void test_dn_02() {
0143:                OntModel mymod = ModelFactory.createOntologyModel(
0144:                        OntModelSpec.OWL_MEM, null);
0145:                mymod.read("file:testing/ontology/testImport3/a.owl");
0146:
0147:                assertEquals("Graph count..", 2, mymod.getSubGraphs().size());
0148:
0149:                //        for (Iterator it = mymod.listImportedModels(); it.hasNext();) {
0150:                for (Iterator it = mymod.listSubModels(); it.hasNext();) {
0151:                    mymod.removeSubModel((Model) it.next());
0152:                }
0153:
0154:                assertEquals("Graph count..", 0, mymod.getSubGraphs().size());
0155:            }
0156:
0157:            /**
0158:             * Bug report by Mariano Rico Almod???var [Mariano.Rico@uam.es] on June 16th.
0159:             * Said to raise exception.
0160:             */
0161:            public void test_mra_01() {
0162:                OntModel m = ModelFactory.createOntologyModel(
0163:                        OntModelSpec.DAML_MEM, null, null);
0164:                String myDicURI = "http://somewhere/myDictionaries/1.0#";
0165:                String damlURI = "http://www.daml.org/2001/03/daml+oil#";
0166:                m.setNsPrefix("DAML", damlURI);
0167:
0168:                String c1_uri = myDicURI + "C1";
0169:                OntClass c1 = m.createClass(c1_uri);
0170:
0171:                DatatypeProperty p1 = m.createDatatypeProperty(myDicURI + "P1");
0172:                p1.setDomain(c1);
0173:
0174:                ByteArrayOutputStream strOut = new ByteArrayOutputStream();
0175:
0176:                m.write(strOut, "RDF/XML-ABBREV", myDicURI);
0177:                //m.write(System.out,"RDF/XML-ABBREV", myDicURI);
0178:
0179:            }
0180:
0181:            /**
0182:             * Bug report from Holger Knublauch on July 25th 2003. Cannot convert
0183:             * owl:Class to an OntClass
0184:             */
0185:            public void test_hk_01() {
0186:                // synthesise a mini-document
0187:                String base = "http://jena.hpl.hp.com/test#";
0188:                String doc = "<rdf:RDF"
0189:                        + "   xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""
0190:                        + "   xmlns:owl=\"http://www.w3.org/2002/07/owl#\">"
0191:                        + "  <owl:Ontology rdf:about=\"\">"
0192:                        + "    <owl:imports rdf:resource=\"http://www.w3.org/2002/07/owl\" />"
0193:                        + "  </owl:Ontology>" + "</rdf:RDF>";
0194:
0195:                // read in the base ontology, which includes the owl language
0196:                // definition
0197:                // note OWL_MEM => no reasoner is used
0198:                OntModel m = ModelFactory.createOntologyModel(
0199:                        OntModelSpec.OWL_MEM, null);
0200:                m.getDocumentManager().setMetadataSearchPath(
0201:                        "file:etc/ont-policy-test.rdf", true);
0202:                m.read(new ByteArrayInputStream(doc.getBytes()), base);
0203:
0204:                // we need a resource corresponding to OWL Class but in m
0205:                Resource owlClassRes = m.getResource(OWL.Class.getURI());
0206:
0207:                // now can we see this as an OntClass?
0208:                OntClass c = (OntClass) owlClassRes.as(OntClass.class);
0209:                assertNotNull("OntClass c should not be null", c);
0210:
0211:                //(OntClass) (ontModel.getProfile().CLASS()).as(OntClass.class);
0212:
0213:            }
0214:
0215:            /**
0216:             * Bug report from Hoger Knublauch on Aug 19th 2003. NPE when setting all
0217:             * distinct members
0218:             */
0219:            public void test_hk_02() {
0220:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
0221:                spec.setReasoner(null);
0222:                OntModel ontModel = ModelFactory
0223:                        .createOntologyModel(spec, null); // ProfileRegistry.OWL_LANG);
0224:                ontModel.createAllDifferent();
0225:                assertTrue(ontModel.listAllDifferent().hasNext());
0226:                AllDifferent allDifferent = (AllDifferent) ontModel
0227:                        .listAllDifferent().next();
0228:                //allDifferent.setDistinct(ontModel.createList());
0229:                assertFalse(allDifferent.listDistinctMembers().hasNext());
0230:            }
0231:
0232:            /** Bug report from Holger Knublauch on Aug 19th, 2003. Initialisation error */
0233:            public void test_hk_03() {
0234:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
0235:                spec.setReasoner(null);
0236:                OntModel ontModel = ModelFactory
0237:                        .createOntologyModel(spec, null);
0238:                OntProperty property = ontModel
0239:                        .createObjectProperty("http://www.aldi.de#property");
0240:                /* MinCardinalityRestriction testClass = */
0241:                ontModel.createMinCardinalityRestriction(null, property, 42);
0242:
0243:            }
0244:
0245:            /**
0246:             * Bug report from Holger Knublauch on Aug 19th, 2003. Document manager alt
0247:             * mechanism breaks relative name translation
0248:             */
0249:            public void test_hk_04() {
0250:                OntModel m = ModelFactory.createOntologyModel();
0251:                m
0252:                        .getDocumentManager()
0253:                        .addAltEntry(
0254:                                "http://jena.hpl.hp.com/testing/ontology/relativenames",
0255:                                "file:testing/ontology/relativenames.rdf");
0256:
0257:                m.read("http://jena.hpl.hp.com/testing/ontology/relativenames");
0258:                assertTrue(
0259:                        "#A should be a class",
0260:                        m
0261:                                .getResource(
0262:                                        "http://jena.hpl.hp.com/testing/ontology/relativenames#A")
0263:                                .canAs(OntClass.class));
0264:                assertFalse("file: #A should not be a class", m.getResource(
0265:                        "file:testing/ontology/relativenames.rdf#A").canAs(
0266:                        OntClass.class));
0267:            }
0268:
0269:            /** Bug report from Holger Knublach: not all elements of a union are removed */
0270:            public void test_hk_05() {
0271:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
0272:                spec.setReasoner(null);
0273:                OntModel ontModel = ModelFactory
0274:                        .createOntologyModel(spec, null);
0275:                String ns = "http://foo.bar/fu#";
0276:                OntClass a = ontModel.createClass(ns + "A");
0277:                OntClass b = ontModel.createClass(ns + "B");
0278:
0279:                int oldCount = getStatementCount(ontModel);
0280:
0281:                RDFList members = ontModel.createList(new RDFNode[] { a, b });
0282:                IntersectionClass intersectionClass = ontModel
0283:                        .createIntersectionClass(null, members);
0284:                intersectionClass.remove();
0285:
0286:                assertEquals("Before and after statement counts are different",
0287:                        oldCount, getStatementCount(ontModel));
0288:            }
0289:
0290:            /**
0291:             * Bug report from Holger Knublach: moving between ontology models - comes
0292:             * down to a test for a resource being in the base model
0293:             */
0294:            public void test_hk_06() throws Exception {
0295:                OntModel ontModel = ModelFactory.createOntologyModel(
0296:                        OntModelSpec.OWL_MEM, null);
0297:                ontModel.read("file:testing/ontology/bugs/test_hk_06/a.owl");
0298:
0299:                String NSa = "http://jena.hpl.hp.com/2003/03/testont/a#";
0300:                String NSb = "http://jena.hpl.hp.com/2003/03/testont/b#";
0301:
0302:                OntClass A = ontModel.getOntClass(NSa + "A");
0303:                assertTrue("class A should be in the base model", ontModel
0304:                        .isInBaseModel(A));
0305:
0306:                OntClass B = ontModel.getOntClass(NSb + "B");
0307:                assertFalse("class B should not be in the base model", ontModel
0308:                        .isInBaseModel(B));
0309:
0310:                assertTrue("A rdf:type owl:Class should be in the base model",
0311:                        ontModel.isInBaseModel(ontModel.createStatement(A,
0312:                                RDF.type, OWL.Class)));
0313:                assertFalse(
0314:                        "B rdf:type owl:Class should not be in the base model",
0315:                        ontModel.isInBaseModel(ontModel.createStatement(B,
0316:                                RDF.type, OWL.Class)));
0317:            }
0318:
0319:            /** Bug report 1408253 from Holger - rdfs:Datatype should be recognised as a RDFS class
0320:             * even without the reasoner
0321:             */
0322:            public void test_hk_07() {
0323:                // owl full
0324:                OntModel m = ModelFactory
0325:                        .createOntologyModel(OntModelSpec.OWL_MEM);
0326:                Resource c = m.createResource();
0327:                c.addProperty(RDF.type, RDFS.Datatype);
0328:                assertTrue(c.canAs(OntClass.class));
0329:
0330:                // owl dl
0331:                m = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
0332:                c = m.createResource();
0333:                c.addProperty(RDF.type, RDFS.Datatype);
0334:                assertTrue(c.canAs(OntClass.class));
0335:
0336:                // owl lite
0337:                m = ModelFactory.createOntologyModel(OntModelSpec.OWL_LITE_MEM);
0338:                c = m.createResource();
0339:                c.addProperty(RDF.type, RDFS.Datatype);
0340:                assertTrue(c.canAs(OntClass.class));
0341:
0342:                // rdfs
0343:                m = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
0344:                c = m.createResource();
0345:                c.addProperty(RDF.type, RDFS.Datatype);
0346:                assertTrue(c.canAs(OntClass.class));
0347:            }
0348:
0349:            public void test_hk_importCache() {
0350:                final String BASE = "http://protege.stanford.edu/plugins/owl/testdata/";
0351:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
0352:                spec.setReasoner(null);
0353:                OntDocumentManager dm = OntDocumentManager.getInstance();
0354:                dm.reset();
0355:                dm.setCacheModels(false);
0356:                dm
0357:                        .addAltEntry(
0358:                                "http://protege.stanford.edu/plugins/owl/testdata/Import-normalizerBug.owl",
0359:                                "file:testing/ontology/bugs/test_hk_import/Import-normalizerBug.owl");
0360:                dm
0361:                        .addAltEntry(
0362:                                "http://protege.stanford.edu/plugins/owl/testdata/normalizerBug.owl",
0363:                                "file:testing/ontology/bugs/test_hk_import/normalizerBug.owl");
0364:                spec.setDocumentManager(dm);
0365:
0366:                OntModel oldOntModel = ModelFactory.createOntologyModel(spec,
0367:                        null);
0368:                oldOntModel.read(BASE + "Import-normalizerBug.owl",
0369:                        FileUtils.langXMLAbbrev);
0370:                Graph oldSubGraph = (Graph) oldOntModel.getSubGraphs()
0371:                        .iterator().next();
0372:                final int oldTripleCount = getTripleCount(oldSubGraph);
0373:                OntClass ontClass = oldOntModel.getOntClass(BASE
0374:                        + "normalizerBug.owl#SuperClass");
0375:                oldSubGraph.add(new Triple(ontClass.asNode(),
0376:                        RDF.type.asNode(), OWL.DeprecatedClass.asNode()));
0377:                assertEquals(oldTripleCount + 1, getTripleCount(oldSubGraph));
0378:
0379:                // TODO this workaround to be removed
0380:                SimpleGraphMaker sgm = (SimpleGraphMaker) ((ModelMakerImpl) spec
0381:                        .getImportModelMaker()).getGraphMaker();
0382:                List toGo = new ArrayList();
0383:                for (Iterator i = sgm.listGraphs(); i.hasNext(); toGo.add(i
0384:                        .next())) {/**/
0385:                }
0386:                for (Iterator i = toGo.iterator(); i.hasNext(); sgm
0387:                        .removeGraph((String) i.next())) {/**/
0388:                }
0389:                dm.clearCache();
0390:
0391:                OntModel newOntModel = ModelFactory.createOntologyModel(spec,
0392:                        null);
0393:                newOntModel.read(BASE + "Import-normalizerBug.owl",
0394:                        FileUtils.langXMLAbbrev);
0395:                Graph newSubGraph = (Graph) newOntModel.getSubGraphs()
0396:                        .iterator().next();
0397:                assertFalse(newOntModel == oldOntModel); // OK!
0398:                assertFalse(newSubGraph == oldSubGraph); // FAILS!
0399:                final int newTripleCount = getTripleCount(newSubGraph);
0400:                assertEquals(oldTripleCount, newTripleCount);
0401:            }
0402:
0403:            private int getTripleCount(Graph graph) {
0404:                int count = 0;
0405:                for (Iterator it = graph.find(null, null, null); it.hasNext();) {
0406:                    it.next();
0407:                    count++;
0408:                }
0409:                return count;
0410:            }
0411:
0412:            /**
0413:             * Bug report by federico.carbone@bt.com, 30-July-2003. A literal can be
0414:             * turned into an individual.
0415:             */
0416:            public void test_fc_01() {
0417:                OntModel m = ModelFactory.createOntologyModel();
0418:
0419:                ObjectProperty p = m.createObjectProperty(NS + "p");
0420:                Restriction r = m.createRestriction(p);
0421:                HasValueRestriction hv = r.convertToHasValueRestriction(m
0422:                        .createTypedLiteral(1));
0423:
0424:                RDFNode n = hv.getHasValue();
0425:                assertFalse(
0426:                        "Should not be able to convert literal to individual",
0427:                        n.canAs(Individual.class));
0428:            }
0429:
0430:            /**
0431:             * Bug report by Christoph Kunze (Christoph.Kunz@iao.fhg.de). 18/Aug/03 No
0432:             * transaction support in ontmodel.
0433:             */
0434:            public void test_ck_01() {
0435:                MockTransactionHandler m_t = new MockTransactionHandler();
0436:                Graph g = Factory.createGraphMemWithTransactionHandler(m_t);
0437:                Model m0 = ModelFactory.createModelForGraph(g);
0438:                OntModel m1 = ModelFactory.createOntologyModel(
0439:                        OntModelSpec.OWL_LITE_MEM, m0);
0440:
0441:                assertFalse("should not initially be in a transaction",
0442:                        m_t.m_inTransaction);
0443:                m1.begin();
0444:                assertTrue("should be in a transaction", m_t.m_inTransaction);
0445:                m1.abort();
0446:                assertFalse("should not still be in transaction",
0447:                        m_t.m_inTransaction);
0448:                assertTrue("transaction should have been aborted",
0449:                        m_t.m_aborted);
0450:                m1.begin();
0451:                assertTrue("should be in a (new) transaction",
0452:                        m_t.m_inTransaction);
0453:                m1.commit();
0454:                assertFalse("should not be in transaction post-commit",
0455:                        m_t.m_inTransaction);
0456:                assertTrue("should be marked committed post-commit",
0457:                        m_t.m_committed);
0458:            }
0459:
0460:            /**
0461:             * Bug report by Christoph Kunz, 26/Aug/03. CCE when creating a statement
0462:             * from a vocabulary
0463:             *
0464:             */
0465:            public void test_ck_02() {
0466:                OntModel vocabModel = ModelFactory.createOntologyModel();
0467:                ObjectProperty p = vocabModel.createObjectProperty("p");
0468:                OntClass A = vocabModel.createClass("A");
0469:
0470:                OntModel workModel = ModelFactory.createOntologyModel();
0471:                Individual sub = workModel.createIndividual("uri1", A);
0472:                Individual obj = workModel.createIndividual("uri2", A);
0473:                workModel.createStatement(sub, p, obj);
0474:            }
0475:
0476:            /**
0477:             * Bug report from Christoph Kunz - reification problems and
0478:             * UnsupportedOperationException
0479:             */
0480:            public void test_ck_03() {
0481:                // part A - surprising reification
0482:                OntModel model1 = ModelFactory.createOntologyModel(
0483:                        OntModelSpec.DAML_MEM, null);
0484:                OntModel model2 = ModelFactory.createOntologyModel(
0485:                        OntModelSpec.DAML_MEM_RULE_INF, null);
0486:
0487:                Individual sub = model1.createIndividual("http://mytest#i1",
0488:                        model1.getProfile().CLASS());
0489:                OntProperty pred = model1.createOntProperty("http://mytest#");
0490:                Individual obj = model1.createIndividual("http://mytest#i2",
0491:                        model1.getProfile().CLASS());
0492:                OntProperty probabilityP = model1
0493:                        .createOntProperty("http://mytest#prob");
0494:
0495:                Statement st = model1.createStatement(sub, pred, obj);
0496:                model1.add(st);
0497:                st.createReifiedStatement().addLiteral(probabilityP, 0.9);
0498:                assertTrue("st should be reified", st.isReified());
0499:
0500:                Statement st2 = model2.createStatement(sub, pred, obj);
0501:                model2.add(st2);
0502:                st2.createReifiedStatement().addLiteral(probabilityP, 0.3);
0503:                assertTrue("st2 should be reified", st2.isReified());
0504:
0505:                sub.addLiteral(probabilityP, 0.3);
0506:                sub.removeAll(probabilityP).addLiteral(probabilityP, 0.3); //!!!
0507:                // exception
0508:
0509:                // Part B - exception in remove All
0510:                Individual sub2 = model2.createIndividual("http://mytest#i1",
0511:                        model1.getProfile().CLASS());
0512:
0513:                sub.addLiteral(probabilityP, 0.3);
0514:                sub.removeAll(probabilityP); //!!! exception
0515:
0516:                sub2.addLiteral(probabilityP, 0.3);
0517:                sub2.removeAll(probabilityP); //!!! exception
0518:
0519:            }
0520:
0521:            /**
0522:             * Bug report by sjooseng [sjooseng@hotmail.com]. CCE in listOneOf in
0523:             * Enumerated Class with DAML profile.
0524:             */
0525:            public void test_sjooseng_01() {
0526:                String source = "<rdf:RDF xmlns:daml='http://www.daml.org/2001/03/daml+oil#'"
0527:                        + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
0528:                        + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#' >"
0529:                        + "    <daml:Class rdf:about='http://localhost:8080/kc2c#C1'>"
0530:                        + "        <daml:subClassOf>"
0531:                        + "            <daml:Restriction>"
0532:                        + "                <daml:onProperty rdf:resource='http://localhost:8080/kc2c#p1'/>"
0533:                        + "                <daml:hasClass>"
0534:                        + "                    <daml:Class>"
0535:                        + "                        <daml:oneOf rdf:parseType=\"daml:collection\">"
0536:                        + "                            <daml:Thing rdf:about='http://localhost:8080/kc2c#i1'/>"
0537:                        + "                            <daml:Thing rdf:about='http://localhost:8080/kc2c#i2'/>"
0538:                        + "                        </daml:oneOf>"
0539:                        + "                    </daml:Class>"
0540:                        + "                </daml:hasClass>"
0541:                        + "            </daml:Restriction>"
0542:                        + "        </daml:subClassOf>"
0543:                        + "    </daml:Class>"
0544:                        + "    <daml:ObjectProperty rdf:about='http://localhost:8080/kc2c#p1'>"
0545:                        + "        <rdfs:label>p1</rdfs:label>"
0546:                        + "    </daml:ObjectProperty>" + "</rdf:RDF>";
0547:
0548:                OntModel m = ModelFactory
0549:                        .createOntologyModel(ProfileRegistry.DAML_LANG);
0550:                m.read(new ByteArrayInputStream(source.getBytes()),
0551:                        "http://localhost:8080/kc2c");
0552:
0553:                OntClass kc1 = m.getOntClass("http://localhost:8080/kc2c#C1");
0554:
0555:                boolean found = false;
0556:
0557:                Iterator it = kc1.listSuperClasses(false);
0558:                while (it.hasNext()) {
0559:                    OntClass oc = (OntClass) it.next();
0560:                    if (oc.isRestriction()) {
0561:                        Restriction r = oc.asRestriction();
0562:                        if (r.isSomeValuesFromRestriction()) {
0563:                            SomeValuesFromRestriction sr = r
0564:                                    .asSomeValuesFromRestriction();
0565:                            OntClass sc = (OntClass) sr.getSomeValuesFrom();
0566:                            if (sc.isEnumeratedClass()) {
0567:                                EnumeratedClass ec = sc.asEnumeratedClass();
0568:                                assertEquals("Enumeration size should be 2", 2,
0569:                                        ec.getOneOf().size());
0570:                                found = true;
0571:                            }
0572:                        }
0573:                    }
0574:                }
0575:
0576:                assertTrue(found);
0577:            }
0578:
0579:            /**
0580:             * Problem reported by Andy Seaborne - combine abox and tbox in RDFS with
0581:             * ontmodel
0582:             */
0583:            public void test_afs_01() {
0584:                String sourceT = "<rdf:RDF "
0585:                        + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
0586:                        + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
0587:                        + "   xmlns:owl=\"http://www.w3.org/2002/07/owl#\">"
0588:                        + "    <owl:Class rdf:about='http://example.org/foo#A'>"
0589:                        + "   </owl:Class>" + "</rdf:RDF>";
0590:
0591:                String sourceA = "<rdf:RDF "
0592:                        + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
0593:                        + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#' "
0594:                        + "   xmlns:owl=\"http://www.w3.org/2002/07/owl#\">"
0595:                        + "    <rdf:Description rdf:about='http://example.org/foo#x'>"
0596:                        + "    <rdf:type rdf:resource='http://example.org/foo#A' />"
0597:                        + "   </rdf:Description>" + "</rdf:RDF>";
0598:
0599:                Model tBox = ModelFactory.createDefaultModel();
0600:                tBox.read(new ByteArrayInputStream(sourceT.getBytes()),
0601:                        "http://example.org/foo");
0602:
0603:                Model aBox = ModelFactory.createDefaultModel();
0604:                aBox.read(new ByteArrayInputStream(sourceA.getBytes()),
0605:                        "http://example.org/foo");
0606:
0607:                Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
0608:                reasoner = reasoner.bindSchema(tBox);
0609:
0610:                OntModelSpec spec = new OntModelSpec(
0611:                        OntModelSpec.OWL_MEM_RULE_INF);
0612:                spec.setReasoner(reasoner);
0613:
0614:                OntModel m = ModelFactory.createOntologyModel(spec, aBox);
0615:
0616:                List inds = new ArrayList();
0617:                for (Iterator i = m.listIndividuals(); i.hasNext();) {
0618:                    inds.add(i.next());
0619:                }
0620:
0621:                assertTrue("x should be an individual", inds.contains(m
0622:                        .getResource("http://example.org/foo#x")));
0623:
0624:            }
0625:
0626:            /**
0627:             * Bug report by Thorsten Ottmann [Thorsten.Ottmann@rwth-aachen.de] -
0628:             * problem accessing elements of DAML list
0629:             */
0630:            public void test_to_01() {
0631:                String sourceT = "<rdf:RDF "
0632:                        + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
0633:                        + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
0634:                        + "    xmlns:daml='http://www.daml.org/2001/03/daml+oil#'>"
0635:                        + "  <daml:Class rdf:about='http://example.org/foo#A'>"
0636:                        + "    <daml:intersectionOf rdf:parseType=\"daml:collection\">"
0637:                        + "       <daml:Class rdf:ID=\"B\" />"
0638:                        + "       <daml:Class rdf:ID=\"C\" />"
0639:                        + "    </daml:intersectionOf>" + "  </daml:Class>"
0640:                        + "</rdf:RDF>";
0641:
0642:                OntModel m = ModelFactory.createOntologyModel(
0643:                        OntModelSpec.DAML_MEM, null);
0644:                m.read(new ByteArrayInputStream(sourceT.getBytes()),
0645:                        "http://example.org/foo");
0646:
0647:                OntClass A = m.getOntClass("http://example.org/foo#A");
0648:                assertNotNull(A);
0649:
0650:                IntersectionClass iA = A.asIntersectionClass();
0651:                assertNotNull(iA);
0652:
0653:                RDFList intersection = iA.getOperands();
0654:                assertNotNull(intersection);
0655:
0656:                assertEquals(2, intersection.size());
0657:                assertTrue(intersection.contains(m
0658:                        .getOntClass("http://example.org/foo#B")));
0659:                assertTrue(intersection.contains(m
0660:                        .getOntClass("http://example.org/foo#C")));
0661:            }
0662:
0663:            /**
0664:             * Bug report by Thorsten Liebig [liebig@informatik.uni-ulm.de] -
0665:             * SymmetricProperty etc not visible in list ont properties
0666:             */
0667:            public void test_tl_01() {
0668:                String sourceT = "<rdf:RDF "
0669:                        + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
0670:                        + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
0671:                        + "    xmlns:owl=\"http://www.w3.org/2002/07/owl#\">"
0672:                        + "   <owl:SymmetricProperty rdf:about='http://example.org/foo#p1'>"
0673:                        + "   </owl:SymmetricProperty>"
0674:                        + "   <owl:TransitiveProperty rdf:about='http://example.org/foo#p2'>"
0675:                        + "   </owl:TransitiveProperty>"
0676:                        + "   <owl:InverseFunctionalProperty rdf:about='http://example.org/foo#p3'>"
0677:                        + "   </owl:InverseFunctionalProperty>" + "</rdf:RDF>";
0678:
0679:                OntModel m = ModelFactory.createOntologyModel(
0680:                        OntModelSpec.OWL_MEM_RULE_INF, null);
0681:                m.read(new ByteArrayInputStream(sourceT.getBytes()),
0682:                        "http://example.org/foo");
0683:
0684:                boolean foundP1 = false;
0685:                boolean foundP2 = false;
0686:                boolean foundP3 = false;
0687:
0688:                // iterator of properties should include p1-3
0689:                for (Iterator i = m.listOntProperties(); i.hasNext();) {
0690:                    Resource r = (Resource) i.next();
0691:                    foundP1 = foundP1
0692:                            || r.getURI().equals("http://example.org/foo#p1");
0693:                    foundP2 = foundP2
0694:                            || r.getURI().equals("http://example.org/foo#p2");
0695:                    foundP3 = foundP3
0696:                            || r.getURI().equals("http://example.org/foo#p3");
0697:                }
0698:
0699:                assertTrue("p1 not listed", foundP1);
0700:                assertTrue("p2 not listed", foundP2);
0701:                assertTrue("p3 not listed", foundP3);
0702:
0703:                foundP1 = false;
0704:                foundP2 = false;
0705:                foundP3 = false;
0706:
0707:                // iterator of object properties should include p1-3
0708:                for (Iterator i = m.listObjectProperties(); i.hasNext();) {
0709:                    Resource r = (Resource) i.next();
0710:                    foundP1 = foundP1
0711:                            || r.getURI().equals("http://example.org/foo#p1");
0712:                    foundP2 = foundP2
0713:                            || r.getURI().equals("http://example.org/foo#p2");
0714:                    foundP3 = foundP3
0715:                            || r.getURI().equals("http://example.org/foo#p3");
0716:                }
0717:
0718:                assertTrue("p1 not listed", foundP1);
0719:                assertTrue("p2 not listed", foundP2);
0720:                assertTrue("p3 not listed", foundP3);
0721:            }
0722:
0723:            /** Bug report by Dave Reynolds - SF bug report 810492 */
0724:            public void test_der_01() {
0725:                OntModel m = ModelFactory.createOntologyModel(
0726:                        OntModelSpec.RDFS_MEM_TRANS_INF, null);
0727:                Resource a = m.createResource("http://example.org#A");
0728:                Resource b = m.createResource("http://example.org#B");
0729:                OntClass A = new OntClassImpl(a.asNode(), (EnhGraph) m) {
0730:                    protected boolean hasSuperClassDirect(Resource cls) {
0731:                        throw new RuntimeException(
0732:                                "did not find direct reasoner");
0733:                    }
0734:                };
0735:
0736:                // will throw an exception if the wrong code path is taken
0737:                A.hasSuperClass(b, true);
0738:            }
0739:
0740:            /**
0741:             * Bug report by Ivan Ferrari (ivan_ferrari_75 [ivan_ferrari_75@yahoo.it]) -
0742:             * duplicate nodes in output
0743:             */
0744:            public void test_if_01() {
0745:                //create a new default model
0746:                OntModel m = ModelFactory.createOntologyModel();
0747:
0748:                m.getDocumentManager().addAltEntry(
0749:                        "http://www.w3.org/2001/sw/WebOnt/guide-src/wine",
0750:                        "file:testing/ontology/bugs/oldwine.owl");
0751:                m.getDocumentManager().addAltEntry(
0752:                        "http://www.w3.org/2001/sw/WebOnt/guide-src/food",
0753:                        "file:testing/ontology/bugs/oldfood.owl");
0754:
0755:                // note: due to bug in the Wine example, we have to manually read the
0756:                // imported food document
0757:                m.getDocumentManager().setProcessImports(false);
0758:                m.read("http://www.w3.org/2001/sw/WebOnt/guide-src/wine");
0759:                m.getDocumentManager().setProcessImports(true);
0760:                m.getDocumentManager().loadImport(m,
0761:                        "http://www.w3.org/2001/sw/WebOnt/guide-src/food");
0762:
0763:                OntClass ontclass = m
0764:                        .getOntClass("http://www.w3.org/2001/sw/WebOnt/guide-src/wine#Wine");
0765:
0766:                int nNamed = 0;
0767:                int nRestriction = 0;
0768:                int nAnon = 0;
0769:
0770:                for (ExtendedIterator iter2 = ontclass.listSuperClasses(true); iter2
0771:                        .hasNext();) {
0772:                    OntClass ontsuper class = (OntClass) iter2.next();
0773:
0774:                    //this is to view different anonymous IDs
0775:                    if (!ontsuper class.isAnon()) {
0776:                        nNamed++;
0777:                    } else if (ontsuper class.canAs(Restriction.class)) {
0778:                        ontsuper class.asRestriction();
0779:                        nRestriction++;
0780:                    } else {
0781:                        //System.out.println("anon. super: " + ontsuperclass.getId());
0782:                        nAnon++;
0783:                    }
0784:                }
0785:
0786:                assertEquals("Should be two named super classes ", 2, nNamed);
0787:                assertEquals("Should be nine named super classes ", 9,
0788:                        nRestriction);
0789:                assertEquals("Should be no named super classes ", 0, nAnon);
0790:            }
0791:
0792:            /** Bug report by Lawrence Tay - missing datatype property */
0793:            public void test_lt_01() {
0794:                OntModel m = ModelFactory.createOntologyModel();
0795:
0796:                DatatypeProperty p = m.createDatatypeProperty(NS + "p");
0797:                OntClass c = m.createClass(NS + "A");
0798:
0799:                Individual i = m.createIndividual(NS + "i", c);
0800:                i.addProperty(p, "testData");
0801:
0802:                int count = 0;
0803:
0804:                for (Iterator j = i.listPropertyValues(p); j.hasNext();) {
0805:                    //System.err.println("Individual i has p value: " + j.next());
0806:                    j.next();
0807:                    count++;
0808:                }
0809:
0810:                assertEquals("i should have one property", 1, count);
0811:            }
0812:
0813:            /** Bug report by David Kensche [david.kensche@post.rwth-aachen.de] - NPE in listDeclaredProperties */
0814:            public void test_dk_01() {
0815:                OntModel m = ModelFactory.createOntologyModel();
0816:                m.read("file:testing/ontology/bugs/test_dk_01.xml");
0817:
0818:                String NS = "http://localhost:8080/Repository/QueryAgent/UserOntology/qgen-example-1#";
0819:                String[] classes = new String[] { NS + "C1", NS + "C3",
0820:                        NS + "C2" };
0821:
0822:                for (int i = 0; i < classes.length; i++) {
0823:                    OntClass c = m.getOntClass(classes[i]);
0824:                    for (Iterator j = c.listDeclaredProperties(); j.hasNext(); j
0825:                            .next()) {/**/
0826:                    }
0827:                }
0828:            }
0829:
0830:            /** Bug report by anon at SourceForge - Bug ID 887409 */
0831:            public void test_anon_0() {
0832:                String NS = "http://example.org/foo#";
0833:                String sourceT = "<rdf:RDF "
0834:                        + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
0835:                        + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
0836:                        + "    xmlns:ex='http://example.org/foo#'"
0837:                        + "    xmlns:owl='http://www.w3.org/2002/07/owl#'>"
0838:                        + "   <owl:ObjectProperty rdf:about='http://example.org/foo#p' />"
0839:                        + "   <owl:Class rdf:about='http://example.org/foo#A' />"
0840:                        + "   <ex:A rdf:about='http://example.org/foo#x' />"
0841:                        + "   <owl:Class rdf:about='http://example.org/foo#B'>"
0842:                        + "     <owl:equivalentClass>"
0843:                        + "      <owl:Restriction>"
0844:                        + "        <owl:onProperty rdf:resource='http://example.org/foo#p' />"
0845:                        + "        <owl:hasValue rdf:resource='http://example.org/foo#x' />"
0846:                        + "      </owl:Restriction>"
0847:                        + "     </owl:equivalentClass>" + "   </owl:Class>"
0848:                        + "</rdf:RDF>";
0849:
0850:                OntModel m = ModelFactory.createOntologyModel(
0851:                        OntModelSpec.OWL_MEM, null);
0852:                m.read(new ByteArrayInputStream(sourceT.getBytes()),
0853:                        "http://example.org/foo");
0854:
0855:                OntClass B = m.getOntClass(NS + "B");
0856:                Restriction r = B.getEquivalentClass().asRestriction();
0857:                HasValueRestriction hvr = r.asHasValueRestriction();
0858:                RDFNode n = hvr.getHasValue();
0859:
0860:                assertTrue("Should be an individual", n instanceof  Individual);
0861:            }
0862:
0863:            /** Bug report by Zhao Jun [jeff@seu.edu.cn] - throws no such element exception */
0864:            public void test_zj_0() {
0865:                String NS = "file:/C:/orel/orel0_5.owl#";
0866:                String sourceT = "<rdf:RDF "
0867:                        + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
0868:                        + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
0869:                        + "    xmlns:ex='http://example.org/foo#'"
0870:                        + "    xmlns:owl='http://www.w3.org/2002/07/owl#'"
0871:                        + "      xmlns:orel='file:/C:/orel/orel0_5.owl#'"
0872:                        + "      xml:base='file:/C:/orel/orel0_5.owl#'"
0873:                        + "      xmlns='file:/C:/orel/orel0_5.owl#'>"
0874:                        + " <owl:ObjectProperty rdf:ID='hasAgent' />"
0875:                        + " <owl:ObjectProperty rdf:ID='hasResource' />"
0876:                        + " <owl:Class rdf:ID='MyPlay'>"
0877:                        + "    <rdfs:subClassOf>"
0878:                        + "      <owl:Restriction>"
0879:                        + "        <owl:onProperty rdf:resource='file:/C:/orel/orel0_5.owl#hasResource'/>"
0880:                        + "        <owl:hasValue>"
0881:                        + "          <orel:Resource rdf:ID='myResource'>"
0882:                        + "            <orel:resourceURI>http://mp3.com/newcd/sample.mp3</orel:resourceURI>"
0883:                        + "          </orel:Resource>"
0884:                        + "        </owl:hasValue>"
0885:                        + "      </owl:Restriction>"
0886:                        + "    </rdfs:subClassOf>"
0887:                        + "    <rdfs:subClassOf rdf:resource='http://www.w3.org/2002/07/owl#Thing'/>"
0888:                        + "    <rdfs:subClassOf>"
0889:                        + "      <owl:Restriction>"
0890:                        + "        <owl:onProperty rdf:resource='file:/C:/orel/orel0_5.owl#hasAgent'/>"
0891:                        + "        <owl:hasValue>"
0892:                        + "          <orel:Agent rdf:ID='myAgent'>"
0893:                        + "            <orel:agentPK>123456789</orel:agentPK>"
0894:                        + "          </orel:Agent>"
0895:                        + "        </owl:hasValue>"
0896:                        + "      </owl:Restriction>"
0897:                        + "    </rdfs:subClassOf>"
0898:                        + "    <rdfs:subClassOf rdf:resource='file:/C:/orel/orel0_5.owl#Play'/>"
0899:                        + "  </owl:Class>" + "</rdf:RDF>";
0900:
0901:                OntModel m = ModelFactory.createOntologyModel(
0902:                        OntModelSpec.OWL_MEM_RULE_INF, null);
0903:                m.read(new ByteArrayInputStream(sourceT.getBytes()),
0904:                        "file:/C:/orel/orel0_5.owl");
0905:
0906:                OntClass myPlay = m.getOntClass(NS + "MyPlay");
0907:                for (Iterator i = myPlay.listDeclaredProperties(); i.hasNext();) {
0908:                    //System.err.println( "prop " + i.next() );
0909:                    i.next();
0910:                }
0911:            }
0912:
0913:            /** Bug report by Harry Chen - closed exception when reading many models */
0914:            public void test_hc_01() throws Exception {
0915:                for (int i = 0; i < 5; i++) {
0916:
0917:                    OntModel m = ModelFactory.createOntologyModel();
0918:
0919:                    FileInputStream ifs = new FileInputStream(
0920:                            "testing/ontology/relativenames.rdf");
0921:
0922:                    //System.out.println("Start reading...");
0923:                    m.read(ifs, "http://example.org/foo");
0924:                    //System.out.println("Done reading...");
0925:
0926:                    ifs.close();
0927:                    //System.out.println("Closed ifs");
0928:                    m.close();
0929:                    //System.out.println("Closed model");
0930:                }
0931:            }
0932:
0933:            /** Bug report by sinclair bain (slbain) SF bugID 912202 - NPE in createOntResource() when 2nd param is null */
0934:            public void test_sb_01() {
0935:                OntModel model = ModelFactory.createOntologyModel(
0936:                        OntModelSpec.OWL_MEM_RDFS_INF, null);
0937:
0938:                Resource result = null;
0939:                Resource nullValueForResourceType = null;
0940:
0941:                result = model.createOntResource(OntResource.class,
0942:                        nullValueForResourceType,
0943:                        "http://www.somewhere.com/models#SomeResourceName");
0944:                assertNotNull(result);
0945:            }
0946:
0947:            /* Bug report from Dave Reynolds: listDeclaredProperties not complete */
0948:            public void test_der_02() {
0949:                String SOURCE = "<?xml version='1.0'?>"
0950:                        + "<!DOCTYPE owl ["
0951:                        + "      <!ENTITY rdf  'http://www.w3.org/1999/02/22-rdf-syntax-ns#' >"
0952:                        + "      <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#' >"
0953:                        + "      <!ENTITY xsd  'http://www.w3.org/2001/XMLSchema#' >"
0954:                        + "      <!ENTITY owl  'http://www.w3.org/2002/07/owl#' >"
0955:                        + "      <!ENTITY dc   'http://purl.org/dc/elements/1.1/' >"
0956:                        + "      <!ENTITY base  'http://jena.hpl.hp.com/test' >"
0957:                        + "    ]>"
0958:                        + "<rdf:RDF xmlns:owl ='&owl;' xmlns:rdf='&rdf;' xmlns:rdfs='&rdfs;' xmlns:dc='&dc;' xmlns='&base;#' xml:base='&base;'>"
0959:                        + "  <owl:ObjectProperty rdf:ID='hasPublications'>"
0960:                        + "    <rdfs:domain>" + "      <owl:Class>"
0961:                        + "        <owl:unionOf rdf:parseType='Collection'>"
0962:                        + "          <owl:Class rdf:about='#Project'/>"
0963:                        + "          <owl:Class rdf:about='#Task'/>"
0964:                        + "        </owl:unionOf>" + "      </owl:Class>"
0965:                        + "    </rdfs:domain>"
0966:                        + "    <rdfs:domain rdf:resource='#Dummy' />"
0967:                        + "    <rdfs:range rdf:resource='#Publications'/>"
0968:                        + "  </owl:ObjectProperty>"
0969:                        + "  <owl:Class rdf:ID='Dummy'>" + "  </owl:Class>"
0970:                        + "</rdf:RDF>";
0971:                String NS = "http://jena.hpl.hp.com/test#";
0972:                OntModel m = ModelFactory.createOntologyModel(
0973:                        OntModelSpec.OWL_MEM_MICRO_RULE_INF, null);
0974:                m.read(new ByteArrayInputStream(SOURCE.getBytes()), NS);
0975:
0976:                //OntClass dummy = m.getOntClass( NS + "Dummy" );
0977:                // assert commented out - bug not accepted -ijd
0978:                //TestUtil.assertIteratorValues( this, dummy.listDeclaredProperties(),
0979:                //                               new Object[] {m.getObjectProperty( NS+"hasPublications")} );
0980:            }
0981:
0982:            /** Bug report from Dave - cycles checking code still not correct */
0983:            public void test_der_03() {
0984:                String NS = "http://jena.hpl.hp.com/test#";
0985:                OntModel om = ModelFactory
0986:                        .createOntologyModel(OntModelSpec.OWL_MEM);
0987:                OntClass A = om.createClass(NS + "A");
0988:                OntClass B = om.createClass(NS + "B");
0989:                OntClass C = om.createClass(NS + "C");
0990:                A.addSuperClass(B);
0991:                A.addSuperClass(C);
0992:                B.addSuperClass(C);
0993:                C.addSuperClass(B);
0994:
0995:                TestUtil.assertIteratorValues(this , A.listSuperClasses(true),
0996:                        new Object[] { B, C });
0997:            }
0998:
0999:            /**
1000:             * Bug report by pierluigi.damadio@katamail.com: raises conversion exception
1001:             */
1002:            public void test_pd_01() {
1003:                String SOURCE = "<?xml version='1.0'?>"
1004:                        + "<rdf:RDF"
1005:                        + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
1006:                        + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
1007:                        + "    xmlns:owl='http://www.w3.org/2002/07/owl#'"
1008:                        + "    xml:base='http://iasi.cnr.it/leks/localSchema1#'"
1009:                        + "    xmlns:test='http://iasi.cnr.it/test/test1#'"
1010:                        + "    xmlns='http://iasi.cnr.it/test/test1#'>"
1011:                        + "    <owl:Ontology rdf:about=''/>"
1012:                        + "    <owl:Class rdf:ID='Hotel'/>"
1013:                        + "    <owl:Class rdf:ID='Hotel5Stars'>"
1014:                        + "        <rdfs:subClassOf>"
1015:                        + "            <owl:Restriction>"
1016:                        + "                <owl:onProperty rdf:resource='#hasCategory'/>"
1017:                        + "                <owl:hasValue rdf:resource='#Category5'/>"
1018:                        + "            </owl:Restriction>"
1019:                        + "        </rdfs:subClassOf>"
1020:                        + "    </owl:Class>"
1021:                        + "    <owl:DatatypeProperty rdf:ID='hasCategory'>"
1022:                        + "        <rdfs:range rdf:resource='http://www.w3.org/2001/XMLSchema#string'/>"
1023:                        + "        <rdfs:domain rdf:resource='#Hotel'/>"
1024:                        + "        <rdf:type rdf:resource='http://www.w3.org/2002/07/owl#FunctionalProperty'/>"
1025:                        + "    </owl:DatatypeProperty>"
1026:                        + "    <owl:Thing rdf:ID='Category5'/>" + "</rdf:RDF>";
1027:                String NS = "http://iasi.cnr.it/leks/localSchema1#";
1028:                OntModel m = ModelFactory.createOntologyModel(
1029:                        OntModelSpec.OWL_DL_MEM, null);
1030:                m.read(new ByteArrayInputStream(SOURCE.getBytes()), NS);
1031:
1032:                for (ExtendedIterator j = m.listRestrictions(); j.hasNext();) {
1033:                    Restriction r = (Restriction) j.next();
1034:                    if (r.isHasValueRestriction()) {
1035:                        HasValueRestriction hv = r.asHasValueRestriction();
1036:                        hv.getHasValue().toString();
1037:                    }
1038:                }
1039:            }
1040:
1041:            /** Bug report from Ole Hjalmar - direct subClassOf not reporting correct result with rule reasoner */
1042:            public void xxtest_oh_01() {
1043:                String NS = "http://www.idi.ntnu.no/~herje/ja/";
1044:                Resource[] expected = new Resource[] {
1045:                        ResourceFactory.createResource(NS
1046:                                + "reiseliv.owl#Reiseliv"),
1047:                        ResourceFactory
1048:                                .createResource(NS + "hotell.owl#Hotell"),
1049:                        ResourceFactory.createResource(NS
1050:                                + "restaurant.owl#Restaurant"),
1051:                        ResourceFactory.createResource(NS
1052:                                + "restaurant.owl#UteRestaurant"),
1053:                        ResourceFactory.createResource(NS
1054:                                + "restaurant.owl#UteBadRestaurant"),
1055:                        ResourceFactory.createResource(NS
1056:                                + "restaurant.owl#UteDoRestaurant"),
1057:                        ResourceFactory.createResource(NS
1058:                                + "restaurant.owl#SkogRestaurant"), };
1059:
1060:                test_oh_01scan(OntModelSpec.OWL_MEM, "No inf", expected);
1061:                test_oh_01scan(OntModelSpec.OWL_MEM_MINI_RULE_INF,
1062:                        "Mini rule inf", expected);
1063:                test_oh_01scan(OntModelSpec.OWL_MEM_RULE_INF, "Full rule inf",
1064:                        expected);
1065:                test_oh_01scan(OntModelSpec.OWL_MEM_MICRO_RULE_INF,
1066:                        "Micro rule inf", expected);
1067:            }
1068:
1069:            private void test_oh_01scan(OntModelSpec s, String prompt,
1070:                    Resource[] expected) {
1071:                String NS = "http://www.idi.ntnu.no/~herje/ja/reiseliv.owl#";
1072:                OntModel m = ModelFactory.createOntologyModel(s, null);
1073:                m.read("file:testing/ontology/bugs/test_oh_01.owl");
1074:
1075:                System.out.println(prompt);
1076:                OntClass r = m.getOntClass(NS + "Reiseliv");
1077:                List q = new ArrayList();
1078:                Set seen = new HashSet();
1079:                q.add(r);
1080:
1081:                while (!q.isEmpty()) {
1082:                    OntClass c = (OntClass) q.remove(0);
1083:                    seen.add(c);
1084:
1085:                    for (Iterator i = c.listSubClasses(true); i.hasNext();) {
1086:                        OntClass sub = (OntClass) i.next();
1087:                        if (!seen.contains(sub)) {
1088:                            q.add(sub);
1089:                        }
1090:                    }
1091:
1092:                    System.out.println("  Seen class " + c);
1093:                }
1094:
1095:                // check we got all classes
1096:                int mask = (1 << expected.length) - 1;
1097:
1098:                for (int j = 0; j < expected.length; j++) {
1099:                    if (seen.contains(expected[j])) {
1100:                        mask &= ~(1 << j);
1101:                    } else {
1102:                        System.out.println("Expected but did not see "
1103:                                + expected[j]);
1104:                    }
1105:                }
1106:
1107:                for (Iterator k = seen.iterator(); k.hasNext();) {
1108:                    Resource res = (Resource) k.next();
1109:                    boolean isExpected = false;
1110:                    for (int j = 0; !isExpected && j < expected.length; j++) {
1111:                        isExpected = expected[j].equals(res);
1112:                    }
1113:                    if (!isExpected) {
1114:                        System.out.println("Got unexpected result " + res);
1115:                    }
1116:                }
1117:
1118:                assertEquals("Some expected results were not seen", 0, mask);
1119:            }
1120:
1121:            /** Test case for SF bug 927641 - list direct subclasses */
1122:            public void test_sf_927641() {
1123:                String NS = "http://example.org/test#";
1124:                OntModel m0 = ModelFactory
1125:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1126:                OntClass c0 = m0.createClass(NS + "C0");
1127:                OntClass c1 = m0.createClass(NS + "C1");
1128:                OntClass c2 = m0.createClass(NS + "C2");
1129:                OntClass c3 = m0.createClass(NS + "C3");
1130:
1131:                c0.addSubClass(c1);
1132:                c1.addSubClass(c2);
1133:                c2.addEquivalentClass(c3);
1134:
1135:                // now c1 is the direct super-class of c2, even allowing for the equiv with c3
1136:                assertFalse("pass 1: c0 should not be a direct super of c2", c2
1137:                        .hasSuperClass(c0, true));
1138:                assertFalse("pass 1: c3 should not be a direct super of c2", c2
1139:                        .hasSuperClass(c3, true));
1140:                assertFalse("pass 1: c2 should not be a direct super of c2", c2
1141:                        .hasSuperClass(c2, true));
1142:                assertTrue("pass 1: c1 should be a direct super of c2", c2
1143:                        .hasSuperClass(c1, true));
1144:
1145:                // second pass - with inference
1146:                m0 = ModelFactory
1147:                        .createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF);
1148:                c0 = m0.createClass(NS + "C0");
1149:                c1 = m0.createClass(NS + "C1");
1150:                c2 = m0.createClass(NS + "C2");
1151:                c3 = m0.createClass(NS + "C3");
1152:
1153:                c0.addSubClass(c1);
1154:                c1.addSubClass(c2);
1155:                c2.addEquivalentClass(c3);
1156:
1157:                // now c1 is the direct super-class of c2, even allowing for the equiv with c3
1158:                assertFalse("pass 2: c0 should not be a direct super of c2", c2
1159:                        .hasSuperClass(c0, true));
1160:                assertFalse("pass 2: c3 should not be a direct super of c2", c2
1161:                        .hasSuperClass(c3, true));
1162:                assertFalse("pass 2: c2 should not be a direct super of c2", c2
1163:                        .hasSuperClass(c2, true));
1164:                assertTrue("pass 2: c1 should be a direct super of c2", c2
1165:                        .hasSuperClass(c1, true));
1166:            }
1167:
1168:            /** Test case for SF bug 934528 - conversion exception with owl:Thing and owl:Nothing when no reasoner */
1169:            public void test_sf_934528() {
1170:                OntModel m = ModelFactory
1171:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1172:
1173:                Resource r = (Resource) OWL.Thing.inModel(m);
1174:                OntClass thingClass = (OntClass) r.as(OntClass.class);
1175:                assertNotNull(thingClass);
1176:
1177:                r = (Resource) OWL.Nothing.inModel(m);
1178:                OntClass nothingClass = (OntClass) r.as(OntClass.class);
1179:                assertNotNull(nothingClass);
1180:
1181:                OntClass c = m.getOntClass(OWL.Thing.getURI());
1182:                assertNotNull(c);
1183:                assertEquals(c, OWL.Thing);
1184:
1185:                c = m.getOntClass(OWL.Nothing.getURI());
1186:                assertNotNull(c);
1187:                assertEquals(c, OWL.Nothing);
1188:            }
1189:
1190:            /** Test case for SF bug 937810 - NPE from ModelSpec.getDescription() */
1191:            /* Test removed 16-Jan-07 following refactoring of ModelSpec code */
1192:            //    public void test_sf_937810() throws IllegalAccessException {
1193:            //        Field[] specs = OntModelSpec.class.getDeclaredFields();
1194:            //
1195:            //        for (int i = 0;  i < specs.length;  i++) {
1196:            //            if (Modifier.isPublic( specs[i].getModifiers()) &&
1197:            //                Modifier.isStatic( specs[i].getModifiers()) &&
1198:            //                specs[i].getType().equals( OntModelSpec.class )) {
1199:            //                OntModelSpec s = (OntModelSpec) specs[i].get( null );
1200:            //                assertNotNull( s.getDescription() );
1201:            //            }
1202:            //        }
1203:            //    }
1204:            /** Test case for SF bug 940570 - listIndividuals not working with RDFS_INF
1205:             */
1206:            public void test_sf_940570() {
1207:                OntModel m = ModelFactory
1208:                        .createOntologyModel(OntModelSpec.OWL_MEM_RDFS_INF);
1209:                OntClass C = m.createClass(NS + "C");
1210:                Resource a = m.createResource(NS + "a", C);
1211:
1212:                TestUtil.assertIteratorValues(this , m.listIndividuals(),
1213:                        new Object[] { a });
1214:
1215:                OntModel dm = ModelFactory
1216:                        .createOntologyModel(OntModelSpec.DAML_MEM_RULE_INF);
1217:                OntClass D = dm.createClass(NS + "D");
1218:                Resource b = dm.createResource(NS + "b", D);
1219:
1220:                TestUtil.assertIteratorValues(this , dm.listIndividuals(),
1221:                        new Object[] { b });
1222:            }
1223:
1224:            /** Test case for SF bug 940570 - listIndividuals not working with RDFS_INF (rdfs case)
1225:             */
1226:            public void test_sf_940570_rdfs() {
1227:                OntModel m = ModelFactory
1228:                        .createOntologyModel(OntModelSpec.OWL_MEM_RDFS_INF);
1229:                OntClass C = m.createClass(NS + "C");
1230:                Resource a = m.createResource(NS + "a", C);
1231:
1232:                TestUtil.assertIteratorValues(this , m.listIndividuals(),
1233:                        new Object[] { a });
1234:            }
1235:
1236:            /** Test case for SF bug 940570 - listIndividuals not working with RDFS_INF (daml case)
1237:             */
1238:            public void test_sf_940570_daml() {
1239:                OntModel dm = ModelFactory
1240:                        .createOntologyModel(OntModelSpec.DAML_MEM_RULE_INF);
1241:                OntClass D = dm.createClass(NS + "D");
1242:                Resource b = dm.createResource(NS + "b", D);
1243:
1244:                TestUtil.assertIteratorValues(this , dm.listIndividuals(),
1245:                        new Object[] { b });
1246:            }
1247:
1248:            /** Test case for SF bug 945436 - a xml:lang='' in the dataset causes sring index exception in getLabel() */
1249:            public void test_sf_945436() {
1250:                String SOURCE = "<?xml version='1.0'?>"
1251:                        + "<!DOCTYPE owl ["
1252:                        + "      <!ENTITY rdf  'http://www.w3.org/1999/02/22-rdf-syntax-ns#' >"
1253:                        + "      <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#' >"
1254:                        + "      <!ENTITY xsd  'http://www.w3.org/2001/XMLSchema#' >"
1255:                        + "      <!ENTITY owl  'http://www.w3.org/2002/07/owl#' >"
1256:                        + "      <!ENTITY dc   'http://purl.org/dc/elements/1.1/' >"
1257:                        + "      <!ENTITY base  'http://jena.hpl.hp.com/test' >"
1258:                        + "    ]>"
1259:                        + "<rdf:RDF xmlns:owl ='&owl;' xmlns:rdf='&rdf;' xmlns:rdfs='&rdfs;' xmlns:dc='&dc;' xmlns='&base;#' xml:base='&base;'>"
1260:                        + "  <C rdf:ID='x'>"
1261:                        + "    <rdfs:label xml:lang=''>a_label</rdfs:label>"
1262:                        + "  </C>" + "  <owl:Class rdf:ID='C'>"
1263:                        + "  </owl:Class>" + "</rdf:RDF>";
1264:                OntModel m = ModelFactory
1265:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1266:                m.read(new StringReader(SOURCE), null);
1267:                Individual x = m.getIndividual("http://jena.hpl.hp.com/test#x");
1268:                assertEquals("Label on resource x", "a_label", x.getLabel(null));
1269:                assertEquals("Label on resource x", "a_label", x.getLabel(""));
1270:                assertSame("fr label on resource x", null, x.getLabel("fr"));
1271:            }
1272:
1273:            /** Test case for SF bug 948995  - OWL full should allow inverse functional datatype properties */
1274:            public void test_sf_948995() {
1275:                OntModel m = ModelFactory
1276:                        .createOntologyModel(OntModelSpec.OWL_DL_MEM); // OWL dl
1277:                DatatypeProperty dp = m.createDatatypeProperty(NS + "dp");
1278:                dp.addRDFType(OWL.InverseFunctionalProperty);
1279:
1280:                boolean ex = false;
1281:                try {
1282:                    dp.as(InverseFunctionalProperty.class);
1283:                } catch (ConversionException e) {
1284:                    ex = true;
1285:                }
1286:                assertTrue("Should have been a conversion exception", ex);
1287:
1288:                m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); // OWL full
1289:                dp = m.createDatatypeProperty(NS + "dp");
1290:                dp.addRDFType(OWL.InverseFunctionalProperty);
1291:
1292:                ex = false;
1293:                try {
1294:                    dp.as(InverseFunctionalProperty.class);
1295:                } catch (ConversionException e) {
1296:                    ex = true;
1297:                }
1298:                assertFalse("Should not have been a conversion exception", ex);
1299:            }
1300:
1301:            /** Test case for SF bug 969475 - the return value for getInverse() on an ObjectProperty should be an object property */
1302:            public void test_sf_969475() {
1303:                String SOURCE = "<?xml version='1.0'?>"
1304:                        + "<!DOCTYPE owl ["
1305:                        + "      <!ENTITY rdf  'http://www.w3.org/1999/02/22-rdf-syntax-ns#' >"
1306:                        + "      <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#' >"
1307:                        + "      <!ENTITY xsd  'http://www.w3.org/2001/XMLSchema#' >"
1308:                        + "      <!ENTITY owl  'http://www.w3.org/2002/07/owl#' >"
1309:                        + "      <!ENTITY dc   'http://purl.org/dc/elements/1.1/' >"
1310:                        + "      <!ENTITY base  'http://jena.hpl.hp.com/test' >"
1311:                        + "    ]>"
1312:                        + "<rdf:RDF xmlns:owl ='&owl;' xmlns:rdf='&rdf;' xmlns:rdfs='&rdfs;' xmlns:dc='&dc;' xmlns='&base;#' xml:base='&base;'>"
1313:                        + "  <owl:ObjectProperty rdf:ID='p0'>"
1314:                        + "    <owl:inverseOf>"
1315:                        + "      <owl:ObjectProperty rdf:ID='q0' />"
1316:                        + "    </owl:inverseOf>" + "  </owl:ObjectProperty>"
1317:                        + "  <owl:ObjectProperty rdf:ID='p1'>"
1318:                        + "    <owl:inverseOf>"
1319:                        + "      <owl:ObjectProperty rdf:ID='q1' />"
1320:                        + "    </owl:inverseOf>" + "  </owl:ObjectProperty>"
1321:                        + "</rdf:RDF>";
1322:                OntModel m = ModelFactory
1323:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1324:                m.read(new StringReader(SOURCE), null);
1325:
1326:                ObjectProperty p0 = m
1327:                        .getObjectProperty("http://jena.hpl.hp.com/test#p0");
1328:                Object invP0 = p0.getInverseOf();
1329:
1330:                assertEquals(m.getResource("http://jena.hpl.hp.com/test#q0"),
1331:                        invP0);
1332:                assertTrue("Should be an ObjectProperty facet",
1333:                        invP0 instanceof  ObjectProperty);
1334:
1335:                ObjectProperty q1 = m
1336:                        .getObjectProperty("http://jena.hpl.hp.com/test#q1");
1337:                Object invQ1 = q1.getInverse();
1338:
1339:                assertEquals(m.getResource("http://jena.hpl.hp.com/test#p1"),
1340:                        invQ1);
1341:                assertTrue("Should be an ObjectProperty facet",
1342:                        invQ1 instanceof  ObjectProperty);
1343:            }
1344:
1345:            /** Test case for SF bug 978259 - missing supports() checks in OWL DL and Lite profiles */
1346:            public void test_sf_978259() {
1347:                OntModel md = ModelFactory
1348:                        .createOntologyModel(OntModelSpec.OWL_DL_MEM);
1349:                OntModel ml = ModelFactory
1350:                        .createOntologyModel(OntModelSpec.OWL_LITE_MEM);
1351:
1352:                DataRange drd = md.createDataRange(md
1353:                        .createList(new Resource[] { OWL.Thing }));
1354:                assertNotNull(drd);
1355:                HasValueRestriction hvrd = md.createHasValueRestriction(null,
1356:                        RDFS.seeAlso, OWL.Thing);
1357:                assertNotNull(hvrd);
1358:
1359:                boolean ex = false;
1360:                try {
1361:                    drd = ml.createDataRange(md
1362:                            .createList(new Resource[] { OWL.Thing }));
1363:                } catch (ProfileException e) {
1364:                    ex = true;
1365:                }
1366:                assertTrue(ex);
1367:
1368:                ex = false;
1369:                try {
1370:                    hvrd = ml.createHasValueRestriction(null, RDFS.seeAlso,
1371:                            OWL.Thing);
1372:                } catch (ProfileException e) {
1373:                    ex = true;
1374:                }
1375:                assertTrue(ex);
1376:            }
1377:
1378:            /**
1379:             * Bug report by Jessica Brown jessicabrown153@yahoo.com: listIndividuals() fails
1380:             * on a composite model in Jena 2.5
1381:             */
1382:            public void test_jb_01() {
1383:                Model schema = ModelFactory.createDefaultModel();
1384:                Model data = ModelFactory.createDefaultModel();
1385:                Resource c = schema
1386:                        .createResource("http://example.com/foo#AClass");
1387:                Resource i = data
1388:                        .createResource("http://example.com/foo#anInd");
1389:                schema.add(c, RDF.type, OWL.Class);
1390:                data.add(i, RDF.type, c);
1391:
1392:                OntModel composite = ModelFactory.createOntologyModel(
1393:                        OntModelSpec.OWL_MEM, schema);
1394:                composite.addSubModel(data);
1395:
1396:                Set s = composite.listIndividuals().toSet();
1397:                assertEquals("should be one individual", 1, s.size());
1398:                assertTrue(s.contains(i));
1399:            }
1400:
1401:            /**
1402:             * Bug report by James Tizard - failure in listIndividuals with DIGexception causes
1403:             * blocked thread
1404:             */
1405:            public void test_jt_01() {
1406:                // set up a configuration resource to connect to the reasoner
1407:                // on port 2004 on the local system
1408:                Model cModel = ModelFactory.createDefaultModel();
1409:                Resource conf = cModel.createResource();
1410:                conf.addProperty(ReasonerVocabulary.EXT_REASONER_URL, cModel
1411:                        .createResource("http://localhost:2004"));
1412:
1413:                // create the reasoner factory and the reasoner
1414:                DIGReasonerFactory drf = (DIGReasonerFactory) ReasonerRegistry
1415:                        .theRegistry().getFactory(DIGReasonerFactory.URI);
1416:                DIGReasoner r = (DIGReasoner) drf.create(conf);
1417:
1418:                // now make a model
1419:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
1420:                spec.setReasoner(r);
1421:                OntModel m = ModelFactory.createOntologyModel(spec, null);
1422:
1423:                boolean ex = false;
1424:                try {
1425:                    Iterator i = m.listIndividuals(); // if this throws a DIG exception
1426:                    System.out.println(i.hasNext()); // then this doesn't return
1427:                } catch (DIGWrappedException e) {
1428:                    ex = true;
1429:                }
1430:                assertTrue(
1431:                        "Should have seen a dig wrapped exception for connection fail",
1432:                        ex);
1433:            }
1434:
1435:            /**
1436:             * Bug report by David Bigwood - listDeclaredProps(false) fails when props
1437:             * are defined in an imported model
1438:             */
1439:            public void test_dab_01() {
1440:                OntModel m0 = ModelFactory
1441:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1442:
1443:                // in model M0, p0 has class c0 in the domain
1444:                OntClass c0 = m0.createClass(NS + "c0");
1445:                ObjectProperty p0 = m0.createObjectProperty(NS + "p0");
1446:                p0.setDomain(c0);
1447:
1448:                // in model M1, class c1 is a subClass of c0
1449:                OntModel m1 = ModelFactory
1450:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1451:                OntClass c1 = m1.createClass(NS + "c1");
1452:                c1.addSuperClass(c0);
1453:
1454:                // simulate imports
1455:                m1.addSubModel(m0);
1456:
1457:                // get a c0 reference from m1
1458:                OntClass cc0 = m1.getOntClass(NS + "c0");
1459:                assertNotNull(cc0);
1460:
1461:                TestUtil.assertIteratorValues(this ,
1462:                        c1.listDeclaredProperties(), new Object[] { p0 });
1463:                TestUtil.assertIteratorValues(this , c0
1464:                        .listDeclaredProperties(false), new Object[] { p0 });
1465:
1466:                // this is the one that fails per David's bug report
1467:                TestUtil.assertIteratorValues(this , cc0
1468:                        .listDeclaredProperties(false), new Object[] { p0 });
1469:            }
1470:
1471:            /**
1472:             * Bug report by David Bigwood - listUnionClasses causes conversion exception
1473:             */
1474:            public void test_dab_02a() {
1475:                String SOURCEA = "<rdf:RDF"
1476:                        + "    xmlns:rdf          ='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
1477:                        + "    xmlns:owl          ='http://www.w3.org/2002/07/owl#'"
1478:                        + "    xml:base           ='http://example.com/a#'"
1479:                        + ">"
1480:                        + "<rdf:Description>"
1481:                        + "  <owl:unionOf "
1482:                        + "  rdf:resource='http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'/> "
1483:                        + "</rdf:Description>" + "</rdf:RDF>";
1484:
1485:                OntModel a0 = ModelFactory
1486:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1487:                a0.read(new StringReader(SOURCEA), null);
1488:
1489:                // throws conversion exception ...
1490:                for (Iterator i = a0.listUnionClasses(); i.hasNext();) {
1491:                    i.next();
1492:                }
1493:
1494:                OntModel a1 = ModelFactory
1495:                        .createOntologyModel(OntModelSpec.OWL_DL_MEM);
1496:                a1.read(new StringReader(SOURCEA), null);
1497:
1498:                // throws conversion exception ...
1499:                for (Iterator i = a1.listUnionClasses(); i.hasNext();) {
1500:                    i.next();
1501:                }
1502:            }
1503:
1504:            public void test_dab_02b() {
1505:                String SOURCEA = "<rdf:RDF"
1506:                        + "    xmlns:rdf          ='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
1507:                        + "    xmlns:owl          ='http://www.w3.org/2002/07/owl#'"
1508:                        + "    xml:base           ='http://example.com/a#'"
1509:                        + ">"
1510:                        + "<rdf:Description>"
1511:                        + "  <owl:intersectionOf "
1512:                        + "  rdf:resource='http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'/> "
1513:                        + "</rdf:Description>" + "</rdf:RDF>";
1514:
1515:                OntModel a0 = ModelFactory
1516:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1517:                a0.read(new StringReader(SOURCEA), null);
1518:
1519:                // throws conversion exception ...
1520:                for (Iterator i = a0.listIntersectionClasses(); i.hasNext();) {
1521:                    i.next();
1522:                }
1523:
1524:                OntModel a1 = ModelFactory
1525:                        .createOntologyModel(OntModelSpec.OWL_DL_MEM);
1526:                a1.read(new StringReader(SOURCEA), null);
1527:
1528:                // throws conversion exception ...
1529:                for (Iterator i = a1.listIntersectionClasses(); i.hasNext();) {
1530:                    i.next();
1531:                }
1532:
1533:                OntModel a2 = ModelFactory
1534:                        .createOntologyModel(OntModelSpec.OWL_LITE_MEM);
1535:                a2.read(new StringReader(SOURCEA), null);
1536:
1537:                // throws conversion exception ...
1538:                for (Iterator i = a2.listIntersectionClasses(); i.hasNext();) {
1539:                    i.next();
1540:                }
1541:            }
1542:
1543:            public void test_dab_02c() {
1544:                String SOURCEA = "<rdf:RDF"
1545:                        + "    xmlns:rdf          ='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
1546:                        + "    xmlns:owl          ='http://www.w3.org/2002/07/owl#'"
1547:                        + "    xml:base           ='http://example.com/a#'"
1548:                        + ">"
1549:                        + "<rdf:Description>"
1550:                        + "  <owl:complementOf "
1551:                        + "  rdf:resource='http://www.w3.org/2002/07/owl#Nothing'/> "
1552:                        + "</rdf:Description>" + "</rdf:RDF>";
1553:
1554:                OntModel a0 = ModelFactory
1555:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1556:                a0.read(new StringReader(SOURCEA), null);
1557:
1558:                // throws conversion exception ...
1559:                for (Iterator i = a0.listComplementClasses(); i.hasNext();) {
1560:                    i.next();
1561:                }
1562:
1563:                OntModel a1 = ModelFactory
1564:                        .createOntologyModel(OntModelSpec.OWL_DL_MEM);
1565:                a1.read(new StringReader(SOURCEA), null);
1566:
1567:                // throws conversion exception ...
1568:                for (Iterator i = a1.listComplementClasses(); i.hasNext();) {
1569:                    i.next();
1570:                }
1571:            }
1572:
1573:            /**
1574:             * Bug report by Othmane Nadjemi - DAML individual whose only type is daml:Thing
1575:             * returns false to isIndividual()
1576:             */
1577:            public void test_on_01() {
1578:                OntModel m = ModelFactory
1579:                        .createOntologyModel(OntModelSpec.DAML_MEM);
1580:                Individual i = m.createIndividual(DAML_OIL.Thing);
1581:                assertTrue(i.isIndividual());
1582:            }
1583:
1584:            /**
1585:             * Bug report by kers - maximal lower elements calculation not correct in models
1586:             * with no reasoner. Manifests as direct sub-class bug.
1587:             */
1588:            public void test_kers_01() {
1589:                OntModel m = ModelFactory
1590:                        .createOntologyModel(OntModelSpec.RDFS_MEM);
1591:                OntClass r = m.createClass(NS + "r");
1592:                OntClass a = m.createClass(NS + "a");
1593:                OntClass b = m.createClass(NS + "b");
1594:                OntClass c = m.createClass(NS + "c");
1595:                OntClass d = m.createClass(NS + "d");
1596:                OntClass e = m.createClass(NS + "e");
1597:                OntClass f = m.createClass(NS + "f");
1598:                OntClass g = m.createClass(NS + "g");
1599:
1600:                g.addSuperClass(c);
1601:                f.addSuperClass(c);
1602:                e.addSuperClass(b);
1603:                d.addSuperClass(b);
1604:                c.addSuperClass(a);
1605:                b.addSuperClass(a);
1606:
1607:                // simulated closure
1608:                r.addSubClass(a);
1609:                r.addSubClass(b);
1610:                r.addSubClass(c);
1611:                r.addSubClass(d);
1612:                r.addSubClass(e);
1613:                r.addSubClass(f);
1614:                r.addSubClass(g);
1615:
1616:                TestUtil.assertIteratorValues(this , r.listSubClasses(true),
1617:                        new Object[] { a });
1618:            }
1619:
1620:            public void test_kers_02() {
1621:                OntModel A = ModelFactory
1622:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1623:                Model B = ModelFactory.createDefaultModel();
1624:                assertTrue(A.getGraph().queryHandler() instanceof  SimpleQueryHandler);
1625:                assertTrue(B.getGraph().queryHandler() instanceof  GraphMemFasterQueryHandler);
1626:                assertTrue(A.getBaseModel().getGraph().queryHandler() instanceof  GraphMemFasterQueryHandler);
1627:            }
1628:
1629:            /**
1630:             * Bug report by Andrew Moreton - addSubModel/removeSubmodel not working from
1631:             * Jena 2.1 to Jena 2.2
1632:             * Variant 1: base = no inf, import = no inf
1633:             */
1634:            public void test_am_01() {
1635:                OntModel m0 = ModelFactory
1636:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1637:                OntModel m1 = ModelFactory
1638:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1639:
1640:                OntClass c = m1.createClass(NS + "c");
1641:
1642:                assertFalse(m0.containsResource(c));
1643:
1644:                m0.addSubModel(m1);
1645:                assertTrue(m0.containsResource(c));
1646:
1647:                m0.removeSubModel(m1);
1648:                assertFalse(m0.containsResource(c));
1649:            }
1650:
1651:            /**
1652:             * Bug report by Andrew Moreton - addSubModel/removeSubmodel not working from
1653:             * Jena 2.1 to Jena 2.2
1654:             * Variant 2: base = inf, import = no inf
1655:             */
1656:            public void test_am_02() {
1657:                OntDocumentManager.getInstance().setProcessImports(false);
1658:                OntDocumentManager.getInstance().addAltEntry(
1659:                        "http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine",
1660:                        "file:testing/ontology/owl/Wine/wine.owl");
1661:                OntModel m0 = ModelFactory
1662:                        .createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
1663:                OntModel m1 = ModelFactory
1664:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1665:
1666:                String namespace = "http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine";
1667:                String classURI = namespace + "#Wine";
1668:                m1.read(namespace);
1669:                OntClass c = m1.getOntClass(classURI);
1670:
1671:                assertFalse(m0.containsResource(c));
1672:                m0.addSubModel(m1);
1673:                assertTrue(m0.containsResource(c));
1674:                m0.removeSubModel(m1);
1675:                assertFalse(m0.containsResource(c));
1676:            }
1677:
1678:            /**
1679:             * Bug report by Andrew Moreton - addSubModel/removeSubmodel not working from
1680:             * Jena 2.1 to Jena 2.2
1681:             * Variant 3: base = no inf, import = inf
1682:             */
1683:            public void test_am_03() {
1684:                OntModel m0 = ModelFactory
1685:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1686:                OntModel m1 = ModelFactory
1687:                        .createOntologyModel(OntModelSpec.OWL_MEM_RDFS_INF);
1688:
1689:                OntClass c = m1.createClass(NS + "c");
1690:
1691:                assertFalse(m0.containsResource(c));
1692:
1693:                m0.addSubModel(m1);
1694:                assertTrue(m0.containsResource(c));
1695:
1696:                m0.removeSubModel(m1);
1697:                assertFalse(m0.containsResource(c));
1698:            }
1699:
1700:            /**
1701:             * Bug report by Andrew Moreton - addSubModel/removeSubmodel not working from
1702:             * Jena 2.1 to Jena 2.2
1703:             * Variant 4: base = inf, import = inf
1704:             */
1705:            public void test_am_04() {
1706:                OntModel m0 = ModelFactory
1707:                        .createOntologyModel(OntModelSpec.OWL_MEM_RDFS_INF);
1708:                OntModel m1 = ModelFactory
1709:                        .createOntologyModel(OntModelSpec.OWL_MEM_RDFS_INF);
1710:
1711:                OntClass c = m1.createClass(NS + "c");
1712:
1713:                assertFalse(m0.containsResource(c));
1714:
1715:                m0.addSubModel(m1);
1716:                assertTrue(m0.containsResource(c));
1717:
1718:                m0.removeSubModel(m1);
1719:                assertFalse(m0.containsResource(c));
1720:            }
1721:
1722:            /**
1723:                The default namespace pefix of a non-base-model should not manifest as the
1724:                 default namespace prefix of the base model or the Ont model.
1725:             */
1726:            public void testHolgersPolyadicPrefixMappingBug() {
1727:                final String IMPORTED_NAMESPACE = "http://imported#";
1728:                final String LOCAL_NAMESPACE = "http://local#";
1729:                Model importedModel = ModelFactory.createDefaultModel();
1730:                importedModel.setNsPrefix("", IMPORTED_NAMESPACE);
1731:                OntModel ontModel = ModelFactory.createOntologyModel();
1732:                ontModel.setNsPrefix("", LOCAL_NAMESPACE);
1733:                ontModel.addSubModel(importedModel);
1734:                assertNull(ontModel.getNsURIPrefix(IMPORTED_NAMESPACE));
1735:            }
1736:
1737:            /**
1738:             * <p>Bug report by Tina (shilei_back06@yahoo.com.cn) - NPE in listHierarchyRootClasses
1739:             * with generic rule reasoner.</p>
1740:             */
1741:            public void test_tina_01() {
1742:                String rule = "(?x rdf:type rdfs:Class) -> (?x rdf:type owl:Class).";
1743:                Reasoner reasoner = new GenericRuleReasoner(Rule
1744:                        .parseRules(rule));
1745:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
1746:                spec.setReasoner(reasoner);
1747:                OntModel ml = ModelFactory.createOntologyModel(spec, null);
1748:
1749:                Iterator it3 = ml.listHierarchyRootClasses();
1750:                while (it3.hasNext()) {
1751:                    it3.next();
1752:                }
1753:            }
1754:
1755:            /**
1756:             * Bug report by mongolito_404 - closed models used in imports raise an exception
1757:             */
1758:            public void test_mongolito_01() {
1759:                String SOURCEA = "<rdf:RDF"
1760:                        + "    xmlns:rdf          ='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
1761:                        + "    xmlns:owl          ='http://www.w3.org/2002/07/owl#'"
1762:                        + "    xml:base           ='http://example.com/a#'"
1763:                        + ">"
1764:                        + "  <owl:Ontology>"
1765:                        + "          <owl:imports rdf:resource='http://example.com/b' />"
1766:                        + "  </owl:Ontology>" + "</rdf:RDF>";
1767:
1768:                OntDocumentManager.getInstance().addAltEntry(
1769:                        "http://example.com/b",
1770:                        "file:testing/ontology/bugs/test_dk_01.xml");
1771:
1772:                OntModel a0 = ModelFactory
1773:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1774:                a0.read(new StringReader(SOURCEA), null);
1775:                long a0count = a0.size();
1776:
1777:                // key step - close a model which is now in the ODM cache
1778:                OntDocumentManager.getInstance().getModel(
1779:                        "http://example.com/b").close();
1780:
1781:                // this line threw an exception before the bug was fixed
1782:                OntModel a1 = ModelFactory
1783:                        .createOntologyModel(OntModelSpec.OWL_MEM);
1784:                a1.read(new StringReader(SOURCEA), null);
1785:
1786:                // for completeness, check that we have read the same contents
1787:                assertEquals("Models should be same size", a0count, a1.size());
1788:            }
1789:
1790:            /** IsIndividual reported not to work with default rdfs reasoner
1791:             */
1792:            public void test_isindividual() {
1793:                OntModel defModel = ModelFactory.createOntologyModel();
1794:                OntClass c = defModel.createClass("http://example.com/test#A");
1795:                Individual i = c.createIndividual();
1796:                assertTrue("i should be an individual", i.isIndividual());
1797:            }
1798:
1799:            /** Reported NPE with owl lite profile */
1800:            public void test_getClassOwlLite() {
1801:                OntModel m = ModelFactory
1802:                        .createOntologyModel(OntModelSpec.OWL_LITE_MEM);
1803:                // throws NPE
1804:                m.getOntClass("http://example.com/foo");
1805:            }
1806:
1807:            /** This underpins a problem I'm having with imports processing */
1808:            public void xxtestModelMakerOpen() {
1809:                ModelMaker mm = ModelFactory.createMemModelMaker();
1810:                Model m = mm.openModel("http://example.com/foo");
1811:                assertTrue(m.isEmpty());
1812:
1813:                m.close();
1814:
1815:                boolean closed = false;
1816:                Model m0 = mm.openModel("http://example.com/foo");
1817:                try {
1818:                    assertTrue(m0.isEmpty());
1819:                } catch (ClosedException unexpected) {
1820:                    closed = true;
1821:                }
1822:                assertFalse("ModelMaker.openModel returned a closed model",
1823:                        closed);
1824:            }
1825:
1826:            /** User requested default prefixes for xsd:, and daml: is now deprecated */
1827:            public void testDefaultPrefixeOWL() {
1828:                OntModel m = ModelFactory.createOntologyModel();
1829:                assertFalse("owl:".equals(m.expandPrefix("owl:")));
1830:            }
1831:
1832:            /** User requested default prefixes for xsd:, and daml: is now deprecated */
1833:            public void testDefaultPrefixeRDF() {
1834:                OntModel m = ModelFactory.createOntologyModel();
1835:                assertFalse("rdf:".equals(m.expandPrefix("rdf:")));
1836:            }
1837:
1838:            /** User requested default prefixes for xsd:, and daml: is now deprecated */
1839:            public void testDefaultPrefixeRDFS() {
1840:                OntModel m = ModelFactory.createOntologyModel();
1841:                assertFalse("rdfs:".equals(m.expandPrefix("rdfs:")));
1842:            }
1843:
1844:            /** User requested default prefixes for xsd:, and daml: is now deprecated */
1845:            public void testDefaultPrefixeXSD() {
1846:                OntModel m = ModelFactory.createOntologyModel();
1847:                assertFalse("xsd:".equals(m.expandPrefix("xsd:")));
1848:            }
1849:
1850:            /** User requested default prefixes for xsd:, and daml: is now deprecated */
1851:            public void testDefaultPrefixeDAML() {
1852:                OntModel m = ModelFactory.createOntologyModel();
1853:                assertEquals("daml:", m.expandPrefix("daml:"));
1854:            }
1855:
1856:            /** User requested default prefixes for xsd:, and daml: is now deprecated */
1857:            public void testDefaultPrefixeDC() {
1858:                OntModel m = ModelFactory.createOntologyModel();
1859:                assertEquals("dc:", m.expandPrefix("dc:"));
1860:            }
1861:
1862:            // Internal implementation methods
1863:            //////////////////////////////////
1864:
1865:            private int getStatementCount(OntModel ontModel) {
1866:                int count = 0;
1867:                for (Iterator it = ontModel.listStatements(); it.hasNext(); it
1868:                        .next()) {
1869:                    count++;
1870:                }
1871:                return count;
1872:            }
1873:
1874:            //==============================================================================
1875:            // Inner class definitions
1876:            //==============================================================================
1877:
1878:            static class MockTransactionHandler extends
1879:                    SimpleTransactionHandler {
1880:                boolean m_inTransaction = false;
1881:                boolean m_aborted = false;
1882:                boolean m_committed = false;
1883:
1884:                public void begin() {
1885:                    m_inTransaction = true;
1886:                }
1887:
1888:                public void abort() {
1889:                    m_inTransaction = false;
1890:                    m_aborted = true;
1891:                }
1892:
1893:                public void commit() {
1894:                    m_inTransaction = false;
1895:                    m_committed = true;
1896:                }
1897:            }
1898:        }
1899:
1900:        /*
1901:         * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP All rights
1902:         * reserved.
1903:         *
1904:         * Redistribution and use in source and binary forms, with or without
1905:         * modification, are permitted provided that the following conditions are met:
1906:         *  1. Redistributions of source code must retain the above copyright notice,
1907:         * this list of conditions and the following disclaimer.
1908:         *  2. Redistributions in binary form must reproduce the above copyright
1909:         * notice, this list of conditions and the following disclaimer in the
1910:         * documentation and/or other materials provided with the distribution.
1911:         *  3. The name of the author may not be used to endorse or promote products
1912:         * derived from this software without specific prior written permission.
1913:         *
1914:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
1915:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1916:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
1917:         * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1918:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
1919:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
1920:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
1921:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
1922:         * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
1923:         * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1924:         */
w___w__w__.jav_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.