📄 testbugreports.java
字号:
*/
public void test_hk_07() {
// owl full
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
Resource c = m.createResource();
c.addProperty( RDF.type, RDFS.Datatype );
assertTrue( c.canAs( OntClass.class ));
// owl dl
m = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM );
c = m.createResource();
c.addProperty( RDF.type, RDFS.Datatype );
assertTrue( c.canAs( OntClass.class ));
// owl lite
m = ModelFactory.createOntologyModel( OntModelSpec.OWL_LITE_MEM );
c = m.createResource();
c.addProperty( RDF.type, RDFS.Datatype );
assertTrue( c.canAs( OntClass.class ));
// rdfs
m = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM );
c = m.createResource();
c.addProperty( RDF.type, RDFS.Datatype );
assertTrue( c.canAs( OntClass.class ));
}
public void test_hk_importCache() {
final String BASE = "http://protege.stanford.edu/plugins/owl/testdata/";
OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
spec.setReasoner(null);
OntDocumentManager dm = OntDocumentManager.getInstance();
dm.reset();
dm.setCacheModels(false);
dm.addAltEntry( "http://protege.stanford.edu/plugins/owl/testdata/Import-normalizerBug.owl",
"file:testing/ontology/bugs/test_hk_import/Import-normalizerBug.owl" );
dm.addAltEntry( "http://protege.stanford.edu/plugins/owl/testdata/normalizerBug.owl",
"file:testing/ontology/bugs/test_hk_import/normalizerBug.owl" );
spec.setDocumentManager(dm);
OntModel oldOntModel = ModelFactory.createOntologyModel(spec, null);
oldOntModel.read(BASE + "Import-normalizerBug.owl", FileUtils.langXMLAbbrev);
Graph oldSubGraph = (Graph) oldOntModel.getSubGraphs().iterator().next();
final int oldTripleCount = getTripleCount(oldSubGraph);
OntClass ontClass = oldOntModel.getOntClass(BASE + "normalizerBug.owl#SuperClass");
oldSubGraph.add(new Triple(ontClass.asNode(), RDF.type.asNode(), OWL.DeprecatedClass.asNode()));
assertEquals(oldTripleCount + 1, getTripleCount(oldSubGraph));
// TODO this workaround to be removed
SimpleGraphMaker sgm = (SimpleGraphMaker) ((ModelMakerImpl) spec.getImportModelMaker()).getGraphMaker();
List toGo = new ArrayList();
for (Iterator i = sgm.listGraphs(); i.hasNext(); toGo.add( i.next() ));
for (Iterator i = toGo.iterator(); i.hasNext(); sgm.removeGraph( (String) i.next() ));
dm.clearCache();
OntModel newOntModel = ModelFactory.createOntologyModel(spec, null);
newOntModel.read(BASE + "Import-normalizerBug.owl", FileUtils.langXMLAbbrev);
Graph newSubGraph = (Graph) newOntModel.getSubGraphs().iterator().next();
assertFalse(newOntModel == oldOntModel); // OK!
assertFalse(newSubGraph == oldSubGraph); // FAILS!
final int newTripleCount = getTripleCount(newSubGraph);
assertEquals(oldTripleCount, newTripleCount);
}
private int getTripleCount(Graph graph) {
int count = 0;
for (Iterator it = graph.find(null, null, null); it.hasNext();) {
it.next();
count++;
}
return count;
}
/**
* Bug report by federico.carbone@bt.com, 30-July-2003. A literal can be
* turned into an individual.
*/
public void test_fc_01() {
OntModel m = ModelFactory.createOntologyModel();
ObjectProperty p = m.createObjectProperty(NS + "p");
Restriction r = m.createRestriction(p);
HasValueRestriction hv = r.convertToHasValueRestriction(m.createLiteral(1));
RDFNode n = hv.getHasValue();
assertFalse("Should not be able to convert literal to individual", n.canAs(Individual.class));
}
/**
* Bug report by Christoph Kunze (Christoph.Kunz@iao.fhg.de). 18/Aug/03 No
* transaction support in ontmodel.
*/
public void test_ck_01() {
MockTransactionHandler m_t = new MockTransactionHandler();
Graph g = Factory.createGraphMemWithTransactionHandler( m_t );
Model m0 = ModelFactory.createModelForGraph( g );
OntModel m1 = ModelFactory.createOntologyModel( OntModelSpec.OWL_LITE_MEM, m0 );
assertFalse( "should not initially be in a transaction", m_t.m_inTransaction );
m1.begin();
assertTrue( "should be in a transaction", m_t.m_inTransaction );
m1.abort();
assertFalse( "should not still be in transaction", m_t.m_inTransaction );
assertTrue( "transaction should have been aborted", m_t.m_aborted );
m1.begin();
assertTrue( "should be in a (new) transaction", m_t.m_inTransaction );
m1.commit();
assertFalse( "should not be in transaction post-commit", m_t.m_inTransaction );
assertTrue( "should be marked committed post-commit", m_t.m_committed );
}
/**
* Bug report by Christoph Kunz, 26/Aug/03. CCE when creating a statement
* from a vocabulary
*
*/
public void test_ck_02() {
OntModel vocabModel = ModelFactory.createOntologyModel();
ObjectProperty p = vocabModel.createObjectProperty("p");
OntClass A = vocabModel.createClass("A");
OntModel workModel = ModelFactory.createOntologyModel();
Individual sub = workModel.createIndividual("uri1", A);
Individual obj = workModel.createIndividual("uri2", A);
workModel.createStatement(sub, p, obj);
}
/**
* Bug report from Christoph Kunz - reification problems and
* UnsupportedOperationException
*/
public void test_ck_03() {
// part A - surprising reification
OntModel model1 = ModelFactory.createOntologyModel(OntModelSpec.DAML_MEM, null);
OntModel model2 = ModelFactory.createOntologyModel(OntModelSpec.DAML_MEM_RULE_INF, null);
Individual sub = model1.createIndividual("http://mytest#i1", model1.getProfile().CLASS());
OntProperty pred = model1.createOntProperty("http://mytest#");
Individual obj = model1.createIndividual("http://mytest#i2", model1.getProfile().CLASS());
OntProperty probabilityP = model1.createOntProperty("http://mytest#prob");
Statement st = model1.createStatement(sub, pred, obj);
model1.add(st);
st.createReifiedStatement().addProperty(probabilityP, 0.9);
assertTrue("st should be reified", st.isReified());
Statement st2 = model2.createStatement(sub, pred, obj);
model2.add(st2);
st2.createReifiedStatement().addProperty(probabilityP, 0.3);
assertTrue("st2 should be reified", st2.isReified());
sub.addProperty(probabilityP, 0.3);
sub.removeAll(probabilityP).addProperty(probabilityP, 0.3); //!!!
// exception
// Part B - exception in remove All
Individual sub2 = model2.createIndividual("http://mytest#i1", model1.getProfile().CLASS());
sub.addProperty(probabilityP, 0.3);
sub.removeAll(probabilityP); //!!! exception
sub2.addProperty(probabilityP, 0.3);
sub2.removeAll(probabilityP); //!!! exception
}
/**
* Bug report by sjooseng [sjooseng@hotmail.com]. CCE in listOneOf in
* Enumerated Class with DAML profile.
*/
public void test_sjooseng_01() {
String source =
"<rdf:RDF xmlns:daml='http://www.daml.org/2001/03/daml+oil#'"
+ " xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
+ " xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#' >"
+ " <daml:Class rdf:about='http://localhost:8080/kc2c#C1'>"
+ " <daml:subClassOf>"
+ " <daml:Restriction>"
+ " <daml:onProperty rdf:resource='http://localhost:8080/kc2c#p1'/>"
+ " <daml:hasClass>"
+ " <daml:Class>"
+ " <daml:oneOf rdf:parseType=\"daml:collection\">"
+ " <daml:Thing rdf:about='http://localhost:8080/kc2c#i1'/>"
+ " <daml:Thing rdf:about='http://localhost:8080/kc2c#i2'/>"
+ " </daml:oneOf>"
+ " </daml:Class>"
+ " </daml:hasClass>"
+ " </daml:Restriction>"
+ " </daml:subClassOf>"
+ " </daml:Class>"
+ " <daml:ObjectProperty rdf:about='http://localhost:8080/kc2c#p1'>"
+ " <rdfs:label>p1</rdfs:label>"
+ " </daml:ObjectProperty>"
+ "</rdf:RDF>";
OntModel m = ModelFactory.createOntologyModel(ProfileRegistry.DAML_LANG);
m.read(new ByteArrayInputStream(source.getBytes()), "http://localhost:8080/kc2c");
OntClass kc1 = m.getOntClass("http://localhost:8080/kc2c#C1");
boolean found = false;
Iterator it = kc1.listSuperClasses(false);
while (it.hasNext()) {
OntClass oc = (OntClass) it.next();
if (oc.isRestriction()) {
Restriction r = oc.asRestriction();
if (r.isSomeValuesFromRestriction()) {
SomeValuesFromRestriction sr = r.asSomeValuesFromRestriction();
OntClass sc = (OntClass) sr.getSomeValuesFrom();
if (sc.isEnumeratedClass()) {
EnumeratedClass ec = sc.asEnumeratedClass();
assertEquals("Enumeration size should be 2", 2, ec.getOneOf().size());
found = true;
}
}
}
}
assertTrue(found);
}
/**
* Problem reported by Andy Seaborne - combine abox and tbox in RDFS with
* ontmodel
*/
public void test_afs_01() {
String sourceT =
"<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#\">"
+ " <owl:Class rdf:about='http://example.org/foo#A'>"
+ " </owl:Class>"
+ "</rdf:RDF>";
String sourceA =
"<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#\">"
+ " <rdf:Description rdf:about='http://example.org/foo#x'>"
+ " <rdf:type rdf:resource='http://example.org/foo#A' />"
+ " </rdf:Description>"
+ "</rdf:RDF>";
Model tBox = ModelFactory.createDefaultModel();
tBox.read(new ByteArrayInputStream(sourceT.getBytes()), "http://example.org/foo");
Model aBox = ModelFactory.createDefaultModel();
aBox.read(new ByteArrayInputStream(sourceA.getBytes()), "http://example.org/foo");
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
reasoner = reasoner.bindSchema(tBox);
OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM_RULE_INF);
spec.setReasoner(reasoner);
OntModel m = ModelFactory.createOntologyModel(spec, aBox);
List inds = new ArrayList();
for (Iterator i = m.listIndividuals(); i.hasNext();) {
inds.add(i.next());
}
assertTrue("x should be an individual", inds.contains(m.getResource("http://example.org/foo#x")));
}
/**
* Bug report by Thorsten Ottmann [Thorsten.Ottmann@rwth-aachen.de] -
* problem accessing elements of DAML list
*/
public void test_to_01() {
String sourceT =
"<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:daml='http://www.daml.org/2001/03/daml+oil#'>"
+ " <daml:Class rdf:about='http://example.org/foo#A'>"
+ " <daml:intersectionOf rdf:parseType=\"daml:collection\">"
+ " <daml:Class rdf:ID=\"B\" />"
+ " <daml:Class rdf:ID=\"C\" />"
+ " </daml:intersectionOf>"
+ " </daml:Class>"
+ "</rdf:RDF>";
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.DAML_MEM, null);
m.read(new ByteArrayInputStream(sourceT.getBytes()), "http://example.org/foo");
OntClass A = m.getOntClass("http://example.org/foo#A");
assertNotNull(A);
IntersectionClass iA = A.asIntersectionClass();
assertNotNull(iA);
RDFList intersection = iA.getOperands();
assertNotNull(intersection);
assertEquals(2, intersection.size());
assertTrue(intersection.contains(m.getOntClass("http://example.org/foo#B")));
assertTrue(intersection.contains(m.getOntClass("http://example.org/foo#C")));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -