package tudelft.healthpsychology.traumaontologies.owltree; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.File; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import org.junit.Before; import org.junit.Test; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; public class OwlTreeReasonerTest { private OWLOntology ontology; private OwlTreeReasoner reasoner; @Before public void before() throws OWLOntologyCreationException { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); ontology = manager.loadOntologyFromOntologyDocument( new File("src/main/resources/Child Sexual Abuse.owl")); reasoner = new OwlTreeReasoner(ontology); } @Test public void smokeTest() { } @Test public void baseNameTest() { assertEquals("http://www.owl-ontologies.com/Ontology1444730995.owl", reasoner.getBaseName()); } @Test public void getObjectTest() { OWLClass bed = reasoner.getObject("Bed"); assertNotNull(bed); } @Test(expected = IllegalArgumentException.class) public void getNonExistingObjectTest() { OWLClass onzin = reasoner.getObject("Onzin"); } @Test public void getObjectParents() { OWLClass bed = reasoner.getObject("Bed"); List parents = reasoner.getAncestors(bed); assertFalse(parents.contains(bed)); OWLClass object = reasoner.getObject("Object"); assertTrue(parents.contains(object)); assertFalse(parents.contains(reasoner.thing)); } @Test public void getRootAncestors() { OWLClass typeloc = reasoner.getObject("Type_Locatie"); List parents = reasoner.getAncestors(typeloc); assertTrue(parents.isEmpty()); } @Test public void getRootParent() { OWLClass typeloc = reasoner.getObject("Type_Locatie"); OWLClass parent = reasoner.getParent(typeloc); assertNull(parent); } @Test public void getChildrenTest() { OWLClass spul = reasoner.getObject("Keukenspullen"); List expected = Arrays .asList("Glas", "Beker", "Pan", "Schaal", "Bestek", "Bord") .stream().map(name -> reasoner.getObject(name)) .collect(Collectors.toList()); assertEquals(expected, reasoner.getChildren(spul)); } @Test public void getParentTest() { OWLClass spul = reasoner.getObject("Keukenspullen"); assertEquals(reasoner.getObject("Spullen"), reasoner.getParent(spul)); } @Test public void getChildrenTest2() { OWLClass spul = reasoner.getObject("Spullen"); List expected = Arrays .asList("Schrijf_spullen", "Voedsel", "Keukenspullen", "Wapen", "Papieren_spullen") .stream().map(name -> reasoner.getObject(name)) .collect(Collectors.toList()); assertEquals(expected, reasoner.getChildren(spul)); } @Test public void getFamilieLeavesTest() { OWLClass familie = reasoner.getObject("Familie"); List expecteddepth1 = Arrays .asList("Broer", "Tante", "Oma", "Zus", "Oom", "Opa").stream() .map(name -> reasoner.getObject(name)) .collect(Collectors.toList()); List expecteddepth2 = Arrays .asList("Broer", "Tante", "Stiefmoeder", "Stiefvader", "Oma", "Zus", "Vader", "Moeder", "Oom", "Opa") .stream().map(name -> reasoner.getObject(name)) .collect(Collectors.toList()); assertEquals(expecteddepth1, reasoner.getLeaves(familie, 1)); assertEquals(expecteddepth2, reasoner.getLeaves(familie, 2)); } @Test public void getFamilieChildrenTest() { OWLClass familie = reasoner.getObject("Familie"); List expecteddepth1 = Arrays .asList("Broer", "Tante", "Stiefouders", "Oma", "Zus", "Ouders", "Oom", "Opa") .stream().map(name -> reasoner.getObject(name)) .collect(Collectors.toList()); List expecteddepth2 = Arrays .asList("Broer", "Tante", "Stiefmoeder", "Stiefvader", "Oma", "Zus", "Vader", "Moeder", "Oom", "Opa") .stream().map(name -> reasoner.getObject(name)) .collect(Collectors.toList()); assertEquals(expecteddepth1, reasoner.getChildren(familie, 1)); assertEquals(expecteddepth2, reasoner.getChildren(familie, 2)); } @Test public void getPropertiesTest() { OWLClass bed = reasoner.getObject("Bed"); List props = reasoner.getProperties(bed); assertTrue(props.get(0).getProperty().toString() .contains("#Locatie_meubel")); assertTrue(props.get(1).getProperty().toString() .contains("#Beschrijving_voorwerp")); assertTrue(props.get(2).getProperty().toString() .contains("#Beschrijving_bed")); } @Test public void getProperty1Test() { OWLClass bed = reasoner.getObject("Bed"); List props = reasoner.getProperties(bed); // locatie_meubel OWLDataPropertyDomainAxiom prop = props.get(0); assertEquals("Kan je beschrijven waar in de ruimte dit meubel stond?", reasoner.getComment(prop)); } @Test public void getProperty1RangeTest() { OWLClass bed = reasoner.getObject("Bed"); List props = reasoner.getProperties(bed); // locatie_meubel OWLDataPropertyDomainAxiom prop = props.get(0); assertEquals("http://www.w3.org/2001/XMLSchema#string", reasoner.getRange(prop)); } }