1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3    Copyright (c) 2005, University of Innsbruck, Austria
4    This library is free software; you can redistribute it and/or modify it under
5    the terms of the GNU Lesser General Public License as published by the Free
6    Software Foundation; either version 2.1 of the License, or (at your option)
7    any later version.
8    This library is distributed in the hope that it will be useful, but WITHOUT
9    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11   details.
12   You should have received a copy of the GNU Lesser General Public License along
13   with this library; if not, write to the Free Software Foundation, Inc.,
14   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15   */
16  package test.wsmo4j.logicalexpression;
17  
18  import java.io.InputStream;
19  import java.io.InputStreamReader;
20  import java.util.Iterator;
21  import java.util.List;
22  
23  import org.deri.wsmo4j.logicalexpression.util.OntologyUtil;
24  import org.omwg.logicalexpression.terms.Term;
25  import org.omwg.ontology.*;
26  
27  import test.wsmo4j.validator.ValidatorTestCase;
28  
29  /**
30   * Test class for testing the collection of concepts, instances, relations 
31   * and attributes via the OntologyUtil.
32   * 
33   * @author Nathalie Steinmetz, DERI Innsbruck
34   *
35   */
36  public class OntologyUtilTest extends ValidatorTestCase {
37  
38      public void testGetConcepts()throws Exception {
39          // read test file and parse it 
40          InputStream is = this.getClass().getClassLoader().getResourceAsStream(
41                  "test/UtilTest.wsml");
42          assertNotNull(is);
43          // assuming first topentity in file is an ontology  
44          ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];  
45  
46          List list = OntologyUtil.getConcepts(ontology);
47          Iterator it = list.iterator();
48          System.out.println("-------------------- Concepts ----------------------");
49          while (it.hasNext()) {
50          	System.out.println(it.next().toString());
51          }
52      }
53      
54      /*
55       * This method tests the incomplete method OntologyUtil.getAttributes(Term, Ontology)
56       */
57  	public void testIncompleteGetAttributes()throws Exception {
58          // read test file and parse it 
59          InputStream is = this.getClass().getClassLoader().getResourceAsStream(
60          		"test/UtilTest.wsml");
61          assertNotNull(is);
62          // assuming first topentity in file is an ontology  
63          ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];  
64  
65          Iterator iterator = ontology.listConcepts().iterator();
66          System.out.println("--------------------Incomplete Attributes ----------------------");
67          while (iterator.hasNext()) {
68          	Concept concept = (Concept) iterator.next();
69          	System.out.println("Concept " + concept.getIdentifier().toString() + ": ");
70          	List list = OntologyUtil.getAttributes(concept);
71              Iterator it = list.iterator();
72              while (it.hasNext()) {
73              	System.out.println("     " + it.next().toString());
74              }
75          }
76      }
77      
78      /*
79       * This method tests the complete method OntologyUtil.getAttributes(Term, Ontology)
80       */
81  	public void testCompleteGetAttributes()throws Exception {
82          // read test file and parse it 
83          InputStream is = this.getClass().getClassLoader().getResourceAsStream(
84          		"test/UtilTest.wsml");
85          assertNotNull(is);
86          // assuming first topentity in file is an ontology  
87          ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];  
88  
89          Iterator iterator = OntologyUtil.getConcepts(ontology).iterator();
90          System.out.println("--------------------Complete Attributes ----------------------");
91          while (iterator.hasNext()) {
92          	Term conceptTerm = (Term) iterator.next();
93          	System.out.println("Concept " + conceptTerm.toString() + ": ");
94          	List list = OntologyUtil.getAttributes(conceptTerm, ontology);
95              Iterator it = list.iterator();
96              while (it.hasNext()) {
97              	System.out.println("     " + it.next().toString());
98              }
99          }
100     }
101     
102     public void testGetInstances()throws Exception {
103         // read test file and parse it 
104         InputStream is = this.getClass().getClassLoader().getResourceAsStream(
105         		"test/UtilTest.wsml");
106         assertNotNull(is);
107         // assuming first topentity in file is an ontology  
108         ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];  
109 
110         List list = OntologyUtil.getInstances(ontology);
111         Iterator it = list.iterator();
112         System.out.println("-------------------- Instances ----------------------");
113         while (it.hasNext()) {
114         	System.out.println(it.next().toString());
115         }
116     }
117     
118     public void testGetRelations()throws Exception {
119         // read test file and parse it 
120         InputStream is = this.getClass().getClassLoader().getResourceAsStream(
121         		"test/UtilTest.wsml");
122         assertNotNull(is);
123         // assuming first topentity in file is an ontology  
124         ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];  
125 
126         List list = OntologyUtil.getRelations(ontology);
127         Iterator it = list.iterator();
128         System.out.println("-------------------- Relations ----------------------");
129         while (it.hasNext()) {
130         	System.out.println(it.next().toString());
131         }
132     }
133     
134 }