|                                                                                                              1
 10  package com.hp.hpl.jena.reasoner.rulesys.test;
 11
 12  import java.io.*;
 13
 14  import com.hp.hpl.jena.datatypes.TypeMapper;
 15  import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
 16  import com.hp.hpl.jena.ontology.*;
 17  import com.hp.hpl.jena.ontology.daml.DAMLModel;
 18  import com.hp.hpl.jena.rdf.model.*;
 19  import com.hp.hpl.jena.reasoner.*;
 20  import com.hp.hpl.jena.reasoner.rulesys.*;
 21  import com.hp.hpl.jena.reasoner.test.TestUtil;
 22  import com.hp.hpl.jena.util.*;
 23  import com.hp.hpl.jena.util.iterator.ClosableIterator;
 24  import com.hp.hpl.jena.util.iterator.ExtendedIterator;
 25  import com.hp.hpl.jena.vocabulary.*;
 26
 27  import junit.framework.TestCase;
 28  import junit.framework.TestSuite;
 29
 30  import java.util.*;
 31
 32
 38  public class TestBugs extends TestCase {
 39
 40
 43      public TestBugs( String
  name ) { 44          super( name );
 45      }
 46
 47
 51      public static TestSuite suite() {
 52          return new TestSuite( TestBugs.class );
 53      }
 57
 58      public void setUp() {
 59                  OntDocumentManager.getInstance().reset( true );
 61      }
 62
 63
 67      public void testIntersectionNPE() {
 68          Model base = ModelFactory.createDefaultModel();
 69          base.read("file:testing/reasoners/bugs/bad-intersection.owl");
 70          boolean foundBadList = false;
 71          try {
 72              InfGraph infgraph = ReasonerRegistry.getOWLReasoner().bind(base.getGraph());
 73              ExtendedIterator ci = infgraph.find(null, RDF.Nodes.type, OWL.Class.asNode());
 74              ci.close();
 75          } catch (ReasonerException e) {
 76              foundBadList = true;
 77          }
 78          assertTrue("Correctly detected the illegal list", foundBadList);
 79      }
 80
 81
 85      public void testCardinality1() {
 86          Model base = ModelFactory.createDefaultModel();
 87          base.read("file:testing/reasoners/bugs/cardFPTest.owl");
 88          InfModel test = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), base);
 89          String
  NAMESPACE = "urn:foo#"; 90          Resource aDocument = test.getResource(NAMESPACE + "aDocument");
 91          Resource documentType = test.getResource(NAMESPACE + "Document");
 92          assertTrue("Cardinality-based classification", test.contains(aDocument, RDF.type, documentType));
 93      }
 94
 95
 99      public void testFunctorCCE() {
 100         Model base = ModelFactory.createDefaultModel();
 101         base.read("file:testing/reasoners/bugs/cceTest.owl");
 102         InfModel test = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), base);
 103
 104         boolean b = anyInstancesOfNothing(test);
 105         ResIterator rIter = test.listSubjects();
 106         while (rIter.hasNext()) {
 107             Resource res = rIter.nextResource();
 108         }
 109     }
 110
 111
 112     private boolean anyInstancesOfNothing(Model model) {
 113         boolean hasAny = false;
 114         try {
 115             ExtendedIterator it = model.listStatements(null, RDF.type, OWL.Nothing);
 116             hasAny = it.hasNext();
 117             it.close();
 118         } catch (ConversionException x) {
 119             hasAny = false;
 120         }
 121         return hasAny;
 122     }
 123
 124
 127     public void testDAMLCCE() {
 128         DAMLModel m = ModelFactory.createDAMLModel();
 129         m.getDocumentManager().setMetadataSearchPath( "file:etc/ont-policy-test.rdf", true );
 130         m.read( "file:testing/reasoners/bugs/literalLeak.daml",
 131                 "http://www.daml.org/2001/03/daml+oil-ex",  null );
 132         ResIterator rIter = m.listSubjects();
 133         while (rIter.hasNext()) {
 134             Resource res = rIter.nextResource();
 135             if (res.getNode().isLiteral()) {
 136                 assertTrue("Error in resource " + res, false);
 137             }
 138         }
 139     }
 140
 141     public static final String
  INPUT_SUBCLASS = 142         "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
 143         "" +
 144         "<rdf:RDF" +
 145         "    xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"" +
 146         "    xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"" +
 147         "    xmlns:daml=\"http://www.daml.org/2001/03/daml+oil#\"" +
 148         "    xmlns:ex=\"http://localhost:8080/axis/daml/a.daml#\"" +
 149         "    xml:base=\"http://localhost:8080/axis/daml/a.daml\">" +
 150         " " +
 151         "    <daml:Ontology rdf:about=\"\">" +
 152         "        <daml:imports rdf:resource=\"http://www.daml.org/2001/03/daml+oil\"/>" +
 153         "    </daml:Ontology>" +
 154         " " +
 155         "    <daml:Class rdf:ID=\"cls1\"/>" +
 156         "    <daml:Class rdf:ID=\"cls2\">" +
 157         "        <daml:subClassOf rdf:resource=\"#cls1\"/>" +
 158         "    </daml:Class>" +
 159         "    <ex:cls2 rdf:ID=\"test\"/>" +
 160         "</rdf:RDF>";
 161
 162
 167     public void testSubClass() {
 168         OntModel model = ModelFactory.createOntologyModel(OntModelSpec.DAML_MEM_RDFS_INF, null);
 169         model.getDocumentManager().setMetadataSearchPath( "file:etc/ont-policy-test.rdf", true );
 170
 171         String
  base = "http://localhost:8080/axis/daml/a.daml#"; 172         model.read( new ByteArrayInputStream( INPUT_SUBCLASS.getBytes() ), base );
 173         OntResource res = (OntResource) model.getResource( base+"test").as(OntResource.class);
 174
 175         OntClass cls1 = (OntClass) model.getResource(base+"cls1").as(OntClass.class);
 176         OntClass cls2 = (OntClass) model.getResource(base+"cls2").as(OntClass.class);
 177
 178         assertTrue( "cls2 should be a super-class of cls1", cls2.hasSuperClass( cls1 ) );
 179         assertTrue( "res should have rdf:type cls1", res.hasRDFType( cls1 ) );
 180         assertTrue( "res should have rdf:type cls2", res.hasRDFType( cls2 ) );
 181     }
 182
 183     public static final String
  INPUT_SUBPROPERTY = 184         "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
 185         "" +
 186         "<rdf:RDF" +
 187         "    xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"" +
 188         "    xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"" +
 189         "    xmlns:daml=\"http://www.daml.org/2001/03/daml+oil#\"" +
 190         "    xmlns=\"urn:x-hp-jena:test#\"" +
 191         "    xml:base=\"urn:x-hp-jena:test\">" +
 192         " " +
 193         "    <daml:Ontology rdf:about=\"\">" +
 194         "        <daml:imports rdf:resource=\"http://www.daml.org/2001/03/daml+oil\"/>" +
 195         "    </daml:Ontology>" +
 196         " " +
 197         "    <daml:Class rdf:ID=\"A\"/>" +
 198         "" +
 199         "    <daml:ObjectProperty rdf:ID=\"p\" />" +
 200         "    <daml:ObjectProperty rdf:ID=\"q\">" +
 201         "        <daml:subPropertyOf rdf:resource=\"#p\"/>" +
 202         "    </daml:ObjectProperty>" +
 203         "" +
 204         "    <A rdf:ID=\"a0\"/>" +
 205         "    <A rdf:ID=\"a1\">" +
 206         "       <q rdf:resource=\"#a0\" />" +
 207         "    </A>" +
 208         "</rdf:RDF>";
 209
 210
 215     public void testSubProperty() {
 216         OntModel model = ModelFactory.createOntologyModel(OntModelSpec.DAML_MEM_RDFS_INF, null);
 217
 218         String
  base = "urn:x-hp-jena:test#"; 219         model.read( new ByteArrayInputStream( INPUT_SUBPROPERTY.getBytes() ), base );
 220
 221         OntResource a0 = (OntResource) model.getResource( base+"a0").as(OntResource.class);
 222         OntResource a1 = (OntResource) model.getResource( base+"a1").as(OntResource.class);
 223
 224         ObjectProperty p = model.getObjectProperty( base+"p" );
 225         ObjectProperty q = model.getObjectProperty( base+"q" );
 226
 227         assertTrue("subProp relation present", q.hasProperty(RDFS.subPropertyOf, p));
 228         assertTrue( "a1 q a0", a1.hasProperty( q, a0 ) );           assertTrue( "a1 p a0", a1.hasProperty( p, a0 ) );       }
 231
 232
 236     public void testEquivalentClass1() {
 237         Model base = ModelFactory.createDefaultModel();
 238         base.read("file:testing/reasoners/bugs/equivalentClassTest.owl");
 239         InfModel test = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), base);
 240         String
  NAMESPACE = "urn:foo#"; 241         Resource A = test.getResource(NAMESPACE + "A");
 242         Resource B = test.getResource(NAMESPACE + "B");
 243         assertTrue("hasValue equiv deduction", test.contains(A, OWL.equivalentClass, B));
 244     }
 245
 246
 249     public void testOWLPropertyAxioms() {
 250         Model data = ModelFactory.createDefaultModel();
 251         Resource fp = data.createResource("urn:x-hp:eg/fp");
 252         Resource ifp = data.createResource("urn:x-hp:eg/ifp");
 253         Resource tp = data.createResource("urn:x-hp:eg/tp");
 254         Resource sp = data.createResource("urn:x-hp:eg/sp");
 255         data.add(fp, RDF.type, OWL.FunctionalProperty);
 256         data.add(ifp, RDF.type, OWL.InverseFunctionalProperty);
 257         data.add(tp, RDF.type, OWL.TransitiveProperty);
 258         data.add(sp, RDF.type, OWL.SymmetricProperty);
 259         InfModel infmodel = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), data);
 260         assertTrue("property class axioms", infmodel.contains(fp, RDF.type, RDF.Property));
 261         assertTrue("property class axioms", infmodel.contains(ifp, RDF.type, RDF.Property));
 262         assertTrue("property class axioms", infmodel.contains(tp, RDF.type, RDF.Property));
 263         assertTrue("property class axioms", infmodel.contains(sp, RDF.type, RDF.Property));
 264         assertTrue("property class axioms", infmodel.contains(ifp, RDF.type, OWL.ObjectProperty));
 265         assertTrue("property class axioms", infmodel.contains(tp, RDF.type,  OWL.ObjectProperty));
 266         assertTrue("property class axioms", infmodel.contains(sp, RDF.type,  OWL.ObjectProperty));
 267     }
 268
 269
 272     public void testDeleteBug() {
 273         Model modelo = ModelFactory.createDefaultModel();
 274         modelo.read("file:testing/reasoners/bugs/deleteBug.owl");
 275         OntModel modeloOnt = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RULE_INF, modelo );
 276         Individual indi = modeloOnt.getIndividual("http://decsai.ugr.es/~ontoserver/bacarex2.owl#JS");
 277         indi.remove();
 278         ClosableIterator it = modeloOnt.listStatements(indi, null, (RDFNode) null);
 279         boolean ok = ! it.hasNext();
 280         it.close();
 281         assertTrue(ok);
 282       }
 283
 284
 287     public void hiddenTestOWLLoop() {
 288         Model data = FileManager.get().loadModel("file:testing/reasoners/bugs/loop.owl");
 289         InfModel infmodel = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), data);
 290         ((FBRuleInfGraph)infmodel.getGraph()).setTraceOn(true);
 291         String
  baseURI = "http://jena.hpl.hp.com/eg#"; 292         Resource C = infmodel.getResource(baseURI + "C");
 293         Resource I = infmodel.getResource(baseURI + "i");
 294         Property R = infmodel.getProperty(baseURI, "R");
 295         System.out.println("Check that the instance does have an R property");
 297         Statement s = I.getProperty(R);
 298         System.out.println(" - " + s);
 299         System.out.println("And that the type of the R property is C");
 300         Statement s2 = ((Resource)s.getObject()).getProperty(RDF.type);
 301         System.out.println(" - " + s2);
 302         System.out.println("But does that have an R property?");
 303         Statement s3 = ((Resource)s.getObject()).getProperty(R);
 304         System.out.println(" - " + s3);
 305         System.out.println("List all instances of C");
 306         int count = 0;
 307         for (Iterator i = infmodel.listStatements(null, RDF.type, C); i.hasNext(); ) {
 308             Statement st = (Statement)i.next();
 309             System.out.println(" - " + st);
 310             count++;
 311         }
 312         System.out.println("OK");
 313     }
 316
 317
 320     public void testRangeBug() {
 321         Model model = FileManager.get().loadModel("file:testing/reasoners/bugs/rangeBug.owl");
 322         Model m = ModelFactory.createDefaultModel();
 323         Reasoner r = ReasonerRegistry.getOWLReasoner();
 324         InfModel omodel = ModelFactory.createInfModel(r, model);
 325         String
  baseuri = "http://decsai.ugr.es/~ontoserver/bacarex2.owl#"; 326         Resource js = omodel.getResource(baseuri + "JS");
 327         Resource surname = omodel.getResource(baseuri + "surname");
 328         Statement s = omodel.createStatement(surname, RDFS.range, OWL.Nothing);
 329         assertTrue(! omodel.contains(s));
 330     }
 331
 332
 335     public void testLiteralBug() {
 336         Model model = FileManager.get().loadModel("file:testing/reasoners/bugs/dtValidation.owl");
 337         Model m = ModelFactory.createDefaultModel();
 338         Reasoner r = ReasonerRegistry.getOWLReasoner();
 339         InfModel infmodel = ModelFactory.createInfModel(r, model);
 340         ValidityReport validity = infmodel.validate();
 341         assertTrue (validity.isValid());
 342     }
 343
 344
 347     public void testHide() {
 348         String
  NS = "http://jena.hpl.hp.com/bugs#"; 349         OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null);
 350         OntClass c = m.createClass(NS + "C");
 351         OntResource i = m.createIndividual(c);
 352         Iterator res = m.listStatements(null, RDF.type, c);
 353         TestUtil.assertIteratorValues(this, res, new Statement[] {
 354             m.createStatement(i, RDF.type, c)
 355         });
 356     }
 357
 358
 361     public void testHideXSDRange() {
 362         OntModelSpec[] specs = new OntModelSpec[] {
 363                 OntModelSpec.OWL_MEM_RULE_INF,
 364                 OntModelSpec.OWL_MEM_RDFS_INF,
 365                 OntModelSpec.OWL_MEM_MINI_RULE_INF,
 366                 OntModelSpec.OWL_MEM_MICRO_RULE_INF
 367         };
 368         for (int os = 0; os < specs.length; os++) {
 369             OntModelSpec spec = specs[os];
 370             OntModel m = ModelFactory.createOntologyModel(spec, null);
 371             Iterator i = m.listOntProperties();
 372             while (i.hasNext()) {
 373                 Resource r = (Resource)i.next();
 374                 if (r.getURI() != null && r.getURI().startsWith(ReasonerVocabulary.RBNamespace)) {
 375                     assertTrue("Rubrik internal property leaked out: " + r + "(" + os + ")", false);
 376                 }
 377             }
 378         }
 379     }
 380
 381
 384     public void testBindSchemaValidate() {
 385         Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
 386         Model schema = FileManager.get().loadModel("file:testing/reasoners/bugs/sbug.owl");
 387         Model data = FileManager.get().loadModel("file:testing/reasoners/bugs/sbug.rdf");
 388
 389                 InfModel infu = ModelFactory.createInfModel(reasoner, data.union(schema));
 391         ValidityReport validity = infu.validate();
 392         assertTrue( ! validity.isValid());
 393
 398                 InfModel inf = ModelFactory.createInfModel(reasoner.bindSchema(schema), data);
 400         validity = inf.validate();
 401         assertTrue( ! validity.isValid());
 402     }
 403
 404
 407     public void testGenericDeleteBug() {
 408         Model data = ModelFactory.createDefaultModel();
 409         String
  NS = "urn:x-hp:eg/"; 410         Property p = data.createProperty(NS, "p");
 411         Resource x = data.createResource(NS + "x");
 412         Resource y = data.createResource(NS + "y");
 413         Statement sy = data.createStatement(y, p, "foo");
 414         data.add(sy);
 415         data.add(x, p, "foo");
 416         String
  rule = "[(?x eg:p ?m) (?y eg:p ?m) -> (?x eg:same ?y) (?y eg:same ?x)]"; 418         GenericRuleReasoner reasoner = (GenericRuleReasoner) GenericRuleReasonerFactory.theInstance().create(null);
 419         reasoner.setMode(GenericRuleReasoner.FORWARD_RETE);
 420         reasoner.setRules(Rule.parseRules(rule));
 421         InfModel inf = ModelFactory.createInfModel(reasoner, data);
 422         TestUtil.assertIteratorLength(inf.listStatements(y, null, (RDFNode)null), 3);
 423         inf.remove(sy);
 424         TestUtil.assertIteratorLength(inf.listStatements(y, null, (RDFNode)null), 0);
 425     }
 426
 427
 430     public void testRETEInc() {
 431        String
  rule = "(?x ?p ?y) -> (?p rdf:type rdf:Property) ."; 432        Reasoner r = new GenericRuleReasoner(Rule.parseRules(rule));
 433        InfModel m = ModelFactory.createInfModel(r, ModelFactory.createDefaultModel());
 434
 435        Resource source = m.createResource("urn:alfie:testResource");
 436        Property prop   = m.createProperty("urn:alfie:testProperty");
 437        Statement s1=m.createStatement(source, prop, "value1");
 438        Statement s2=m.createStatement(source, prop, "value2");
 439
 440        m.add(s1);
 441        assertIsProperty(m, prop);
 442        m.add(s2);
 443        m.remove(s1);
 444        assertIsProperty(m, prop);
 445     }
 446
 447
 450     public void testRETEDec() {
 451        String
  rule = "(?x ?p ?y) -> (?p rdf:type rdf:Property) ."; 452        Reasoner r = new GenericRuleReasoner(Rule.parseRules(rule));
 453        InfModel m = ModelFactory.createInfModel(r, ModelFactory.createDefaultModel());
 454
 455        Resource source = m.createResource("urn:alfie:testResource");
 456        Property prop   = m.createProperty("urn:alfie:testProperty");
 457        Statement s1=m.createStatement(source, prop, "value1");
 458        Statement s2=m.createStatement(source, prop, "value2");
 459
 460        m.add(prop, RDF.type, RDF.Property);
 461        m.add(s1);
 462        m.prepare();
 463        m.remove(s1);
 464        assertIsProperty(m, prop);
 465     }
 466
 467     private void assertIsProperty(Model m, Property prop) {
 468         assertTrue(m.contains(prop, RDF.type, RDF.Property));
 469     }
 470
 471
 472
 475     public void testHideOnOWLThing() {
 476         Reasoner r = ReasonerRegistry.getOWLReasoner();
 477         Model data = ModelFactory.createDefaultModel();
 478         InfModel inf = ModelFactory.createInfModel(r, data);
 479         StmtIterator things = inf.listStatements(null, RDF.type, OWL.Thing);
 480         TestUtil.assertIteratorLength(things, 0);
 481     }
 482
 483
 486     public void testSomeDatatype() throws IOException {
 487         String
  uri = "http://www.daml.org/2001/03/daml+oil-ex-dt"; 488         String
  filename = "testing/xsd/daml+oil-ex-dt.xsd"; 489         TypeMapper tm = TypeMapper.getInstance();
 490         XSDDatatype.loadUserDefined(uri, new FileReader(filename), null, tm);
 491
 492         Model data = ModelFactory.createDefaultModel();
 493         data.read("file:testing/reasoners/bugs/userDatatypes.owl");
 494         InfModel inf = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), data);
 495
 496         String
  egNS = "http://jena.hpl.hp.com/eg#"; 497         Resource meR = inf.getResource(egNS + "me");
 498         Resource TestR = inf.getResource(egNS + "Test");
 499         assertTrue("somevalues inf for datatypes", inf.contains(meR, RDF.type, TestR));
 500
 501         Resource Test2R = inf.getResource(egNS + "Test2");
 502         Resource me2R = inf.getResource(egNS + "me2");
 503         assertTrue("somevalues inf for datatypes", inf.contains(me2R, RDF.type, Test2R));
 504         assertTrue("somevalues inf for user datatypes", inf.contains(meR, RDF.type, Test2R));
 505     }
 506
 507
 508     public void testDAMLMicroReasonerSupports() {
 509         Reasoner r = DAMLMicroReasonerFactory.theInstance().create( null );
 510         assertTrue( "Should support daml:subClassOf", r.supportsProperty( DAML_OIL.subClassOf ));
 511         assertTrue( "Should support daml:subPropertyOf", r.supportsProperty( DAML_OIL.subPropertyOf));
 512         assertTrue( "Should support daml:domain", r.supportsProperty( DAML_OIL.domain ));
 513         assertTrue( "Should support daml:range", r.supportsProperty( DAML_OIL.range ));
 514     }
 515
 516
 520     public static Model modelFromN3(String
  src) { 521         String
  fullSource = "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n" + 522         "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" +
 523         "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n" +
 524         "@prefix eg: <http://jena.hpl.hp.com/eg#> .\n" +
 525                     "@prefix : <#> .\n"+ src + "\n";
 526         Model result = ModelFactory.createDefaultModel();
 527         result.read(new StringReader(fullSource), "", "N3");
 528         return result;
 529     }
 530
 531
 532     public void test_oh_01() {
 533         String
  NS = "http://www.idi.ntnu.no/~herje/ja/"; 534         Resource[] expected = new Resource[] {
 535                 ResourceFactory.createResource( NS+"reiseliv.owl#Reiseliv" ),
 536                 ResourceFactory.createResource( NS+"hotell.owl#Hotell" ),
 537                 ResourceFactory.createResource( NS+"restaurant.owl#Restaurant" ),
 538                 ResourceFactory.createResource( NS+"restaurant.owl#UteRestaurant" ),
 539                 ResourceFactory.createResource( NS+"restaurant.owl#UteBadRestaurant" ),
 540                 ResourceFactory.createResource( NS+"restaurant.owl#UteDoRestaurant" ),
 541                 ResourceFactory.createResource( NS+"restaurant.owl#SkogRestaurant" ),
 542             };
 543
 544         test_oh_01scan( OntModelSpec.OWL_MEM, "No inf", expected );
 545         test_oh_01scan( OntModelSpec.OWL_MEM_MINI_RULE_INF, "Mini rule inf", expected );
 546         test_oh_01scan( OntModelSpec.OWL_MEM_MICRO_RULE_INF, "Micro rule inf", expected );
 547         test_oh_01scan( OntModelSpec.OWL_MEM_RULE_INF, "Full rule inf", expected );
 548     }
 549
 550
 551     public void test_der_validation() {
 552         Model abox = FileManager.get().loadModel("file:testing/reasoners/owl/nondetbug.rdf");
 553         List rules = FBRuleReasoner.loadRules("testing/reasoners/owl/nondetbug.rules");
 554         GenericRuleReasoner r = new GenericRuleReasoner(rules);
 555         for (int i = 0; i < 10; i++) {
 557             InfModel im = ModelFactory.createInfModel(r, abox);
 558             assertTrue("failed on count " + i, im.contains(null, ReasonerVocabulary.RB_VALIDATION_REPORT, (RDFNode)null));
 559         }
 560     }
 561
 562         private void test_oh_01scan( OntModelSpec s, String
  prompt, Resource[] expected ) { 564         String
  NS = "http://www.idi.ntnu.no/~herje/ja/reiseliv.owl#"; 565         OntModel m = ModelFactory.createOntologyModel(s, null);
 566         m.read( "file:testing/ontology/bugs/test_oh_01.owl");
 567
 568         OntClass r = m.getOntClass( NS + "Reiseliv" );
 570
 571         List q = new ArrayList();
 572         Set seen = new HashSet();
 573         q.add( r );
 574
 575         while (!q.isEmpty()) {
 576             OntClass c = (OntClass) q.remove( 0 );
 577             seen.add( c );
 578
 579             for (Iterator i = c.listSubClasses( true ); i.hasNext(); ) {
 580                 OntClass sub = (OntClass) i.next();
 581                 if (!seen.contains( sub )) {
 582                     q.add( sub );
 583                 }
 584             }
 585
 586         }
 588
 589                 int mask = (1 << expected.length) - 1;
 591
 592         for (int j = 0;  j < expected.length; j++) {
 593             if (seen.contains( expected[j] )) {
 594                 mask &= ~(1 << j);
 595             }
 596             else {
 597             }
 599         }
 600
 601         for (Iterator k = seen.iterator();  k.hasNext(); ) {
 602             Resource res = (Resource) k.next();
 603             boolean isExpected = false;
 604             for (int j = 0;  !isExpected && j < expected.length; j++) {
 605                 isExpected = expected[j].equals( res );
 606             }
 607             if (!isExpected) {
 608             }
 610         }
 611
 612         assertEquals( "Some expected results were not seen", 0, mask );
 613     }
 614
 615
 618     public void test_domainInf() {
 619                 OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null );
 621                 String
  NS = "http://m3t4.com/ont/#"; 623         OntClass c1 = m.createClass( NS + "c1" );
 624         OntClass c2 = m.createClass( NS + "c2" );
 625         OntClass c3 = m.createClass( NS + "c3" );
 626         OntProperty p1 = m.createObjectProperty( NS + "p1" );
 627                 UnionClass uc = m.createUnionClass(null, null);
 629                 uc.addOperand( c1 );
 631         assertEquals( "Size should be 1", 1, uc.getOperands().size() );
 632         assertTrue( "uc should have c1 as union member", uc.getOperands().contains( c1 ) );
 633                 uc.addOperand( c2 );
 635         assertEquals( "Size should be 2", 2, uc.getOperands().size() );
 636         TestUtil.assertIteratorValues(this, uc.listOperands(), new Object
  [] { c1, c2 } ); 637                 uc.addOperand( c3 );
 639         assertEquals( "Size should be 3", 3, uc.getOperands().size() );
 640         TestUtil.assertIteratorValues(this,  uc.listOperands(), new Object
  [] { c1, c2, c3} ); 641                 p1.addDomain(uc);
 643     }
 644
 645         private void tempList(Model m, Resource s, Property p, RDFNode o) {
 647         System.out.println("Listing of " + PrintUtil.print(s) + " " + PrintUtil.print(p) + " " + PrintUtil.print(o));
 648         for (StmtIterator i = m.listStatements(s, p, o); i.hasNext(); ) {
 649             System.out.println(" - " + i.next());
 650         }
 651     }
 652
 653     public static void main(String
  [] args) { 654         TestBugs test = new TestBugs("test");
 655     }
 657 }
 658
 659
                                                                                                                                                                                                             |                                                                       
 
 
 
 
 
                                                                                   Popular Tags                                                                                                                                                                                              |