📄 testbugreports.java
字号:
/*****************************************************************************
* Source code information
* -----------------------
* Original author Ian Dickinson, HP Labs Bristol
* Author email Ian.Dickinson@hp.com
* Package Jena 2
* Web http://sourceforge.net/projects/jena/
* Created 16-Jun-2003
* Filename $RCSfile: TestBugReports.java,v $
* Revision $Revision: 1.83 $
* Release status $State: Exp $
*
* Last modified on $Date: 2007/01/29 13:25:04 $
* by $Author: chris-dollin $
*
* (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
* (see footer for full conditions)
*****************************************************************************/
// Package
///////////////
package com.hp.hpl.jena.ontology.impl.test;
// Imports
///////////////
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
import com.hp.hpl.jena.enhanced.EnhGraph;
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.graph.impl.*;
import com.hp.hpl.jena.graph.query.*;
import com.hp.hpl.jena.mem.faster.GraphMemFasterQueryHandler;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.ontology.daml.*;
import com.hp.hpl.jena.ontology.impl.OntClassImpl;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.rdf.model.impl.ModelMakerImpl;
import com.hp.hpl.jena.reasoner.*;
import com.hp.hpl.jena.reasoner.dig.*;
import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
import com.hp.hpl.jena.reasoner.rulesys.Rule;
import com.hp.hpl.jena.reasoner.test.TestUtil;
import com.hp.hpl.jena.shared.ClosedException;
import com.hp.hpl.jena.util.FileUtils;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.util.iterator.Map1;
import com.hp.hpl.jena.vocabulary.*;
import junit.framework.*;
/**
* <p>
* Unit tests that are derived from user bug reports
* </p>
*
* @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com" >
* email</a>)
* @version CVS $Id: TestBugReports.java,v 1.23 2003/11/20 17:53:10
* ian_dickinson Exp $
*/
public class TestBugReports
extends TestCase
{
// Constants
//////////////////////////////////
public static String NS = "http://example.org/test#";
// Static variables
//////////////////////////////////
// Instance variables
//////////////////////////////////
public TestBugReports(String name) {
super(name);
}
// Constructors
//////////////////////////////////
// External signature methods
//////////////////////////////////
public void setUp() {
// ensure the ont doc manager is in a consistent state
OntDocumentManager.getInstance().reset( true );
}
/** Bug report by Danah Nada - listIndividuals returning too many results */
public void test_dn_0() {
OntModel schema = ModelFactory.createOntologyModel( OntModelSpec.OWL_LITE_MEM_RULES_INF, null );
schema.read( "file:doc/inference/data/owlDemoSchema.xml", null );
int count = 0;
for (Iterator i = schema.listIndividuals(); i.hasNext(); ) {
//Resource r = (Resource) i.next();
i.next();
count++;
/* Debugging * /
for (StmtIterator j = r.listProperties(RDF.type); j.hasNext(); ) {
System.out.println( "ind - " + r + " rdf:type = " + j.nextStatement().getObject() );
}
System.out.println("----------"); /**/
}
assertEquals( "Expecting 6 individuals", 6, count );
}
/* Bug report by Danah Nada - duplicate elements in property domain */
public void test_dn_01() {
// direct reading for the model method 1
OntModel m0 = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM_RULE_INF, null );
m0.read( "file:testing/ontology/bugs/test_hk_07B.owl" );
OntProperty p0 = m0.getOntProperty( "file:testing/ontology/bugs/test_hk_07B.owl#PropB" );
int count = 0;
for (Iterator i = p0.listDomain(); i.hasNext();) {
count++;
i.next();
}
assertEquals( 3, count );
// repeat test - thus using previously cached model for import
OntModel m1 = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM_RULE_INF, null );
m1.read( "file:testing/ontology/bugs/test_hk_07B.owl" );
OntProperty p1 = m1.getOntProperty( "file:testing/ontology/bugs/test_hk_07B.owl#PropB" );
count = 0;
for (Iterator i = p1.listDomain(); i.hasNext();) {
count++;
i.next();
}
assertEquals( 3, count );
}
/** Bug report by Danah Nada - cannot remove import */
public void test_dn_02() {
OntModel mymod = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );
mymod.read( "file:testing/ontology/testImport3/a.owl" );
assertEquals( "Graph count..", 2, mymod.getSubGraphs().size() );
for (Iterator it = mymod.listImportedModels(); it.hasNext();) {
mymod.removeSubModel( (Model) it.next() );
}
assertEquals( "Graph count..", 0, mymod.getSubGraphs().size() );
}
/**
* Bug report by Mariano Rico Almod???var [Mariano.Rico@uam.es] on June 16th.
* Said to raise exception.
*/
public void test_mra_01() {
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.DAML_MEM, null, null);
String myDicURI = "http://somewhere/myDictionaries/1.0#";
String damlURI = "http://www.daml.org/2001/03/daml+oil#";
m.setNsPrefix("DAML", damlURI);
String c1_uri = myDicURI + "C1";
OntClass c1 = m.createClass(c1_uri);
DatatypeProperty p1 = m.createDatatypeProperty(myDicURI + "P1");
p1.setDomain(c1);
ByteArrayOutputStream strOut = new ByteArrayOutputStream();
m.write(strOut, "RDF/XML-ABBREV", myDicURI);
//m.write(System.out,"RDF/XML-ABBREV", myDicURI);
}
/**
* Bug report from Holger Knublauch on July 25th 2003. Cannot convert
* owl:Class to an OntClass
*/
public void test_hk_01() {
// synthesise a mini-document
String base = "http://jena.hpl.hp.com/test#";
String doc =
"<rdf:RDF"
+ " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""
+ " xmlns:owl=\"http://www.w3.org/2002/07/owl#\">"
+ " <owl:Ontology rdf:about=\"\">"
+ " <owl:imports rdf:resource=\"http://www.w3.org/2002/07/owl\" />"
+ " </owl:Ontology>"
+ "</rdf:RDF>";
// read in the base ontology, which includes the owl language
// definition
// note OWL_MEM => no reasoner is used
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
m.getDocumentManager().setMetadataSearchPath( "file:etc/ont-policy-test.rdf", true );
m.read(new ByteArrayInputStream(doc.getBytes()), base);
// we need a resource corresponding to OWL Class but in m
Resource owlClassRes = m.getResource(OWL.Class.getURI());
// now can we see this as an OntClass?
OntClass c = (OntClass) owlClassRes.as(OntClass.class);
assertNotNull("OntClass c should not be null", c);
//(OntClass) (ontModel.getProfile().CLASS()).as(OntClass.class);
}
/**
* Bug report from Hoger Knublauch on Aug 19th 2003. NPE when setting all
* distinct members
*/
public void test_hk_02() {
OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
spec.setReasoner(null);
OntModel ontModel = ModelFactory.createOntologyModel(spec, null); // ProfileRegistry.OWL_LANG);
ontModel.createAllDifferent();
assertTrue(ontModel.listAllDifferent().hasNext());
AllDifferent allDifferent = (AllDifferent) ontModel.listAllDifferent().next();
//allDifferent.setDistinct(ontModel.createList());
assertFalse(allDifferent.listDistinctMembers().hasNext());
}
/** Bug report from Holger Knublauch on Aug 19th, 2003. Initialisation error */
public void test_hk_03() {
OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
spec.setReasoner(null);
OntModel ontModel = ModelFactory.createOntologyModel(spec, null);
OntProperty property = ontModel.createObjectProperty("http://www.aldi.de#property");
/* MinCardinalityRestriction testClass = */
ontModel.createMinCardinalityRestriction(null, property, 42);
}
/**
* Bug report from Holger Knublauch on Aug 19th, 2003. Document manager alt
* mechanism breaks relative name translation
*/
public void test_hk_04() {
OntModel m = ModelFactory.createOntologyModel();
m.getDocumentManager().addAltEntry(
"http://jena.hpl.hp.com/testing/ontology/relativenames",
"file:testing/ontology/relativenames.rdf");
m.read("http://jena.hpl.hp.com/testing/ontology/relativenames");
assertTrue(
"#A should be a class",
m.getResource("http://jena.hpl.hp.com/testing/ontology/relativenames#A").canAs(OntClass.class));
assertFalse(
"file: #A should not be a class",
m.getResource("file:testing/ontology/relativenames.rdf#A").canAs(OntClass.class));
}
/** Bug report from Holger Knublach: not all elements of a union are removed */
public void test_hk_05() {
OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
spec.setReasoner(null);
OntModel ontModel = ModelFactory.createOntologyModel(spec, null);
String ns = "http://foo.bar/fu#";
OntClass a = ontModel.createClass(ns + "A");
OntClass b = ontModel.createClass(ns + "B");
int oldCount = getStatementCount(ontModel);
RDFList members = ontModel.createList(new RDFNode[] { a, b });
IntersectionClass intersectionClass = ontModel.createIntersectionClass(null, members);
intersectionClass.remove();
assertEquals("Before and after statement counts are different", oldCount, getStatementCount(ontModel));
}
/**
* Bug report from Holger Knublach: moving between ontology models - comes
* down to a test for a resource being in the base model
*/
public void test_hk_06() throws Exception {
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
ontModel.read("file:testing/ontology/bugs/test_hk_06/a.owl");
String NSa = "http://jena.hpl.hp.com/2003/03/testont/a#";
String NSb = "http://jena.hpl.hp.com/2003/03/testont/b#";
OntClass A = ontModel.getOntClass(NSa + "A");
assertTrue("class A should be in the base model", ontModel.isInBaseModel(A));
OntClass B = ontModel.getOntClass(NSb + "B");
assertFalse("class B should not be in the base model", ontModel.isInBaseModel(B));
assertTrue(
"A rdf:type owl:Class should be in the base model",
ontModel.isInBaseModel(ontModel.createStatement(A, RDF.type, OWL.Class)));
assertFalse(
"B rdf:type owl:Class should not be in the base model",
ontModel.isInBaseModel(ontModel.createStatement(B, RDF.type, OWL.Class)));
}
/** Bug report 1408253 from Holger - rdfs:Datatype should be recognised as a RDFS class
* even without the reasoner
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -