📄 testbugreports.java
字号:
public void test_der_02() {
String SOURCE=
"<?xml version='1.0'?>" +
"<!DOCTYPE owl [" +
" <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' >" +
" <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#' >" +
" <!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#' >" +
" <!ENTITY owl 'http://www.w3.org/2002/07/owl#' >" +
" <!ENTITY dc 'http://purl.org/dc/elements/1.1/' >" +
" <!ENTITY base 'http://jena.hpl.hp.com/test' >" +
" ]>" +
"<rdf:RDF xmlns:owl ='&owl;' xmlns:rdf='&rdf;' xmlns:rdfs='&rdfs;' xmlns:dc='&dc;' xmlns='&base;#' xml:base='&base;'>" +
" <owl:ObjectProperty rdf:ID='hasPublications'>" +
" <rdfs:domain>" +
" <owl:Class>" +
" <owl:unionOf rdf:parseType='Collection'>" +
" <owl:Class rdf:about='#Project'/>" +
" <owl:Class rdf:about='#Task'/>" +
" </owl:unionOf>" +
" </owl:Class>" +
" </rdfs:domain>" +
" <rdfs:domain rdf:resource='#Dummy' />" +
" <rdfs:range rdf:resource='#Publications'/>" +
" </owl:ObjectProperty>" +
" <owl:Class rdf:ID='Dummy'>" +
" </owl:Class>" +
"</rdf:RDF>";
String NS = "http://jena.hpl.hp.com/test#";
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF, null);
m.read(new ByteArrayInputStream( SOURCE.getBytes()), NS );
//OntClass dummy = m.getOntClass( NS + "Dummy" );
// assert commented out - bug not accepted -ijd
//TestUtil.assertIteratorValues( this, dummy.listDeclaredProperties(),
// new Object[] {m.getObjectProperty( NS+"hasPublications")} );
}
/** Bug report from Dave - cycles checking code still not correct */
public void test_der_03() {
String NS = "http://jena.hpl.hp.com/test#";
OntModel om = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
OntClass A = om.createClass(NS+"A");
OntClass B = om.createClass(NS+"B");
OntClass C = om.createClass(NS+"C");
A.addSuperClass(B);
A.addSuperClass(C);
B.addSuperClass(C);
C.addSuperClass(B);
TestUtil.assertIteratorValues( this, A.listSuperClasses( true ), new Object[] {B,C} );
}
/**
* Bug report by pierluigi.damadio@katamail.com: raises conversion exception
*/
public void test_pd_01() {
String SOURCE =
"<?xml version='1.0'?>" +
"<rdf:RDF" +
" xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'" +
" xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'" +
" xmlns:owl='http://www.w3.org/2002/07/owl#'" +
" xml:base='http://iasi.cnr.it/leks/localSchema1#'" +
" xmlns:test='http://iasi.cnr.it/test/test1#'" +
" xmlns='http://iasi.cnr.it/test/test1#'>" +
" <owl:Ontology rdf:about=''/>" +
" <owl:Class rdf:ID='Hotel'/>" +
" <owl:Class rdf:ID='Hotel5Stars'>" +
" <rdfs:subClassOf>" +
" <owl:Restriction>" +
" <owl:onProperty rdf:resource='#hasCategory'/>" +
" <owl:hasValue rdf:resource='#Category5'/>" +
" </owl:Restriction>" +
" </rdfs:subClassOf>" +
" </owl:Class>" +
" <owl:DatatypeProperty rdf:ID='hasCategory'>" +
" <rdfs:range rdf:resource='http://www.w3.org/2001/XMLSchema#string'/>" +
" <rdfs:domain rdf:resource='#Hotel'/>" +
" <rdf:type rdf:resource='http://www.w3.org/2002/07/owl#FunctionalProperty'/>" +
" </owl:DatatypeProperty>" +
" <owl:Thing rdf:ID='Category5'/>" +
"</rdf:RDF>";
String NS = "http://iasi.cnr.it/leks/localSchema1#";
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, null);
m.read(new ByteArrayInputStream( SOURCE.getBytes()), NS );
for (ExtendedIterator j = m.listRestrictions(); j.hasNext(); ) {
Restriction r = (Restriction) j.next();
if (r.isHasValueRestriction()) {
HasValueRestriction hv = r.asHasValueRestriction();
hv.getHasValue().toString();
}
}
}
/** Bug report from Ole Hjalmar - direct subClassOf not reporting correct result with rule reasoner */
public void xxtest_oh_01() {
String NS = "http://www.idi.ntnu.no/~herje/ja/";
Resource[] expected = new Resource[] {
ResourceFactory.createResource( NS+"reiseliv.owl#Reiseliv" ),
ResourceFactory.createResource( NS+"hotell.owl#Hotell" ),
ResourceFactory.createResource( NS+"restaurant.owl#Restaurant" ),
ResourceFactory.createResource( NS+"restaurant.owl#UteRestaurant" ),
ResourceFactory.createResource( NS+"restaurant.owl#UteBadRestaurant" ),
ResourceFactory.createResource( NS+"restaurant.owl#UteDoRestaurant" ),
ResourceFactory.createResource( NS+"restaurant.owl#SkogRestaurant" ),
};
test_oh_01scan( OntModelSpec.OWL_MEM, "No inf", expected );
test_oh_01scan( OntModelSpec.OWL_MEM_MINI_RULE_INF, "Mini rule inf", expected );
test_oh_01scan( OntModelSpec.OWL_MEM_RULE_INF, "Full rule inf", expected );
test_oh_01scan( OntModelSpec.OWL_MEM_MICRO_RULE_INF, "Micro rule inf", expected );
}
private void test_oh_01scan( OntModelSpec s, String prompt, Resource[] expected ) {
String NS = "http://www.idi.ntnu.no/~herje/ja/reiseliv.owl#";
OntModel m = ModelFactory.createOntologyModel(s, null);
m.read( "file:testing/ontology/bugs/test_oh_01.owl");
System.out.println( prompt );
OntClass r = m.getOntClass( NS + "Reiseliv" );
List q = new ArrayList();
Set seen = new HashSet();
q.add( r );
while (!q.isEmpty()) {
OntClass c = (OntClass) q.remove( 0 );
seen.add( c );
for (Iterator i = c.listSubClasses( true ); i.hasNext(); ) {
OntClass sub = (OntClass) i.next();
if (!seen.contains( sub )) {
q.add( sub );
}
}
System.out.println( " Seen class " + c );
}
// check we got all classes
int mask = (1 << expected.length) - 1;
for (int j = 0; j < expected.length; j++) {
if (seen.contains( expected[j] )) {
mask &= ~(1 << j);
}
else {
System.out.println( "Expected but did not see " + expected[j] );
}
}
for (Iterator k = seen.iterator(); k.hasNext(); ) {
Resource res = (Resource) k.next();
boolean isExpected = false;
for (int j = 0; !isExpected && j < expected.length; j++) {
isExpected = expected[j].equals( res );
}
if (!isExpected) {
System.out.println( "Got unexpected result " + res );
}
}
assertEquals( "Some expected results were not seen", 0, mask );
}
/** Test case for SF bug 927641 - list direct subclasses */
public void test_sf_927641() {
String NS = "http://example.org/test#";
OntModel m0 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
OntClass c0 = m0.createClass( NS + "C0" );
OntClass c1 = m0.createClass( NS + "C1" );
OntClass c2 = m0.createClass( NS + "C2" );
OntClass c3 = m0.createClass( NS + "C3" );
c0.addSubClass( c1 );
c1.addSubClass( c2 );
c2.addEquivalentClass( c3 );
// now c1 is the direct super-class of c2, even allowing for the equiv with c3
assertFalse( "pass 1: c0 should not be a direct super of c2", c2.hasSuperClass( c0, true ) );
assertFalse( "pass 1: c3 should not be a direct super of c2", c2.hasSuperClass( c3, true ) );
assertFalse( "pass 1: c2 should not be a direct super of c2", c2.hasSuperClass( c2, true ) );
assertTrue( "pass 1: c1 should be a direct super of c2", c2.hasSuperClass( c1, true ) );
// second pass - with inference
m0 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RULE_INF );
c0 = m0.createClass( NS + "C0" );
c1 = m0.createClass( NS + "C1" );
c2 = m0.createClass( NS + "C2" );
c3 = m0.createClass( NS + "C3" );
c0.addSubClass( c1 );
c1.addSubClass( c2 );
c2.addEquivalentClass( c3 );
// now c1 is the direct super-class of c2, even allowing for the equiv with c3
assertFalse( "pass 2: c0 should not be a direct super of c2", c2.hasSuperClass( c0, true ) );
assertFalse( "pass 2: c3 should not be a direct super of c2", c2.hasSuperClass( c3, true ) );
assertFalse( "pass 2: c2 should not be a direct super of c2", c2.hasSuperClass( c2, true ) );
assertTrue( "pass 2: c1 should be a direct super of c2", c2.hasSuperClass( c1, true ) );
}
/** Test case for SF bug 934528 - conversion exception with owl:Thing and owl:Nothing when no reasoner */
public void test_sf_934528() {
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
Resource r = (Resource) OWL.Thing.inModel( m );
OntClass thingClass = (OntClass) r.as( OntClass.class );
assertNotNull( thingClass );
r = (Resource) OWL.Nothing.inModel( m );
OntClass nothingClass = (OntClass) r.as( OntClass.class );
assertNotNull( nothingClass );
OntClass c = m.getOntClass( OWL.Thing.getURI() );
assertNotNull( c );
assertEquals( c, OWL.Thing );
c = m.getOntClass( OWL.Nothing.getURI() );
assertNotNull( c );
assertEquals( c, OWL.Nothing );
}
/** Test case for SF bug 937810 - NPE from ModelSpec.getDescription() */
public void test_sf_937810() throws IllegalAccessException {
Field[] specs = OntModelSpec.class.getDeclaredFields();
for (int i = 0; i < specs.length; i++) {
if (Modifier.isPublic( specs[i].getModifiers()) &&
Modifier.isStatic( specs[i].getModifiers()) &&
specs[i].getType().equals( OntModelSpec.class )) {
OntModelSpec s = (OntModelSpec) specs[i].get( null );
assertNotNull( s.getDescription() );
}
}
}
/** Test case for SF bug 940570 - listIndividuals not working with RDFS_INF
*/
public void test_sf_940570() {
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RDFS_INF );
OntClass C = m.createClass( NS + "C" );
Resource a = m.createResource( NS + "a", C );
TestUtil.assertIteratorValues( this, m.listIndividuals(), new Object[] {a} );
OntModel dm = ModelFactory.createOntologyModel( OntModelSpec.DAML_MEM_RULE_INF );
OntClass D = dm.createClass( NS + "D" );
Resource b = dm.createResource( NS + "b", D );
TestUtil.assertIteratorValues( this, dm.listIndividuals(), new Object[] {b} );
}
/** Test case for SF bug 940570 - listIndividuals not working with RDFS_INF (rdfs case)
*/
public void test_sf_940570_rdfs() {
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RDFS_INF );
OntClass C = m.createClass( NS + "C" );
Resource a = m.createResource( NS + "a", C );
TestUtil.assertIteratorValues( this, m.listIndividuals(), new Object[] {a} );
}
/** Test case for SF bug 940570 - listIndividuals not working with RDFS_INF (daml case)
*/
public void test_sf_940570_daml() {
OntModel dm = ModelFactory.createOntologyModel( OntModelSpec.DAML_MEM_RULE_INF );
OntClass D = dm.createClass( NS + "D" );
Resource b = dm.createResource( NS + "b", D );
TestUtil.assertIteratorValues( this, dm.listIndividuals(), new Object[] {b} );
}
/** Test case for SF bug 945436 - a xml:lang='' in the dataset causes sring index exception in getLabel() */
public void test_sf_945436() {
String SOURCE=
"<?xml version='1.0'?>" +
"<!DOCTYPE owl [" +
" <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' >" +
" <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#' >" +
" <!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#' >" +
" <!ENTITY owl 'http://www.w3.org/2002/07/owl#' >" +
" <!ENTITY dc 'http://purl.org/dc/elements/1.1/' >" +
" <!ENTITY base 'http://jena.hpl.hp.com/test' >" +
" ]>" +
"<rdf:RDF xmlns:owl ='&owl;' xmlns:rdf='&rdf;' xmlns:rdfs='&rdfs;' xmlns:dc='&dc;' xmlns='&base;#' xml:base='&base;'>" +
" <C rdf:ID='x'>" +
" <rdfs:label xml:lang=''>a_label</rdfs:label>" +
" </C>" +
" <owl:Class rdf:ID='C'>" +
" </owl:Class>" +
"</rdf:RDF>";
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
m.read( new StringReader( SOURCE ), null );
Individual x = m.getIndividual( "http://jena.hpl.hp.com/test#x" );
assertEquals( "Label on resource x", "a_label", x.getLabel( null) );
assertEquals( "Label on resource x", "a_label", x.getLabel( "" ) );
assertSame( "fr label on resource x", null, x.getLabel( "fr" ) );
}
/** Test case for SF bug 948995 - OWL full should allow inverse functional datatype properties */
public void test_sf_948995() {
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM ); // OWL dl
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -