| 1 |
package bugs; |
| 2 |
|
| 3 |
import static org.junit.Assert.assertEquals; |
| 4 |
|
| 5 |
import java.util.Arrays; |
| 6 |
import java.util.Set; |
| 7 |
import java.util.TreeSet; |
| 8 |
|
| 9 |
import javax.annotation.Nonnull; |
| 10 |
|
| 11 |
import org.junit.Before; |
| 12 |
import org.semanticweb.owlapi.apibinding.OWLManager; |
| 13 |
import org.semanticweb.owlapi.formats.FunctionalSyntaxDocumentFormat; |
| 14 |
import org.semanticweb.owlapi.io.StringDocumentSource; |
| 15 |
import org.semanticweb.owlapi.io.SystemOutDocumentTarget; |
| 16 |
import org.semanticweb.owlapi.model.IRI; |
| 17 |
import org.semanticweb.owlapi.model.OWLClass; |
| 18 |
import org.semanticweb.owlapi.model.OWLDataFactory; |
| 19 |
import org.semanticweb.owlapi.model.OWLDataProperty; |
| 20 |
import org.semanticweb.owlapi.model.OWLEntity; |
| 21 |
import org.semanticweb.owlapi.model.OWLNamedIndividual; |
| 22 |
import org.semanticweb.owlapi.model.OWLObjectProperty; |
| 23 |
import org.semanticweb.owlapi.model.OWLOntology; |
| 24 |
import org.semanticweb.owlapi.model.OWLOntologyCreationException; |
| 25 |
import org.semanticweb.owlapi.model.OWLOntologyStorageException; |
| 26 |
import org.semanticweb.owlapi.profiles.OWLProfileReport; |
| 27 |
import org.semanticweb.owlapi.profiles.OWLProfileViolation; |
| 28 |
import org.semanticweb.owlapi.profiles.Profiles; |
| 29 |
import org.semanticweb.owlapi.reasoner.InferenceType; |
| 30 |
import org.semanticweb.owlapi.reasoner.Node; |
| 31 |
import org.semanticweb.owlapi.reasoner.NodeSet; |
| 32 |
import org.semanticweb.owlapi.reasoner.OWLReasoner; |
| 33 |
|
| 34 |
import testbase.TestBase; |
| 35 |
|
| 36 |
@SuppressWarnings("javadoc") |
| 37 |
public abstract class VerifyComplianceBase extends TestBase { |
| 38 |
|
| 39 |
protected abstract String input(); |
| 40 |
|
| 41 |
protected OWLReasoner reasoner; |
| 42 |
protected OWLDataFactory df = OWLManager.getOWLDataFactory(); |
| 43 |
|
| 44 |
@Nonnull |
| 45 |
protected OWLOntology load(String in) throws OWLOntologyCreationException { |
| 46 |
OWLOntology onto = OWLManager.createOWLOntologyManager() |
| 47 |
.loadOntologyFromOntologyDocument( |
| 48 |
VerifyComplianceBase.class.getResourceAsStream(in)); |
| 49 |
OWLProfileReport checkOntology = Profiles.OWL2_DL.checkOntology(onto); |
| 50 |
if (!checkOntology.isInProfile()) { |
| 51 |
for (OWLProfileViolation v : checkOntology.getViolations()) { |
| 52 |
System.out.println("VerifyComplianceBase.load() " + v); |
| 53 |
} |
| 54 |
} |
| 55 |
return onto; |
| 56 |
} |
| 57 |
|
| 58 |
@Nonnull |
| 59 |
protected OWLOntology loadFromString(@Nonnull String in) |
| 60 |
throws OWLOntologyCreationException { |
| 61 |
return OWLManager.createOWLOntologyManager() |
| 62 |
.loadOntologyFromOntologyDocument(new StringDocumentSource(in)); |
| 63 |
} |
| 64 |
|
| 65 |
protected static String set(Iterable<OWLEntity> i) { |
| 66 |
Set<String> s = new TreeSet<>(); |
| 67 |
for (OWLEntity e : i) { |
| 68 |
s.add(e.getIRI().getShortForm()); |
| 69 |
} |
| 70 |
return s.toString().replace("[", "").replace("]", "") |
| 71 |
.replace(", ", "\n"); |
| 72 |
} |
| 73 |
|
| 74 |
@SuppressWarnings({ "unchecked" }) |
| 75 |
protected static void equal(NodeSet<?> node, OWLEntity... objects) { |
| 76 |
assertEquals(set(Arrays.asList(objects)), |
| 77 |
set((Set<OWLEntity>) node.getFlattened())); |
| 78 |
} |
| 79 |
|
| 80 |
@SuppressWarnings("unchecked") |
| 81 |
protected static void equal(Node<?> node, OWLEntity... objects) { |
| 82 |
assertEquals(set(Arrays.asList(objects)), |
| 83 |
set((Set<OWLEntity>) node.getEntities())); |
| 84 |
} |
| 85 |
|
| 86 |
protected static void equal(Object o, boolean object) { |
| 87 |
assertEquals(object, o); |
| 88 |
} |
| 89 |
|
| 90 |
@Nonnull |
| 91 |
protected OWLClass C(@Nonnull String i) { |
| 92 |
return df.getOWLClass(IRI.create(i)); |
| 93 |
} |
| 94 |
|
| 95 |
@Nonnull |
| 96 |
protected OWLNamedIndividual I(@Nonnull String i) { |
| 97 |
return df.getOWLNamedIndividual(IRI.create(i)); |
| 98 |
} |
| 99 |
|
| 100 |
@Nonnull |
| 101 |
protected OWLObjectProperty OP(@Nonnull String i) { |
| 102 |
return df.getOWLObjectProperty(IRI.create(i)); |
| 103 |
} |
| 104 |
|
| 105 |
@Nonnull |
| 106 |
protected OWLDataProperty DP(@Nonnull String i) { |
| 107 |
return df.getOWLDataProperty(IRI.create(i)); |
| 108 |
} |
| 109 |
|
| 110 |
@Nonnull |
| 111 |
protected OWLDataProperty bottomDataProperty = df |
| 112 |
.getOWLBottomDataProperty(); |
| 113 |
@Nonnull |
| 114 |
protected OWLDataProperty topDataProperty = df.getOWLTopDataProperty(); |
| 115 |
@Nonnull |
| 116 |
protected OWLObjectProperty topObjectProperty = df |
| 117 |
.getOWLTopObjectProperty(); |
| 118 |
@Nonnull |
| 119 |
protected OWLObjectProperty bottomObjectProperty = df |
| 120 |
.getOWLBottomObjectProperty(); |
| 121 |
@Nonnull |
| 122 |
protected OWLClass owlThing = df.getOWLThing(); |
| 123 |
@Nonnull |
| 124 |
protected OWLClass owlNothing = df.getOWLNothing(); |
| 125 |
|
| 126 |
@Before |
| 127 |
public void setUp() throws OWLOntologyCreationException { |
| 128 |
reasoner = factory().createReasoner(load(input())); |
| 129 |
reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); |
| 130 |
} |
| 131 |
|
| 132 |
protected void switchLoggingOn() { |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
protected void print() { |
| 137 |
OWLOntology o = reasoner.getRootOntology(); |
| 138 |
try { |
| 139 |
o.getOWLOntologyManager().saveOntology(o, |
| 140 |
new FunctionalSyntaxDocumentFormat(), |
| 141 |
new SystemOutDocumentTarget()); |
| 142 |
} catch (OWLOntologyStorageException e) { |
| 143 |
e.printStackTrace(); |
| 144 |
} |
| 145 |
} |
| 146 |
} |