| 1 |
package bugs; |
| 2 |
|
| 3 |
import static org.junit.Assert.*; |
| 4 |
|
| 5 |
import org.junit.Test; |
| 6 |
import org.semanticweb.owlapi.apibinding.OWLManager; |
| 7 |
import org.semanticweb.owlapi.io.StringDocumentSource; |
| 8 |
import org.semanticweb.owlapi.model.IRI; |
| 9 |
import org.semanticweb.owlapi.model.OWLClass; |
| 10 |
import org.semanticweb.owlapi.model.OWLDataFactory; |
| 11 |
import org.semanticweb.owlapi.model.OWLDataProperty; |
| 12 |
import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom; |
| 13 |
import org.semanticweb.owlapi.model.OWLDatatype; |
| 14 |
import org.semanticweb.owlapi.model.OWLFacetRestriction; |
| 15 |
import org.semanticweb.owlapi.model.OWLIndividual; |
| 16 |
import org.semanticweb.owlapi.model.OWLNamedIndividual; |
| 17 |
import org.semanticweb.owlapi.model.OWLObjectProperty; |
| 18 |
import org.semanticweb.owlapi.model.OWLOntology; |
| 19 |
import org.semanticweb.owlapi.model.OWLOntologyCreationException; |
| 20 |
import org.semanticweb.owlapi.model.OWLOntologyManager; |
| 21 |
import org.semanticweb.owlapi.reasoner.InferenceType; |
| 22 |
import org.semanticweb.owlapi.reasoner.NodeSet; |
| 23 |
import org.semanticweb.owlapi.reasoner.OWLReasoner; |
| 24 |
import org.semanticweb.owlapi.vocab.OWL2Datatype; |
| 25 |
import org.semanticweb.owlapi.vocab.OWLFacet; |
| 26 |
|
| 27 |
import testbase.TestBase; |
| 28 |
|
| 29 |
@SuppressWarnings("javadoc") |
| 30 |
public class AddIndividualsAfterLoadingTestCase extends TestBase { |
| 31 |
|
| 32 |
@Test |
| 33 |
public void shouldLoadAndNotFailQuery() throws Exception { |
| 34 |
|
| 35 |
OWLOntology o = OWLManager.createOWLOntologyManager().createOntology(); |
| 36 |
OWLOntologyManager m = o.getOWLOntologyManager(); |
| 37 |
OWLDataFactory f = m.getOWLDataFactory(); |
| 38 |
OWLClass c1 = f.getOWLClass(IRI.create("urn:test#c1")); |
| 39 |
OWLClass c2 = f.getOWLClass(IRI.create("urn:test#c2")); |
| 40 |
OWLObjectProperty p = f.getOWLObjectProperty(IRI.create("urn:test#p")); |
| 41 |
m.addAxiom(o, f.getOWLDisjointClassesAxiom(c1, c2)); |
| 42 |
m.addAxiom(o, f.getOWLObjectPropertyDomainAxiom(p, c1)); |
| 43 |
m.addAxiom(o, f.getOWLObjectPropertyRangeAxiom(p, c2)); |
| 44 |
|
| 45 |
|
| 46 |
OWLIndividual i = f.getOWLNamedIndividual(IRI.create("urn:test#i")); |
| 47 |
OWLIndividual j = f.getOWLNamedIndividual(IRI.create("urn:test#j")); |
| 48 |
m.addAxiom(o, f.getOWLObjectPropertyAssertionAxiom(p, i, j)); |
| 49 |
|
| 50 |
|
| 51 |
OWLReasoner r = factory().createReasoner(o); |
| 52 |
r.precomputeInferences(InferenceType.CLASS_HIERARCHY); |
| 53 |
OWLIndividual k = f.getOWLNamedIndividual(IRI.create("urn:test#k")); |
| 54 |
OWLIndividual l = f.getOWLNamedIndividual(IRI.create("urn:test#l")); |
| 55 |
m.addAxiom(o, f.getOWLObjectPropertyAssertionAxiom(p, k, l)); |
| 56 |
OWLDataProperty dt = f.getOWLDataProperty(IRI.create("urn:test#dt")); |
| 57 |
m.addAxiom(o, f.getOWLDeclarationAxiom(dt)); |
| 58 |
m.addAxiom( |
| 59 |
o, |
| 60 |
f.getOWLDataPropertyRangeAxiom(dt, |
| 61 |
f.getOWLDatatype(OWL2Datatype.XSD_STRING.getIRI()))); |
| 62 |
m.addAxiom( |
| 63 |
o, |
| 64 |
f.getOWLDataPropertyAssertionAxiom(dt, l, |
| 65 |
f.getOWLLiteral("test"))); |
| 66 |
r.flush(); |
| 67 |
r.precomputeInferences(InferenceType.CLASS_HIERARCHY); |
| 68 |
assertTrue(r.isConsistent()); |
| 69 |
} |
| 70 |
|
| 71 |
@Test |
| 72 |
public void shouldLoadAndNotFailQueryDataHasValue() throws Exception { |
| 73 |
OWLOntology o = OWLManager.createOWLOntologyManager().createOntology(); |
| 74 |
OWLOntologyManager m = o.getOWLOntologyManager(); |
| 75 |
OWLDataFactory f = m.getOWLDataFactory(); |
| 76 |
OWLDataProperty p = f.getOWLDataProperty(IRI.create("urn:test#p")); |
| 77 |
m.addAxiom(o, |
| 78 |
f.getOWLDataPropertyRangeAxiom(p, f.getFloatOWLDatatype())); |
| 79 |
OWLNamedIndividual i = f |
| 80 |
.getOWLNamedIndividual(IRI.create("urn:test#i")); |
| 81 |
m.addAxiom(o, f.getOWLDataPropertyAssertionAxiom(p, i, 19.0F)); |
| 82 |
OWLDatatype fdt = f.getFloatOWLDatatype(); |
| 83 |
OWLFacetRestriction fLess20 = f.getOWLFacetRestriction( |
| 84 |
OWLFacet.MAX_INCLUSIVE, 20f); |
| 85 |
OWLReasoner r = factory().createReasoner(o); |
| 86 |
r.precomputeInferences(InferenceType.CLASS_HIERARCHY); |
| 87 |
assertFalse(r.getInstances( |
| 88 |
f.getOWLDataAllValuesFrom(p, |
| 89 |
f.getOWLDatatypeRestriction(fdt, fLess20)), false) |
| 90 |
.containsEntity(i)); |
| 91 |
} |
| 92 |
|
| 93 |
@Test |
| 94 |
public void debug() throws OWLOntologyCreationException { |
| 95 |
String input = "Prefix(owl:=<http://www.w3.org/2002/07/owl#>)\n" |
| 96 |
+ "Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)\n" |
| 97 |
+ "Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)\n" |
| 98 |
+ "Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)\n" |
| 99 |
+ "Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)\n" |
| 100 |
+ "\n" |
| 101 |
+ "\n" |
| 102 |
+ "Ontology(<urn:test>\n" |
| 103 |
+ "\n" |
| 104 |
+ "Declaration(Class(<urn:test#Producto>))\n" |
| 105 |
+ "Declaration(Class(<urn:test#lessThan20>))\n" |
| 106 |
+ "Declaration(DataProperty(<urn:test#hasEnergia>))\n" |
| 107 |
+ "Declaration(NamedIndividual(<urn:test#prod1>))\n" |
| 108 |
+ "Declaration(NamedIndividual(<urn:test#prod2>))\n" |
| 109 |
+ "Declaration(NamedIndividual(<urn:test#prod3>))\n" |
| 110 |
+ "Declaration(NamedIndividual(<urn:test#prod4>))\n" |
| 111 |
+ "Declaration(NamedIndividual(<urn:test#prod5>))\n" |
| 112 |
+ "EquivalentClasses(<urn:test#lessThan20> ObjectIntersectionOf(DataSomeValuesFrom(<urn:test#hasEnergia> DatatypeRestriction(xsd:float xsd:maxExclusive \"20.0\"^^xsd:float)) <urn:test#Producto>))\n" |
| 113 |
+ "SubClassOf(<urn:test#lessThan20> <urn:test#Producto>)\n" |
| 114 |
+ "FunctionalDataProperty(<urn:test#hasEnergia>)\n" |
| 115 |
+ "DataPropertyDomain(<urn:test#hasEnergia> <urn:test#Producto>)\n" |
| 116 |
+ "DataPropertyRange(<urn:test#hasEnergia> xsd:float)\n" |
| 117 |
+ "DataPropertyAssertion(<urn:test#hasEnergia> <urn:test#prod1> \"30.0\"^^xsd:float)\n" |
| 118 |
+ "DataPropertyAssertion(<urn:test#hasEnergia> <urn:test#prod2> \"35.0\"^^xsd:float)\n" |
| 119 |
+ "DataPropertyAssertion(<urn:test#hasEnergia> <urn:test#prod3> \"58.0\"^^xsd:float)\n" |
| 120 |
+ "DataPropertyAssertion(<urn:test#hasEnergia> <urn:test#prod4> \"14.0\"^^xsd:float)\n" |
| 121 |
+ "DataPropertyAssertion(<urn:test#hasEnergia> <urn:test#prod5> \"5.0\"^^xsd:float))"; |
| 122 |
OWLOntology o = OWLManager.createOWLOntologyManager() |
| 123 |
.loadOntologyFromOntologyDocument( |
| 124 |
new StringDocumentSource(input)); |
| 125 |
OWLOntologyManager m = o.getOWLOntologyManager(); |
| 126 |
OWLDataFactory f = m.getOWLDataFactory(); |
| 127 |
OWLReasoner r = factory().createReasoner(o); |
| 128 |
r.precomputeInferences(InferenceType.CLASS_HIERARCHY); |
| 129 |
OWLDataProperty p = f.getOWLDataProperty(IRI |
| 130 |
.create("urn:test#hasEnergia")); |
| 131 |
OWLNamedIndividual i = f.getOWLNamedIndividual(IRI |
| 132 |
.create("urn:test#prod4")); |
| 133 |
OWLDatatype fdt = f.getFloatOWLDatatype(); |
| 134 |
OWLFacetRestriction fLess20 = f.getOWLFacetRestriction( |
| 135 |
OWLFacet.MAX_INCLUSIVE, 20f); |
| 136 |
OWLDataSomeValuesFrom dsv = f.getOWLDataSomeValuesFrom(p, |
| 137 |
f.getOWLDatatypeRestriction(fdt, fLess20)); |
| 138 |
NodeSet<OWLNamedIndividual> instances = r.getInstances(dsv, false); |
| 139 |
assertTrue(instances.containsEntity(i)); |
| 140 |
} |
| 141 |
} |