source: TraumaOntologies/src/test/java/tudelft/healthpsychology/traumaontologies/owltree/OwlTreeReasonerTest.java@ 4

Last change on this file since 4 was 4, checked in by Bart Vastenhouw, 5 years ago

Added traumaontologies

File size: 5.5 KB
Line 
1package tudelft.healthpsychology.traumaontologies.owltree;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertNotNull;
6import static org.junit.Assert.assertNull;
7import static org.junit.Assert.assertTrue;
8
9import java.io.File;
10import java.util.Arrays;
11import java.util.List;
12import java.util.stream.Collectors;
13
14import org.junit.Before;
15import org.junit.Test;
16import org.semanticweb.owlapi.apibinding.OWLManager;
17import org.semanticweb.owlapi.model.OWLClass;
18import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
19import org.semanticweb.owlapi.model.OWLOntology;
20import org.semanticweb.owlapi.model.OWLOntologyCreationException;
21import org.semanticweb.owlapi.model.OWLOntologyManager;
22
23public class OwlTreeReasonerTest {
24 private OWLOntology ontology;
25 private OwlTreeReasoner reasoner;
26
27 @Before
28 public void before() throws OWLOntologyCreationException {
29 OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
30 ontology = manager.loadOntologyFromOntologyDocument(
31 new File("src/main/resources/Child Sexual Abuse.owl"));
32 reasoner = new OwlTreeReasoner(ontology);
33
34 }
35
36 @Test
37 public void smokeTest() {
38 }
39
40 @Test
41 public void baseNameTest() {
42 assertEquals("http://www.owl-ontologies.com/Ontology1444730995.owl",
43 reasoner.getBaseName());
44 }
45
46 @Test
47 public void getObjectTest() {
48 OWLClass bed = reasoner.getObject("Bed");
49 assertNotNull(bed);
50 }
51
52 @Test(expected = IllegalArgumentException.class)
53 public void getNonExistingObjectTest() {
54 OWLClass onzin = reasoner.getObject("Onzin");
55 }
56
57 @Test
58 public void getObjectParents() {
59 OWLClass bed = reasoner.getObject("Bed");
60 List<OWLClass> parents = reasoner.getAncestors(bed);
61 assertFalse(parents.contains(bed));
62
63 OWLClass object = reasoner.getObject("Object");
64 assertTrue(parents.contains(object));
65 assertFalse(parents.contains(reasoner.thing));
66 }
67
68 @Test
69 public void getRootAncestors() {
70 OWLClass typeloc = reasoner.getObject("Type_Locatie");
71 List<OWLClass> parents = reasoner.getAncestors(typeloc);
72 assertTrue(parents.isEmpty());
73 }
74
75 @Test
76 public void getRootParent() {
77 OWLClass typeloc = reasoner.getObject("Type_Locatie");
78 OWLClass parent = reasoner.getParent(typeloc);
79 assertNull(parent);
80 }
81
82 @Test
83 public void getChildrenTest() {
84 OWLClass spul = reasoner.getObject("Keukenspullen");
85
86 List<OWLClass> expected = Arrays
87 .asList("Glas", "Beker", "Pan", "Schaal", "Bestek", "Bord")
88 .stream().map(name -> reasoner.getObject(name))
89 .collect(Collectors.toList());
90
91 assertEquals(expected, reasoner.getChildren(spul));
92 }
93
94 @Test
95 public void getParentTest() {
96 OWLClass spul = reasoner.getObject("Keukenspullen");
97 assertEquals(reasoner.getObject("Spullen"), reasoner.getParent(spul));
98 }
99
100 @Test
101 public void getChildrenTest2() {
102 OWLClass spul = reasoner.getObject("Spullen");
103
104 List<OWLClass> expected = Arrays
105 .asList("Schrijf_spullen", "Voedsel", "Keukenspullen", "Wapen",
106 "Papieren_spullen")
107 .stream().map(name -> reasoner.getObject(name))
108 .collect(Collectors.toList());
109
110 assertEquals(expected, reasoner.getChildren(spul));
111 }
112
113 @Test
114 public void getFamilieLeavesTest() {
115 OWLClass familie = reasoner.getObject("Familie");
116
117 List<OWLClass> expecteddepth1 = Arrays
118 .asList("Broer", "Tante", "Oma", "Zus", "Oom", "Opa").stream()
119 .map(name -> reasoner.getObject(name))
120 .collect(Collectors.toList());
121
122 List<OWLClass> expecteddepth2 = Arrays
123 .asList("Broer", "Tante", "Stiefmoeder", "Stiefvader", "Oma",
124 "Zus", "Vader", "Moeder", "Oom", "Opa")
125 .stream().map(name -> reasoner.getObject(name))
126 .collect(Collectors.toList());
127
128 assertEquals(expecteddepth1, reasoner.getLeaves(familie, 1));
129 assertEquals(expecteddepth2, reasoner.getLeaves(familie, 2));
130 }
131
132 @Test
133 public void getFamilieChildrenTest() {
134 OWLClass familie = reasoner.getObject("Familie");
135
136 List<OWLClass> expecteddepth1 = Arrays
137 .asList("Broer", "Tante", "Stiefouders", "Oma", "Zus", "Ouders",
138 "Oom", "Opa")
139 .stream().map(name -> reasoner.getObject(name))
140 .collect(Collectors.toList());
141
142 List<OWLClass> expecteddepth2 = Arrays
143 .asList("Broer", "Tante", "Stiefmoeder", "Stiefvader", "Oma",
144 "Zus", "Vader", "Moeder", "Oom", "Opa")
145 .stream().map(name -> reasoner.getObject(name))
146 .collect(Collectors.toList());
147
148 assertEquals(expecteddepth1, reasoner.getChildren(familie, 1));
149 assertEquals(expecteddepth2, reasoner.getChildren(familie, 2));
150 }
151
152 @Test
153 public void getPropertiesTest() {
154 OWLClass bed = reasoner.getObject("Bed");
155 List<OWLDataPropertyDomainAxiom> props = reasoner.getProperties(bed);
156 assertTrue(props.get(0).getProperty().toString()
157 .contains("#Locatie_meubel"));
158 assertTrue(props.get(1).getProperty().toString()
159 .contains("#Beschrijving_voorwerp"));
160 assertTrue(props.get(2).getProperty().toString()
161 .contains("#Beschrijving_bed"));
162 }
163
164 @Test
165 public void getProperty1Test() {
166 OWLClass bed = reasoner.getObject("Bed");
167 List<OWLDataPropertyDomainAxiom> props = reasoner.getProperties(bed);
168 // locatie_meubel
169 OWLDataPropertyDomainAxiom prop = props.get(0);
170 assertEquals("Kan je beschrijven waar in de ruimte dit meubel stond?",
171 reasoner.getComment(prop));
172 }
173
174 @Test
175 public void getProperty1RangeTest() {
176 OWLClass bed = reasoner.getObject("Bed");
177 List<OWLDataPropertyDomainAxiom> props = reasoner.getProperties(bed);
178 // locatie_meubel
179 OWLDataPropertyDomainAxiom prop = props.get(0);
180 assertEquals("http://www.w3.org/2001/XMLSchema#string",
181 reasoner.getRange(prop));
182 }
183
184}
Note: See TracBrowser for help on using the repository browser.