📄 testontmodel.java
字号:
public void testGetImportedModel() {
OntModel m = ModelFactory.createOntologyModel();
m.read( "file:testing/ontology/testImport6/a.owl" );
OntModel m0 = m.getImportedModel( "file:testing/ontology/testImport6/b.owl" );
OntModel m1 = m.getImportedModel( "file:testing/ontology/testImport6/c.owl" );
OntModel m2 = m.getImportedModel( "file:testing/ontology/testImport6/d.owl" );
OntModel m3 = m.getImportedModel( "file:testing/ontology/testImport6/b.owl" )
.getImportedModel( "file:testing/ontology/testImport6/c.owl" );
OntModel m4 = m.getImportedModel( "file:testing/ontology/testImport6/a.owl" );
assertNotNull( "Import model b should not be null", m0 );
assertNotNull( "Import model c should not be null", m1 );
assertNotNull( "Import model d should not be null", m2 );
assertNotNull( "Import model b-c should not be null", m3 );
assertNull( "Import model a should be null", m4 );
}
/**
* Test that the supports checks that are defined in the OWL full profile are not
* missing in the DL and Lite profiles, unless by design.
* Not strictly a model test, but it has to go somewhere */
public void testProfiles() {
List notInDL = Arrays.asList( new Class[] {} );
List notInLite = Arrays.asList( new Class[] {DataRange.class, HasValueRestriction.class} );
Map fullProfileMap = new OWLProfileExt().getSupportsMap();
Map dlProfileMap = new OWLDLProfileExt().getSupportsMap();
Map liteProfileMap = new OWLLiteProfileExt().getSupportsMap();
for (Iterator i = fullProfileMap.entrySet().iterator(); i.hasNext(); ) {
Map.Entry kv = (Map.Entry) i.next();
Class c = (Class) kv.getKey();
assertTrue( "Key in OWL DL profile: " + c.getName(), dlProfileMap.containsKey( c ) || notInDL.contains( c ));
assertTrue( "Key in OWL lite profile: " + c.getName(), liteProfileMap.containsKey( c ) || notInLite.contains( c ));
}
}
/**
Added by kers to ensure that bulk update works; should really be a test
of the ontology Graph using AbstractTestGraph, but that fails because there
are too many things that don't pass those tests.
<p>
<b>Yet</b>.
*/
public void testBulkAddWorks()
{
OntModel om1= ModelFactory.createOntologyModel();
OntModel om2 = ModelFactory.createOntologyModel();
om1.add( om2 );
}
public void testRead() {
String base0 = "http://example.com/test0";
String ns0 = base0 + "#";
String base1 = "http://example.com/test1";
String ns1 = base1 + "#";
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
m.getDocumentManager().reset();
m.getDocumentManager().addAltEntry( base0, "file:testing/ontology/relativenames.rdf" );
m.read( base0, "RDF/XML" );
assertNotNull( "Should be a class ns0:A", m.getOntClass( ns0 + "A" ) );
assertNull( "Should not be a class ns1:A", m.getOntClass( ns1 + "A" ) );
m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
m.getDocumentManager().reset();
m.getDocumentManager().addAltEntry( base0, "file:testing/ontology/relativenames.rdf" );
m.read( base0, base1, "RDF/XML" );
assertNull( "Should not be a class ns0:A", m.getOntClass( ns0 + "A" ) );
assertNotNull( "Should be a class ns1:A", m.getOntClass( ns1 + "A" ) );
}
public void testListDataRange() {
String base = "http://jena.hpl.hp.com/test#";
String doc =
"<?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:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
+ " xmlns:owl='http://www.w3.org/2002/07/owl#'>"
+ " <owl:DataRange>"
+ " <owl:oneOf>"
+ " <rdf:List>"
+ " <rdf:first rdf:datatype='&xsd;integer'>0</rdf:first>"
+ " <rdf:rest rdf:resource='&rdf;nil' />"
+ " </rdf:List>"
+ " </owl:oneOf>"
+ " </owl:DataRange>"
+ "</rdf:RDF>";
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
m.read(new StringReader(doc), base);
Iterator i = m.listDataRanges();
assertTrue( "Should be at least one DataRange", i.hasNext() );
Object dr = i.next();
assertInstanceOf( DataRange.class, dr );
assertFalse( "Should no more DataRange", i.hasNext() );
}
public void testListHierarchyRoots0() {
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
assertFalse( m.listHierarchyRootClasses().hasNext() );
m = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM );
assertFalse( m.listHierarchyRootClasses().hasNext() );
}
public void testListHierarchyRoots1() {
String doc =
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. "
+ "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. "
+ "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. "
+ "@prefix owl: <http://www.w3.org/2002/07/owl#>. "
+ "@prefix : <" + NS + ">. "
+ ":A a owl:Class. "
;
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
m.read( new StringReader(doc), NS, "N3" );
OntClass a = m.getOntClass(NS+"A");
TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(),
new Object[] {a} );
}
public void testListHierarchyRoots2() {
String doc =
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. "
+ "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. "
+ "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. "
+ "@prefix owl: <http://www.w3.org/2002/07/owl#>. "
+ "@prefix : <" + NS + ">. "
+ ":A a owl:Class. "
;
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null);
m.read( new StringReader(doc), NS, "N3" );
OntClass a = m.getOntClass(NS+"A");
TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(),
new Object[] {a} );
}
public void testListHierarchyRoots3() {
String doc =
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. "
+ "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. "
+ "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. "
+ "@prefix owl: <http://www.w3.org/2002/07/owl#>. "
+ "@prefix : <" + NS + ">. "
+ ":A a owl:Class. "
+ ":B a owl:Class ; rdfs:subClassOf :A . "
;
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MINI_RULE_INF, null);
m.read( new StringReader(doc), NS, "N3" );
OntClass a = m.getOntClass(NS+"A");
TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(),
new Object[] {a} );
}
public void testListHierarchyRoots4() {
String doc =
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. "
+ "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. "
+ "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. "
+ "@prefix owl: <http://www.w3.org/2002/07/owl#>. "
+ "@prefix : <" + NS + ">. "
+ ":A a rdfs:Class. "
+ ":C a rdfs:Class. "
+ ":B a rdfs:Class ; rdfs:subClassOf :A . "
;
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF, null);
m.read( new StringReader(doc), NS, "N3" );
OntClass a = m.getOntClass(NS+"A");
OntClass c = m.getOntClass(NS+"C");
TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(),
new Object[] {a,c} );
}
/* Auto-loading of imports is off by default */
public void testLoadImports0() {
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
Resource a = m.getResource( "file:testing/ontology/testImport3/a.owl" );
Resource b = m.getResource( "file:testing/ontology/testImport3/b.owl" );
m.add( a, m.getProfile().IMPORTS(), b );
// not dymamically imported by default
assertEquals( "Marker count not correct", 0, TestOntDocumentManager.countMarkers( m ) );
assertFalse( "c should not be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) );
assertFalse( "b should not be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) );
m.loadImports();
assertEquals( "Marker count not correct", 2, TestOntDocumentManager.countMarkers( m ) );
assertTrue( "c should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) );
assertTrue( "b should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) );
}
/* Auto-loading of imports = on */
public void testLoadImports1() {
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
Resource a = m.getResource( "file:testing/ontology/testImport3/a.owl" );
Resource b = m.getResource( "file:testing/ontology/testImport3/b.owl" );
m.setDynamicImports( true );
m.add( a, m.getProfile().IMPORTS(), b );
assertEquals( "Marker count not correct", 2, TestOntDocumentManager.countMarkers( m ) );
assertTrue( "c should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) );
assertTrue( "b should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) );
// this should have no effect
m.loadImports();
assertEquals( "Marker count not correct", 2, TestOntDocumentManager.countMarkers( m ) );
assertTrue( "c should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) );
assertTrue( "b should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) );
}
// Internal implementation methods
//////////////////////////////////
//==============================================================================
// Inner class definitions
//==============================================================================
protected class OWLProfileExt extends OWLProfile
{
public Map getSupportsMap() {
return getCheckTable();
}
}
protected class OWLDLProfileExt extends OWLDLProfile
{
public Map getSupportsMap() {
return getCheckTable();
}
}
protected class OWLLiteProfileExt extends OWLLiteProfile
{
public Map getSupportsMap() {
return getCheckTable();
}
}
}
/*
(c) Copyright 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -