1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
31
32
33
34
35
36 public class OntologyUtilTest extends ValidatorTestCase {
37
38 public void testGetConcepts()throws Exception {
39
40 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
41 "test/UtilTest.wsml");
42 assertNotNull(is);
43
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
56
57 public void testIncompleteGetAttributes()throws Exception {
58
59 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
60 "test/UtilTest.wsml");
61 assertNotNull(is);
62
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
80
81 public void testCompleteGetAttributes()throws Exception {
82
83 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
84 "test/UtilTest.wsml");
85 assertNotNull(is);
86
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
104 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
105 "test/UtilTest.wsml");
106 assertNotNull(is);
107
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
120 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
121 "test/UtilTest.wsml");
122 assertNotNull(is);
123
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 }