001    /**
002     * Copyright (C) 2007-2008, Jens Lehmann
003     *
004     * This file is part of DL-Learner.
005     * 
006     * DL-Learner is free software; you can redistribute it and/or modify
007     * it under the terms of the GNU General Public License as published by
008     * the Free Software Foundation; either version 3 of the License, or
009     * (at your option) any later version.
010     *
011     * DL-Learner is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     * GNU General Public License for more details.
015     *
016     * You should have received a copy of the GNU General Public License
017     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018     *
019     */
020    package org.dllearner.test.junit;
021    
022    import static org.junit.Assert.assertTrue;
023    
024    import java.util.LinkedHashMap;
025    import java.util.Map;
026    import java.util.Set;
027    import java.util.TreeSet;
028    import java.util.Map.Entry;
029    
030    import org.dllearner.algorithms.el.ELDescriptionNode;
031    import org.dllearner.algorithms.el.ELDescriptionTree;
032    import org.dllearner.core.ReasonerComponent;
033    import org.dllearner.core.owl.NamedClass;
034    import org.dllearner.core.owl.ObjectProperty;
035    import org.dllearner.parser.KBParser;
036    import org.dllearner.test.junit.TestOntologies.TestOntology;
037    import org.junit.Test;
038    
039    /**
040     * We test whether level-restricted, non-reflexive simulations on
041     * EL description trees are correctly computed.
042     * 
043     * @author Jens Lehmann
044     *
045     */
046    public class SimulationTests {
047            
048            /**
049             * Empty tree - empty simulation.
050             *
051             */
052            @Test
053            public void test1() {
054                    // perform test with empty background knowledge and TOP concept
055                    ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.EMPTY);
056                    ELDescriptionTree tree = new ELDescriptionTree(rs);
057                    ELDescriptionNode root = new ELDescriptionNode(tree);
058                    
059                    // simulation relation should be empty
060                    assertEmpty(root);
061            }
062            
063            /**
064             *   v1:{A1}
065             *         / \
066             *       r1  r2
067             *       /     \
068             *      v2:{} v3:{}
069         *
070             *      v1: -
071             *      v2: in=inSC1=inSC2=out=outSC1=outSC2={v3}
072             *      v3: in=inSC1=inSC2=out=outSC1=outSC2={v2}
073             */
074            @Test
075            public void test2() {
076                    // perform test with empty background knowledge and A1 AND EXISTS r1.TOP AND EXISTS r2.TOP
077                    ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.EMPTY);
078                    ELDescriptionTree tree = new ELDescriptionTree(rs);
079                    NamedClass a1 = new NamedClass(uri("a1"));
080                    ELDescriptionNode v1 = new ELDescriptionNode(tree);
081                    v1.extendLabel(a1);
082                    ObjectProperty r1 = new ObjectProperty(uri("r1"));
083                    ELDescriptionNode v2 = new ELDescriptionNode(v1, r1, new TreeSet<NamedClass>());
084                    ObjectProperty r2 = new ObjectProperty(uri("r2"));
085                    ELDescriptionNode v3 = new ELDescriptionNode(v1, r2, new TreeSet<NamedClass>());
086                                    
087                    assertEmpty(v1);
088                    assertAll(v2, v3);
089                    assertAll(v3, v2);
090            }
091            
092            /**
093             * K: r1 \sqsubset r2
094         *
095         *           v1:{}
096         *       /     |     \
097         *     r1     r1      r2
098         *     /       |        \
099         * v2:{A1,A2} v3:{A2} v4:{A1}
100         *
101         * v1: -
102         * v2: in=inSC1=inSC2=outSC2={v3,v4}
103         * v3: out=outSC1={v2}, inSC2=outSC2={v2,v4}
104         * v4: out=outSC1={v2}, inSC2=outSC2={v2,v3}
105             */
106            @Test
107            public void test3() {   
108                    // background knowledge, concepts, roles
109                    ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.R1SUBR2);
110                    ObjectProperty r1 = new ObjectProperty(uri("r1"));
111                    NamedClass a1 = new NamedClass(uri("a1"));
112                    NamedClass a2 = new NamedClass(uri("a2"));
113                    ObjectProperty r2 = new ObjectProperty(uri("r2"));
114                    
115                    // iteratively building up the tree (nodeNames is used for logging/debugging)
116                    ELDescriptionTree tree = new ELDescriptionTree(rs);
117                    Map<ELDescriptionNode,String> nodeNames = new LinkedHashMap<ELDescriptionNode,String>();                            
118                    ELDescriptionNode v1 = new ELDescriptionNode(tree);
119                    nodeNames.put(v1, "v1");
120    //              log("root node v1", tree, nodeNames);
121                    ELDescriptionNode v2 = new ELDescriptionNode(v1, r1);
122                    nodeNames.put(v2, "v2");
123    //              log("edge to v2 added", tree, nodeNames);
124                    v2.extendLabel(a1);
125    //              log("a1 added to v2", tree, nodeNames);
126                    v2.extendLabel(a2);
127    //              log("a2 added to v2", tree, nodeNames);
128                    ELDescriptionNode v3 = new ELDescriptionNode(v1, r1);
129                    nodeNames.put(v3, "v3");
130    //              log("edge to v3 added", tree, nodeNames);
131                    v3.extendLabel(a2);
132    //              log("a2 added to v3", tree, nodeNames);
133                    ELDescriptionNode v4 = new ELDescriptionNode(v1, r2);
134                    nodeNames.put(v4, "v4");
135    //              log("edge to v4 added", tree, nodeNames);
136                    v4.extendLabel(a1);
137    //              log("a1 added to v4", tree, nodeNames);
138    //              log("tree 3", tree, nodeNames);
139                    
140                    assertEmpty(v1);
141                    
142                    assertAllIn(v2, v3, v4);
143                    assertOutSC2(v2, v3, v4);
144                    assertOutSC1(v2);
145                    assertOut(v2);
146                    
147                    assertOut(v3,v2);
148                    assertOutSC1(v3,v2);
149                    assertSC2(v3, v2, v4);
150                    assertInSC1(v3);
151                    assertIn(v3);
152                    
153                    assertOut(v4,v2);
154                    assertOutSC1(v4,v2);
155                    assertSC2(v4, v2, v3);
156                    assertInSC1(v4);
157                    assertIn(v4);                   
158            }
159            
160            /**
161             * K: r2 \sqsubset r3; A2 \sqsubset A3
162             * 
163             *            v1: {}
164         *           /      \
165         *         r1        r1
166         *         /          \
167         *     v2:{A2,A3}    v3:{}
168         *     /      |        |
169         *   r1      r2        r3
170         *   /        |        |
171         * v4:{A1} v5:{A1,A2} v6:{A3}
172             *
173             * v1: -
174         * v2: in=inSC1=inSC2={v3}, out=outSC1=outSC2={}
175         * v3: in=inSC1=inSC2={}, out=outSC1=outSC2={v2}
176         * v4: out=outSC1={v5}, outSC2=inSC2={v5,v6}, in=inSC1={}
177         * v5: out=outSC1={}, in=inSC1=inSC2=outSC2={v4,v6}
178         * v6: out=outSC1={v5}, outSC2=inSC2={v4,v5}, in=inSC1={}
179             *
180             */
181            @Test
182            public void test4() {
183                    ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE2);
184                    ELDescriptionTree tree = new ELDescriptionTree(rs);
185                    Map<ELDescriptionNode,String> nodeNames = new LinkedHashMap<ELDescriptionNode,String>();                            
186                    
187                    ObjectProperty r1 = new ObjectProperty(uri("r1"));
188                    ObjectProperty r2 = new ObjectProperty(uri("r2"));
189                    ObjectProperty r3 = new ObjectProperty(uri("r3"));
190                    NamedClass a1 = new NamedClass(uri("a1"));
191                    NamedClass a2 = new NamedClass(uri("a2"));
192                    NamedClass a3 = new NamedClass(uri("a3"));              
193    
194                    ELDescriptionNode v1 = new ELDescriptionNode(tree);
195                    nodeNames.put(v1, "v1");
196                    ELDescriptionNode v2 = new ELDescriptionNode(v1, r1, a2, a3);
197                    nodeNames.put(v2, "v2");
198    //              log("v2 added", tree, nodeNames);
199                    ELDescriptionNode v3 = new ELDescriptionNode(v1, r1);
200                    nodeNames.put(v3, "v3");
201    //              log("v3 added", tree, nodeNames);
202                    ELDescriptionNode v4 = new ELDescriptionNode(v2, r1, a1);
203                    nodeNames.put(v4, "v4");
204    //              log("v4 added", tree, nodeNames);
205                    ELDescriptionNode v5 = new ELDescriptionNode(v2, r3);
206                    nodeNames.put(v5, "v5");
207    //              log("tmp 1", tree, nodeNames);
208                    v5.extendLabel(a1);
209    //              log("tmp 2", tree, nodeNames);
210                    v5.extendLabel(a2);
211    //              log("v5 added", tree, nodeNames);
212                    v2.refineEdge(1, r2);
213    //              log("edge refined", tree, nodeNames);
214                    ELDescriptionNode v6 = new ELDescriptionNode(v3, r3);
215                    nodeNames.put(v6, "v6");
216    //              log("v6 added", tree, nodeNames);               
217                    v6.extendLabel(a3);
218    //              log("tree 4", tree, nodeNames);
219                    
220                    assertEmpty(v1);
221                    
222                    assertAllIn(v2, v3);
223                    assertAllOut(v2);
224                    
225                    assertAllIn(v3);
226                    assertAllOut(v2);
227                    
228                    assertSC2(v4,v5,v6);
229                    assertInSC1(v4);
230                    assertIn(v4);
231                    assertOut(v4,v5);
232                    assertOutSC1(v4,v5);
233                    
234                    assertAllIn(v5,v4,v6);
235                    assertOutSC2(v5,v4,v6);
236                    assertOutSC1(v5);
237                    assertOut(v5);
238                    
239                    assertSC2(v6,v4,v5);
240                    assertInSC1(v6);
241                    assertIn(v6);
242                    assertOut(v6,v5);
243                    assertOutSC1(v6,v5);    
244            }
245            
246            /**
247             *                  v_1
248         *                /     \
249         *               r_2    r_1
250         *              /         \
251         *            v_2         v_3
252         *            /  |        |  \
253         *          r_1 r_1      r_1 r_2
254         *          /    |        |    \
255         *        v_4   v_5      v_6   v_7
256         *        / |   |  \      |     |
257         *      r_2 r_1 r_2 r_2  r_1   r_2
258         *      /   |   |    |    |     |
259         *    v_8  v_9 v_10 v_11 v_12  v_13
260         *    A_1  A_2  A_2 A_1  A_2   A_2 
261         *    
262         * Knowledge base: A_1\sqsubseteq A_2
263                           r_1\sqsubseteq r_2   
264         *    
265             * inSC1:
266             * (v_8,{v_9,..,v_13}), (v_9,{v_10,v_12,v_13}),... (Pattern wiederholt sich dann fuer die A_1 bzw A_2 Blaetter), 
267             * (v_4,{v_5,v_6,v_7}),... (selbiges hier) (v_2,{v_3}), (v_3,{v_2})
268             *
269             * outSC1:
270             * (v_8,{v_11}), v_9,{v_8, v_10,...v_13}),... Pattern wiederholt sich
271             * fuer restliche Knoten gilt inSC1=outSC1
272             * 
273             * inSC2:
274             * {v_8,...,v_13}2, (v_4,{v_5, v_6, v_7}), (v_5,{v_7}), (v_6,{v_7})
275             * (v_2,{v_3})
276             * 
277             * outSC2:
278             * {v_8,...,v_13}2, (v_5,{v_4}), (v_6,{v_4}), (v_7,{v_5, v_6}), (v_3,{v_2})
279             * 
280             * Baum ist nicht minimal. 
281             */
282            @Test
283            public void test5() {
284                    ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE3);
285                    ELDescriptionTree tree = new ELDescriptionTree(rs);
286                    Map<ELDescriptionNode,String> nodeNames = new LinkedHashMap<ELDescriptionNode,String>();                            
287                                    
288                    ObjectProperty r1 = new ObjectProperty(uri("r1"));
289                    ObjectProperty r2 = new ObjectProperty(uri("r2"));
290                    NamedClass a1 = new NamedClass(uri("a1"));
291                    NamedClass a2 = new NamedClass(uri("a2"));
292                    
293                    ELDescriptionNode v1 = new ELDescriptionNode(tree);
294                    nodeNames.put(v1, "v1");
295                    ELDescriptionNode v2 = new ELDescriptionNode(v1, r2);
296                    nodeNames.put(v2, "v2");
297                    ELDescriptionNode v3 = new ELDescriptionNode(v1, r1);
298                    nodeNames.put(v3, "v3");
299                    ELDescriptionNode v4 = new ELDescriptionNode(v2, r1);
300                    nodeNames.put(v4, "v4");
301                    ELDescriptionNode v5 = new ELDescriptionNode(v2, r1);
302                    nodeNames.put(v5, "v5");
303                    ELDescriptionNode v6 = new ELDescriptionNode(v3, r1);
304                    nodeNames.put(v6, "v6");
305                    ELDescriptionNode v7 = new ELDescriptionNode(v3, r2);
306                    nodeNames.put(v7, "v7");
307                    ELDescriptionNode v8 = new ELDescriptionNode(v4, r2, a1);
308                    nodeNames.put(v8, "v8");
309                    ELDescriptionNode v9 = new ELDescriptionNode(v4, r1, a2);
310                    nodeNames.put(v9, "v9");
311                    ELDescriptionNode v10 = new ELDescriptionNode(v5, r2, a2);
312                    nodeNames.put(v10, "v10");
313                    ELDescriptionNode v11 = new ELDescriptionNode(v5, r2, a1);
314                    nodeNames.put(v11, "v11");
315                    ELDescriptionNode v12 = new ELDescriptionNode(v6, r1, a2);
316                    nodeNames.put(v12, "v12");
317                    ELDescriptionNode v13 = new ELDescriptionNode(v7, r2, a2);
318                    nodeNames.put(v13, "v13");
319                    
320    //              log("tree 5", tree, nodeNames);
321                    
322                    assertTrue(!tree.isMinimal());
323                    
324                    // automatically generated asserts
325                    
326                    assertInSC1(v1);
327                    assertInSC2(v1);
328                    assertIn(v1);
329                    assertOutSC1(v1);
330                    assertOutSC2(v1);
331                    assertOut(v1);
332    
333                    assertInSC1(v2,v3);
334                    assertInSC2(v2,v3);
335                    assertIn(v2,v3);
336                    assertOutSC1(v2,v3);
337                    assertOutSC2(v2);
338                    assertOut(v2);
339    
340                    assertInSC1(v3,v2);
341                    assertInSC2(v3);
342                    assertIn(v3);
343                    assertOutSC1(v3,v2);
344                    assertOutSC2(v3,v2);
345                    assertOut(v3,v2);
346    
347                    assertInSC1(v4,v6,v5,v7);
348                    assertInSC2(v4,v6,v5,v7);
349                    assertIn(v4,v6,v5,v7);
350                    assertOutSC1(v4,v6,v5,v7);
351                    assertOutSC2(v4);
352                    assertOut(v4);
353    
354                    assertInSC1(v5,v4,v6,v7);
355                    assertInSC2(v5,v7);
356                    assertIn(v5,v7);
357                    assertOutSC1(v5,v4,v6,v7);
358                    assertOutSC2(v5,v4);
359                    assertOut(v5,v4);
360    
361                    assertInSC1(v6,v4,v5,v7);
362                    assertInSC2(v6,v7);
363                    assertIn(v6,v7);
364                    assertOutSC1(v6,v4,v5,v7);
365                    assertOutSC2(v6,v4);
366                    assertOut(v6,v4);
367    
368                    assertInSC1(v7,v4,v6,v5);
369                    assertInSC2(v7);
370                    assertIn(v7);
371                    assertOutSC1(v7,v4,v6,v5);
372                    assertOutSC2(v7,v4,v6,v5);
373                    assertOut(v7,v4,v6,v5);
374    
375                    assertInSC1(v8,v10,v13,v11,v9,v12);
376                    assertInSC2(v8,v10,v13,v11,v9,v12);
377                    assertIn(v8,v10,v13,v11,v9,v12);
378                    assertOutSC1(v8,v11);
379                    assertOutSC2(v8,v10,v13,v11,v9,v12);
380                    assertOut(v8,v11);
381    
382                    assertInSC1(v9,v10,v13,v12);
383                    assertInSC2(v9,v10,v13,v11,v12,v8);
384                    assertIn(v9,v10,v13,v12);
385                    assertOutSC1(v9,v10,v13,v11,v12,v8);
386                    assertOutSC2(v9,v10,v13,v11,v12,v8);
387                    assertOut(v9,v10,v13,v11,v12,v8);
388    
389                    assertInSC1(v10,v13,v9,v12);
390                    assertInSC2(v10,v13,v11,v9,v12,v8);
391                    assertIn(v10,v13,v9,v12);
392                    assertOutSC1(v10,v13,v11,v9,v12,v8);
393                    assertOutSC2(v10,v13,v11,v9,v12,v8);
394                    assertOut(v10,v13,v11,v9,v12,v8);
395    
396                    assertInSC1(v11,v10,v13,v9,v12,v8);
397                    assertInSC2(v11,v10,v13,v9,v12,v8);
398                    assertIn(v11,v10,v13,v9,v12,v8);
399                    assertOutSC1(v11,v8);
400                    assertOutSC2(v11,v10,v13,v9,v12,v8);
401                    assertOut(v11,v8);
402    
403                    assertInSC1(v12,v10,v13,v9);
404                    assertInSC2(v12,v10,v13,v11,v9,v8);
405                    assertIn(v12,v10,v13,v9);
406                    assertOutSC1(v12,v10,v13,v11,v9,v8);
407                    assertOutSC2(v12,v10,v13,v11,v9,v8);
408                    assertOut(v12,v10,v13,v11,v9,v8);
409    
410                    assertInSC1(v13,v10,v9,v12);
411                    assertInSC2(v13,v10,v11,v9,v8,v12);
412                    assertIn(v13,v10,v9,v12);
413                    assertOutSC1(v13,v10,v11,v9,v8,v12);
414                    assertOutSC2(v13,v10,v11,v9,v8,v12);
415                    assertOut(v13,v10,v11,v9,v8,v12);
416                    
417    //              logAsserts(tree, nodeNames);
418            }
419            
420            /**
421             *                -------v_22-------
422         *               /         |        \
423         *              r_1       r_1       r_1
424         *             /           |          \
425         *           v_19         v_20         v_21
426         *           /  \         /  \         /  \
427         *         r_2 r_2     r_2  r_2      r_2  r_2
428         *        /      |      |     |        |    |
429         *       v_13   v_14   v_15  v_16     v_17  v_18__
430         *      /  \    /\      /\     / \     /  |    |  \
431         *    r_3 r_4 r_3 r_5 r_3 r_5 r_4 r_5 r_4 r_5 r_3 r_4
432         *     |   |   |   |   |   |   |   |   |   |   |    |
433         *    v_1 v_2 v_3 v_4 v_5 v_6 v_7 v_8 v_9 v_10 v_11 v_12
434         *
435             * SC1=inSC1=outSC1={v_1,..,v_12}2 U {v_13,..,v_18}2 U {v_19,v_20,v_21}2
436             *
437             * SC2={v_1,..,v_12}2 U {(v_13, v_18), (v_14,v_15), (v_16,v_17)} U
438             * {(v_18, v_13), (v_15,v_14), (v_17,v_16)}
439             * 
440             * S={v_1,..,v_12}2 
441             */
442            @Test
443            public void test6() {
444                    ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.FIVE_ROLES);
445                    ELDescriptionTree tree = new ELDescriptionTree(rs);
446                    Map<ELDescriptionNode,String> nodeNames = new LinkedHashMap<ELDescriptionNode,String>();                            
447                    
448                    ObjectProperty r1 = new ObjectProperty(uri("r1"));
449                    ObjectProperty r2 = new ObjectProperty(uri("r2"));
450                    ObjectProperty r3 = new ObjectProperty(uri("r3"));
451                    ObjectProperty r4 = new ObjectProperty(uri("r4"));
452                    ObjectProperty r5 = new ObjectProperty(uri("r5"));
453            
454                    ELDescriptionNode v22 = new ELDescriptionNode(tree);
455                    nodeNames.put(v22, "v22");
456                    ELDescriptionNode v21 = new ELDescriptionNode(v22, r1);
457                    nodeNames.put(v21, "v21");
458                    ELDescriptionNode v20 = new ELDescriptionNode(v22, r1);
459                    nodeNames.put(v20, "v20");
460                    ELDescriptionNode v19 = new ELDescriptionNode(v22, r1);
461                    nodeNames.put(v19, "v19");
462                    ELDescriptionNode v18 = new ELDescriptionNode(v21, r2);
463                    nodeNames.put(v18, "v18");
464                    ELDescriptionNode v17 = new ELDescriptionNode(v21, r2);
465                    nodeNames.put(v17, "v17");
466                    ELDescriptionNode v16 = new ELDescriptionNode(v20, r2);
467                    nodeNames.put(v16, "v16");
468                    ELDescriptionNode v15 = new ELDescriptionNode(v20, r2);
469                    nodeNames.put(v15, "v15");
470                    ELDescriptionNode v14 = new ELDescriptionNode(v19, r2);
471                    nodeNames.put(v14, "v14");
472                    ELDescriptionNode v13 = new ELDescriptionNode(v19, r2);
473                    nodeNames.put(v13, "v13");
474                    ELDescriptionNode v12 = new ELDescriptionNode(v18, r4);
475                    nodeNames.put(v12, "v12");
476                    ELDescriptionNode v11 = new ELDescriptionNode(v18, r3);
477                    nodeNames.put(v11, "v11");
478                    ELDescriptionNode v10 = new ELDescriptionNode(v17, r5);
479                    nodeNames.put(v10, "v10");
480                    ELDescriptionNode v9 = new ELDescriptionNode(v17, r4);
481                    nodeNames.put(v9, "v9");
482                    ELDescriptionNode v8 = new ELDescriptionNode(v16, r5);
483                    nodeNames.put(v8, "v8");
484                    ELDescriptionNode v7 = new ELDescriptionNode(v16, r4);
485                    nodeNames.put(v7, "v7");
486                    ELDescriptionNode v6 = new ELDescriptionNode(v15, r5);
487                    nodeNames.put(v6, "v6");
488                    ELDescriptionNode v5 = new ELDescriptionNode(v15, r3);
489                    nodeNames.put(v5, "v5");
490                    ELDescriptionNode v4 = new ELDescriptionNode(v14, r5);
491                    nodeNames.put(v4, "v4");
492                    ELDescriptionNode v3 = new ELDescriptionNode(v14, r3);
493                    nodeNames.put(v3, "v3");
494                    ELDescriptionNode v2 = new ELDescriptionNode(v13, r4);
495                    nodeNames.put(v2, "v2");
496                    ELDescriptionNode v1 = new ELDescriptionNode(v13, r3);
497                    nodeNames.put(v1, "v1");
498    
499    //              log("tree 6", tree, nodeNames);
500    //              logAsserts(tree, nodeNames);
501                    
502                    assertTrue(tree.isMinimal());
503                    
504                    // automatically added asserts          
505                    assertInSC1(v22);
506                    assertInSC2(v22);
507                    assertIn(v22);
508                    assertOutSC1(v22);
509                    assertOutSC2(v22);
510                    assertOut(v22);
511    
512                    assertInSC1(v21,v20,v19);
513                    assertInSC2(v21);
514                    assertIn(v21);
515                    assertOutSC1(v21,v20,v19);
516                    assertOutSC2(v21);
517                    assertOut(v21);
518    
519                    assertInSC1(v20,v21,v19);
520                    assertInSC2(v20);
521                    assertIn(v20);
522                    assertOutSC1(v20,v21,v19);
523                    assertOutSC2(v20);
524                    assertOut(v20);
525    
526                    assertInSC1(v19,v20,v21);
527                    assertInSC2(v19);
528                    assertIn(v19);
529                    assertOutSC1(v19,v20,v21);
530                    assertOutSC2(v19);
531                    assertOut(v19);
532    
533                    assertInSC1(v18,v14,v16,v15,v17,v13);
534                    assertInSC2(v18,v13);
535                    assertIn(v18,v13);
536                    assertOutSC1(v18,v14,v16,v15,v17,v13);
537                    assertOutSC2(v18,v13);
538                    assertOut(v18,v13);
539    
540                    assertInSC1(v17,v14,v16,v18,v15,v13);
541                    assertInSC2(v17,v16);
542                    assertIn(v17,v16);
543                    assertOutSC1(v17,v14,v16,v18,v15,v13);
544                    assertOutSC2(v17,v16);
545                    assertOut(v17,v16);
546    
547                    assertInSC1(v16,v14,v18,v15,v17,v13);
548                    assertInSC2(v16,v17);
549                    assertIn(v16,v17);
550                    assertOutSC1(v16,v14,v18,v15,v17,v13);
551                    assertOutSC2(v16,v17);
552                    assertOut(v16,v17);
553    
554                    assertInSC1(v15,v14,v16,v18,v17,v13);
555                    assertInSC2(v15,v14);
556                    assertIn(v15,v14);
557                    assertOutSC1(v15,v14,v16,v18,v17,v13);
558                    assertOutSC2(v15,v14);
559                    assertOut(v15,v14);
560    
561                    assertInSC1(v14,v16,v18,v15,v17,v13);
562                    assertInSC2(v14,v15);
563                    assertIn(v14,v15);
564                    assertOutSC1(v14,v16,v18,v15,v17,v13);
565                    assertOutSC2(v14,v15);
566                    assertOut(v14,v15);
567    
568                    assertInSC1(v13,v14,v16,v18,v15,v17);
569                    assertInSC2(v13,v18);
570                    assertIn(v13,v18);
571                    assertOutSC1(v13,v14,v16,v18,v15,v17);
572                    assertOutSC2(v13,v18);
573                    assertOut(v13,v18);
574    
575                    assertInSC1(v12,v3,v8,v5,v11,v4,v9,v1,v2,v7,v6,v10);
576                    assertInSC2(v12,v3,v8,v5,v11,v4,v9,v1,v2,v7,v6,v10);
577                    assertIn(v12,v3,v8,v5,v11,v4,v9,v1,v2,v7,v6,v10);
578                    assertOutSC1(v12,v3,v8,v5,v11,v4,v9,v1,v2,v7,v6,v10);
579                    assertOutSC2(v12,v3,v8,v5,v11,v4,v9,v1,v2,v7,v6,v10);
580                    assertOut(v12,v3,v8,v5,v11,v4,v9,v1,v2,v7,v6,v10);
581    
582                    assertInSC1(v11,v3,v8,v5,v4,v9,v1,v2,v7,v6,v10,v12);
583                    assertInSC2(v11,v3,v8,v5,v4,v9,v1,v2,v7,v6,v10,v12);
584                    assertIn(v11,v3,v8,v5,v4,v9,v1,v2,v7,v6,v10,v12);
585                    assertOutSC1(v11,v3,v8,v5,v4,v9,v1,v2,v7,v6,v10,v12);
586                    assertOutSC2(v11,v3,v8,v5,v4,v9,v1,v2,v7,v6,v10,v12);
587                    assertOut(v11,v3,v8,v5,v4,v9,v1,v2,v7,v6,v10,v12);
588    
589                    assertInSC1(v10,v3,v8,v5,v11,v4,v9,v1,v2,v7,v6,v12);
590                    assertInSC2(v10,v3,v8,v5,v11,v4,v9,v1,v2,v7,v6,v12);
591                    assertIn(v10,v3,v8,v5,v11,v4,v9,v1,v2,v7,v6,v12);
592                    assertOutSC1(v10,v3,v8,v5,v11,v4,v9,v1,v2,v7,v6,v12);
593                    assertOutSC2(v10,v3,v8,v5,v11,v4,v9,v1,v2,v7,v6,v12);
594                    assertOut(v10,v3,v8,v5,v11,v4,v9,v1,v2,v7,v6,v12);
595    
596                    assertInSC1(v9,v3,v8,v5,v11,v4,v1,v2,v7,v6,v10,v12);
597                    assertInSC2(v9,v3,v8,v5,v11,v4,v1,v2,v7,v6,v10,v12);
598                    assertIn(v9,v3,v8,v5,v11,v4,v1,v2,v7,v6,v10,v12);
599                    assertOutSC1(v9,v3,v8,v5,v11,v4,v1,v2,v7,v6,v10,v12);
600                    assertOutSC2(v9,v3,v8,v5,v11,v4,v1,v2,v7,v6,v10,v12);
601                    assertOut(v9,v3,v8,v5,v11,v4,v1,v2,v7,v6,v10,v12);
602    
603                    assertInSC1(v8,v3,v5,v11,v4,v9,v1,v2,v7,v6,v10,v12);
604                    assertInSC2(v8,v3,v5,v11,v4,v9,v1,v2,v7,v6,v10,v12);
605                    assertIn(v8,v3,v5,v11,v4,v9,v1,v2,v7,v6,v10,v12);
606                    assertOutSC1(v8,v3,v5,v11,v4,v9,v1,v2,v7,v6,v10,v12);
607                    assertOutSC2(v8,v3,v5,v11,v4,v9,v1,v2,v7,v6,v10,v12);
608                    assertOut(v8,v3,v5,v11,v4,v9,v1,v2,v7,v6,v10,v12);
609    
610                    assertInSC1(v7,v3,v8,v5,v11,v4,v9,v1,v2,v6,v10,v12);
611                    assertInSC2(v7,v3,v8,v5,v11,v4,v9,v1,v2,v6,v10,v12);
612                    assertIn(v7,v3,v8,v5,v11,v4,v9,v1,v2,v6,v10,v12);
613                    assertOutSC1(v7,v3,v8,v5,v11,v4,v9,v1,v2,v6,v10,v12);
614                    assertOutSC2(v7,v3,v8,v5,v11,v4,v9,v1,v2,v6,v10,v12);
615                    assertOut(v7,v3,v8,v5,v11,v4,v9,v1,v2,v6,v10,v12);
616    
617                    assertInSC1(v6,v3,v8,v5,v11,v4,v9,v1,v2,v7,v10,v12);
618                    assertInSC2(v6,v3,v8,v5,v11,v4,v9,v1,v2,v7,v10,v12);
619                    assertIn(v6,v3,v8,v5,v11,v4,v9,v1,v2,v7,v10,v12);
620                    assertOutSC1(v6,v3,v8,v5,v11,v4,v9,v1,v2,v7,v10,v12);
621                    assertOutSC2(v6,v3,v8,v5,v11,v4,v9,v1,v2,v7,v10,v12);
622                    assertOut(v6,v3,v8,v5,v11,v4,v9,v1,v2,v7,v10,v12);
623    
624                    assertInSC1(v5,v3,v8,v11,v4,v9,v1,v2,v7,v10,v6,v12);
625                    assertInSC2(v5,v3,v8,v11,v4,v9,v1,v2,v7,v10,v6,v12);
626                    assertIn(v5,v3,v8,v11,v4,v9,v1,v2,v7,v10,v6,v12);
627                    assertOutSC1(v5,v3,v8,v11,v4,v9,v1,v2,v7,v10,v6,v12);
628                    assertOutSC2(v5,v3,v8,v11,v4,v9,v1,v2,v7,v10,v6,v12);
629                    assertOut(v5,v3,v8,v11,v4,v9,v1,v2,v7,v10,v6,v12);
630    
631                    assertInSC1(v4,v3,v8,v11,v5,v9,v1,v2,v7,v10,v6,v12);
632                    assertInSC2(v4,v3,v8,v11,v5,v9,v1,v2,v7,v10,v6,v12);
633                    assertIn(v4,v3,v8,v11,v5,v9,v1,v2,v7,v10,v6,v12);
634                    assertOutSC1(v4,v3,v8,v11,v5,v9,v1,v2,v7,v10,v6,v12);
635                    assertOutSC2(v4,v3,v8,v11,v5,v9,v1,v2,v7,v10,v6,v12);
636                    assertOut(v4,v3,v8,v11,v5,v9,v1,v2,v7,v10,v6,v12);
637    
638                    assertInSC1(v3,v8,v11,v5,v4,v9,v1,v2,v7,v10,v6,v12);
639                    assertInSC2(v3,v8,v11,v5,v4,v9,v1,v2,v7,v10,v6,v12);
640                    assertIn(v3,v8,v11,v5,v4,v9,v1,v2,v7,v10,v6,v12);
641                    assertOutSC1(v3,v8,v11,v5,v4,v9,v1,v2,v7,v10,v6,v12);
642                    assertOutSC2(v3,v8,v11,v5,v4,v9,v1,v2,v7,v10,v6,v12);
643                    assertOut(v3,v8,v11,v5,v4,v9,v1,v2,v7,v10,v6,v12);
644    
645                    assertInSC1(v2,v8,v3,v11,v5,v4,v9,v1,v7,v10,v6,v12);
646                    assertInSC2(v2,v8,v3,v11,v5,v4,v9,v1,v7,v10,v6,v12);
647                    assertIn(v2,v8,v3,v11,v5,v4,v9,v1,v7,v10,v6,v12);
648                    assertOutSC1(v2,v8,v3,v11,v5,v4,v9,v1,v7,v10,v6,v12);
649                    assertOutSC2(v2,v8,v3,v11,v5,v4,v9,v1,v7,v10,v6,v12);
650                    assertOut(v2,v8,v3,v11,v5,v4,v9,v1,v7,v10,v6,v12);
651    
652                    assertInSC1(v1,v8,v3,v11,v5,v4,v9,v2,v7,v10,v6,v12);
653                    assertInSC2(v1,v8,v3,v11,v5,v4,v9,v2,v7,v10,v6,v12);
654                    assertIn(v1,v8,v3,v11,v5,v4,v9,v2,v7,v10,v6,v12);
655                    assertOutSC1(v1,v8,v3,v11,v5,v4,v9,v2,v7,v10,v6,v12);
656                    assertOutSC2(v1,v8,v3,v11,v5,v4,v9,v2,v7,v10,v6,v12);
657                    assertOut(v1,v8,v3,v11,v5,v4,v9,v2,v7,v10,v6,v12);
658    
659                    // adding an edge leads to a non-minimal tree (it collapses)
660                    new ELDescriptionNode(v13, r5);
661                    assertTrue(!tree.isMinimal());
662                    
663            }
664            
665            @Test
666            public void test7() {
667                    ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE);
668                    ELDescriptionTree tree = new ELDescriptionTree(rs);
669                    
670                    ObjectProperty has = new ObjectProperty(uri("has"));
671                    ObjectProperty hasChild = new ObjectProperty(uri("hasChild"));
672                    NamedClass human = new NamedClass(uri("human"));
673                    NamedClass animal = new NamedClass(uri("animal"));              
674                    
675                    ELDescriptionNode v1 = new ELDescriptionNode(tree, human);
676                    new ELDescriptionNode(v1, has, animal);
677                    new ELDescriptionNode(v1, hasChild);
678                    
679    //              System.out.println(tree.toSimulationString());
680                    
681                    assertTrue(tree.isMinimal());
682            }
683            
684            // display a simulation as debug log
685            @SuppressWarnings("unused")
686            private void log(String message, ELDescriptionTree tree, Map<ELDescriptionNode,String> nodeNames) {
687                    // print underlined message
688                    System.out.println(message);
689                    for(int i=0; i<=message.length(); i++) {
690                            System.out.print("=");
691                    }
692                    System.out.println("\n");
693                    System.out.println(tree.toSimulationString(nodeNames));
694            }
695            
696            // display Java code for assertions, i.e. the method generates the assertion code
697            // (under the assumption that the current algorithm output is correct, which needs
698            // to be verified of course)
699            @SuppressWarnings("unused")
700            private void logAsserts(ELDescriptionTree tree, Map<ELDescriptionNode,String> nodeNames) {
701                    String str = "";
702                    for(Entry<ELDescriptionNode,String> entry : nodeNames.entrySet()) {
703                            String nodeName = entry.getValue();
704                            ELDescriptionNode node = entry.getKey();
705                            str += "assertInSC1" + getAssertString(node, nodeName, node.getInSC1(), nodeNames);
706                            str += "assertInSC2" + getAssertString(node, nodeName, node.getInSC2(), nodeNames);
707                            str += "assertIn" + getAssertString(node, nodeName, node.getIn(), nodeNames);
708                            str += "assertOutSC1" + getAssertString(node, nodeName, node.getOutSC1(), nodeNames);
709                            str += "assertOutSC2" + getAssertString(node, nodeName, node.getOutSC2(), nodeNames);
710                            str += "assertOut" + getAssertString(node, nodeName, node.getOut(), nodeNames);
711                            str += "\n";
712                    }               
713                    System.out.println(str);
714            }
715            
716            // convenience method 
717            private String getAssertString(ELDescriptionNode node, String nodeName, Set<ELDescriptionNode> nodes, Map<ELDescriptionNode,String> nodeNames) {
718                    if(nodes.isEmpty()) {
719                            return "(" + nodeName+");\n";
720                    } else {
721                            return "(" + nodeName+","+ELDescriptionNode.toString(nodes, nodeNames) + ");\n";
722                    }
723            }
724            
725            // all relations (in, inSC1, inSC2) should have the 
726            // the specified node set as value
727            private void assertAll(ELDescriptionNode node, ELDescriptionNode... nodes) {
728                    assertAllIn(node, nodes);
729                    assertAllOut(node, nodes);
730            }
731            
732            // all in relations (in, inSC1, inSC2) should have the 
733            // specified node set as value
734            private void assertAllIn(ELDescriptionNode node, ELDescriptionNode... nodesIn) {
735                    assertIn(node, nodesIn);
736                    assertInSC1(node, nodesIn);
737                    assertInSC2(node, nodesIn);
738            }
739            
740            // all out relations (out, outSC1, outSC2) should have the 
741            // specified node set as value
742            private void assertAllOut(ELDescriptionNode node, ELDescriptionNode... nodesOut) {
743                    assertOut(node, nodesOut);
744                    assertOutSC1(node, nodesOut);
745                    assertOutSC2(node, nodesOut);
746            }
747            
748            @SuppressWarnings("unused")
749            private void assertSC(ELDescriptionNode node, ELDescriptionNode... nodesOut) {
750                    assertIn(node, nodesOut);
751                    assertOut(node, nodesOut);
752            }
753            
754            @SuppressWarnings("unused")
755            private void assertSC1(ELDescriptionNode node, ELDescriptionNode... nodesOut) {
756                    assertInSC1(node, nodesOut);
757                    assertOutSC1(node, nodesOut);
758            }       
759            
760            private void assertSC2(ELDescriptionNode node, ELDescriptionNode... nodesOut) {
761                    assertInSC2(node, nodesOut);
762                    assertOutSC2(node, nodesOut);
763            }
764            
765            private void assertInSC1(ELDescriptionNode node, ELDescriptionNode... nodes) {
766                    for(ELDescriptionNode nodeTmp : nodes) {
767                            assertTrue(node.getInSC1().contains(nodeTmp));
768                    }
769                    assertTrue(node.getInSC1().size() == nodes.length);
770            }
771            
772            private void assertInSC2(ELDescriptionNode node, ELDescriptionNode... nodes) {
773                    for(ELDescriptionNode nodeTmp : nodes) {
774                            assertTrue(node.getInSC2().contains(nodeTmp));
775                    }
776                    assertTrue(node.getInSC2().size() == nodes.length);
777            }       
778            
779            private void assertIn(ELDescriptionNode node, ELDescriptionNode... nodes) {
780                    for(ELDescriptionNode nodeTmp : nodes) {
781                            assertTrue(node.getIn().contains(nodeTmp));
782                    }
783                    assertTrue(node.getIn().size() == nodes.length);
784            }       
785            
786            private void assertOutSC2(ELDescriptionNode node, ELDescriptionNode... nodes) {
787                    for(ELDescriptionNode nodeTmp : nodes) {
788                            assertTrue(node.getOutSC2().contains(nodeTmp));
789                    }
790                    assertTrue(node.getOutSC2().size() == nodes.length);
791            }               
792            
793            private void assertOutSC1(ELDescriptionNode node, ELDescriptionNode... nodes) {
794                    for(ELDescriptionNode nodeTmp : nodes) {
795                            assertTrue(node.getOutSC1().contains(nodeTmp));
796                    }
797                    assertTrue(node.getOutSC1().size() == nodes.length);
798            }       
799            
800            private void assertOut(ELDescriptionNode node, ELDescriptionNode... nodes) {
801                    for(ELDescriptionNode nodeTmp : nodes) {
802                            assertTrue(node.getOut().contains(nodeTmp));
803                    }
804                    assertTrue(node.getOut().size() == nodes.length);
805            }               
806            
807            // all simulation relations should be empty for this node
808            private void assertEmpty(ELDescriptionNode node) {
809                    assertTrue(node.getIn().isEmpty());
810                    assertTrue(node.getInSC1().isEmpty());
811                    assertTrue(node.getInSC2().isEmpty());
812                    assertTrue(node.getOut().isEmpty());
813                    assertTrue(node.getOutSC1().isEmpty());
814                    assertTrue(node.getOutSC2().isEmpty());         
815            }
816            
817            // we use the standard KB file prefix
818            private String uri(String localname) {
819                    return KBParser.getInternalURI(localname);
820            }
821    }