1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| package org.deri.wsmo4j.io.parser.rdf; |
17 |
| |
18 |
| import java.util.HashSet; |
19 |
| import java.util.Iterator; |
20 |
| import java.util.Map; |
21 |
| import java.util.Set; |
22 |
| import java.util.Map.Entry; |
23 |
| |
24 |
| import org.omwg.logicalexpression.LogicalExpression; |
25 |
| import org.omwg.ontology.Attribute; |
26 |
| import org.omwg.ontology.Axiom; |
27 |
| import org.omwg.ontology.Concept; |
28 |
| import org.omwg.ontology.DataValue; |
29 |
| import org.omwg.ontology.Instance; |
30 |
| import org.omwg.ontology.Ontology; |
31 |
| import org.omwg.ontology.Parameter; |
32 |
| import org.omwg.ontology.Relation; |
33 |
| import org.omwg.ontology.RelationInstance; |
34 |
| import org.omwg.ontology.Type; |
35 |
| import org.omwg.ontology.WsmlDataType; |
36 |
| import org.openrdf.model.BNode; |
37 |
| import org.openrdf.model.Graph; |
38 |
| import org.openrdf.model.GraphException; |
39 |
| import org.openrdf.model.Resource; |
40 |
| import org.openrdf.model.Statement; |
41 |
| import org.openrdf.model.URI; |
42 |
| import org.openrdf.model.Value; |
43 |
| import org.openrdf.model.impl.GraphImpl; |
44 |
| import org.openrdf.model.impl.URIImpl; |
45 |
| import org.openrdf.sesame.sail.StatementIterator; |
46 |
| import org.openrdf.vocabulary.RDF; |
47 |
| import org.openrdf.vocabulary.RDFS; |
48 |
| import org.openrdf.vocabulary.XmlSchema; |
49 |
| import org.wsmo.common.Entity; |
50 |
| import org.wsmo.common.IRI; |
51 |
| import org.wsmo.common.Namespace; |
52 |
| import org.wsmo.common.WSML; |
53 |
| import org.wsmo.common.exception.InvalidModelException; |
54 |
| import org.wsmo.common.exception.SynchronisationException; |
55 |
| import org.wsmo.factory.DataFactory; |
56 |
| import org.wsmo.factory.LogicalExpressionFactory; |
57 |
| import org.wsmo.factory.WsmoFactory; |
58 |
| import org.wsmo.wsml.ParserException; |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
| public class RDFExprParser { |
74 |
| |
75 |
| private String DC = "http://purl.org/dc/elements/1.1#"; |
76 |
| private String OWL = "http://www.w3.org/2002/07/owl#"; |
77 |
| private String LABEL = "title"; |
78 |
| private String COMMENT = "description"; |
79 |
| private String RELATION = "relation"; |
80 |
| |
81 |
| public final static String WSML_AXIOM = "http://www.wsmo.org/wsml/wsml-syntax#axiom"; |
82 |
| public final static String CONSTRAINING_ATTR = "constraining attribute"; |
83 |
| public final static String TRANSITIVE_ATTR = "transitive attribute"; |
84 |
| public final static String REFLEXIVE_ATTR = "reflexive attribute"; |
85 |
| public final static String SYMMETRIC_ATTR = "symmetric attribute"; |
86 |
| public final static String CONSTRAINING_REL_1 = "constraining relation parameter 1"; |
87 |
| public final static String CONSTRAINING_REL_2 = "constraining relation parameter 2"; |
88 |
| public final static String WSML_INVERSE_ATTR = "http://www.wsmo.org/wsml/wsml-syntax#inverseAttribute"; |
89 |
| public final static String WSML_ONTOLOGY_ID = "http://www.wsmo.org/wsml/wsml-syntax#ontologyID"; |
90 |
| |
91 |
| private Set <String> idConcepts = null; |
92 |
| private Set <String> idInstances = null; |
93 |
| private Set <String> idRelations = null; |
94 |
| |
95 |
| private WsmoFactory factory = null; |
96 |
| private LogicalExpressionFactory leFactory = null; |
97 |
| private DataFactory dataFactory = null; |
98 |
| private RDFParseErrorListener errorListener = null; |
99 |
| |
100 |
| private String properties = null; |
101 |
| private String labels = null; |
102 |
| private Ontology ontology = null; |
103 |
| private Graph graph2 = null; |
104 |
| private Namespace defaultNS = null; |
105 |
| private boolean noDCNFP = false; |
106 |
| |
107 |
0
| public RDFExprParser(WsmoFactory factory, LogicalExpressionFactory leFactory,
|
108 |
| DataFactory dataFactory, String properties, String labels, RDFParseErrorListener errorListener) { |
109 |
0
| this.factory = factory;
|
110 |
0
| this.leFactory = leFactory;
|
111 |
0
| this.dataFactory = dataFactory;
|
112 |
0
| this.properties = properties;
|
113 |
0
| this.labels = labels;
|
114 |
0
| this.errorListener = errorListener;
|
115 |
0
| this.graph2 = new GraphImpl();
|
116 |
0
| this.defaultNS = null;
|
117 |
0
| this.idConcepts = new HashSet <String> ();
|
118 |
0
| this.idInstances = new HashSet <String> ();
|
119 |
0
| this.idRelations = new HashSet <String> ();
|
120 |
| } |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
| |
128 |
| |
129 |
| |
130 |
| |
131 |
| |
132 |
| |
133 |
0
| public void rdf2Wsml(Graph graph, Map namespaces)
|
134 |
| throws GraphException, SynchronisationException, InvalidModelException, ParserException { |
135 |
| |
136 |
| |
137 |
0
| createOntology(graph, namespaces);
|
138 |
0
| setNamespaces(namespaces);
|
139 |
| |
140 |
| |
141 |
0
| StatementIterator iterator = graph.getStatements();
|
142 |
0
| while(iterator.hasNext()) {
|
143 |
0
| Statement statement = iterator.next();
|
144 |
| |
145 |
0
| if ((statement.getPredicate().getURI().equals(RDF.TYPE)) &&
|
146 |
| (statement.getObject().toString().equals(RDFS.CLASS))){ |
147 |
0
| visitClass(statement);
|
148 |
0
| graph2.add(statement);
|
149 |
| } |
150 |
| |
151 |
| |
152 |
0
| else if ((statement.getPredicate().getURI().equals(RDF.TYPE)) &&
|
153 |
| (statement.getObject().toString().equals(RDF.PROPERTY))){ |
154 |
0
| if (properties.equals(RDFParserImpl.RDF_PROP_AS_ATTR)) {
|
155 |
0
| visitPropertyAsAttribute(statement);
|
156 |
0
| graph2.add(statement);
|
157 |
| } |
158 |
0
| else if (properties.equals(RDFParserImpl.RDF_PROP_AS_REL)) {
|
159 |
0
| visitPropertyAsRelation(statement);
|
160 |
0
| graph2.add(statement);
|
161 |
| } |
162 |
| } |
163 |
| |
164 |
0
| else if (statement.getPredicate().getURI().equals(RDF.TYPE)) {
|
165 |
0
| visitInstance(statement);
|
166 |
0
| graph2.add(statement);
|
167 |
| } |
168 |
| |
169 |
| |
170 |
0
| else if (statement.getPredicate().getURI().equals(
|
171 |
| WSML_AXIOM)) { |
172 |
0
| visitAxiom(statement);
|
173 |
0
| graph2.add(statement);
|
174 |
| } |
175 |
| } |
176 |
| |
177 |
| |
178 |
0
| graph.remove(graph2);
|
179 |
0
| iterator = graph.getStatements();
|
180 |
0
| while(iterator.hasNext()) {
|
181 |
0
| Statement stat = iterator.next();
|
182 |
0
| addWarning("Statement/-s containing the predicate \"" +
|
183 |
| stat.getPredicate().getLocalName() + |
184 |
| "\" has/have not been transformed to WSML!", stat); |
185 |
| } |
186 |
0
| setWsmlVariant();
|
187 |
| } |
188 |
| |
189 |
| |
190 |
| |
191 |
| |
192 |
| |
193 |
| |
194 |
| |
195 |
| |
196 |
0
| private void visitClass(Statement statement)
|
197 |
| throws GraphException, SynchronisationException, InvalidModelException { |
198 |
| |
199 |
0
| Concept concept = createConcept(statement.getSubject().toString(), statement);
|
200 |
0
| if (concept != null) {
|
201 |
| |
202 |
0
| StatementIterator it = statement.getSubject().getSubjectStatements();
|
203 |
0
| while (it != null && it.hasNext()) {
|
204 |
0
| Statement stat = it.next();
|
205 |
0
| checkForNFP(concept,stat);
|
206 |
| |
207 |
0
| if (stat.getPredicate().getURI().equals(RDFS.SUBCLASSOF)) {
|
208 |
| |
209 |
0
| Concept superConcept = createConcept(stat.getObject().toString(), stat);
|
210 |
0
| if (superConcept != null) {
|
211 |
0
| addSuperConcept(concept, superConcept, stat);
|
212 |
| } |
213 |
0
| graph2.add(stat);
|
214 |
| } |
215 |
| } |
216 |
| } |
217 |
| } |
218 |
| |
219 |
0
| private void checkForNFP(Entity entity, Statement stat) throws InvalidModelException {
|
220 |
| |
221 |
0
| if (stat.getPredicate().getURI().equals(RDFS.LABEL)) {
|
222 |
| |
223 |
| |
224 |
| |
225 |
| |
226 |
0
| if (entity instanceof Axiom && noDCNFP) {
|
227 |
0
| addNFP(entity, RDFS.LABEL, stat.getObject().toString());
|
228 |
0
| graph2.add(stat);
|
229 |
| } |
230 |
0
| else if (labels.equals(RDFParserImpl.DC_TITLE)){
|
231 |
0
| addNFP(entity, DC + LABEL, stat.getObject().toString());
|
232 |
0
| graph2.add(stat);
|
233 |
| } |
234 |
| else { |
235 |
0
| addNFP(entity, RDFS.LABEL, stat.getObject().toString());
|
236 |
0
| graph2.add(stat);
|
237 |
| } |
238 |
| } |
239 |
| |
240 |
0
| else if (stat.getPredicate().getURI().equals(RDFS.COMMENT)) {
|
241 |
0
| if (entity instanceof Attribute) {
|
242 |
0
| if (stat.getObject().toString().equals(CONSTRAINING_ATTR)) {
|
243 |
0
| ((Attribute) entity).setConstraining(true);
|
244 |
0
| graph2.add(stat);
|
245 |
| } |
246 |
0
| if (stat.getObject().toString().equals(TRANSITIVE_ATTR)) {
|
247 |
0
| ((Attribute) entity).setTransitive(true);
|
248 |
0
| graph2.add(stat);
|
249 |
| } |
250 |
0
| if (stat.getObject().toString().equals(REFLEXIVE_ATTR)) {
|
251 |
0
| ((Attribute) entity).setReflexive(true);
|
252 |
0
| graph2.add(stat);
|
253 |
| } |
254 |
0
| if (stat.getObject().toString().equals(SYMMETRIC_ATTR)) {
|
255 |
0
| ((Attribute) entity).setSymmetric(true);
|
256 |
0
| graph2.add(stat);
|
257 |
| } |
258 |
| } |
259 |
| else { |
260 |
0
| addNFP(entity, DC + COMMENT, stat.getObject().toString());
|
261 |
0
| graph2.add(stat);
|
262 |
| } |
263 |
| } |
264 |
| |
265 |
0
| else if (stat.getPredicate().getURI().equals(RDFS.SEEALSO)) {
|
266 |
0
| addNFP(entity, DC + RELATION, stat.getObject().toString());
|
267 |
0
| graph2.add(stat);
|
268 |
| } |
269 |
| |
270 |
0
| else if (stat.getPredicate().getURI().equals(RDFS.ISDEFINEDBY)) {
|
271 |
0
| addNFP(entity, DC + RELATION, stat.getObject().toString());
|
272 |
0
| graph2.add(stat);
|
273 |
| } |
274 |
| } |
275 |
| |
276 |
| |
277 |
| |
278 |
| |
279 |
| |
280 |
| |
281 |
| |
282 |
| |
283 |
| |
284 |
| |
285 |
| |
286 |
| |
287 |
| |
288 |
0
| private void visitPropertyAsAttribute(Statement statement)
|
289 |
| throws GraphException, SynchronisationException, InvalidModelException, ParserException { |
290 |
0
| Concept concept = null;
|
291 |
0
| Attribute attribute = null;
|
292 |
| |
293 |
| |
294 |
0
| StatementIterator it = statement.getSubject().getSubjectStatements();
|
295 |
0
| while (it != null && it.hasNext()) {
|
296 |
0
| Statement stat = it.next();
|
297 |
| |
298 |
0
| if (stat.getPredicate().getURI().equals(RDFS.DOMAIN)) {
|
299 |
0
| concept = createConcept(stat.getObject().toString(), stat);
|
300 |
0
| graph2.add(stat);
|
301 |
| } |
302 |
| } |
303 |
| |
304 |
0
| if (concept == null) {
|
305 |
0
| concept = createConcept(RDFS.CLASS, null);
|
306 |
| } |
307 |
| |
308 |
| |
309 |
0
| attribute = createAttribute(concept, statement.getSubject().toString(), statement);
|
310 |
| |
311 |
| |
312 |
0
| it = statement.getSubject().getSubjectStatements();
|
313 |
0
| while (it != null && it.hasNext()) {
|
314 |
0
| Statement stat = it.next();
|
315 |
0
| checkForNFP(attribute,stat);
|
316 |
0
| if (stat.getPredicate().getURI().equals(WSML_INVERSE_ATTR)) {
|
317 |
0
| attribute.setInverseOf(factory.createIRI(
|
318 |
| stat.getObject().toString())); |
319 |
0
| graph2.add(stat);
|
320 |
| } |
321 |
| } |
322 |
| |
323 |
| |
324 |
0
| it = statement.getSubject().getSubjectStatements();
|
325 |
0
| while (it != null && it.hasNext()) {
|
326 |
0
| Statement stat = it.next();
|
327 |
0
| if (stat.getPredicate().getURI().equals(RDFS.RANGE)) {
|
328 |
0
| boolean range = false;
|
329 |
0
| IRI iri = null;
|
330 |
| |
331 |
0
| try {
|
332 |
0
| iri = factory.createIRI(stat.getObject().toString());
|
333 |
| } catch (IllegalArgumentException e) { |
334 |
0
| addWarning("Anonymous identifiers problem - One or more " +
|
335 |
| "anonymous concepts have not been added to " + |
336 |
| "the WSMO object model!", statement); |
337 |
0
| return;
|
338 |
| } |
339 |
0
| iri = factory.createIRI(stat.getObject().toString());
|
340 |
0
| if (attribute != null) {
|
341 |
0
| if (ontology.listConcepts().size() > 0) {
|
342 |
0
| Iterator iter = ontology.listConcepts().iterator();
|
343 |
0
| while (iter.hasNext()) {
|
344 |
0
| Concept conc = (Concept) iter.next();
|
345 |
0
| if (conc.getIdentifier().equals(iri)) {
|
346 |
0
| range = true;
|
347 |
0
| addAttributeType(attribute, conc);
|
348 |
0
| graph2.add(stat);
|
349 |
| } |
350 |
0
| else if (iri.toString().equals(RDFS.CLASS)) {
|
351 |
0
| conc = createConcept(iri.toString(), null);
|
352 |
0
| range = true;
|
353 |
0
| addAttributeType(attribute, conc);
|
354 |
0
| graph2.add(stat);
|
355 |
| } |
356 |
| } |
357 |
| } |
358 |
0
| if (!range) {
|
359 |
0
| if (iri.toString().equals(RDFS.LITERAL)) {
|
360 |
0
| Type t = dataFactory.createWsmlDataType(WsmlDataType.WSML_STRING);
|
361 |
0
| addWarning("A property range of type rdfs:Literal is transformed " +
|
362 |
| "to WSML_STRING", stat); |
363 |
0
| addAttributeType(attribute, t);
|
364 |
0
| graph2.add(stat);
|
365 |
| } |
366 |
0
| else if (iri.getNamespace().equals(XmlSchema.NAMESPACE)) {
|
367 |
0
| Type t = createWsmlDataType(iri);
|
368 |
0
| if (t != null) {
|
369 |
0
| addAttributeType(attribute, t);
|
370 |
0
| graph2.add(stat);
|
371 |
| } |
372 |
| } |
373 |
| else { |
374 |
0
| Concept conc = createConcept(iri.toString(), null);
|
375 |
0
| addAttributeType(attribute, conc);
|
376 |
0
| graph2.add(stat);
|
377 |
| } |
378 |
| } |
379 |
| } |
380 |
| } |
381 |
| } |
382 |
0
| if (attribute.listTypes().size() == 0 && attribute != null) {
|
383 |
0
| Concept tmp = createConcept(RDFS.CLASS, null);
|
384 |
0
| addAttributeType(attribute, tmp);
|
385 |
| } |
386 |
| |
387 |
| |
388 |
0
| it = statement.getSubject().getSubjectStatements();
|
389 |
0
| while(it != null && it.hasNext()) {
|
390 |
0
| Statement stat = it.next();
|
391 |
0
| if (stat.getPredicate().getURI().equals(RDFS.SUBPROPERTYOF)) {
|
392 |
0
| Attribute b = null;
|
393 |
0
| String superProperty = stat.getObject().toString();
|
394 |
0
| if (ontology.listConcepts().size() > 0) {
|
395 |
0
| Iterator iter = ontology.listConcepts().iterator();
|
396 |
0
| while (iter.hasNext()) {
|
397 |
0
| Concept conc = (Concept) iter.next();
|
398 |
0
| if (conc.listAttributes().size() > 0) {
|
399 |
0
| Iterator iter2 = conc.listAttributes().iterator();
|
400 |
0
| while (iter2.hasNext()) {
|
401 |
0
| Attribute attr = (Attribute) iter2.next();
|
402 |
0
| if (attr.getIdentifier().toString().equals(superProperty)) {
|
403 |
0
| b = attr;
|
404 |
| } |
405 |
| } |
406 |
| } |
407 |
| } |
408 |
| } |
409 |
0
| if (b == null) {
|
410 |
0
| Concept conc = createConcept(RDFS.CLASS, null);
|
411 |
0
| b = createAttribute(conc, superProperty, null);
|
412 |
| } |
413 |
| |
414 |
0
| Axiom axiom = createAxiom(attribute, b);
|
415 |
0
| addNFP(axiom, DC + RELATION, ((IRI) concept.getIdentifier()).getLocalName());
|
416 |
0
| addNFP(concept, DC + RELATION, ((IRI) axiom.getIdentifier()).getLocalName());
|
417 |
| |
418 |
0
| graph2.add(stat);
|
419 |
| } |
420 |
| } |
421 |
| } |
422 |
| |
423 |
| |
424 |
| |
425 |
| |
426 |
| |
427 |
| |
428 |
| |
429 |
| |
430 |
| |
431 |
| |
432 |
0
| private void visitPropertyAsRelation(Statement statement)
|
433 |
| throws GraphException, SynchronisationException, InvalidModelException { |
434 |
0
| Concept concept = null;
|
435 |
0
| Relation relation = null;
|
436 |
| |
437 |
| |
438 |
0
| relation = createRelation(statement.getSubject().toString(), statement);
|
439 |
| |
440 |
0
| if (relation != null) {
|
441 |
| |
442 |
0
| StatementIterator it = statement.getSubject().getSubjectStatements();
|
443 |
0
| while (it != null && it.hasNext()) {
|
444 |
0
| Statement stat = it.next();
|
445 |
0
| checkForNFP(relation,stat);
|
446 |
| } |
447 |
| |
448 |
| |
449 |
0
| it = statement.getSubject().getSubjectStatements();
|
450 |
0
| while (it != null && it.hasNext()) {
|
451 |
0
| Statement stat = it.next();
|
452 |
| |
453 |
0
| if (stat.getPredicate().getURI().equals(RDFS.DOMAIN)) {
|
454 |
0
| concept = createConcept(stat.getObject().toString(), stat);
|
455 |
0
| graph2.add(stat);
|
456 |
| } |
457 |
| } |
458 |
| |
459 |
0
| if (concept == null) {
|
460 |
0
| concept = createConcept(RDFS.CLASS, null);
|
461 |
| } |
462 |
| |
463 |
| |
464 |
0
| it = statement.getSubject().getSubjectStatements();
|
465 |
0
| while (it != null && it.hasNext()) {
|
466 |
0
| Statement stat = it.next();
|
467 |
0
| if (stat.getPredicate().getURI().equals(RDFS.RANGE)) {
|
468 |
0
| boolean range = false;
|
469 |
0
| IRI iri = factory.createIRI(stat.getObject().toString());
|
470 |
0
| String localName = iri.getLocalName();
|
471 |
0
| if (ontology.listConcepts().size() > 0) {
|
472 |
0
| Iterator iter = ontology.listConcepts().iterator();
|
473 |
0
| while (iter.hasNext()) {
|
474 |
0
| Concept conc = (Concept) iter.next();
|
475 |
0
| if (conc.getIdentifier().equals(iri)) {
|
476 |
0
| range = true;
|
477 |
0
| addRelationType(relation, concept, conc);
|
478 |
0
| graph2.add(stat);
|
479 |
| } |
480 |
0
| else if (iri.toString().equals(RDFS.CLASS)) {
|
481 |
0
| range = true;
|
482 |
0
| conc = createConcept(iri.toString(), stat);
|
483 |
0
| addRelationType(relation, concept, conc);
|
484 |
0
| graph2.add(stat);
|
485 |
| } |
486 |
| } |
487 |
| } |
488 |
0
| if (!range) {
|
489 |
0
| if (localName.endsWith("Literal")) {
|
490 |
0
| Type t = dataFactory.createWsmlDataType(WsmlDataType.WSML_STRING);
|
491 |
0
| addWarning("A property range of type rdfs:Literal is transformed " +
|
492 |
| "to WSML_STRING", stat); |
493 |
0
| addRelationType(relation, concept, t);
|
494 |
0
| graph2.add(stat);
|
495 |
| } |
496 |
0
| else if (iri.getNamespace().equals(XmlSchema.NAMESPACE)) {
|
497 |
0
| Type t = createWsmlDataType(iri);
|
498 |
0
| if (t != null) {
|
499 |
0
| addRelationType(relation, concept, t);
|
500 |
0
| graph2.add(stat);
|
501 |
| } |
502 |
| } |
503 |
| else { |
504 |
0
| Concept conc = createConcept(iri.toString(), stat);
|
505 |
0
| addRelationType(relation, concept, conc);
|
506 |
0
| graph2.add(stat);
|
507 |
| } |
508 |
| } |
509 |
| } |
510 |
| } |
511 |
0
| if (relation.listParameters().get(0).listTypes().size() == 0) {
|
512 |
0
| Concept tmp = createConcept(RDFS.CLASS, null);
|
513 |
0
| addRelationType(relation, concept, tmp);
|
514 |
| } |
515 |
| |
516 |
| |
517 |
0
| it = statement.getSubject().getSubjectStatements();
|
518 |
0
| while(it != null && it.hasNext()) {
|
519 |
0
| Statement stat = it.next();
|
520 |
0
| if (stat.getPredicate().getURI().equals(RDFS.SUBPROPERTYOF)) {
|
521 |
0
| Relation superRelation = createRelation(stat.getObject().toString(), stat);
|
522 |
0
| if (superRelation != null) {
|
523 |
0
| addSuperRelation(relation, superRelation);
|
524 |
| } |
525 |
0
| graph2.add(stat);
|
526 |
| } |
527 |
0
| else if (stat.getPredicate().getURI().equals(RDFS.COMMENT)) {
|
528 |
0
| if (stat.getObject().toString().equals(CONSTRAINING_REL_1)) {
|
529 |
0
| relation.listParameters().get(0).setConstraining(true);
|
530 |
0
| graph2.add(stat);
|
531 |
| } |
532 |
0
| if (stat.getObject().toString().equals(CONSTRAINING_REL_2)) {
|
533 |
0
| relation.listParameters().get(1).setConstraining(true);
|
534 |
0
| graph2.add(stat);
|
535 |
| } |
536 |
| } |
537 |
| } |
538 |
| } |
539 |
| } |
540 |
| |
541 |
| |
542 |
| |
543 |
| |
544 |
0
| private void visitInstance(Statement statement)
|
545 |
| throws SynchronisationException, InvalidModelException, GraphException { |
546 |
0
| Concept concept = null;
|
547 |
| |
548 |
| |
549 |
0
| Instance instance = createInstance(statement.getSubject().toString(), statement);
|
550 |
| |
551 |
0
| if (instance != null) {
|
552 |
| |
553 |
0
| Iterator iter = ontology.listConcepts().iterator();
|
554 |
0
| while (iter.hasNext()) {
|
555 |
0
| Concept tmp = (Concept) iter.next();
|
556 |
0
| if (tmp.getIdentifier().toString().equals(statement.getObject().toString())) {
|
557 |
0
| concept = tmp;
|
558 |
| } |
559 |
| } |
560 |
0
| if (concept == null) {
|
561 |
0
| concept = createConcept(statement.getObject().toString(), statement);
|
562 |
| } |
563 |
0
| concept.addInstance(instance);
|
564 |
| |
565 |
| |
566 |
0
| StatementIterator it = statement.getSubject().getSubjectStatements();
|
567 |
0
| while (it != null && it.hasNext()) {
|
568 |
0
| Statement stat = it.next();
|
569 |
0
| checkForNFP(instance,stat);
|
570 |
0
| if (properties.equals(RDFParserImpl.RDF_PROP_AS_ATTR)) {
|
571 |
0
| if (!addAttributeValue(concept, instance, stat)
|
572 |
| && nonRDFSProperty(stat.getPredicate().getURI())) { |
573 |
0
| Attribute attribute = createAttribute(concept, stat.getPredicate().toString(), stat);
|
574 |
0
| Concept tmp = createConcept(RDFS.CLASS, stat);
|
575 |
0
| addAttributeType(attribute, tmp);
|
576 |
0
| if (stat.getObject() instanceof URI) {
|
577 |
0
| Instance temp = createInstance(stat.getObject().toString(), stat);
|
578 |
0
| instance.addAttributeValue(attribute.getIdentifier(), temp);
|
579 |
0
| } else if (stat.getObject() instanceof BNode) {
|
580 |
0
| String name = "blank:" + stat.getObject().toString();
|
581 |
0
| Instance temp = createInstance(name, stat);
|
582 |
0
| instance.addAttributeValue(attribute.getIdentifier(), temp);
|
583 |
| } else { |
584 |
0
| DataValue dataValue = dataFactory.createWsmlString(stat.getObject().toString());
|
585 |
0
| instance.addAttributeValue(attribute.getIdentifier(), dataValue);
|
586 |
| } |
587 |
| } |
588 |
0
| graph2.add(stat);
|
589 |
0
| } else if (properties.equals(RDFParserImpl.RDF_PROP_AS_REL)) {
|
590 |
0
| if (nonRDFSProperty(stat.getPredicate().getURI())) {
|
591 |
0
| addRelationInstances(concept, instance, stat);
|
592 |
0
| graph2.add(stat);
|
593 |
| } |
594 |
| } |
595 |
| |
596 |
| } |
597 |
| } |
598 |
| } |
599 |
| |
600 |
| |
601 |
| |
602 |
| |
603 |
| |
604 |
| |
605 |
0
| private void visitAxiom(Statement statement)
|
606 |
| throws GraphException, SynchronisationException, InvalidModelException, ParserException { |
607 |
| |
608 |
0
| Axiom axiom = createAxiom(statement.getSubject().toString(), statement);
|
609 |
0
| if (axiom != null) {
|
610 |
| |
611 |
0
| StatementIterator it = statement.getSubject().getSubjectStatements();
|
612 |
0
| while (it != null && it.hasNext()) {
|
613 |
0
| Statement stat = it.next();
|
614 |
0
| noDCNFP = true;
|
615 |
0
| checkForNFP(axiom,stat);
|
616 |
0
| noDCNFP = false;
|
617 |
| |
618 |
0
| if (stat.getPredicate().getURI().equals(WSML_AXIOM)) {
|
619 |
| |
620 |
0
| LogicalExpression logExpr = leFactory.createLogicalExpression(statement.getObject().toString(),
|
621 |
| axiom.getOntology()); |
622 |
0
| axiom.addDefinition(logExpr);
|
623 |
0
| graph2.add(stat);
|
624 |
| } |
625 |
| } |
626 |
| } |
627 |
| } |
628 |
| |
629 |
| |
630 |
| |
631 |
| |
632 |
0
| private boolean addAttributeValue(Concept concept, Instance instance, Statement statement)
|
633 |
| throws SynchronisationException, InvalidModelException { |
634 |
0
| Iterator iter = concept.listAttributes().iterator();
|
635 |
0
| while (iter.hasNext()) {
|
636 |
0
| Attribute attribute = (Attribute) iter.next();
|
637 |
0
| if (statement.getPredicate().toString().equals(attribute.getIdentifier().toString())) {
|
638 |
0
| Instance tmp = getInstance(statement.getObject());
|
639 |
0
| if (tmp == null) {
|
640 |
0
| if (statement.getObject() instanceof URI) {
|
641 |
0
| tmp = createInstance(statement.getObject().toString(), statement);
|
642 |
0
| instance.addAttributeValue(attribute.getIdentifier(), tmp);
|
643 |
0
| } else if (statement.getObject() instanceof BNode) {
|
644 |
0
| String name = "blank:" + statement.getObject().toString();
|
645 |
0
| Instance temp = createInstance(name, statement);
|
646 |
0
| instance.addAttributeValue(attribute.getIdentifier(), temp);
|
647 |
| } else { |
648 |
0
| DataValue dataValue = dataFactory.createWsmlString(statement.getObject().toString());
|
649 |
0
| instance.addAttributeValue(attribute.getIdentifier(), dataValue);
|
650 |
| } |
651 |
| } |
652 |
| else { |
653 |
0
| instance.addAttributeValue(attribute.getIdentifier(), tmp);
|
654 |
| } |
655 |
0
| return true;
|
656 |
| } |
657 |
| } |
658 |
0
| if (concept.listSuperConcepts().size() > 0) {
|
659 |
0
| Iterator iter2 = concept.listSuperConcepts().iterator();
|
660 |
0
| while (iter2.hasNext()) {
|
661 |
0
| Concept tmp = (Concept) iter2.next();
|
662 |
0
| return addAttributeValue(tmp, instance, statement);
|
663 |
| } |
664 |
| } |
665 |
0
| return false;
|
666 |
| } |
667 |
| |
668 |
| |
669 |
| |
670 |
| |
671 |
0
| private void addRelationInstances(Concept concept, Instance instance, Statement statement)
|
672 |
| throws SynchronisationException, InvalidModelException { |
673 |
0
| Relation relation = null;
|
674 |
0
| RelationInstance relationInstance = null;
|
675 |
0
| Iterator it = ontology.listRelations().iterator();
|
676 |
0
| while (it.hasNext()) {
|
677 |
0
| relation = (Relation) it.next();
|
678 |
0
| if (relation.getIdentifier().toString().equals(statement.getPredicate().toString())) {
|
679 |
0
| relationInstance = createRelationInstance(instance, relation, statement);
|
680 |
| } |
681 |
| } |
682 |
0
| if (relationInstance == null) {
|
683 |
0
| relation = createRelation(statement.getPredicate().toString(), statement);
|
684 |
0
| if (relation != null) {
|
685 |
0
| relationInstance = createRelationInstance(instance, relation, statement);
|
686 |
| } |
687 |
| } |
688 |
| } |
689 |
| |
690 |
| |
691 |
| |
692 |
| |
693 |
0
| private void createOntology(Graph g, Map ns) throws GraphException {
|
694 |
0
| String ontID = null;
|
695 |
| |
696 |
0
| Resource r = new URIImpl(OWL+"Ontology");
|
697 |
0
| StatementIterator i = g.getStatements(null, null, r);
|
698 |
0
| while (i.hasNext()){
|
699 |
0
| Statement s = i.next();
|
700 |
0
| URI pred = s.getPredicate();
|
701 |
0
| if (pred!=null && pred.getURI().equals(RDF.TYPE)){
|
702 |
0
| ontID = s.getSubject().toString();
|
703 |
0
| g.remove(s);
|
704 |
| } |
705 |
| } |
706 |
0
| if (ontID == null){
|
707 |
| |
708 |
| |
709 |
0
| StatementIterator it = g.getStatements(
|
710 |
| null, new URIImpl(WSML_ONTOLOGY_ID), null); |
711 |
0
| while (it.hasNext()) {
|
712 |
0
| Statement s = it.next();
|
713 |
0
| ontID= s.getObject().toString();
|
714 |
0
| g.remove(s);
|
715 |
| } |
716 |
| } |
717 |
0
| if (ontID == null) {
|
718 |
| |
719 |
0
| ontID = getDefaultNamespace(ns).getIRI() + "GENID" + System.currentTimeMillis();
|
720 |
| } |
721 |
0
| ontology = factory.createOntology(factory.createIRI(ontID));
|
722 |
| } |
723 |
| |
724 |
| |
725 |
| |
726 |
| |
727 |
| |
728 |
| |
729 |
0
| private void setWsmlVariant() {
|
730 |
0
| Iterator it = idConcepts.iterator();
|
731 |
0
| while (it.hasNext()) {
|
732 |
0
| String id = (String) it.next();
|
733 |
0
| if (idInstances.contains(id) || idRelations.contains(id)) {
|
734 |
0
| ontology.setWsmlVariant(org.wsmo.common.WSML.WSML_FLIGHT);
|
735 |
| } |
736 |
| } |
737 |
0
| it = idInstances.iterator();
|
738 |
0
| while (it.hasNext()) {
|
739 |
0
| String id = (String) it.next();
|
740 |
0
| if (idConcepts.contains(id) || idRelations.contains(id)) {
|
741 |
0
| ontology.setWsmlVariant(org.wsmo.common.WSML.WSML_FLIGHT);
|
742 |
| } |
743 |
| } |
744 |
0
| it = idRelations.iterator();
|
745 |
0
| while (it.hasNext()) {
|
746 |
0
| String id = (String) it.next();
|
747 |
0
| if (idConcepts.contains(id) || idInstances.contains(id)) {
|
748 |
0
| ontology.setWsmlVariant(org.wsmo.common.WSML.WSML_FLIGHT);
|
749 |
| } |
750 |
| } |
751 |
0
| if (ontology.getWsmlVariant() == null) {
|
752 |
0
| ontology.setWsmlVariant(org.wsmo.common.WSML.WSML_CORE);
|
753 |
| } |
754 |
| } |
755 |
| |
756 |
| |
757 |
| |
758 |
| |
759 |
| |
760 |
| |
761 |
| |
762 |
| |
763 |
0
| private void setNamespaces(Map namespaces) {
|
764 |
0
| boolean rdf = false;
|
765 |
0
| boolean rdfs = false;
|
766 |
| |
767 |
0
| ontology.addNamespace(
|
768 |
| factory.createNamespace("dc", factory.createIRI(DC))); |
769 |
0
| ontology.addNamespace(
|
770 |
| factory.createNamespace("wsml", factory.createIRI(WSML.WSML_NAMESPACE))); |
771 |
| |
772 |
0
| Iterator it = namespaces.entrySet().iterator();
|
773 |
0
| while (it.hasNext()) {
|
774 |
0
| Entry entry = (Entry) it.next();
|
775 |
0
| String key = (String) entry.getKey();
|
776 |
0
| String value = (String) entry.getValue();
|
777 |
| |
778 |
| |
779 |
0
| if (key.equals("rdf")) {
|
780 |
0
| if (value.equals(RDF.NAMESPACE)){
|
781 |
0
| rdf = true;
|
782 |
| }else{ |
783 |
0
| key = "rdf-old";
|
784 |
| } |
785 |
| } |
786 |
0
| else if (key.equals("rdfs")) {
|
787 |
0
| if (value.equals(RDFS.NAMESPACE)){
|
788 |
0
| rdfs=true;
|
789 |
| }else{ |
790 |
0
| key = "rdfs-old";
|
791 |
| } |
792 |
| } |
793 |
| |
794 |
0
| ontology.addNamespace(
|
795 |
| factory.createNamespace(key , factory.createIRI(value))); |
796 |
| } |
797 |
| |
798 |
0
| ontology.setDefaultNamespace(getDefaultNamespace(namespaces));
|
799 |
| |
800 |
0
| if (!rdf) {
|
801 |
0
| ontology.addNamespace(
|
802 |
| factory.createNamespace("rdf", factory.createIRI(RDF.NAMESPACE))); |
803 |
| } |
804 |
0
| if (!rdfs) {
|
805 |
0
| ontology.addNamespace(
|
806 |
| factory.createNamespace("rdfs", factory.createIRI(RDFS.NAMESPACE))); |
807 |
| } |
808 |
| } |
809 |
| |
810 |
| |
811 |
0
| private Namespace getDefaultNamespace(Map namespaces){
|
812 |
0
| if(this.defaultNS!=null) {
|
813 |
0
| return defaultNS;
|
814 |
| } else{ |
815 |
0
| String defaultNsCandidate="http://www.example.org/ontologies/example#";
|
816 |
0
| String defaultNsPrefix=null;
|
817 |
0
| Iterator it = namespaces.entrySet().iterator();
|
818 |
0
| while (it.hasNext()) {
|
819 |
0
| Entry entry = (Entry) it.next();
|
820 |
0
| String key = (String) entry.getKey();
|
821 |
0
| String value = (String) entry.getValue();
|
822 |
0
| if (key.equals("")){
|
823 |
0
| defaultNS = factory.createNamespace("",factory.createIRI(value));
|
824 |
| } |
825 |
| |
826 |
| |
827 |
0
| if (!key.equals("dc") && !key.equals("owl")
|
828 |
| && !key.equals("xsd") && !key.equals("part-whole") |
829 |
| && !key.equals("rdf") && !key.equals("rdfs") |
830 |
| && !key.equals("wsmo") && !key.equals("foaf")) { |
831 |
0
| defaultNsCandidate = value;
|
832 |
0
| defaultNsPrefix = key;
|
833 |
| } |
834 |
| } |
835 |
0
| if (defaultNS == null){
|
836 |
0
| if(defaultNsPrefix!=null) {
|
837 |
0
| namespaces.remove(defaultNsPrefix);
|
838 |
| } |
839 |
0
| defaultNS = factory.createNamespace("",factory.createIRI(defaultNsCandidate));
|
840 |
| } |
841 |
0
| return defaultNS;
|
842 |
| } |
843 |
| } |
844 |
| |
845 |
| |
846 |
| |
847 |
| |
848 |
| |
849 |
| |
850 |
0
| public Ontology getOntology() {
|
851 |
0
| return ontology;
|
852 |
| } |
853 |
| |
854 |
| |
855 |
| |
856 |
| |
857 |
0
| private Concept createConcept(String name, Statement statement)
|
858 |
| throws SynchronisationException, InvalidModelException { |
859 |
0
| Concept concept = null;
|
860 |
0
| IRI iri = null;
|
861 |
| |
862 |
| |
863 |
0
| if (name.indexOf(" ") != -1) {
|
864 |
0
| name = name.replaceAll(" ", "%20");
|
865 |
0
| addWarning("No spaces allowed in identifiers! - Spaces in " +
|
866 |
| "one or more concept identifiers " + |
867 |
| "have been replaced by '%20'!", statement); |
868 |
| } |
869 |
| |
870 |
| |
871 |
0
| try {
|
872 |
0
| iri = factory.createIRI(name);
|
873 |
| } catch (IllegalArgumentException e) { |
874 |
0
| addWarning("Anonymous identifiers problem - One or more " +
|
875 |
| "anonymous concepts have not been added to " + |
876 |
| "the WSMO object model!", statement); |
877 |
0
| return null;
|
878 |
| } |
879 |
0
| if (ontology.findConcept(iri) == null) {
|
880 |
0
| concept = factory.createConcept(iri);
|
881 |
0
| ontology.addConcept(concept);
|
882 |
0
| idConcepts.add(concept.getIdentifier().toString());
|
883 |
0
| return concept;
|
884 |
| } |
885 |
| else { |
886 |
0
| return ontology.findConcept(iri);
|
887 |
| } |
888 |
| } |
889 |
| |
890 |
| |
891 |
| |
892 |
| |
893 |
0
| private void addSuperConcept(Concept concept, Concept superConcept, Statement statement)
|
894 |
| throws SynchronisationException, InvalidModelException { |
895 |
0
| String localName = ((IRI) superConcept.getIdentifier()).getLocalName();
|
896 |
0
| if (localName.equals("Resource") && !concept.getIdentifier().toString().equals(RDFS.CLASS)) {
|
897 |
| |
898 |
| } |
899 |
0
| if (!concept.getIdentifier().equals(superConcept.getIdentifier())) {
|
900 |
0
| concept.addSuperConcept(superConcept);
|
901 |
| } |
902 |
| } |
903 |
| |
904 |
| |
905 |
| |
906 |
| |
907 |
0
| private void addNFP(Entity entity, String identifier, String value)
|
908 |
| throws SynchronisationException, InvalidModelException { |
909 |
0
| IRI key = factory.createIRI(identifier);
|
910 |
0
| DataValue dataValue = dataFactory.createWsmlString(value);
|
911 |
0
| entity.addNFPValue(key, dataValue);
|
912 |
| } |
913 |
| |
914 |
| |
915 |
| |
916 |
| |
917 |
0
| private Attribute createAttribute(Concept concept, String name, Statement statement)
|
918 |
| throws InvalidModelException { |
919 |
0
| IRI iri = null;
|
920 |
| |
921 |
| |
922 |
0
| if (name.indexOf(" ") != -1) {
|
923 |
0
| name = name.replaceAll(" ", "%20");
|
924 |
0
| addWarning("No spaces allowed in identifiers! - Spaces in " +
|
925 |
| "one or more attribute identifiers " + |
926 |
| "have been replaced by '%20'!", statement); |
927 |
| } |
928 |
| |
929 |
| |
930 |
0
| try {
|
931 |
0
| iri = factory.createIRI(name);
|
932 |
| } catch (IllegalArgumentException e) { |
933 |
0
| addWarning("Anonymous identifiers problem - One or more " +
|
934 |
| "anonymous attributes have not been added to " + |
935 |
| "the WSMO object model!", statement); |
936 |
0
| return null;
|
937 |
| } |
938 |
0
| return concept.createAttribute(iri);
|
939 |
| } |
940 |
| |
941 |
| |
942 |
| |
943 |
| |
944 |
0
| private void addAttributeType(Attribute attribute, Type type)
|
945 |
| throws InvalidModelException { |
946 |
0
| attribute.addType(type);
|
947 |
| } |
948 |
| |
949 |
| |
950 |
| |
951 |
| |
952 |
| |
953 |
0
| private Axiom createAxiom(Attribute a, Attribute b)
|
954 |
| throws ParserException, SynchronisationException, InvalidModelException{ |
955 |
| |
956 |
0
| Axiom axiom = factory.createAxiom(factory.createIRI(
|
957 |
| defaultNS.getIRI().toString() + |
958 |
| ((IRI) a.getIdentifier()).getLocalName() + "_is_" + |
959 |
| ((IRI) b.getIdentifier()).getLocalName())); |
960 |
| |
961 |
0
| ontology.addAxiom(axiom);
|
962 |
0
| String le = "?x[" + ((IRI) a.getIdentifier()).getLocalName() + " hasValue ?y] implies ?x[" +
|
963 |
| ((IRI) b.getIdentifier()).getLocalName() + " hasValue ?y]."; |
964 |
0
| LogicalExpression logExpr = leFactory.createLogicalExpression(le, ontology);
|
965 |
0
| axiom.addDefinition(logExpr);
|
966 |
0
| return axiom;
|
967 |
| } |
968 |
| |
969 |
| |
970 |
| |
971 |
| |
972 |
| |
973 |
0
| private Axiom createAxiom(String name, Statement statement)
|
974 |
| throws ParserException, SynchronisationException, InvalidModelException{ |
975 |
0
| IRI iri = null;
|
976 |
| |
977 |
| |
978 |
0
| if (name.indexOf(" ") != -1) {
|
979 |
0
| name = name.replaceAll(" ", "%20");
|
980 |
0
| addWarning("No spaces allowed in identifiers! - Spaces in " +
|
981 |
| "one or more instances identifiers " + |
982 |
| "have been replaced by '%20'!", statement); |
983 |
| } |
984 |
| |
985 |
| |
986 |
0
| try {
|
987 |
0
| iri = factory.createIRI(name);
|
988 |
| } catch (IllegalArgumentException e) { |
989 |
0
| if(name.startsWith("node")) {
|
990 |
0
| iri = factory.createIRI("blank:" + name);
|
991 |
| } else { |
992 |
0
| addWarning("Anonymous identifiers problem - One or more " +
|
993 |
| "anonymous instances have not been added to " + |
994 |
| "the WSMO object model!", statement); |
995 |
0
| return null;
|
996 |
| } |
997 |
| } |
998 |
0
| if (ontology.findAxiom(iri) == null) {
|
999 |
0
| Axiom axiom = factory.createAxiom(iri);
|
1000 |
0
| ontology.addAxiom(axiom);
|
1001 |
0
| return axiom;
|
1002 |
| } |
1003 |
| else { |
1004 |
0
| return ontology.findAxiom(iri);
|
1005 |
| } |
1006 |
| } |
1007 |
| |
1008 |
| |
1009 |
| |
1010 |
| |
1011 |
0
| private Relation createRelation(String name, Statement statement)
|
1012 |
| throws SynchronisationException, InvalidModelException { |
1013 |
0
| IRI iri = null;
|
1014 |
| |
1015 |
| |
1016 |
0
| if (name.indexOf(" ") != -1) {
|
1017 |
0
| name = name.replaceAll(" ", "%20");
|
1018 |
0
| addWarning("No spaces allowed in identifiers! - Spaces in " +
|
1019 |
| "one or more relation identifiers " + |
1020 |
| "have been replaced by '%20'!", statement); |
1021 |
| } |
1022 |
| |
1023 |
| |
1024 |
0
| try {
|
1025 |
0
| iri = factory.createIRI(name);
|
1026 |
| } catch (IllegalArgumentException e) { |
1027 |
0
| addWarning("Anonymous identifiers problem - One or more " +
|
1028 |
| "anonymous relations have not been added to " + |
1029 |
| "the WSMO object model!", statement); |
1030 |
0
| return null;
|
1031 |
| } |
1032 |
0
| if (ontology.findRelation(iri) == null) {
|
1033 |
0
| Relation relation = factory.createRelation(iri);
|
1034 |
0
| relation.createParameter((byte) 0);
|
1035 |
0
| relation.createParameter((byte) 1);
|
1036 |
0
| ontology.addRelation(relation);
|
1037 |
0
| idRelations.add(relation.getIdentifier().toString());
|
1038 |
0
| return relation;
|
1039 |
| } |
1040 |
| else { |
1041 |
0
| return ontology.findRelation(iri);
|
1042 |
| } |
1043 |
| } |
1044 |
| |
1045 |
| |
1046 |
| |
1047 |
| |
1048 |
0
| private void addSuperRelation(Relation relation, Relation superRelation)
|
1049 |
| throws SynchronisationException, InvalidModelException { |
1050 |
0
| relation.addSuperRelation(superRelation);
|
1051 |
| } |
1052 |
| |
1053 |
| |
1054 |
| |
1055 |
| |
1056 |
0
| private void addRelationType(Relation relation, Type type1, Type type2)
|
1057 |
| throws SynchronisationException, InvalidModelException { |
1058 |
0
| Parameter p1 = relation.listParameters().get(0);
|
1059 |
0
| Parameter p2 = relation.listParameters().get(1);
|
1060 |
0
| p1.addType(type1);
|
1061 |
0
| p2.addType(type2);
|
1062 |
| } |
1063 |
| |
1064 |
| |
1065 |
| |
1066 |
| |
1067 |
0
| private Instance createInstance(String name, Statement statement)
|
1068 |
| throws SynchronisationException, InvalidModelException { |
1069 |
0
| IRI iri = null;
|
1070 |
| |
1071 |
| |
1072 |
0
| if (name.indexOf(" ") != -1) {
|
1073 |
0
| name = name.replaceAll(" ", "%20");
|
1074 |
0
| addWarning("No spaces allowed in identifiers! - Spaces in " +
|
1075 |
| "one or more instances identifiers " + |
1076 |
| "have been replaced by '%20'!", statement); |
1077 |
| } |
1078 |
| |
1079 |
| |
1080 |
0
| try {
|
1081 |
0
| iri = factory.createIRI(name);
|
1082 |
| } catch (IllegalArgumentException e) { |
1083 |
0
| if(name.startsWith("node")) {
|
1084 |
0
| iri = factory.createIRI("blank:" + name);
|
1085 |
| } else { |
1086 |
0
| addWarning("Anonymous identifiers problem - One or more " +
|
1087 |
| "anonymous instances have not been added to " + |
1088 |
| "the WSMO object model!", statement); |
1089 |
0
| return null;
|
1090 |
| } |
1091 |
| } |
1092 |
0
| if (ontology.findInstance(iri) == null) {
|
1093 |
0
| Instance instance = factory.createInstance(iri);
|
1094 |
0
| ontology.addInstance(instance);
|
1095 |
0
| idInstances.add(instance.getIdentifier().toString());
|
1096 |
0
| return instance;
|
1097 |
| } |
1098 |
| else { |
1099 |
0
| return ontology.findInstance(iri);
|
1100 |
| } |
1101 |
| } |
1102 |
| |
1103 |
| |
1104 |
| |
1105 |
| |
1106 |
| |
1107 |
0
| private Instance getInstance(Value object) {
|
1108 |
0
| IRI iri = null;
|
1109 |
0
| try {
|
1110 |
0
| iri = factory.createIRI(object.toString());
|
1111 |
| } catch (IllegalArgumentException e) { |
1112 |
0
| if(object instanceof URI) {
|
1113 |
0
| iri = factory.createIRI(ontology.getDefaultNamespace().getIRI() + object.toString());
|
1114 |
0
| } else if (object instanceof BNode) {
|
1115 |
0
| iri = factory.createIRI("blank:" + object.toString());
|
1116 |
| } else { |
1117 |
0
| return null;
|
1118 |
| } |
1119 |
| } |
1120 |
0
| if (ontology.findInstance(iri) != null) {
|
1121 |
0
| return ontology.findInstance(iri);
|
1122 |
| } |
1123 |
| else { |
1124 |
0
| return null;
|
1125 |
| } |
1126 |
| } |
1127 |
| |
1128 |
| |
1129 |
| |
1130 |
| |
1131 |
| |
1132 |
| |
1133 |
| |
1134 |
0
| private RelationInstance createRelationInstance(Instance instance, Relation relation, Statement statement)
|
1135 |
| throws SynchronisationException, InvalidModelException { |
1136 |
0
| RelationInstance relationInstance = factory.createRelationInstance(relation);
|
1137 |
0
| ontology.addRelationInstance(relationInstance);
|
1138 |
0
| Instance tmp = getInstance(statement.getObject());
|
1139 |
0
| if (tmp == null) {
|
1140 |
0
| if (statement.getObject() instanceof URI) {
|
1141 |
0
| tmp = createInstance(statement.getObject().toString(), statement);
|
1142 |
0
| relationInstance.setParameterValue((byte) 1, tmp);
|
1143 |
| } |
1144 |
| else { |
1145 |
0
| DataValue dataValue = dataFactory.createWsmlString(statement.getObject().toString());
|
1146 |
0
| relationInstance.setParameterValue((byte) 1, dataValue);
|
1147 |
| } |
1148 |
| } |
1149 |
| else { |
1150 |
0
| relationInstance.setParameterValue((byte) 1, tmp);
|
1151 |
| } |
1152 |
0
| relationInstance.setParameterValue((byte) 0, instance);
|
1153 |
| |
1154 |
0
| return relationInstance;
|
1155 |
| } |
1156 |
| |
1157 |
0
| private Type createWsmlDataType(IRI iri) {
|
1158 |
0
| Type t = null;
|
1159 |
0
| if (iri.toString().equals(XmlSchema.STRING)) {
|
1160 |
0
| t = dataFactory.createWsmlDataType(WsmlDataType.WSML_STRING);
|
1161 |
| } |
1162 |
0
| else if (iri.toString().equals(XmlSchema.DECIMAL)) {
|
1163 |
0
| t = dataFactory.createWsmlDataType(WsmlDataType.WSML_DECIMAL);
|
1164 |
| } |
1165 |
0
| else if (iri.toString().equals(XmlSchema.INTEGER)) {
|
1166 |
0
| t = dataFactory.createWsmlDataType(WsmlDataType.WSML_INTEGER);
|
1167 |
| } |
1168 |
0
| else if (iri.toString().equals(XmlSchema.BOOLEAN)) {
|
1169 |
0
| t = dataFactory.createWsmlDataType(WsmlDataType.WSML_BOOLEAN);
|
1170 |
| } |
1171 |
0
| else if (iri.toString().equals(XmlSchema.DATE)) {
|
1172 |
0
| t = dataFactory.createWsmlDataType(WsmlDataType.WSML_DATE);
|
1173 |
| } |
1174 |
0
| else if (iri.toString().equals(XmlSchema.DATETIME)) {
|
1175 |
0
| t = dataFactory.createWsmlDataType(WsmlDataType.WSML_DATETIME);
|
1176 |
| } |
1177 |
0
| else if (iri.toString().equals(XmlSchema.TIME)) {
|
1178 |
0
| t = dataFactory.createWsmlDataType(WsmlDataType.WSML_TIME);
|
1179 |
| } |
1180 |
0
| else if (iri.toString().equals(XmlSchema.ANYURI)) {
|
1181 |
0
| t = dataFactory.createWsmlDataType(WsmlDataType.WSML_IRI);
|
1182 |
| } |
1183 |
0
| return t;
|
1184 |
| } |
1185 |
| |
1186 |
0
| private boolean nonRDFSProperty(String uri) {
|
1187 |
0
| return !uri.equals(RDF.TYPE)
|
1188 |
| && !uri.equals(RDFS.LABEL) |
1189 |
| && !uri.equals(RDFS.COMMENT) |
1190 |
| && !uri.equals(RDFS.SEEALSO); |
1191 |
| } |
1192 |
| |
1193 |
| |
1194 |
| |
1195 |
| |
1196 |
0
| private void addWarning(String message, Statement statement) {
|
1197 |
0
| errorListener.warning(message, -1, -1, statement);
|
1198 |
| } |
1199 |
| |
1200 |
| } |
1201 |
| |
1202 |
| |
1203 |
| |
1204 |
| |
1205 |
| |
1206 |
| |
1207 |
| |
1208 |
| |
1209 |
| |
1210 |
| |
1211 |
| |
1212 |
| |
1213 |
| |
1214 |
| |
1215 |
| |
1216 |
| |
1217 |
| |
1218 |
| |
1219 |
| |
1220 |
| |
1221 |
| |
1222 |
| |
1223 |
| |
1224 |
| |
1225 |
| |
1226 |
| |
1227 |
| |
1228 |
| |
1229 |
| |
1230 |
| |
1231 |
| |
1232 |
| |
1233 |
| |
1234 |
| |
1235 |
| |
1236 |
| |
1237 |
| |
1238 |
| |
1239 |
| |
1240 |
| |
1241 |
| |
1242 |
| |
1243 |
| |
1244 |
| |
1245 |
| |
1246 |
| |
1247 |
| |
1248 |
| |