|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| package com.ontotext.wsmo4j.examples; |
|
20 |
| |
|
21 |
| import java.io.IOException; |
|
22 |
| import java.io.PrintWriter; |
|
23 |
| import java.util.HashMap; |
|
24 |
| |
|
25 |
| import org.omwg.ontology.Attribute; |
|
26 |
| import org.omwg.ontology.Concept; |
|
27 |
| import org.omwg.ontology.Instance; |
|
28 |
| import org.omwg.ontology.Ontology; |
|
29 |
| import org.omwg.ontology.Parameter; |
|
30 |
| import org.omwg.ontology.Relation; |
|
31 |
| import org.omwg.ontology.RelationInstance; |
|
32 |
| import org.omwg.ontology.WsmlDataType; |
|
33 |
| import org.wsmo.common.Namespace; |
|
34 |
| import org.wsmo.common.TopEntity; |
|
35 |
| import org.wsmo.common.exception.InvalidModelException; |
|
36 |
| import org.wsmo.factory.DataFactory; |
|
37 |
| import org.wsmo.factory.Factory; |
|
38 |
| import org.wsmo.factory.WsmoFactory; |
|
39 |
| import org.wsmo.wsml.Serializer; |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| public class CreateOntologyExample { |
|
60 |
| |
|
61 |
| private WsmoFactory factory; |
|
62 |
| |
|
63 |
| private DataFactory dataFactory; |
|
64 |
| |
|
65 |
0
| public static Ontology showExample() throws InvalidModelException {
|
|
66 |
0
| CreateOntologyExample example = new CreateOntologyExample();
|
|
67 |
0
| example.createFactory();
|
|
68 |
0
| return example.createSimpleOntology();
|
|
69 |
| } |
|
70 |
| |
|
71 |
0
| private void createFactory() {
|
|
72 |
| |
|
73 |
0
| factory = Factory.createWsmoFactory(null);
|
|
74 |
0
| dataFactory = Factory.createDataFactory(null);
|
|
75 |
| } |
|
76 |
| |
|
77 |
0
| private Ontology createSimpleOntology() throws InvalidModelException {
|
|
78 |
| |
|
79 |
0
| Ontology ontology = factory.createOntology(factory.createIRI("http://www.example.org/ontologies/example"));
|
|
80 |
0
| Namespace nsDefault = factory.createNamespace("default", factory
|
|
81 |
| .createIRI("http://www.example.org/ontologies/example")); |
|
82 |
0
| Namespace nsDC = factory.createNamespace("dc", factory.createIRI("http://purl.org/dc/elements/1.1"));
|
|
83 |
| |
|
84 |
| |
|
85 |
0
| ontology.addNFPValue(factory.createIRI(nsDefault, "title"), dataFactory.createWsmlString("WSML example ontology"));
|
|
86 |
0
| ontology.addNFPValue(factory.createIRI(nsDefault, "date"), dataFactory.createWsmlDate(2005, 9, 15, 12, 30));
|
|
87 |
0
| ontology.addNFPValue(factory.createIRI(nsDC, "rights"), factory.createIRI("http://www.deri.org/privacy.html"));
|
|
88 |
| |
|
89 |
| |
|
90 |
0
| Concept human = factory.createConcept(factory.createIRI(nsDefault, "Human"));
|
|
91 |
| |
|
92 |
| |
|
93 |
0
| Attribute attributeName = human.createAttribute(factory.createIRI(nsDefault, "hasName"));
|
|
94 |
0
| attributeName.addType(dataFactory.createWsmlDataType(WsmlDataType.WSML_STRING));
|
|
95 |
| |
|
96 |
| |
|
97 |
0
| Attribute attributeAge = human.createAttribute(factory.createIRI(nsDefault, "hasAge"));
|
|
98 |
0
| attributeAge.addType(dataFactory.createWsmlDataType(WsmlDataType.WSML_INTEGER));
|
|
99 |
| |
|
100 |
| |
|
101 |
0
| Attribute attributeChild = human.createAttribute(factory.createIRI(nsDefault, "hasChild"));
|
|
102 |
0
| attributeChild.addType(human);
|
|
103 |
0
| attributeChild.setInverseOf(factory.createIRI(nsDefault, "hasParent"));
|
|
104 |
| |
|
105 |
| |
|
106 |
0
| Attribute attributeParent = human.createAttribute(factory.createIRI(nsDefault, "hasParent"));
|
|
107 |
0
| attributeParent.addType(human);
|
|
108 |
0
| attributeParent.setInverseOf(factory.createIRI(nsDefault, "hasChild"));
|
|
109 |
| |
|
110 |
| |
|
111 |
0
| Attribute attributeMarriedTo = human.createAttribute(factory.createIRI(nsDefault, "isMarriedTo"));
|
|
112 |
0
| attributeMarriedTo.addType(human);
|
|
113 |
0
| attributeMarriedTo.setSymmetric(true);
|
|
114 |
0
| attributeMarriedTo.setMinCardinality(0);
|
|
115 |
0
| attributeMarriedTo.setMaxCardinality(1);
|
|
116 |
| |
|
117 |
| |
|
118 |
0
| Concept man = factory.createConcept(factory.createIRI(nsDefault, "Man"));
|
|
119 |
0
| man.addSuperConcept(human);
|
|
120 |
0
| Concept woman = factory.createConcept(factory.createIRI(nsDefault, "Woman"));
|
|
121 |
0
| woman.addSuperConcept(human);
|
|
122 |
| |
|
123 |
| |
|
124 |
0
| Concept country = factory.createConcept(factory.createIRI(nsDefault, "Country"));
|
|
125 |
0
| Attribute attributeCountrName = country.createAttribute(factory.createIRI(nsDefault, "hasCountryName"));
|
|
126 |
0
| attributeCountrName.addType(dataFactory.createWsmlDataType(WsmlDataType.WSML_STRING));
|
|
127 |
| |
|
128 |
| |
|
129 |
0
| Relation citizenOf = factory.createRelation(factory.createIRI(nsDefault, "CitizenOf"));
|
|
130 |
0
| Parameter parameterHuman = citizenOf.createParameter((byte) 0);
|
|
131 |
0
| parameterHuman.addType(human);
|
|
132 |
0
| Parameter parameterCountry = citizenOf.createParameter((byte) 1);
|
|
133 |
0
| parameterCountry.addType(country);
|
|
134 |
| |
|
135 |
| |
|
136 |
0
| Instance joe = factory.createInstance(factory.createIRI(nsDefault, "Joe"), man);
|
|
137 |
0
| joe.addAttributeValue(attributeName.getIdentifier(), dataFactory.createWsmlString("Joe"));
|
|
138 |
0
| joe.addAttributeValue(attributeAge.getIdentifier(), dataFactory.createWsmlInteger("28"));
|
|
139 |
0
| joe.addAttributeValue(attributeChild.getIdentifier(), factory.getInstance(factory.createIRI(nsDefault, "Paul")));
|
|
140 |
0
| joe.addAttributeValue(attributeMarriedTo.getIdentifier(), factory.getInstance(factory.createIRI(nsDefault, "Mary")));
|
|
141 |
| |
|
142 |
| |
|
143 |
0
| Instance mary = factory.createInstance(factory.createIRI(nsDefault, "Mary"), woman);
|
|
144 |
0
| mary.addAttributeValue(attributeName.getIdentifier(), dataFactory.createWsmlString("Mary"));
|
|
145 |
0
| mary.addAttributeValue(attributeAge.getIdentifier(), dataFactory.createWsmlInteger("27"));
|
|
146 |
0
| mary.addAttributeValue(attributeChild.getIdentifier(), factory.getInstance(factory.createIRI(nsDefault, "Paul")));
|
|
147 |
0
| mary.addAttributeValue(attributeMarriedTo.getIdentifier(), factory.getInstance(factory.createIRI(nsDefault, "Joe")));
|
|
148 |
| |
|
149 |
| |
|
150 |
0
| Instance paul = factory.createInstance(factory.createIRI(nsDefault, "Paul"), man);
|
|
151 |
0
| paul.addAttributeValue(attributeName.getIdentifier(), dataFactory.createWsmlString("John"));
|
|
152 |
0
| paul.addAttributeValue(attributeAge.getIdentifier(), dataFactory.createWsmlInteger("4"));
|
|
153 |
0
| paul.addAttributeValue(attributeParent.getIdentifier(), factory.getInstance(factory.createIRI(nsDefault, "Joe")));
|
|
154 |
0
| paul.addAttributeValue(attributeParent.getIdentifier(), factory.getInstance(factory.createIRI(nsDefault, "Mary")));
|
|
155 |
| |
|
156 |
| |
|
157 |
0
| Instance uk = factory.createInstance(factory.createIRI(nsDefault, "UK"), country);
|
|
158 |
0
| uk.addAttributeValue(attributeCountrName.getIdentifier(), dataFactory.createWsmlString("UK"));
|
|
159 |
0
| Instance france = factory.createInstance(factory.createIRI(nsDefault, "France"), country);
|
|
160 |
0
| france.addAttributeValue(attributeCountrName.getIdentifier(), dataFactory.createWsmlString("France"));
|
|
161 |
| |
|
162 |
| |
|
163 |
0
| RelationInstance relInstanceJoe = factory.createRelationInstance(citizenOf);
|
|
164 |
0
| relInstanceJoe.setParameterValue((byte) 0, paul);
|
|
165 |
0
| relInstanceJoe.setParameterValue((byte) 1, uk);
|
|
166 |
| |
|
167 |
| |
|
168 |
0
| RelationInstance relInstanceMary = factory.createRelationInstance(citizenOf);
|
|
169 |
0
| relInstanceMary.setParameterValue((byte) 0, mary);
|
|
170 |
0
| relInstanceMary.setParameterValue((byte) 1, france);
|
|
171 |
| |
|
172 |
| |
|
173 |
0
| RelationInstance relInstancePaul = factory.createRelationInstance(citizenOf);
|
|
174 |
0
| relInstancePaul.setParameterValue((byte) 0, joe);
|
|
175 |
0
| relInstancePaul.setParameterValue((byte) 1, uk);
|
|
176 |
| |
|
177 |
| |
|
178 |
0
| ontology.addConcept(human);
|
|
179 |
0
| ontology.addConcept(man);
|
|
180 |
0
| ontology.addConcept(woman);
|
|
181 |
0
| ontology.addConcept(country);
|
|
182 |
0
| ontology.addRelation(citizenOf);
|
|
183 |
0
| ontology.addInstance(joe);
|
|
184 |
0
| ontology.addInstance(mary);
|
|
185 |
0
| ontology.addInstance(paul);
|
|
186 |
0
| ontology.addInstance(uk);
|
|
187 |
0
| ontology.addInstance(france);
|
|
188 |
0
| ontology.addRelationInstance(relInstanceJoe);
|
|
189 |
0
| ontology.addRelationInstance(relInstanceMary);
|
|
190 |
0
| ontology.addRelationInstance(relInstancePaul);
|
|
191 |
| |
|
192 |
0
| return ontology;
|
|
193 |
| } |
|
194 |
| |
|
195 |
0
| public static void main(String[] args) throws InvalidModelException, IOException {
|
|
196 |
0
| Ontology ontology = CreateOntologyExample.showExample();
|
|
197 |
| |
|
198 |
0
| Serializer serializer = Factory.createSerializer(new HashMap<String, Object>(0));
|
|
199 |
0
| serializer.serialize(new TopEntity[] {ontology}, new PrintWriter(System.out));
|
|
200 |
| } |
|
201 |
| } |
|
202 |
| |
|
203 |
| |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
| |
|
211 |
| |
|
212 |
| |
|
213 |
| |
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
| |
|
218 |
| |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
| |