Skip to content

Commit 398df2b

Browse files
authored
Merge pull request #723 from cambridge-cares/dev-UnitTest-TBoxGenerator
dev-UnitTest-TBoxGenerator Added three Unit Tests
2 parents d04f82d + ec837ff commit 398df2b

File tree

3 files changed

+552
-0
lines changed

3 files changed

+552
-0
lines changed

JPS_BASE_LIB/src/test/java/uk/ac/cam/cares/jps/base/converter/test/TBoxGenerationTest.java

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,20 @@ public class TBoxGenerationTest {
3131
private final String SAMPLE_TBOX_CSV_TEMPLATE_FILE_3 = "sample-tbox-template-input-3.csv";
3232
private final String SAMPLE_TBOX_CSV_TEMPLATE_FILE_4 = "sample-tbox-template-input-4.csv";
3333
private final String SAMPLE_TBOX_CSV_TEMPLATE_FILE_5 = "sample-tbox-template-input-5.csv";
34+
private final String SAMPLE_TBOX_CSV_TEMPLATE_FILE_6 = "sample-tbox-template-input-6.csv";
35+
private final String SAMPLE_TBOX_CSV_TEMPLATE_FILE_7 = "sample-tbox-template-input-7.csv";
36+
private final String SAMPLE_TBOX_CSV_TEMPLATE_FILE_8 = "sample-tbox-template-input-8.csv";
37+
private final String SAMPLE_TBOX_CSV_TEMPLATE_FILE_9 = "sample-tbox-template-input-9.csv";
3438

3539
private final String REFERENCE_OWL_FILE_1 = "sample-tbox-template-input-1.owl";
3640
private final String REFERENCE_OWL_FILE_2 = "sample-tbox-template-input-2.owl";
3741
private final String REFERENCE_OWL_FILE_3 = "sample-tbox-template-input-3.owl";
3842
private final String REFERENCE_OWL_FILE_4 = "sample-tbox-template-input-4.owl";
3943
private final String REFERENCE_OWL_FILE_5 = "sample-tbox-template-input-5.owl";
44+
private final String REFERENCE_OWL_FILE_6 = "sample-tbox-template-input-6.owl";
45+
private final String REFERENCE_OWL_FILE_7 = "sample-tbox-template-input-7.owl";
46+
private final String REFERENCE_OWL_FILE_8 = "sample-tbox-template-input-8.owl";
47+
private final String REFERENCE_OWL_FILE_9 = "sample-tbox-template-input-9.owl";
4048

4149
private final String FILE_EXTENSION_CSV = ".csv";
4250
private final String FILE_EXTENSION_OWL = ".owl";
@@ -140,7 +148,93 @@ public void testClassEquivalentRelation(){
140148
assertEquals(referenceOntology.getAxiomCount(), generatedOntology.getAxiomCount());
141149
assertEquals(referenceOntology.getAxioms(), generatedOntology.getAxioms());
142150
}
151+
152+
/**
153+
* This is to test if the Domain-Range will not be created when:
154+
* (a) there is a presence of a Quantifier in the Domain-Range relationship
155+
* AND
156+
* (b) when there IS-A relation between the ancestors of the Domain and Range with the same Object Property
157+
*/
158+
@Test
159+
public void testSkipDomainRangeCreation(){
160+
OWLOntology generatedOntology = generateOntology(SAMPLE_CSV_FILE_PATH+SAMPLE_TBOX_CSV_TEMPLATE_FILE_6);
161+
if (generatedOntology == null) {
162+
throw new JPSRuntimeException("The requested CSV file could not be converted into an ontology.");
163+
}
164+
165+
OWLOntology referenceOntology = readReferenceOntology(REFERENCE_OWL_FILE_PATH+REFERENCE_OWL_FILE_6);
166+
if (referenceOntology == null) {
167+
throw new JPSRuntimeException("The requested reference ontology could not be read from the provided path.");
168+
}
169+
170+
assertEquals(referenceOntology.getAxiomCount(), generatedOntology.getAxiomCount());
171+
assertEquals(referenceOntology.getAxioms(), generatedOntology.getAxioms());
172+
}
173+
174+
/**
175+
* This is to test if the Domain-Range that are Union-ed will not be created when:
176+
* (a) there is a presence of a Quantifier in the Domain-Range relationship
177+
* AND
178+
* (b) when there IS-A relation between the ancestors of the Domain and Range with the same Object Property
179+
*/
180+
@Test
181+
public void testSkipDomainRangeCreationUnion(){
182+
OWLOntology generatedOntology = generateOntology(SAMPLE_CSV_FILE_PATH+SAMPLE_TBOX_CSV_TEMPLATE_FILE_7);
183+
if (generatedOntology == null) {
184+
throw new JPSRuntimeException("The requested CSV file could not be converted into an ontology.");
185+
}
186+
187+
OWLOntology referenceOntology = readReferenceOntology(REFERENCE_OWL_FILE_PATH+REFERENCE_OWL_FILE_7);
188+
if (referenceOntology == null) {
189+
throw new JPSRuntimeException("The requested reference ontology could not be read from the provided path.");
190+
}
191+
192+
assertEquals(referenceOntology.getAxiomCount(), generatedOntology.getAxiomCount());
193+
assertEquals(referenceOntology.getAxioms(), generatedOntology.getAxioms());
194+
}
195+
196+
/**
197+
* This is to test if the Domain-Range that are Intersect-ed will not be created when:
198+
* (a) there is a presence of a Quantifier in the Domain-Range relationship
199+
* AND
200+
* (b) when there IS-A relation between the ancestors of the Domain and Range with the same Object Property
201+
*/
202+
@Test
203+
public void testSkipDomainRangeCreationIntersection(){
204+
OWLOntology generatedOntology = generateOntology(SAMPLE_CSV_FILE_PATH+SAMPLE_TBOX_CSV_TEMPLATE_FILE_8);
205+
if (generatedOntology == null) {
206+
throw new JPSRuntimeException("The requested CSV file could not be converted into an ontology.");
207+
}
208+
209+
OWLOntology referenceOntology = readReferenceOntology(REFERENCE_OWL_FILE_PATH+REFERENCE_OWL_FILE_8);
210+
if (referenceOntology == null) {
211+
throw new JPSRuntimeException("The requested reference ontology could not be read from the provided path.");
212+
}
213+
214+
assertEquals(referenceOntology.getAxiomCount(), generatedOntology.getAxiomCount());
215+
assertEquals(referenceOntology.getAxioms(), generatedOntology.getAxioms());
216+
}
143217

218+
/**
219+
* This is to test if the Domain-Range creation with a mix of Union and Intersect are created correctly
220+
*/
221+
@Test
222+
public void testSkipDomainRangeCreationWithUnionAndIntersectionMix(){
223+
OWLOntology generatedOntology = generateOntology(SAMPLE_CSV_FILE_PATH+SAMPLE_TBOX_CSV_TEMPLATE_FILE_9);
224+
if (generatedOntology == null) {
225+
throw new JPSRuntimeException("The requested CSV file could not be converted into an ontology.");
226+
}
227+
228+
OWLOntology referenceOntology = readReferenceOntology(REFERENCE_OWL_FILE_PATH+REFERENCE_OWL_FILE_9);
229+
if (referenceOntology == null) {
230+
throw new JPSRuntimeException("The requested reference ontology could not be read from the provided path.");
231+
}
232+
233+
assertEquals(referenceOntology.getAxiomCount(), generatedOntology.getAxiomCount());
234+
assertEquals(referenceOntology.getAxioms(), generatedOntology.getAxioms());
235+
}
236+
237+
144238
/**
145239
* Reads an ontology from a file located in the file system.
146240
*
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Source,Type,Target,Relation,Domain,Range,Quantifier,Comment,Defined By,Label
2+
TestTBox,TBox,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,https://www.w3.org/2007/05/powder-s#hasIRI,,,,,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,
3+
TestTBox,TBox,1,http://www.w3.org/2002/07/owl#versionInfo,,,,,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,
4+
TestTBox,TBox,OntoKin is an ontology developed for representing chemical kinetic reaction mechanisms.,http://www.w3.org/2000/01/rdf-schema#comment,,,,,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,
5+
TestTBox,TBox,,http://www.w3.org/2002/07/owl#imports,,,,,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,
6+
A,Class,,,,,,Comment for A,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,A
7+
B,Class,A,IS-A,,,,Comment for B,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,B
8+
C,Class,B,IS-A,,,,Comment for C,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,C
9+
D,Class,,,,,,Comment for D,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,D
10+
E,Class,,,,,,Comment for E,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,E
11+
F,Class,,,,,,Comment for F,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,F
12+
G,Class,,,,,,Comment for G,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,G
13+
I,Class,,,,,,Comment for I,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,I
14+
J,Class,,,,,,Comment for J,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,J
15+
K,Class,,,,,,Comment for K,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,K
16+
L,Class,,,,,,Comment for L,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,L
17+
M,Class,,,,,,Comment for M,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,M
18+
N,Class,,,,,,Comment for N,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,N
19+
O,Class,,,,,,Comment for O,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,O
20+
X,Class,,,,,,Comment for X,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,X
21+
Y,Class,X,IS-A,,,,Comment for Y,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,Y
22+
Z,Class,Y,IS-A,,,,Comment for Z,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,Z
23+
has,Object Property,,,A,X,,Comment for A has X,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,has
24+
has,Object Property,,,B UNION D,Y UNION E,some,Comment for B has Y,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,has
25+
has,Object Property,,,C UNION F,Z,only,Comment for C has Z,http://www.theworldavatar.com/ontology/testtbox/TestTBox.owl,has
26+
hasR,Object Property,,,G,I INTERSECTION J,some,Comment for G hasR I Union J,,hasR
27+
hasRel,Object Property,,,K INTERSECTION L,M INTERSECTION N INTERSECTION O,only,,,hasRel
28+
hasRel,Object Property,,,K INTERSECTION L,M INTERSECTION N INTERSECTION O,some,,,hasRel

0 commit comments

Comments
 (0)