4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
UploadOntology.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Author: Ing. Jaroslav Dytrych idytrych@fit.vutbr.cz
4  * File: UploadOntology.java
5  * Description: Backbean for page for uploading ontology
6  */
7 
8 /**
9  * @file UploadOntology.java
10  *
11  * @brief Backbean for page for uploading ontology
12  */
13 
14 package cz.vutbr.fit.knot.annotations.web;
15 
26 import java.io.ByteArrayInputStream;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.io.Serializable;
30 import java.io.StringWriter;
31 import java.io.UnsupportedEncodingException;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.HashMap;
35 import java.util.HashSet;
36 import java.util.Iterator;
37 import java.util.LinkedList;
38 import java.util.List;
39 import java.util.Map;
40 import java.util.Set;
41 import javax.faces.bean.ManagedBean;
42 import javax.faces.bean.ViewScoped;
43 import javax.persistence.EntityManager;
44 import javax.persistence.EntityTransaction;
45 import javax.persistence.Query;
46 import org.apache.commons.io.IOUtils;
47 import org.apache.myfaces.custom.fileupload.UploadedFile;
48 import org.semanticweb.owlapi.apibinding.OWLManager;
49 import org.semanticweb.owlapi.model.ClassExpressionType;
50 import org.semanticweb.owlapi.model.OWLAnnotation;
51 import org.semanticweb.owlapi.model.OWLAnnotationProperty;
52 import org.semanticweb.owlapi.model.OWLAnnotationPropertyDomainAxiom;
53 import org.semanticweb.owlapi.model.OWLAnnotationPropertyRangeAxiom;
54 import org.semanticweb.owlapi.model.OWLAnnotationValue;
55 import org.semanticweb.owlapi.model.OWLAxiom;
56 import org.semanticweb.owlapi.model.OWLClass;
57 import org.semanticweb.owlapi.model.OWLClassExpression;
58 import org.semanticweb.owlapi.model.OWLDataFactory;
59 import org.semanticweb.owlapi.model.OWLDataProperty;
60 import org.semanticweb.owlapi.model.OWLDataPropertyExpression;
61 import org.semanticweb.owlapi.model.OWLDataRange;
62 import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
63 import org.semanticweb.owlapi.model.OWLIndividual;
64 import org.semanticweb.owlapi.model.OWLLiteral;
65 import org.semanticweb.owlapi.model.OWLNamedIndividual;
66 import org.semanticweb.owlapi.model.OWLObjectIntersectionOf;
67 import org.semanticweb.owlapi.model.OWLObjectOneOf;
68 import org.semanticweb.owlapi.model.OWLObjectProperty;
69 import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom;
70 import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
71 import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom;
72 import org.semanticweb.owlapi.model.OWLObjectUnionOf;
73 import org.semanticweb.owlapi.model.OWLOntology;
74 import org.semanticweb.owlapi.model.OWLOntologyCreationException;
75 import org.semanticweb.owlapi.model.OWLOntologyManager;
76 import org.semanticweb.owlapi.model.OWLSubAnnotationPropertyOfAxiom;
77 import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom;
78 import org.semanticweb.owlapi.util.OWLOntologyWalker;
79 import org.semanticweb.owlapi.util.OWLOntologyWalkerVisitor;
80 import uk.ac.manchester.cs.owl.owlapi.OWLDatatypeImpl;
81 
82 /**
83  * Backbean for page for uploading ontology
84  *
85  * @brief Backbean for for page for uploading ontology
86  * @author idytrych
87  */
88 @ManagedBean
89 @ViewScoped
90 public class UploadOntology implements Serializable {
91  /**
92  * Error message displayed in form
93  */
94  private String errorMessage = "";
95  /**
96  * Success message displayed in form
97  */
98  private String successMessage = "";
99  /**
100  * Uploading indicator
101  */
102  private Boolean ontologyUploaded = false;
103  /**
104  * Uploaded file
105  */
106  private UploadedFile uploadedFile = null;
107  /**
108  * File name
109  */
110  private String fileName;
111  /**
112  * User group in which uploaded types will be shared
113  */
114  private String uGroup;
115  /**
116  * Selected import method
117  */
118  private int iMethod = 0;
119  /**
120  * Count of recursive call in inverse property processing.
121  */
122  private int recursiveInverseCount = 0;
123  /**
124  * Import method 0: If type already exists, error.
125  */
126  public static final int METHOD_0_ERROR = 0;
127  /**
128  * Import method 1: If type already exists, use it (do not create or update).
129  */
130  public static final int METHOD_1_USE = 1;
131  /**
132  * Import method 0: If type already exists, update it.
133  */
134  public static final int METHOD_2_UPDATE = 2;
135  /**
136  * Import language
137  */
138  private String importLang;
139  /**
140  * Language number
141  */
142  private int lNum;
143 
144 
145 
146 
147  // <editor-fold defaultstate="collapsed" desc="helper classes">
148 
149  // <editor-fold defaultstate="collapsed" desc="BooleanHolder">
150  /**
151  * Class for boolean reference pass.
152  *
153  * @brief Class for boolean reference pass.
154  * @author Marek Kopecky
155  */
156  private static class BooleanHolder {
157  /** Value */
158  boolean value;
159  /**
160  * Constructor
161  */
162  public BooleanHolder() {
163  value = false;
164  }
165  }
166  // </editor-fold>
167 
168  // <editor-fold defaultstate="collapsed" desc="AnnotTypeInfo">
169  /**
170  * Class for additional information about AnnotType.
171  *
172  * @brief Class for additional information about AnnotType.
173  * @author Marek Kopecky
174  */
175  public class AnnotTypeInfo {
176 
177  /** URI of type origin */
178  public String originUri;
179  /** Corrected URI */
180  public String correctedUri;
181  /** Was it object (individual)? */
182  public boolean wasObject;
183  /** Was it anonymous class? */
184  public boolean wasAnonymous;
185  /** Class in OWL */
186  public OWLClass owlClass;
187  /** Set of disjoint ones */
188  public Set<String> disjointWithSet;
189 
190  /**
191  * Construtor
192  *
193  * @param originUri URI of type origin
194  * @param correctedUri Corrected URI
195  * @param owlClass OWL class
196  * @param wasObject True, if it was object (individual), false otherwise
197  * @param wasAnonymous True, if it was oanonymous class, false otherwise
198  */
199  public AnnotTypeInfo(String originUri, String correctedUri, OWLClass owlClass, boolean wasObject, boolean wasAnonymous) {
200  this.correctedUri = correctedUri;
201  this.originUri = originUri;
202  this.owlClass = owlClass;
203  this.wasObject = wasObject;
204  this.wasAnonymous = wasAnonymous;
205  this.disjointWithSet = new HashSet<String>();
206  }
207 
208  /**
209  * Constructor
210  *
211  * @param originUri URI of type origin
212  * @param correctedUri Corrected URI
213  * @param owlClass OWL class
214  */
215  public AnnotTypeInfo(String originUri, String correctedUri, OWLClass owlClass) {
216  this(originUri, correctedUri, owlClass, true, false);
217  }
218 
219  /**
220  * Constructor
221  *
222  * @param originUri URI of type origin
223  * @param owlClass OWL class
224  */
225  public AnnotTypeInfo(String originUri, OWLClass owlClass) {
226  this(originUri, originUri, owlClass, true, false);
227  }
228  } // public class AnnotTypeInfo
229  // </editor-fold>
230 
231  // <editor-fold defaultstate="collapsed" desc="PropertyReference class">
232  /**
233  * Class with reference to OWLObjectProperty or OWLDataProperty.
234  *
235  * @brief Class with reference to OWLObjectProperty or OWLDataProperty.
236  * @author Marek Kopecky
237  */
238  private static class PropertyReference {
239  private OWLObjectProperty objectProperty;
240  private OWLDataProperty dataProperty;
241 
242  /**
243  * Constructor for objectProperty.
244  * @param objectProperty
245  */
246  public PropertyReference(OWLObjectProperty objectProperty) {
247  this.objectProperty = objectProperty;
248  this.dataProperty = null;
249  }
250 
251  /**
252  * Constructor for dataProperty.
253  * @param dataProperty
254  */
255  public PropertyReference(OWLDataProperty dataProperty) {
256  this.objectProperty = null;
257  this.dataProperty = dataProperty;
258  }
259 
260  /**
261  * Constructor for rdf:property.
262  */
263  public PropertyReference() {
264  this.objectProperty = null;
265  this.dataProperty = null;
266  }
267 
268  public OWLObjectProperty getObjectProperty() {
269  return objectProperty;
270  }
271 
272  public OWLDataProperty getDataProperty() {
273  return dataProperty;
274  }
275  }
276  // </editor-fold>
277 
278  // </editor-fold>
279 
280 
281 
282 
283  // <editor-fold defaultstate="collapsed" desc="Helper functions">
284 
285  /**
286  * Delete name in URI if anonymous property.
287  * Old anonymous uri type example: http://www.co-ode.org/ontologies/pizza/pizza2.owl#genid4 to http://www.co-ode.org/ontologies/pizza/pizza2.owl#
288  *
289  * @param originURI Original URI
290  * @param isAnonymous Output parameter - if anonymous, it will be set to true, false otherwise
291  * @return Returns URI without name
292  */
293  private String deleteNameInURIIfAnonymousProperty(String originURI, BooleanHolder isAnonymous) {
294  isAnonymous.value = false;
295  // new anonymous URI type
296  if (originURI.startsWith("_:genid")) {
297  String endOfUrl;
298  try {
299  endOfUrl = originURI.substring(7);
300  } catch (Exception e) { // substring error
301  return originURI;
302  }
304  isAnonymous.value = true;
305  return AppBean.getBaseUri() + "#";
306  }
307  }
308 
309  // old anonymous URI type
310  int anonymousStartName = originURI.lastIndexOf("#genid");
311  // property is not anonymous
312  if (anonymousStartName == -1) {
313  return originURI;
314  }
315  if (!OWLVisitorForRestrictionData.tryParseInt(originURI.substring(anonymousStartName + 6))) {
316  return originURI;
317  }
318  isAnonymous.value = true;
319  return originURI.substring(0, anonymousStartName + 1);
320  }
321 
322  /**
323  * Delete name in URI
324  *
325  * @param originURI
326  * @return Uri without name
327  */
328  private String deleteNameInURI(String originURI) {
329  int startName = originURI.lastIndexOf("#");
330  // property is not anonymous
331  if (startName == -1) {
332  return originURI;
333  }
334  return originURI.substring(0, startName + 1);
335  }
336 
337  /**
338  * Return argument with first upper character.
339  * @param str Original string.
340  * @return Argument with first upper character.
341  */
342  private String upperFirstChar(String str) {
343  return str.substring(0, 1).toUpperCase() + str.substring(1);
344  }
345 
346  /**
347  * Rename uri to acceptable format, if its class is annonymous
348  *
349  * @param uri Original uri
350  * @param isAnnonymous Function set value of this object.
351  * @return Corrected uri
352  */
353  private String renameIfAnonymous(String uri, BooleanHolder isAnnonymous) {
354  isAnnonymous.value = false;
355  if (uri.startsWith("http://org.semanticweb.owlapi/error#Error")) { // anonymous class
356  isAnnonymous.value = true;
357  return AppBean.getBaseOntoUploadUri() + "anonymous#classgenid" + uri.substring(41);
358  }
359  return uri; // named class
360  }
361 
362  /**
363  * Rename uri to acceptable format, if its class is annonymous
364  *
365  * @param uri Original uri
366  * @return Corrected uri
367  */
368  private String renameIfAnonymous(String uri) {
369  return renameIfAnonymous(uri, new BooleanHolder()); // named class
370  }
371 
372  /**
373  * Get class name from URI.
374  *
375  * @param uri
376  * @return Name
377  */
378  public static String getNameFromURI(String uri) {
379  int startIndex = uri.indexOf("#"); // uri specified by owl file
380  if (startIndex == -1) { // uri not specified by owl file
381  startIndex = uri.lastIndexOf("/"); // if -1, uri is damaged
382  }
383  return uri.substring(++startIndex);
384  }
385 
386  // </editor-fold>
387 
388  // <editor-fold defaultstate="collapsed" desc="createAnnotTypeFromIndividual">
389  /**
390  * Create AnnotType object from OWL object (individual).
391  *
392  * @param oModel Ontology model
393  * @param oFactory Ontology factory
394  * @param newTypes List with new (imported) types of annotations
395  * @param newTypesMap Map with new (imported) types of annotations
396  * @param newTypesMapInfo Map with information about element in newTypesMap
397  * @param userGroup User group in which uploaded types will be shared
398  * @param individual Individual
399  * @param name Individual name.
400  * @param anonymousIndividualCount Count of parsed anonymous individuals.
401  * @return New count of parsed anonymous individuals.
402  */
403  private int createAnnotTypeFromIndividual(OWLOntology oModel, OWLDataFactory oFactory, ArrayList<AnnotType> newTypes, Map<String, AnnotType> newTypesMap, Map<String, AnnotTypeInfo> newTypesMapInfo, UserGroup userGroup, OWLIndividual individual, String name, int anonymousIndividualCount) {
404  String individualUri = individual.toStringID();
405  String individualCorrectUri = individualUri;
406  if (individual.isAnonymous()) {
407  int indexSharp = individualCorrectUri.indexOf("#");
408  if (indexSharp == -1) { // anonymous individual should be in form ...#genidx
409  if (!individualCorrectUri.startsWith("_:genid")) {
410  return anonymousIndividualCount;
411  }
412  individualCorrectUri = AppBean.getBaseUri() + "#Specific" + name + ++anonymousIndividualCount;
413  } else { // old type of anonymous object (owl:individual) uri
414  int indexHttp = individualCorrectUri.indexOf("http://");
415  if (indexHttp == -1) { // anonymous individual should be in form http://...
416  return anonymousIndividualCount;
417  }
418  individualCorrectUri = individualCorrectUri.substring(indexHttp, indexSharp+1) + "Specific" + name + ++anonymousIndividualCount;
419  }
420  }
421 
422 
423  String individualName = getNameFromURI(individualCorrectUri); // get class name
424  AnnotType individualType = new AnnotType(null, individualName, null, userGroup);
425  individualType.setUriInOntology(individualCorrectUri);
426  AnnotTypeInfo individualInfo = new AnnotTypeInfo(individualUri, individualCorrectUri, null, true, individual.isAnonymous());
427  if (newTypesMap.containsKey(individualCorrectUri)) { // duplicit class
428  errorMessage = errorMessage + MessageProvider.getMessage("duplicitClassFound") + ": " + individualName + "<br/>";
429  return anonymousIndividualCount;
430  }
431 
432  String comment = "";
433  if (!individual.isAnonymous()) {
434  try { // asOWLNamedIndividual function can throw exception, but should not (because individual is not anonymous
435  comment = getComments(oFactory, individual.asOWLNamedIndividual().getAnnotations(oModel));
436  } catch (Exception e) {}
437  }
438  if (!comment.isEmpty()) {
439  individualType.setComment(comment);
440  }
441  newTypes.add(individualType);
442  newTypesMap.put(individualCorrectUri, individualType);
443  newTypesMapInfo.put(individualUri, individualInfo);
444  return anonymousIndividualCount;
445  }
446  // </editor-fold>
447 
448  // <editor-fold defaultstate="collapsed" desc="processModelPhase1">
449  /**
450  * Processing of ontology model - phase 1:
451  * - get classes and create types of annotations
452  *
453  * @param oModel Ontology model
454  * @param oFactory Ontology factory
455  * @param newTypes List with new (imported) types of annotations
456  * @param newTypesMap Map with new (imported) types of annotations
457  * @param userGroup User group in which uploaded types will be shared
458  * @param newTypesMapInfo Map with information about element in newTypesMap
459  * @return If error occurred, returns true, false otherwise
460  */
461  private boolean processModelPhase1(OWLOntology oModel, OWLDataFactory oFactory, ArrayList<AnnotType> newTypes, Map<String, AnnotType> newTypesMap, UserGroup userGroup, Map<String, AnnotTypeInfo> newTypesMapInfo) {
462  // We must create all types firstly and then add attributes and new URIs
463  for (OWLClass ontClass : oModel.getClassesInSignature()) { // for all classes
464  String uri = ontClass.toStringID(); // get class uri
465 
466  BooleanHolder isAnnonymous = new BooleanHolder();
467  uri = renameIfAnonymous(uri, isAnnonymous); // rename uri to acceptable format, if its class is annonymous
468  String name = getNameFromURI(uri); // get class name
469  AnnotTypeInfo info = new AnnotTypeInfo(ontClass.toStringID(), uri,
470  ontClass, false, (name.isEmpty() ? true : isAnnonymous.value));
471  AnnotType type = new AnnotType(null, name, null, userGroup);
472  type.setUriInOntology(uri);
473  if (newTypesMap.containsKey(uri)) { // duplicit class
474  errorMessage = errorMessage + MessageProvider.getMessage("duplicitClassFound") + ": " + name + "<br/>";
475  continue;
476  }
477  if (Constants.RESTRICT_TYPES_IMPORTED_FROM_ONTO) { // attributes restriction
478  type.setRestrictedAtt(true);
479  }
480  newTypesMapInfo.put(ontClass.toStringID(), info);
481  newTypes.add(type);
482  newTypesMap.put(uri, type);
483  Set<OWLIndividual> classIndividuals = ontClass.getIndividuals(oModel);
484  int anonymousIndividualCount = 0;
485  for (OWLIndividual individual : classIndividuals) {
486  anonymousIndividualCount = createAnnotTypeFromIndividual(oModel, oFactory, newTypes,
487  newTypesMap, newTypesMapInfo, userGroup, individual, name, anonymousIndividualCount);
488  }
489  }
490  return false;
491  } // processModelPhase1()
492  // </editor-fold>
493 
494  // <editor-fold defaultstate="collapsed" desc="ProcessPropertyFunctions">
495 
496  // <editor-fold defaultstate="collapsed" desc="noRangePropertyProcess">
497  /**
498  * Add attribute with no object (no range) to AnnotType.
499  *
500  * @param type AnnotType object.
501  * @param prName Property name.
502  * @param prUri Property URI.
503  * @param comment Property comment.
504  */
505  private void noRangePropertyProcess(AnnotType type, String prName, String prUri, String comment) {
506  Iterator<AnnotTypeAttr> atrIt = type.getAttributes().iterator();
507  boolean aFound = false;
508  while (atrIt.hasNext()) { // check whether is not already presented
509  AnnotTypeAttr aTA = atrIt.next();
510  if (aTA.getName().equals(prName)) {
511  aFound = true;
512  }
513  }
514  if (!aFound) { // if attribute is not presented, add it
515  AnnotTypeAttr attr = new AnnotTypeAttr(type, prName, "AnyAnnotation", false);
516  attr.setUriInOntology(prUri);
517  if (!comment.isEmpty()) {
518  attr.setComment(comment);
519  }
520  type.getAttributes().add(attr);
521  }
522  }
523  // </editor-fold>
524 
525  // <editor-fold defaultstate="collapsed" desc="getStringTypeFromOntologyURI">
526  /**
527  * Convert datatype URI in ontology to datatype name, used in this server.
528  *
529  * @param stringURI Datatype URI in ontology.
530  * @param generateError If true, then generate error, when URI is not corrected.
531  * @param isRequired This function set this value to true, if attribute should be required.
532  * @return Datatype name in server.
533  */
534  private String getStringTypeFromOntologyURI(String stringURI, boolean generateError, BooleanHolder isRequired) {
535  isRequired.value = false;
536  String stringType = "";
537  if (stringURI.contains("XMLSchema#string")) {
538  stringType = "String";
539  } else if (stringURI.contains("XMLSchema#anyURI")) {
540  stringType = "URI";
541  } else if (stringURI.contains("XMLSchema#float") || stringURI.contains("XMLSchema#double")) {
542  stringType = "Decimal";
543  } else if (stringURI.contains("XMLSchema#dateTime")) {
544  stringType = "DateTime";
545  } else if (stringURI.contains("XMLSchema#decimal")) {
546  stringType = "Decimal";
547  } else if (stringURI.contains("XMLSchema#date")
548  || stringURI.contains("XMLSchema#gYearMonth")
549  || stringURI.contains("XMLSchema#gYear")
550  || stringURI.contains("XMLSchema#gDay")
551  || stringURI.contains("XMLSchema#gMonth")
552  || stringURI.contains("XMLSchema#gMonthDay")) {
553  stringType = "Date";
554  } else if (stringURI.contains("XMLSchema#time")) {
555  stringType = "Time";
556  } else if (stringURI.contains("XMLSchema#boolean")) {
557  stringType = "Boolean";
558  } else if (stringURI.contains("XMLSchema#integer")
559  || stringURI.contains("XMLSchema#long")
560  || stringURI.contains("XMLSchema#int")
561  || stringURI.contains("XMLSchema#short")
562  || stringURI.contains("XMLSchema#byte")
563  || stringURI.contains("XMLSchema#nonPositiveInteger")
564  || stringURI.contains("XMLSchema#negativeInteger")
565  || stringURI.contains("XMLSchema#nonNegativeInteger")
566  || stringURI.contains("XMLSchema#positiveInteger")
567  || stringURI.contains("XMLSchema#unsignedLong")
568  || stringURI.contains("XMLSchema#unsignedInt")
569  || stringURI.contains("XMLSchema#unsignedShort")
570  || stringURI.contains("XMLSchema#unsignedByte")) { // integer derivatives
571  stringType = "Integer";
572  } else if (stringURI.contains("XMLSchema#normalizedString")
573  || stringURI.contains("XMLSchema#token")
574  || stringURI.contains("XMLSchema#language")
575  || stringURI.contains("XMLSchema#QName")
576  || stringURI.contains("XMLSchema#NOTATION")
577  || stringURI.contains("XMLSchema#ID")
578  || stringURI.contains("XMLSchema#ENTITY")
579  || stringURI.contains("XMLSchema#ENTITIES")
580  || stringURI.contains("XMLSchema#IDREF")
581  || stringURI.contains("XMLSchema#IDREFS")
582  || stringURI.contains("XMLSchema#Name")
583  || stringURI.contains("XMLSchema#NCName")) { // string derivatives
584  stringType = "String";
585  } else if (stringURI.contains("XMLSchema#NMTOKEN")
586  || stringURI.contains("XMLSchema#NMTOKENS")) {
587  stringType = "String";
588  isRequired.value = true;
589  } else if (stringURI.contains("XMLSchema#base64Binary")
590  || stringURI.contains("XMLSchema#hexBinary")) { // Binary
591  stringType = "Binary";
592  } else if (stringURI.contains("XMLSchema#duration")) { // duration
593  stringType = "Duration";
594  } else { // unsupported (so far)
595  if (generateError) {
596  errorMessage = errorMessage + MessageProvider.getMessage("unsupportedLiteralDatatype1")
597  + stringURI + MessageProvider.getMessage("unsupportedLiteralDatatype2") + "<br/>";
598  }
599  }
600  return stringType;
601  }
602  // </editor-fold>
603 
604  // <editor-fold defaultstate="collapsed" desc="getStringTypeFromOntologyURI">
605  /**
606  * Add property to AnnotType object in newTypesMap.
607  *
608  * @param prUri Property URI in ontology.
609  * @param propertyReference Reference to The OWL API structure for this property.
610  * @param comment Comment.
611  * @param subjectSetClassURI Set of subject URI.
612  * @param objectSetClassURI Set of object URI.
613  * @param newTypesMap Map with new (imported) types of annotations
614  * @param newTypesMapInfo Information about newNewTypesMap
615  * @param ontoAttrs List with attributes of unknown types of annotations
616  * @param userGroup User group in which uploaded types will be shared
617  * @param superPropertiesStringSet Set of super properties.
618  * @param inversePropertiesID Set of inverse properties URI.
619  * @param oModel Ontology model
620  */
621  private void processProperties(String prUri, PropertyReference propertyReference, String comment,
622  HashSet<String> subjectSetClassURI, HashSet<String> objectSetClassURI,
623  Map<String, AnnotType> newTypesMap,
624  Map<String, AnnotTypeInfo> newTypesMapInfo, ArrayList<TypeAttrOnto> ontoAttrs,
625  UserGroup userGroup, Set<String> superPropertiesStringSet,
626  Set<String> inversePropertiesID, OWLOntology oModel) {
627  if (prUri == null) { // fatal error, The OWL API generate URI and name if it is not set normally
628  errorMessage = errorMessage + MessageProvider.getMessage("badPropertyFound") + "<br/>";
629  return;
630  }
631  BooleanHolder anonymousProperty = new BooleanHolder();
632  prUri = deleteNameInURIIfAnonymousProperty(prUri, anonymousProperty);
633 
634  // if anonymous, generate new name
635  if (anonymousProperty.value) {
636  if (!inversePropertiesID.isEmpty()) {
637  anonymousProperty.value = false;
638  Iterator<String> itr = inversePropertiesID.iterator();
639  String firstInverseProperty = itr.next();
640  prUri += "not" + upperFirstChar(firstInverseProperty);
641  } else {
642  if (superPropertiesStringSet.isEmpty()) {
643  prUri += "has";
644  } else {
645  Iterator<String> itr = superPropertiesStringSet.iterator();
646  String ancestor = itr.next();
647  prUri += getNameFromURI(ancestor) + "Has";
648  }
649  }
650  }
651 
652  // property name
653  String prName = getNameFromURI(prUri); // predicate name
654  if (prName.isEmpty()) { // generate name for anonymous property
655  errorMessage = errorMessage + MessageProvider.getMessage("badPropertyFound") + "<br/>";
656  return;
657  }
658 
659  // add information about property type to comment (transitive, reflexive, functional, etc.)
660  comment = procesSpecialPropertyType(comment, propertyReference, objectSetClassURI.size(), prName, oModel);
661 
662 
663  // attribute without subject
664  if (subjectSetClassURI.isEmpty()) {
665  processPropertyWS(prUri, prName, comment, objectSetClassURI, userGroup, ontoAttrs, newTypesMap, anonymousProperty.value);
666  return;
667  }
668 
669  for (String subjectUri : subjectSetClassURI) { // for all domain in property
670  AnnotTypeInfo info = newTypesMapInfo.get(subjectUri);
671  if (info == null) {
672  errorMessage = errorMessage + MessageProvider.getMessage("badClassInOntology") + ": " + subjectUri + "<br/>";
673  continue; // unknown subject - property can't be processed
674  }
675  AnnotType type = newTypesMap.get(info.correctedUri); // get type created for this class
676  if (type == null) {
677  errorMessage = errorMessage + MessageProvider.getMessage("badClassInOntology") + ": " + subjectUri + "<br/>";
678  continue; // unknown subject - property can't be processed
679  }
680  String subjectName = getNameFromURI(subjectUri);
681 
682  // no range in property (no object) or rdf-schema#Literal in range in owl:ObjectProperty
683  if (objectSetClassURI.isEmpty()) {
684  if (!anonymousProperty.value) { // any usefull information
685  noRangePropertyProcess(type, prName, prUri, comment);
686  }
687  continue;
688  }
689 
690  for (String objUri : objectSetClassURI) { // rdfs:range = object
691  String objName = getNameFromURI(objUri);
692  String newPrUri = prUri;
693  String newPrName = prName;
694  if (!anonymousProperty.value) {
695  if (objectSetClassURI.size() != 1) {
696  newPrUri += "." + objName;
697  newPrName += "." + objName;
698  }
699  } else { // appending of object name
700  String objNameUpperFirstChar = upperFirstChar(objName);
701  newPrUri += objNameUpperFirstChar;
702  newPrName += objNameUpperFirstChar;
703  }
704  if (objUri.endsWith("rdf-schema#Literal")) {
705  if (!anonymousProperty.value) { // any usefull information
706  noRangePropertyProcess(type, prName, prUri, comment);
707  }
708  continue;
709  }
710  AnnotTypeInfo pInfo = newTypesMapInfo.get(objUri);
711  AnnotType pType = null;
712  if (pInfo != null) {
713  pType = newTypesMap.get(pInfo.correctedUri);
714  }
715  if (pType != null && pInfo != null) { // if type was found
716  Iterator<AnnotTypeAttr> atrIt = type.getAttributes().iterator();
717  boolean aFound = false;
718  while (atrIt.hasNext()) { // check whether is not already presented
719  AnnotTypeAttr aTA = atrIt.next();
720  if (aTA.getName().equals(newPrName)) {
721  aFound = true;
722  }
723  }
724  if (!aFound) { // if attribute is not presented, add it
725  AnnotTypeAttr attr = new AnnotTypeAttr(type, newPrName, pType, false);
726  attr.setUriInOntology(newPrUri);
727  if (comment != null) {
728  if (!comment.isEmpty()) {
729  attr.setComment(comment);
730  }
731  }
732  type.getAttributes().add(attr);
733  }
734  } else {
735  if (objUri.contains("XMLSchema#")) {
736  BooleanHolder isRequired = new BooleanHolder();
737  String simpleType = getStringTypeFromOntologyURI(objUri, true, isRequired);
738  if (simpleType.isEmpty()) {
739  continue;
740  }
741  AnnotTypeAttr attr = new AnnotTypeAttr(type, newPrName, simpleType, isRequired.value);
742  attr.setUriInOntology(newPrUri);
743  if (!comment.isEmpty()) {
744  attr.setComment(comment);
745  }
746  // WARNING: Value (variable objString) discarded - there is no place for it!
747  Iterator<AnnotTypeAttr> atrIt = type.getAttributes().iterator();
748  boolean aFound = false;
749  while (atrIt.hasNext()) { // check whether is not already presented
750  AnnotTypeAttr aTA = atrIt.next();
751  if (aTA.getName().equals(prName)) {
752  aFound = true;
753  }
754  }
755  if (!aFound) { // if it is not already presented
756  type.getAttributes().add(attr);
757  }
758  } else {
759  errorMessage = errorMessage + MessageProvider.getMessage("badPropertyFound") + ": " + prUri + "<br/>";
760  }
761  continue;
762  }
763  }
764  }
765  }
766  // </editor-fold>
767 
768  // <editor-fold defaultstate="collapsed" desc="addSuperPropertiesToComment">
769  /**
770  * Add information about superProperties to comment of property.
771  * @param propertyURI Property URI.
772  * @param comment Origin comment.
773  * @param superClasses Set of super classes URI.
774  * @return New comment.
775  */
776  private String addSuperPropertiesToComment(String propertyURI, String comment, Set<String> superClasses) {
777  for (String superClass : superClasses) {
778  if (superClass.equals(propertyURI)) {
779  continue;
780  }
781  BooleanHolder isAnonymous = new BooleanHolder();
782  deleteNameInURIIfAnonymousProperty(superClass, isAnonymous);
783  if (isAnonymous.value) { // information about anonymous property was skipped
784  continue;
785  }
786  comment = prepareCommentToAdding(comment);
787  comment += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SUB_PROPERTY_COMMENT_1) +
788  getNameFromURI(superClass) +
789  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SUB_PROPERTY_COMMENT_2);
790  }
791  return comment;
792  }
793  // </editor-fold>
794 
795  // <editor-fold defaultstate="collapsed" desc="addSuperObjectPropertiesToSet">
796  /**
797  * This function is for OWLObjectProperty.
798  * It create set of superProperties URI.
799  *
800  * @param propertyURI Property URI.
801  * @param superProperties Set of superProperties as OWLObjectPropertyExpression.
802  * @param superClasses Set of superProperties as String (URI).
803  */
804  private void addSuperObjectPropertiesToSet(String propertyURI,
805  Set<OWLObjectPropertyExpression> superProperties,
806  Set<String> superClasses) {
807  for (OWLObjectPropertyExpression superProperty : superProperties) {
808  String property;
809  try {
810  property = superProperty.asOWLObjectProperty().toStringID();
811  if (propertyURI.equals(property)) {
812  continue;
813  }
814  superClasses.add(property);
815  } catch (Exception e) {
816  continue;
817  }
818  }
819  }
820  // </editor-fold>
821 
822  // <editor-fold defaultstate="collapsed" desc="addSuperDataPropertiesToSet">
823  /**
824  * This function is for OWLDatatypeProperty.
825  * It create set of superProperties URI.
826  *
827  * @param propertyURI Property URI.
828  * @param superProperties Set of superProperties as OWLObjectPropertyExpression.
829  * @param superClasses Set of superProperties as String (URI).
830  */
831  private void addSuperDataPropertiesToSet(String propertyURI,
832  Set<OWLDataPropertyExpression> superProperties,
833  Set<String> superClasses) {
834  for (OWLDataPropertyExpression superProperty : superProperties) {
835  String property;
836  try {
837  property = superProperty.asOWLDataProperty().toStringID();
838  if (propertyURI.equals(property)) {
839  continue;
840  }
841  superClasses.add(property);
842  } catch (Exception e) {
843  continue;
844  }
845  }
846  }
847  // </editor-fold>
848 
849  // <editor-fold defaultstate="collapsed" desc="prepareCommentToAdding">
850  /**
851  * Prepare comment string to add another comment.
852  * @param comment Origin comment.
853  * @return New comment.
854  */
855  private String prepareCommentToAdding(String comment) {
856  if (comment == null) {
857  comment = "";
858  }
859  if (!comment.isEmpty()) {
860  comment += "\n";
861  }
862  return comment;
863  }
864  // </editor-fold>
865 
866  // <editor-fold defaultstate="collapsed" desc="editCommentBaseOnType">
867  /**
868  * Add property type information to property comment.
869  * For example, type can be "reflexive", "functional", etc.
870  *
871  * @param originalComment Original comment.
872  * @param action If true, property is of selected type.
873  * @param objectCount Count of property object.
874  * @param propertyName Property name.
875  * @param oneComment Text to comment, if property has one object.
876  * @param moreComment1 First text to comment, if property has more objects.
877  * @param moreComment2 Second text to comment, if property has more objects
878  * @return New comment.
879  */
880  private String editCommentBaseOnType(String originalComment, boolean action, int objectCount,
881  String propertyName, String oneComment,
882  String moreComment1, String moreComment2) {
883  if (!action) {
884  return originalComment;
885  }
886  originalComment = prepareCommentToAdding(originalComment);
887  if (objectCount > 1) {
888  originalComment += moreComment1 + propertyName + moreComment2;
889  } else {
890  originalComment += oneComment;
891  }
892  return originalComment;
893  }
894  // </editor-fold>
895 
896  // <editor-fold defaultstate="collapsed" desc="procesSpecialPropertyType">
897  /**
898  * Add information about all types to property comment.
899  * @param comment Original comment.
900  * @param propertyReference Reference to The OWL API structure for this property.
901  * @param objectCount Count of property object.
902  * @param newPropertyName Property name.
903  * @param oModel Ontology model.
904  * @return New comment.
905  */
906  private String procesSpecialPropertyType(String comment, PropertyReference propertyReference, int objectCount, String newPropertyName, OWLOntology oModel) {
907  try {
908  OWLDataProperty dataProperty = propertyReference.getDataProperty();
909  OWLObjectProperty objectProperty = propertyReference.getObjectProperty();
910 
911  if (dataProperty != null) {
912  comment = editCommentBaseOnType(comment, dataProperty.isFunctional(oModel), objectCount,
913  newPropertyName, TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.FUNCTIONAL_PROPERTY_ONE_OBJECT_COMMENT),
915  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.FUNCTIONAL_PROPERTY_MORE_OBJECT_COMMENT_2));
916  } else if (objectProperty != null) {
917  comment = editCommentBaseOnType(comment, objectProperty.isFunctional(oModel), objectCount,
918  newPropertyName, TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.FUNCTIONAL_PROPERTY_ONE_OBJECT_COMMENT),
920  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.FUNCTIONAL_PROPERTY_MORE_OBJECT_COMMENT_2));
921  comment = editCommentBaseOnType(comment, objectProperty.isAsymmetric(oModel), objectCount,
922  newPropertyName, TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.ASSYMETRIC_PROPERTY_ONE_OBJECT_COMMENT),
924  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.ASSYMETRIC_PROPERTY_MORE_OBJECT_COMMENT_2));
925  comment = editCommentBaseOnType(comment, objectProperty.isInverseFunctional(oModel), objectCount,
926  newPropertyName, TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.INVERSE_FUNCTIONAL_PROPERTY_ONE_OBJECT_COMMENT),
929  comment = editCommentBaseOnType(comment, objectProperty.isIrreflexive(oModel), objectCount,
930  newPropertyName, TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.IRREFLEXIVE_PROPERTY_ONE_OBJECT_COMMENT),
932  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.IRREFLEXIVE_PROPERTY_MORE_OBJECT_COMMENT_2));
933  comment = editCommentBaseOnType(comment, objectProperty.isReflexive(oModel), objectCount,
934  newPropertyName, TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.REFLEXIVE_PROPERTY_ONE_OBJECT_COMMENT),
936  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.REFLEXIVE_PROPERTY_MORE_OBJECT_COMMENT_2));
937  comment = editCommentBaseOnType(comment, objectProperty.isSymmetric(oModel), objectCount,
938  newPropertyName, TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SYMETRIC_PROPERTY_ONE_OBJECT_COMMENT),
940  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SYMETRIC_PROPERTY_MORE_OBJECT_COMMENT_2));
941  comment = editCommentBaseOnType(comment, objectProperty.isTransitive(oModel), objectCount,
942  newPropertyName, TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.TRANSITIVE_PROPERTY_ONE_OBJECT_COMMENT),
944  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.TRANSITIVE_PROPERTY_MORE_OBJECT_COMMENT_2));
945  }
946  } catch (Exception e) {}
947  return comment;
948  }
949  // </editor-fold>
950 
951  // </editor-fold>
952 
953  // <editor-fold defaultstate="collapsed" desc="getComments">
954  /**
955  * Get comments from annotationSet (annotation of OWL Class).
956  *
957  * @param oFactory Ontology factory
958  * @param annotationSet Set of annotation of OWL Class.
959  * @return Comment.
960  */
961  private String getComments( OWLDataFactory oFactory, Set<OWLAnnotation> annotationSet) {
962  String comment = "";
963  for (OWLAnnotation propertyAnnotation : annotationSet) {
964  OWLAnnotationProperty propertyType = propertyAnnotation.getProperty();
965  OWLAnnotationValue value = propertyAnnotation.getValue();
966 
967  if (value instanceof OWLLiteral) {
968  OWLLiteral literalValue = (OWLLiteral) value;
969  // RDFS Comment
970  literalValue.getObjectPropertiesInSignature();
971  if (propertyType.equals(oFactory.getRDFSComment())) {
972  String commentValue = literalValue.getLiteral();
973  if (!comment.isEmpty()) {
974  comment = comment + " \n" + commentValue.trim();
975  } else {
976  comment = commentValue.trim();
977  }
978  continue;
979  }
980  }
981  }
982  return comment;
983  }
984  // </editor-fold>
985 
986  // <editor-fold defaultstate="collapsed" desc="processOWLClassExpression">
987  /**
988  * Get all class URI from OWLClassExpression.
989  * This function is used for get subject (domain) and object (range) from property.
990  *
991  * @param oModel Ontology model.
992  * @param exp OWLClassExpression value.
993  * @return Set of class URI
994  */
995  private HashSet<String> processOWLClassExpression(OWLOntology oModel, OWLClassExpression exp) {
996  HashSet<String> set = new HashSet<String>();
997  try { // cast can throw exception, but should not (try is used just to be sure)
998  if (exp.getClassExpressionType().equals(ClassExpressionType.OWL_CLASS)) {
999  set.add(exp.asOWLClass().toStringID());
1000  }
1001  else if (exp.getClassExpressionType().equals(ClassExpressionType.OBJECT_UNION_OF)) {
1002  Set<OWLClass> classSet = ((OWLObjectUnionOf) exp).getClassesInSignature();
1003  for (OWLClass cls : classSet) {
1004  set.add(cls.toStringID());
1005  }
1006  }
1007  } catch (Exception e) {}
1008  return set;
1009  }
1010  // </editor-fold>
1011 
1012  // <editor-fold defaultstate="collapsed" desc="process inverse property">
1013  /**
1014  * Get inverse ane equivalent properties of property. Recursive function.
1015  * Property or expression argument should be null.
1016  *
1017  * @param processedProperty URI of properties, that has been already processed.
1018  * @param property Property object.
1019  * @param expression Expression object.
1020  * @param oModel Ontology model
1021  * @param inversePropertyURI Set of inverse properties URI
1022  * @param equivalentPropertyURI Set of equivalent properties URI
1023  */
1024  private void getInverseEquivalentPropertyUri(Set<String> processedProperty,
1025  OWLObjectProperty property, OWLObjectPropertyExpression expression,
1026  OWLOntology oModel, Set<OWLObjectPropertyExpression> inversePropertyURI,
1027  Set<OWLObjectPropertyExpression> equivalentPropertyURI) {
1028  // security condition
1030  if (recursiveInverseCount > 5000) {
1031  return;
1032  }
1033 
1034  Set<OWLObjectPropertyExpression> inverses;
1035  Set<OWLObjectPropertyExpression> equivalents;
1036  if (property != null) {
1037  property.getInverseProperty().getRanges(oModel).toString();
1038  inverses = property.getInverses(oModel);
1039  equivalents = property.getEquivalentProperties(oModel);
1040  } else {
1041  if (expression == null) { // fatal error
1042  return;
1043  }
1044  inverses = expression.getInverses(oModel);
1045  equivalents = expression.getEquivalentProperties(oModel);
1046  }
1047 
1048  for (OWLObjectPropertyExpression propertyExpression : inverses) {
1049  if (processedProperty.contains(propertyExpression.toString())) {
1050  continue;
1051  }
1052  processedProperty.add(propertyExpression.toString());
1053  inversePropertyURI.add(propertyExpression);
1054  getInverseEquivalentPropertyUri(processedProperty, null, propertyExpression, oModel,
1055  equivalentPropertyURI, inversePropertyURI);
1056  }
1057  for (OWLObjectPropertyExpression propertyExpression : equivalents) {
1058  if (processedProperty.contains(propertyExpression.toString())) {
1059  continue;
1060  }
1061  //System.out.println(propertyExpression.toString());
1062  processedProperty.add(propertyExpression.toString());
1063  equivalentPropertyURI.add(propertyExpression);
1064  getInverseEquivalentPropertyUri(processedProperty, null, propertyExpression, oModel,
1065  inversePropertyURI, equivalentPropertyURI);
1066  }
1067  }
1068 
1069  /**
1070  *
1071  * @param oModel Ontology model
1072  * @param property Property object
1073  * @param objectSetExpression Set of object class expression
1074  * @param subjectSetExpression Set of subject class expression
1075  * @param inversePropertiesStringSet Set of inverse properties URI. This set is fill with data up in this function.
1076  */
1077  private void processInverseProperty(OWLOntology oModel, OWLObjectProperty property,
1078  Set<OWLClassExpression> objectSetExpression,
1079  Set<OWLClassExpression> subjectSetExpression,
1080  Set<String> inversePropertiesStringSet) {
1081  try {
1083  Set<OWLObjectPropertyExpression> inverseSet = new HashSet<OWLObjectPropertyExpression>();
1084  Set<OWLObjectPropertyExpression> equivalentSet = new HashSet<OWLObjectPropertyExpression>();
1085  getInverseEquivalentPropertyUri(new HashSet<String>(), property, null, oModel, inverseSet, equivalentSet);
1086  // detect all inverse properties and get subject or object from them
1087  for (OWLObjectPropertyExpression propertyExpression : inverseSet) {
1088  if (!propertyExpression.isAnonymous()) { // name of anonymous property is useless
1089  String inversePropertyNameID = propertyExpression.getNamedProperty().toStringID();
1090  inversePropertiesStringSet.add(inversePropertyNameID);
1091  } else { // anonymous property, but The OWL API didn't generate anonymous name in form genidX (where X is unique number)
1092  BooleanHolder isAnonymousByName = new BooleanHolder();
1093  deleteNameInURIIfAnonymousProperty(propertyExpression.toString(), isAnonymousByName);
1094  if (!isAnonymousByName.value) {
1095  isAnonymousByName.value = true;
1096  }
1097  }
1098  if (subjectSetExpression.isEmpty()) {
1099  subjectSetExpression.addAll(propertyExpression.getRanges(oModel));
1100  }
1101  if (objectSetExpression.isEmpty()) {
1102  objectSetExpression.addAll(propertyExpression.getDomains(oModel));
1103  }
1104  }
1105  // attempt to get object and subject from equivalent property
1106  for (OWLObjectPropertyExpression propertyExpression : equivalentSet) {
1107  // not equivalent class
1108  if (propertyExpression.toString().startsWith("InverseOf") || !propertyExpression.toString().startsWith("<")) {
1109  continue;
1110  }
1111  // this class is skipped
1112  if (!propertyExpression.isAnonymous()) {
1113  if (propertyExpression.getNamedProperty().toStringID().equalsIgnoreCase(property.toStringID())) {
1114  continue;
1115  }
1116  }
1117  if (subjectSetExpression.isEmpty()) {
1118  subjectSetExpression.addAll(propertyExpression.getDomains(oModel));
1119  }
1120  if (objectSetExpression.isEmpty()) {
1121  objectSetExpression.addAll(propertyExpression.getRanges(oModel));
1122  }
1123  }
1124  } catch (Exception e) {}
1125  }
1126  // </editor-fold>
1127 
1128  // <editor-fold defaultstate="collapsed" desc="processSuperClass">
1129  /**
1130  * Get super classes URI of OWL class.
1131  *
1132  * @param oModel Ontology model
1133  * @param ontClass Class object
1134  * @return List of super classes URI.
1135  */
1136  private LinkedList<String> processSuperClass(OWLOntology oModel, OWLClass ontClass) {
1137  LinkedList<String> allAncestorList = new LinkedList<String>();
1138  try { // cast can throw exception, but should not (try is used just to be sure)
1139  OWLClass actualClass = ontClass;
1140  while (true) {
1141  Set<OWLClassExpression> ancestorSet = actualClass.getSuperClasses(oModel);
1142  Iterator<OWLClassExpression> ancestorIt = ancestorSet.iterator();
1143  if (!ancestorIt.hasNext()) { // any ancestor found
1144  break;
1145  }
1146  OWLClassExpression ancestor = ancestorIt.next();
1147  String ancestorString = ancestor.asOWLClass().toStringID();
1148  actualClass = ancestor.asOWLClass();
1149  if (allAncestorList.contains(ancestorString)) {
1150  break;
1151  }
1152  allAncestorList.addLast(ancestorString);
1153  }
1154  } catch (Exception e) {}
1155  return allAncestorList;
1156  }
1157 
1158  /**
1159  * Add list of super-classes to AnnotType object.
1160  *
1161  * @param newTypes List with new (imported) types of annotations
1162  * @param newTypesMap Map with new (imported) types of annotations
1163  * @param userGroup User group in which uploaded types will be shared
1164  * @param type AnnotType object.
1165  * @param superClasses List of super classes URI. This list is fill up in this function.
1166  */
1167  private void addSuperClassesToAnnotType(ArrayList<AnnotType> newTypes, Map<String, AnnotType> newTypesMap, UserGroup userGroup, AnnotType type, List<String> superClasses) {
1168  Iterator<String> superClassesIt = superClasses.iterator();
1169  while (superClassesIt.hasNext()) {
1170  String parentUri = renameIfAnonymous(superClassesIt.next());
1171  AnnotType aType = newTypesMap.get(parentUri);
1172  if (aType != null) { // if ancestor was found
1173  type.addAncestorType(aType);
1174  } else {
1175  if (!parentUri.equals("http://www.w3.org/2002/07/owl#Thing")) {
1176  errorMessage = errorMessage + MessageProvider.getMessage("badSuperclassInOntology") + ": " + parentUri + "<br/>";
1177  } else { // if it is Thing
1178  if (!newTypesMap.containsKey(parentUri)) { // if Thing not presented
1179  // Create Thing
1180  AnnotType thing = new AnnotType(null, "Thing", null, userGroup);
1181  thing.setUri(thing.getGeneratedURI());
1182  thing.setUriInOntology(parentUri);
1183  newTypesMap.put(parentUri, thing);
1184  newTypes.add(thing);
1185  aType = thing;
1186  type.addAncestorType(aType);
1187  }
1188  } // if it is Thing
1189  }
1190  }
1191  }
1192  // </editor-fold>
1193 
1194  // <editor-fold defaultstate="collapsed" desc="processRdfPropertyAxioms">
1195  /**
1196  * Process set of OWL Axiom and get subject, object and ancestor for rdf:property element.
1197  *
1198  * @param objectSetClassURI Set of object URI string.
1199  * @param subjectSetClassURI Set of subject URI string.
1200  * @param ancestorSetClassURI Set of ancestor URI string.
1201  * @param allAxioms Set of all axiom to selected property.
1202  * @return Count of unsupported axioms.
1203  */
1204  private int processRdfPropertyAxioms(HashSet<String> objectSetClassURI,
1205  HashSet<String> subjectSetClassURI,
1206  HashSet<String> ancestorSetClassURI,
1207  Set<OWLAxiom> allAxioms) {
1208  int anotherAxioms = 0;
1209  for (OWLAxiom ax : allAxioms) {
1210  if (ax.getAxiomType().getName().equals("AnnotationPropertyRangeOf") &&
1211  ax instanceof OWLAnnotationPropertyRangeAxiom) {
1212  OWLAnnotationPropertyRangeAxiom range = (OWLAnnotationPropertyRangeAxiom) ax;
1213  objectSetClassURI.add(range.getRange().toString());
1214  } else if (ax.getAxiomType().getName().equals("AnnotationPropertyDomain") &&
1215  ax instanceof OWLAnnotationPropertyDomainAxiom) {
1216  OWLAnnotationPropertyDomainAxiom domain = (OWLAnnotationPropertyDomainAxiom) ax;
1217  subjectSetClassURI.add(domain.getDomain().toString());
1218  } else if (ax.getAxiomType().getName().equals("SubAnnotationPropertyOf") &&
1219  ax instanceof OWLSubAnnotationPropertyOfAxiom) {
1220  try { // cast can throw exception, but should not (try is used just to be sure)
1221  OWLSubAnnotationPropertyOfAxiom ancestor = (OWLSubAnnotationPropertyOfAxiom) ax;
1222  OWLAnnotationProperty ancestorProperty = ancestor.getSuperProperty();
1223  if (ancestorProperty.isOWLObjectProperty()) {
1224  ancestorSetClassURI.add(ancestorProperty.asOWLObjectProperty().toStringID());
1225  } else {
1226  ancestorSetClassURI.add(ancestorProperty.getIRI().toString());
1227  }
1228  } catch (Exception e) {}
1229  }
1230  else if (ax.getAxiomType().getName().equals("AnnotationAssertion")) {
1231  anotherAxioms++;
1232  continue; // elements like this: <test:whatever rdf:resource="#aaa"/> in class tag is processed in another place
1233  } else {
1234  anotherAxioms++;
1235  }
1236  }
1237  return anotherAxioms;
1238  }
1239  // </editor-fold>
1240 
1241  // <editor-fold defaultstate="collapsed" desc="processPropertyWS">
1242  /**
1243  * Process property without subject
1244  * - creates attribute of unknown type of annotation
1245  *
1246  * @param prUri Property URI in ontology
1247  * @param prName Name of property to process
1248  * @param comment Comment of property to process
1249  * @param objectSetClassURI Set of object URI.
1250  * @param userGroup User group in which uploaded types will be shared
1251  * @param ontoAttrs List with attributes of unknown types of annotations
1252  * @param newTypesMap Map with new (imported) types of annotations
1253  * @param isAnonymous True if it is anonymous, false otherwise
1254  */
1255  private void processPropertyWS(String prUri, String prName, String comment, HashSet<String> objectSetClassURI, UserGroup userGroup, ArrayList<TypeAttrOnto> ontoAttrs, Map<String, AnnotType> newTypesMap, boolean isAnonymous) {
1256  Iterator<String> it = objectSetClassURI.iterator();
1257  while (it.hasNext()) {
1258  String objectURI = it.next();
1259  if (objectURI.endsWith("rdf-schema#Literal")) {
1260  it.remove();
1261  }
1262  }
1263  if (objectSetClassURI.isEmpty()) {
1264  if (isAnonymous) {
1265  return;
1266  }
1267  Iterator<TypeAttrOnto> atrIt = ontoAttrs.iterator();
1268  boolean aFound = false;
1269  while (atrIt.hasNext()) { // check whether is not already presented
1270  TypeAttrOnto aTA = atrIt.next();
1271  if (aTA.getName().equals(prName)) {
1272  aFound = true;
1273  }
1274  }
1275  if (!aFound) { // if attribute is not presented, add it
1276  TypeAttrOnto attr = new TypeAttrOnto(userGroup, prName, "AnyAnnotation");
1277  attr.setUriInOntology(prUri);
1278  if (!comment.isEmpty()) {
1279  attr.setComment(comment);
1280  }
1281  ontoAttrs.add(attr);
1282  }
1283  return;
1284  }
1285 
1286  if (prName.equals("subClassOf")) { // if object is superclass
1287  errorMessage = errorMessage + MessageProvider.getMessage("badSuperclassInOntology") + "<br/>";
1288  return;
1289  }
1290 
1291  // for all objects
1292  for (String objUri : objectSetClassURI) {
1293  String newPrName = prName;
1294  String newPrUri = prUri;
1295  // update property name
1296  if (!isAnonymous) {
1297  if (objectSetClassURI.size() > 1) {
1298  String objName = getNameFromURI(objUri);
1299  newPrName += "." + objName;
1300  newPrUri += "." + objName;
1301  }
1302  } else { // is anonymous
1303  String objName = upperFirstChar(getNameFromURI(objUri));
1304  newPrName += objName;
1305  newPrUri += objName;
1306  }
1307  AnnotType pType = newTypesMap.get(objUri);
1308  if (pType != null) { // if type was found
1309  Iterator<TypeAttrOnto> atrIt = ontoAttrs.iterator();
1310  boolean aFound = false;
1311  while (atrIt.hasNext()) { // check whether is not already presented
1312  TypeAttrOnto aTA = atrIt.next();
1313  if (aTA.getName().equals(newPrName)) {
1314  aFound = true;
1315  }
1316  }
1317  if (!aFound) { // if attribute is not presented, add it
1318  TypeAttrOnto attr = new TypeAttrOnto(userGroup, newPrName, pType);
1319  attr.setUriInOntology(newPrUri);
1320  if (!comment.isEmpty()) {
1321  attr.setComment(comment);
1322  }
1323  ontoAttrs.add(attr);
1324  }
1325  } else {
1326 
1327  if (objUri.contains("XMLSchema#")) {
1328  BooleanHolder isRequired = new BooleanHolder(); // not used here
1329  String simpleType = getStringTypeFromOntologyURI(objUri, true, isRequired);
1330  if (simpleType.isEmpty()) {
1331  return;
1332  }
1333  Iterator<TypeAttrOnto> atrIt = ontoAttrs.iterator();
1334  boolean aFound = false;
1335  while (atrIt.hasNext()) { // check whether is not already presented
1336  TypeAttrOnto aTA = atrIt.next();
1337  if (aTA.getName().equals(newPrName)) {
1338  aFound = true;
1339  }
1340  }
1341  if (!aFound) { // if attribute is not presented, add it
1342  TypeAttrOnto attr = new TypeAttrOnto(userGroup, newPrName, simpleType);
1343  attr.setUriInOntology(newPrUri);
1344  if (!comment.isEmpty()) {
1345  attr.setComment(comment);
1346  }
1347  ontoAttrs.add(attr);
1348  }
1349  } else {
1350  errorMessage = errorMessage + MessageProvider.getMessage("badPropertyFound") + ": " + prUri + "<br/>";
1351  return;
1352  }
1353  }
1354  }
1355  } // processPropertyWS()
1356  // </editor-fold>
1357 
1358  // <editor-fold defaultstate="collapsed" desc="getOntoPropertyMayMove">
1359  /**
1360  * Find properties in ontoAttrs, if found, remove from ontoAttrs and add to ontoAttrsDeleted
1361  * This is for restriction in anonymous class.
1362  *
1363  * @param propertyURI Uri of property in restriction.
1364  * @param ontoAttrs List with attributes of unknown types of annotations
1365  * @param ontoAttrsDeleted List with attributes of known types of annotations (types are known from restriction in anonymous class)
1366  * @return If found, all properties in set, else null.
1367  */
1368  private ArrayList<TypeAttrOnto> getOntoPropertyMayMove(String propertyURI, ArrayList<TypeAttrOnto> ontoAttrs,
1369  ArrayList<TypeAttrOnto> ontoAttrsDeleted) {
1370  Iterator<TypeAttrOnto> it = ontoAttrs.iterator();
1371  ArrayList<TypeAttrOnto> ontoList = new ArrayList<TypeAttrOnto>();
1372  boolean ontoAtrFound = false;
1373  TypeAttrOnto ontoAtr;
1374  while (it.hasNext()) {
1375  ontoAtr = it.next();
1376  String uri = ontoAtr.getUriInOntology();
1377  if (uri.startsWith(propertyURI + ".") || uri.equalsIgnoreCase(propertyURI)) {
1378  ontoAtrFound = true;
1379  it.remove();
1380  ontoAttrsDeleted.add(ontoAtr);
1381  ontoList.add(ontoAtr);
1382  }
1383  }
1384  if (ontoAtrFound) {
1385  return ontoList;
1386  }
1387  // try to found in ontoAttrsDeleted
1388  it = ontoAttrsDeleted.iterator();
1389  while (it.hasNext()) {
1390  ontoAtr = it.next();
1391  if (ontoAtr.getUriInOntology().startsWith(propertyURI + ".") ||
1392  ontoAtr.getUriInOntology().equalsIgnoreCase(propertyURI)) {
1393  ontoAtrFound = true;
1394  ontoList.add(ontoAtr);
1395  }
1396  }
1397  if (ontoAtrFound) {
1398  return ontoList;
1399  }
1400  // nothing found
1401  return null;
1402  }
1403  // </editor-fold>
1404 
1405  // <editor-fold defaultstate="collapsed" desc="addPropertyInAnonymousClassFromCardinalityRestriction">
1406  /**
1407  * Add property to anonymous class. Property is marked only in restriction.
1408  *
1409  * @param ontoAttrs List with attributes of unknown types of annotations
1410  * @param ontoAttrsDeleted List with attributes of known types of annotations (types are known from restriction in anonymous class)
1411  * @param data Information about restriction.
1412  * @param typeURI Subject class URI.
1413  * @param newTypesMap Map with new (imported) types of annotations
1414  * @param newTypesMapInfo Map with informations about new (imported) types of annotations
1415  * @param oModel Ontology model
1416  * @param userGroup User group in which uploaded types will be shared
1417  * @return Count of new atributes.
1418  */
1419  private int addPropertyInAnonymousClassFromCardinalityRestriction(ArrayList<TypeAttrOnto> ontoAttrs,
1420  ArrayList<TypeAttrOnto> ontoAttrsDeleted, OWLVisitorForRestrictionData.CardinalityData data,
1421  String typeURI, Map<String, AnnotType> newTypesMap,
1422  Map<String, AnnotTypeInfo> newTypesMapInfo, OWLOntology oModel, UserGroup userGroup) {
1423  int counter = 0;
1424  // try to get object from ontoAttrs
1425  ArrayList<TypeAttrOnto> ontoAtrList = getOntoPropertyMayMove(data.propertyURI, ontoAttrs, ontoAttrsDeleted);
1426  HashSet<String> subjectSetClassURI = new HashSet<String>();
1427  subjectSetClassURI.add(typeURI);
1428  if (ontoAtrList != null) {
1429  for (TypeAttrOnto oAtr : ontoAtrList) {
1430  HashSet<String> objectSetClassURI = new HashSet<String>();
1431  if (oAtr.getAttributeType() != null) {
1432  objectSetClassURI.add(oAtr.getAttributeType().getUriInOntology());
1433  }
1434  String comment = oAtr.getComment();
1435  processProperties(oAtr.getUriInOntology(), new PropertyReference(),
1436  (comment == null ? "" : comment), subjectSetClassURI, objectSetClassURI, newTypesMap, newTypesMapInfo, ontoAttrs,
1437  userGroup, new HashSet<String>(), new HashSet<String>(), oModel);
1438  counter++;
1439  }
1440  } else { // unknown object, we set object from someValue-restriction (best information, that we have)
1441  HashSet<String> objectSetClassURI = new HashSet<String>();
1442  processProperties(data.propertyURI, new PropertyReference(),
1443  "", subjectSetClassURI, objectSetClassURI, newTypesMap, newTypesMapInfo, ontoAttrs,
1444  userGroup, new HashSet<String>(), new HashSet<String>(), oModel);
1445  counter++;
1446  }
1447  return counter;
1448  }
1449  // </editor-fold>
1450 
1451  // <editor-fold defaultstate="collapsed" desc="getNewNameForAnonymousClass">
1452  /**
1453  * Create new name for anonymous class.
1454  *
1455  * @param info AnnotTypeInfo object for class
1456  * @param type AnnotType object for class
1457  * @return New name
1458  */
1460  String URIWithoutName = deleteNameInURI(info.correctedUri);
1461  String newName = "";
1462 
1463  // get suitable label (if any)
1464  boolean isSuitableLabel = false; // The OWL API error
1465  boolean onlyLabel = false;
1466  if (isSuitableLabel && info.disjointWithSet.isEmpty() && type.getAttributes().isEmpty() && isSuitableLabel) {
1467  onlyLabel = true;
1468  }
1469 
1470 
1471  boolean firstPart = true;
1472  // add information about ancestor to name
1473  boolean ancestorInName = false;
1474  AnnotType ancestorType = type.getAncestorType();
1475  if (ancestorType != null && !onlyLabel) {
1476  if (info.disjointWithSet.isEmpty() && type.getAttributes().isEmpty()) {
1477  newName += "specific" + upperFirstChar(ancestorType.getName());
1478  } else {
1479  newName += ancestorType.getName();
1480  }
1481  ancestorInName = true;
1482  firstPart = false;
1483  }
1484  // add information about disjointClasses to name
1485  int disjointClassesCount = 0;
1486  for (String disjointClass : info.disjointWithSet) {
1487  if (firstPart) {
1488  newName += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.DISJOINT_WITH_ANONYMOUS_NAME_FIRST);
1489  firstPart = false;
1490  } else {
1491  newName += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.DISJOINT_WITH_ANONYMOUS_NAME);
1492  }
1493  newName += upperFirstChar(getNameFromURI(disjointClass));
1494  disjointClassesCount++;
1495  if (disjointClassesCount >= 5) {
1496  break;
1497  }
1498  }
1499  // add information about attributes to name
1500  if (info.disjointWithSet.isEmpty()) {
1501  int attributesCount = type.getAttributes().size();
1502  for (Object atrObj : type.getAttributes()) {
1503  if (!(atrObj instanceof AnnotTypeAttr)) {
1504  continue;
1505  }
1506  AnnotTypeAttr atr = (AnnotTypeAttr) atrObj;
1507  if (ancestorInName) {
1508  if (attributesCount == 1) {
1509  newName += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.ATTRIBUTE_WITH_ANONYMOUS_NAME_FIRST_AFTER);
1510  } else {
1511  newName += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.ATTRIBUTES_WITH_ANONYMOUS_NAME_FIRST_AFTER);
1512  }
1513  ancestorInName = false;
1514  } else if (firstPart) {
1515  if (attributesCount == 1) {
1516  newName += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.ATTRIBUTE_WITH_ANONYMOUS_NAME_FIRST);
1517  } else {
1518  newName += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.ATTRIBUTES_WITH_ANONYMOUS_NAME_FIRST);
1519  }
1520  firstPart = false;
1521  } else {
1522  newName += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.ATTRIBUTES_WITH_ANONYMOUS_NAME);
1523  }
1524  newName += upperFirstChar(atr.getName());
1525  }
1526  }
1527 
1528  if (!newName.isEmpty()) {
1529  return URIWithoutName + newName;
1530  }
1531  return info.correctedUri; //we don't know any information, final name will be genidX (where X is unique number)
1532  }
1533  // </editor-fold>
1534 
1535  // <editor-fold defaultstate="collapsed" desc="processing of collection information">
1536 
1537  // <editor-fold defaultstate="collapsed" desc="processOWLClassExpressionIntersectionOfOneOf">
1538  /**
1539  * Get oneOf and intersectionOf classes URI from OWLClassExpression.
1540  *
1541  * @param exp OWLClassExpression value.
1542  * @param intersectionOfSet This function add URI of class to this set.
1543  * @param oneOfSet This function add URI of class to this set.
1544  */
1545  private void processOWLClassExpressionIntersectionOfOneOf(OWLClassExpression exp,
1546  HashSet<String> intersectionOfSet, HashSet<String> oneOfSet) {
1547  try { // cast can throw exception, but should not (try is used just to be sure)
1548  if (exp.getClassExpressionType().equals(ClassExpressionType.OBJECT_ONE_OF)) {
1549  Set<OWLNamedIndividual> classSet = ((OWLObjectOneOf) exp).getIndividualsInSignature();
1550  for (OWLNamedIndividual individual : classSet) {
1551  oneOfSet.add(individual.toStringID());
1552  }
1553  }
1554  else if (exp.getClassExpressionType().equals(ClassExpressionType.OBJECT_INTERSECTION_OF)) {
1555  Set<OWLClass> classSet = ((OWLObjectIntersectionOf) exp).getClassesInSignature();
1556  for (OWLClass cls : classSet) {
1557  intersectionOfSet.add(cls.toStringID());
1558  }
1559  }
1560  } catch (Exception e) {}
1561  }
1562  // </editor-fold>
1563 
1564  // <editor-fold defaultstate="collapsed" desc="addInfoAboutCollectionToComment">
1565  /**
1566  * Add information about oneOf, unionOf and intersectionOf to comment
1567  *
1568  * @param type Information about type.
1569  * @param setOfURI This class is in collection.
1570  * @param commentStr1 1. constant to comment.
1571  * @param commentStr2 2. constant to comment.
1572  * @param commentStr3 3. constant to comment.
1573  */
1574  private void addInfoAboutCollectionToComment(AnnotType type, HashSet<String> setOfURI,
1575  String commentStr1, String commentStr2, String commentStr3) {
1576  if (setOfURI.size() > 1) {
1577  String comment = prepareCommentToAdding(type.getComment());
1578  comment += commentStr1;
1579  boolean first = true;
1580  for (String cls : setOfURI) {
1581  if (first) {
1582  first = false;
1583  } else {
1584  comment += commentStr2;
1585  }
1586  comment += getNameFromURI(cls);
1587  }
1588  comment += commentStr3;
1589  type.setComment(comment);
1590  }
1591  }
1592  // </editor-fold>
1593 
1594  // <editor-fold defaultstate="collapsed" desc="processUnionOfOneOfIntersectionOf">
1595  /**
1596  * Get axiom of class about unionOf, oneOf and intersectionOf elements and add it to comment.
1597  *
1598  * @param ontClass OWL class
1599  * @param type Information about type
1600  * @param oModel Ontology model
1601  */
1602  private void processUnionOfOneOfIntersectionOf(OWLClass ontClass, AnnotType type, OWLOntology oModel) {
1603  HashSet<String> unionOfClasses = new HashSet<String>();
1604  for (OWLAxiom axiom : ontClass.getReferencingAxioms(oModel)) {
1605  if (axiom instanceof OWLEquivalentClassesAxiom) {
1606  try { // cast can throw exception, but should not (try is used just to be sure)
1607  OWLEquivalentClassesAxiom equivalentAxiom = (OWLEquivalentClassesAxiom) axiom;
1608  Set<OWLClassExpression> equivalentClasses = equivalentAxiom.getClassExpressions();
1609  // one of equivalent class is not this class, than bad axiom founded
1610  boolean classFound = false;
1611  for (OWLClassExpression exp : equivalentClasses) {
1612  if (exp.getClassExpressionType().equals(ClassExpressionType.OWL_CLASS)) {
1613  if (exp.asOWLClass().toStringID().equals(ontClass.toStringID())) {
1614  classFound = true;
1615  }
1616  }
1617  }
1618  if (!classFound) {
1619  continue;
1620  }
1621  // proces collection
1622  for (OWLClassExpression exp : equivalentClasses) {
1623  // unionOf
1624  HashSet<String> classes = processOWLClassExpression(oModel, exp);
1625  if (classes.contains(ontClass.toStringID())) { // axiom contains ontClass URI too
1626  classes.remove(ontClass.toStringID());
1627  }
1628  unionOfClasses.addAll(classes);
1629  // intersectionOf and oneOf
1630  HashSet<String> intersectionOfSet = new HashSet<String>();
1631  HashSet<String> oneOfSet = new HashSet<String>();
1632  processOWLClassExpressionIntersectionOfOneOf(exp, intersectionOfSet, oneOfSet);
1633  // add information of intersectionOf to comment
1634  addInfoAboutCollectionToComment(type, intersectionOfSet,
1636  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.INTERSECTION_OF_COMMENT_2),
1638  // add information of oneOf to comment
1639  // OWL object is represented by AnnotType too (as well as OWL class)
1640  addInfoAboutCollectionToComment(type, oneOfSet,
1642  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.UNION_OF_COMMENT_2),
1644  }
1645  } catch (Exception e) {}
1646  }
1647  }
1648  // add information to comments
1649  addInfoAboutCollectionToComment(type, unionOfClasses,
1651  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.UNION_OF_COMMENT_2),
1653  }
1654  // </editor-fold>
1655 
1656  // </editor-fold>
1657 
1658  // <editor-fold defaultstate="collapsed" desc="processModelPhase2">
1659  /**
1660  * Processing of ontology model - phase 2:
1661  * - get properties and create attributes of types of annotations
1662  * - assign ancestors and primary ancestors to types of annotations
1663  *
1664  * @param oModel Ontology model
1665  * @param oFactory Ontology factory
1666  * @param newTypes List with new (imported) types of annotations
1667  * @param newTypesMap Map with new (imported) types of annotations
1668  * @param newTypesMapInfo Information about newNewTypesMap
1669  * @param ontoAttrs List with attributes of unknown types of annotations
1670  * @param userGroup User group in which uploaded types will be shared
1671  * @return If error occurred, returns true, false otherwise
1672  */
1673  private boolean processModelPhase2(OWLOntology oModel, OWLDataFactory oFactory,
1674  ArrayList<AnnotType> newTypes, Map<String, AnnotType> newTypesMap,
1675  Map<String, AnnotTypeInfo> newTypesMapInfo, ArrayList<TypeAttrOnto> ontoAttrs,
1676  UserGroup userGroup) {
1677 
1678  HashMap<String, HashSet<String>> objectMap = new HashMap<String, HashSet<String>>();
1679  HashMap<String, HashSet<String>> subjectMap = new HashMap<String, HashSet<String>>();
1680  HashMap<String, HashSet<String>> ancestorMap = new HashMap<String, HashSet<String>>();
1681 
1682  // <editor-fold defaultstate="collapsed" desc="rdf:Property note object and subject">
1683  for (OWLAnnotationProperty property : oModel.getAnnotationPropertiesInSignature()) {
1684  String prUri = property.toStringID(); // URI
1685  if (prUri.contains("rdf-schema#")) { // for example http://www.w3.org/2000/01/rdf-schema#comment, it is getting by another way
1686  continue;
1687  }
1688 
1689  // definition of subejct and object
1690  HashSet<String> objectSetClassURI = new HashSet<String>(); // range
1691  HashSet<String> subjectSetClassURI = new HashSet<String>(); // domain
1692  HashSet<String> ancestorSetClassURI = new HashSet<String>();
1693  Set<OWLAxiom> allAxioms = property.getReferencingAxioms(oModel);
1694  int anotherAxioms = processRdfPropertyAxioms(objectSetClassURI, subjectSetClassURI, ancestorSetClassURI, allAxioms);
1695 
1696  if (subjectSetClassURI.isEmpty() && objectSetClassURI.isEmpty() && anotherAxioms != 0) {
1697  continue;
1698  }
1699 
1700  objectMap.put(prUri, objectSetClassURI);
1701  subjectMap.put(prUri, subjectSetClassURI);
1702  ancestorMap.put(prUri, ancestorSetClassURI);
1703  }
1704  // </editor-fold>
1705 
1706 
1707  // <editor-fold defaultstate="collapsed" desc="get owl:ObjectProperty">
1708  // generate map of all properties
1709  HashSet<String> ObjectAndDataPropertiesMap = new HashSet<String>();
1710  for (OWLObjectProperty property : oModel.getObjectPropertiesInSignature()) {
1711  ObjectAndDataPropertiesMap.add(property.toStringID());
1712  }
1713  // process all properties
1714  for (OWLObjectProperty property : oModel.getObjectPropertiesInSignature()) {
1715  String prUri = property.toStringID(); // URI
1716 
1717  // set of ancestors
1718  Set<OWLObjectPropertyExpression> superProperties = property.getSuperProperties(oModel);
1719 
1720  // definition of subejct and object
1721  Set<OWLClassExpression> objectSetExpression = property.getRanges(oModel);
1722  Set<OWLClassExpression> subjectSetExpression = property.getDomains(oModel);
1723 
1724  // anonymous property (property.isAnonymous() don't work correctly), another detection of anonymous property
1725  if (objectSetExpression.isEmpty() && subjectSetExpression.isEmpty() && prUri.indexOf("genid") != -1) { // previous two function don't work correctly for anonymous properties
1726  Set<OWLAxiom> axioms = property.getReferencingAxioms(oModel);
1727  for (OWLAxiom axiom : axioms) {
1728  String axiomName = axiom.getAxiomType().getName();
1729  if (axiomName.equals("ObjectPropertyRange") &&
1730  axiom instanceof OWLObjectPropertyRangeAxiom) {
1731  OWLObjectPropertyRangeAxiom range = (OWLObjectPropertyRangeAxiom) axiom;
1732  objectSetExpression.add(range.getRange());
1733  }
1734  if (axiomName.equals("ObjectPropertyDomain") &&
1735  axiom instanceof OWLObjectPropertyDomainAxiom) {
1736  OWLObjectPropertyDomainAxiom domain = (OWLObjectPropertyDomainAxiom) axiom;
1737  subjectSetExpression.add(domain.getDomain());
1738  }
1739  if (axiomName.equals("SubObjectPropertyOf") &&
1740  axiom instanceof OWLSubObjectPropertyOfAxiom) {
1741  try {
1742  OWLSubObjectPropertyOfAxiom subProperty = (OWLSubObjectPropertyOfAxiom) axiom;
1743  if (!subProperty.getSuperProperty().asOWLObjectProperty().toStringID().equals(prUri)) {
1744  superProperties.add(subProperty.getSuperProperty());
1745  }
1746  } catch (Exception e) {
1747  continue; // not Object Property
1748  }
1749  }
1750  }
1751  }
1752 
1753  Set<String> superPropertiesStringSet = new HashSet<String>();
1754  addSuperObjectPropertiesToSet(prUri, superProperties, superPropertiesStringSet);
1755 
1756  Set<String> inversePropertiesID = new HashSet<String>();
1757  // get object and subject from inverse properties
1758  processInverseProperty(oModel, property, objectSetExpression, subjectSetExpression, inversePropertiesID);
1759 
1760  // get list of objectClass and subjectClass
1761  HashSet<String> objectSetClassURI = new HashSet<String>();
1762  for (OWLClassExpression exp : objectSetExpression) {
1763  objectSetClassURI.addAll(processOWLClassExpression(oModel, exp));
1764  }
1765  HashSet<String> subjectSetClassURI = new HashSet<String>();
1766  for (OWLClassExpression exp : subjectSetExpression) {
1767  subjectSetClassURI.addAll(processOWLClassExpression(oModel, exp));
1768  }
1769 
1770  // add object and subject from annotation property (for rdf:proprety elements)
1771  boolean addObjectFromAnnotationProperty = objectSetClassURI.isEmpty();
1772  if (objectSetClassURI.size() == 1) {
1773  Iterator<String> it = objectSetClassURI.iterator();
1774  if (it.next().endsWith("rdf-schema#Literal")) {
1775  addObjectFromAnnotationProperty = true;
1776  }
1777  }
1778  boolean addSubjectFromAnnotationProperty = subjectSetClassURI.isEmpty();
1779  if (subjectSetClassURI.size() == 1) {
1780  Iterator<String> it = subjectSetClassURI.iterator();
1781  if (it.next().endsWith("rdf-schema#Literal")) {
1782  addSubjectFromAnnotationProperty = true;
1783  }
1784  }
1785  if (addObjectFromAnnotationProperty) {
1786  if (objectMap.containsKey(prUri)) {
1787  objectSetClassURI.addAll(objectMap.get(prUri));
1788  }
1789  }
1790  if (addSubjectFromAnnotationProperty) {
1791  if (subjectMap.containsKey(prUri)) {
1792  subjectSetClassURI.addAll(subjectMap.get(prUri));
1793  }
1794  }
1795  if (superPropertiesStringSet.isEmpty()) {
1796  if (ancestorMap.containsKey(prUri)) {
1797  superPropertiesStringSet.addAll(ancestorMap.get(prUri));
1798  }
1799  }
1800 
1801  String comment = getComments(oFactory, property.getAnnotations(oModel));
1802  comment = addSuperPropertiesToComment(prUri, comment, superPropertiesStringSet);
1803 
1804  PropertyReference propertyReference = new PropertyReference(property);
1805  processProperties(prUri, propertyReference, comment, subjectSetClassURI, objectSetClassURI, newTypesMap, newTypesMapInfo, ontoAttrs, userGroup, superPropertiesStringSet, inversePropertiesID, oModel);
1806  }
1807  // </editor-fold>
1808 
1809 
1810  // <editor-fold defaultstate="collapsed" desc="DatatypeProperty">
1811  for (OWLDataProperty dataProperty : oModel.getDataPropertiesInSignature()) {
1812  ObjectAndDataPropertiesMap.add(dataProperty.toStringID());
1813  }
1814  for (OWLDataProperty dataProperty : oModel.getDataPropertiesInSignature()) {
1815  String prUri = dataProperty.toStringID();
1816  Set<OWLDataRange> rangeSet = dataProperty.getRanges(oModel);
1817  Set<OWLClassExpression> subjectSet = dataProperty.getDomains(oModel);
1818 
1819  // get URIs
1820  HashSet<String> subjectSetClassURI = new HashSet<String>();
1821  for (OWLClassExpression exp : subjectSet) {
1822  subjectSetClassURI.addAll(processOWLClassExpression(oModel, exp));
1823  }
1824  HashSet<String> objectSetClassURI = new HashSet<String>();
1825  for (OWLDataRange range : rangeSet) {
1826  if (range instanceof OWLDatatypeImpl) {
1827  OWLDatatypeImpl concreteRange = (OWLDatatypeImpl) range;
1828  objectSetClassURI.add(concreteRange.getIRI().toString());
1829  }
1830  }
1831 
1832  Set<OWLDataPropertyExpression> superProperties = dataProperty.getSuperProperties(oModel);
1833 
1834  //get comments
1835  Set<String> superPropertiesStringSet = new HashSet<String>();
1836  addSuperDataPropertiesToSet(prUri, superProperties, superPropertiesStringSet);
1837 
1838  // add object and subject from annotation property (for rdf:proprety elements)
1839  boolean addObjectFromAnnotationProperty = objectSetClassURI.isEmpty();
1840  if (objectSetClassURI.size() == 1) {
1841  Iterator<String> it = objectSetClassURI.iterator();
1842  if (it.next().endsWith("rdf-schema#Literal")) {
1843  addObjectFromAnnotationProperty = true;
1844  }
1845  }
1846  boolean addSubjectFromAnnotationProperty = subjectSetClassURI.isEmpty();
1847  if (subjectSetClassURI.size() == 1) {
1848  Iterator<String> it = subjectSetClassURI.iterator();
1849  if (it.next().endsWith("rdf-schema#Literal")) {
1850  addSubjectFromAnnotationProperty = true;
1851  }
1852  }
1853  if (addObjectFromAnnotationProperty) {
1854  if (objectMap.containsKey(prUri)) {
1855  objectSetClassURI.addAll(objectMap.get(prUri));
1856  }
1857  }
1858  if (addSubjectFromAnnotationProperty) {
1859  if (subjectMap.containsKey(prUri)) {
1860  subjectSetClassURI.addAll(subjectMap.get(prUri));
1861  }
1862  }
1863  if (superPropertiesStringSet.isEmpty()) {
1864  if (ancestorMap.containsKey(prUri)) {
1865  superPropertiesStringSet.addAll(ancestorMap.get(prUri));
1866  }
1867  }
1868 
1869  String comment = getComments(oFactory, dataProperty.getAnnotations(oModel));
1870  comment = addSuperPropertiesToComment(prUri, comment, superPropertiesStringSet);
1871 
1872  // inverse property is not allowed in datatypeProeprty
1873  processProperties(prUri, new PropertyReference(dataProperty), comment, subjectSetClassURI, objectSetClassURI, newTypesMap, newTypesMapInfo, ontoAttrs, userGroup, superPropertiesStringSet, new HashSet<String>(), oModel);
1874  }
1875 
1876  // </editor-fold>
1877 
1878 
1879  // <editor-fold defaultstate="collapsed" desc="get rdf:Property">
1880  for (OWLAnnotationProperty property : oModel.getAnnotationPropertiesInSignature()) {
1881  String prUri = property.toStringID(); // URI
1882  if (prUri.contains("rdf-schema#")) { // for example http://www.w3.org/2000/01/rdf-schema#comment, it is getting by another way
1883  continue;
1884  }
1885 
1886  // definition of subejct and object
1887 
1888  HashSet<String> objectSetClassURI = new HashSet<String>(); // range
1889  HashSet<String> subjectSetClassURI = new HashSet<String>(); // domain
1890  HashSet<String> ancestorSetClassURI = new HashSet<String>();
1891  Set<OWLAxiom> allAxioms = property.getReferencingAxioms(oModel);
1892  int anotherAxioms = processRdfPropertyAxioms(objectSetClassURI, subjectSetClassURI, ancestorSetClassURI, allAxioms);
1893 
1894  //ObjectPropertiesMap.get(prUri).getRanges(oModel).toString();
1895  if (ObjectAndDataPropertiesMap.contains(prUri)) { // property is owl:ObjectProperty, not rdf:Property
1896  continue;
1897  }
1898  if (subjectSetClassURI.isEmpty() && objectSetClassURI.isEmpty() && anotherAxioms != 0) {
1899  continue;
1900  }
1901 
1902  String comment = getComments(oFactory, property.getAnnotations(oModel));
1903  comment = addSuperPropertiesToComment(property.toStringID(), comment, ancestorSetClassURI);
1904 
1905  // inverse property can't be defined in rdf:Property
1906  processProperties(prUri, new PropertyReference(), comment, subjectSetClassURI, objectSetClassURI, newTypesMap, newTypesMapInfo, ontoAttrs, userGroup, ancestorSetClassURI, new HashSet<String>(), oModel);
1907  }
1908 
1909  // </editor-fold>
1910 
1911  // Set of annotation property URIs
1912  Set<String> annotationPropertyURIs = new HashSet<String>();
1913  Set<OWLAnnotationProperty> annotationProperty = oModel.getAnnotationPropertiesInSignature();
1914  for (OWLAnnotationProperty anotProp : annotationProperty) {
1915  String anotPropURI = anotProp.toStringID();
1916  annotationPropertyURIs.add(anotPropURI);
1917  // <editor-fold defaultstate="collapsed" desc="process comment in annonymous class">
1918  // attempt of avoid of The OWL API bug
1919  /*if (anotPropURI.equalsIgnoreCase("http://www.w3.org/2000/01/rdf-schema#comment")) {
1920  for (OWLAxiom ax : anotProp.getReferencingAxioms(oModel)) {
1921  if (ax.getAxiomType().toString().equals("AnnotationAssertion")) {
1922  try {
1923  OWLAnnotationAssertionAxiom anAx = (OWLAnnotationAssertionAxiom) ax;
1924  String subject = anAx.getSubject().toString();
1925  // The OWL API bug (URI of subject is little diferent than URI of anonymous class)
1926  subject = "http://org.semanticweb.owlapi/error#Error" + subject.substring(7);
1927  if (newTypesMapInfo.containsKey(subject)) {
1928  AnnotTypeInfo info = newTypesMapInfo.get(subject);
1929  if (info.wasAnonymous) {
1930  OWLAnnotationValue val = anAx.getValue();
1931  if (val instanceof OWLLiteral) {
1932  AnnotType typeForComment = newTypesMap.get(info.correctedUri);
1933  String comment = typeForComment.getComment();
1934  comment = prepareCommentToAdding(comment);
1935  comment += ((OWLLiteral) val).getLiteral();
1936  typeForComment.setComment(comment);
1937  }
1938  }
1939  };
1940  anAx.getSubject().toString();
1941  } catch (Exception e) {}
1942  ax.getClassesInSignature();
1943  }
1944  }
1945  }*/
1946  // </editor-fold>
1947  }
1948 
1949  // create attributes in all classes
1950  for (OWLClass ontClass : oModel.getClassesInSignature()) { // for all classes
1951  String uri = ontClass.toStringID(); // get class uri
1952  AnnotTypeInfo info = newTypesMapInfo.get(uri);
1953  if (info == null) {
1954  continue;
1955  }
1956  uri = info.correctedUri; // rename uri to acceptable format, if its class is annonymous
1957  String name = getNameFromURI(uri); // get class name
1958  AnnotType type = newTypesMap.get(uri); // get type created for this class
1959  if (type == null) {
1960  errorMessage = MessageProvider.getMessage("unknownOntologyError");
1961  return true;
1962  }
1963 
1964  // <editor-fold defaultstate="collapsed" desc="process complementOf classes">
1965  for (OWLClassExpression clsExp : ontClass.getEquivalentClasses(oModel)) {
1966  if (clsExp.toString().startsWith("ObjectComplementOf")) {
1967  try {
1968  if (!clsExp.getComplementNNF().asOWLClass().isAnonymous()) {
1969  String newComment = TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.COMPLEMENT_OF_COMMENT_1) +
1970  getNameFromURI(clsExp.getComplementNNF().asOWLClass().toStringID()) +
1972  String comment = prepareCommentToAdding(type.getComment());
1973  type.setComment(comment + newComment);
1974  }
1975  } catch (Exception e) {
1976  // complement is not Class
1977  }
1978  }
1979  clsExp.toString();
1980  }
1981  // </editor-fold>
1982 
1983  // <editor-fold defaultstate="collapsed" desc="process superclasses">
1984  LinkedList<String> superClasses = processSuperClass(oModel, ontClass);
1985  addSuperClassesToAnnotType(newTypes, newTypesMap, userGroup, type, superClasses);
1986 
1987  // assign primary ancestor
1988  if (!type.getAncestorTypes().isEmpty()) {
1989  AnnotType anc = type.getAncestorTypes().get(0);
1990  type.setAncestorType(anc);
1991  }
1992  // </editor-fold>
1993 
1994  // <editor-fold defaultstate="collapsed" desc="process superclasses to individuals">
1995  superClasses.addFirst(uri);
1996  Set<OWLIndividual> classIndividuals = ontClass.getIndividuals(oModel);
1997  for (OWLIndividual individual : classIndividuals) {
1998  AnnotTypeInfo individualInfo = newTypesMapInfo.get(individual.toStringID());
1999  if (individualInfo == null) { // fatal error
2000  continue;
2001  }
2002  AnnotType individualType = newTypesMap.get(individualInfo.correctedUri); // correctedUri is renamed, if individual is annonymous
2003  if (individualType == null) {
2004  errorMessage = MessageProvider.getMessage("unknownOntologyError");
2005  return true;
2006  }
2007  addSuperClassesToAnnotType(newTypes, newTypesMap, userGroup, individualType, superClasses);
2008  // assign primary ancestor
2009  if (!individualType.getAncestorTypes().isEmpty()) {
2010  AnnotType anc = individualType.getAncestorTypes().get(0);
2011  individualType.setAncestorType(anc);
2012  }
2013  }
2014  // </editor-fold>
2015 
2016 
2017  // <editor-fold defaultstate="collapsed" desc="process disjoint classes">
2018  Set<OWLClassExpression> disjointClasses = ontClass.getDisjointClasses(oModel);
2019  HashSet<String> disjointClassesURI = new HashSet<String>();
2020  for (OWLClassExpression exp : disjointClasses) {
2021  disjointClassesURI.addAll(processOWLClassExpression(oModel, exp));
2022  }
2023  for (String disjointClass : disjointClassesURI) {
2024  BooleanHolder isAnonymous = new BooleanHolder();
2025  renameIfAnonymous(disjointClass, isAnonymous);
2026  if (isAnonymous.value) { // comment or name of anonymous class will be confusing
2027  continue;
2028  }
2029  String newComment = TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.DISJOINT_WITH_COMMENT_1) + getNameFromURI(disjointClass) +
2030  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.DISJOINT_WITH_COMMENT_2);
2031  String comment = prepareCommentToAdding(type.getComment());
2032  type.setComment(comment + newComment);
2033  if (info.wasAnonymous) {
2034  info.disjointWithSet.add(disjointClass);
2035  }
2036  }
2037  // </editor-fold>
2038 
2039  processUnionOfOneOfIntersectionOf(ontClass, type, oModel);
2040 
2041  // get properties
2042  for (OWLAnnotation statement : ontClass.getAnnotations(oModel)) {
2043  // get informations about object
2044  OWLAnnotationValue object = statement.getValue();
2045  String objUri;
2046  String objString;
2047  OWLAnnotationProperty property = statement.getProperty();
2048 
2049  // RDFS isDefinedBy
2050  if (property.equals(oFactory.getRDFSIsDefinedBy())) {
2051  // Not usable (object is only URI which can't be used separately)
2052  // IsDefinedBy value is mostly in Class URI too
2053  continue;
2054  }
2055 
2056  // <editor-fold defaultstate="collapsed" desc="Literal (comment and label)">
2057  if (object instanceof OWLLiteral) {
2058  OWLLiteral objLiteral = (OWLLiteral) object;
2059 
2060  // RDFS Comment
2061  if (property.equals(oFactory.getRDFSComment())) {
2062  objString = objLiteral.getLiteral();
2063  String comment = prepareCommentToAdding(type.getComment());
2064  type.setComment(comment + objString.trim());
2065  continue;
2066  }
2067 
2068  // RDFS Label
2069  if (property.equals(oFactory.getRDFSLabel())) {
2070  objString = objLiteral.getLiteral();
2071  String comment = prepareCommentToAdding(type.getComment());
2072  type.setComment(comment +
2073  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.LABEL_COMMENT_1) + objString.trim()
2074  + TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.LABEL_COMMENT_2));
2075  continue;
2076  }
2077 
2078  // test datatype in class
2079  if (annotationPropertyURIs.contains(property.toStringID())) {
2080  String objLitS = objLiteral.toString();
2081  int index = objLitS.lastIndexOf(":");
2082  if (index != -1) {
2083  BooleanHolder isRequired = new BooleanHolder();
2084  String simpleType = getStringTypeFromOntologyURI("XMLSchema#" + objLitS.substring(index+1), false, isRequired);
2085  if (!simpleType.isEmpty()) {
2086  String newPrUri = property.toStringID();
2087  String prName = getNameFromURI(newPrUri);
2088  AnnotTypeAttr attr = new AnnotTypeAttr(type, prName, simpleType, isRequired.value);
2089  attr.setUriInOntology(newPrUri);
2090  // WARNING: Value (variable objString) discarded - there is no place for it!
2091  Iterator<AnnotTypeAttr> atrIt = type.getAttributes().iterator();
2092  boolean aFound = false;
2093  while (atrIt.hasNext()) { // check whether is not already presented
2094  AnnotTypeAttr aTA = atrIt.next();
2095  if (aTA.getName().equals(prName)) {
2096  aFound = true;
2097  }
2098  }
2099  if (!aFound) { // if it is not already presented
2100  type.getAttributes().add(attr);
2101  }
2102  continue;
2103  }
2104  }
2105  }
2106  }
2107  // </editor-fold>
2108 
2109  // <editor-fold defaultstate="collapsed" desc="object property in class">
2110  objUri = object.toString();
2111  String prUri = property.toStringID();
2112  String prName = getNameFromURI(prUri);
2113  if (prName.isEmpty()) {
2114  errorMessage = errorMessage + MessageProvider.getMessage("badPropertyFound") + "<br/>";
2115  continue;
2116  }
2117  // property
2118  if (prUri.indexOf("http://www.w3.org/2000/01/rdf-schema") == -1) {
2119  AnnotType pType = newTypesMap.get(objUri);
2120  if (pType == null && objUri.startsWith("\"") && objUri.endsWith("\"") && objUri.length() > 2) {
2121  String nUri = objUri.substring(1, objUri.length() - 1);
2122  pType = newTypesMap.get(nUri);
2123  }
2124  if (pType != null) { // if type was found
2125  AnnotTypeAttr attr = new AnnotTypeAttr(type, prName, pType, false);
2126  attr.setUriInOntology(prUri);
2127  Iterator<AnnotTypeAttr> atrIt = type.getAttributes().iterator();
2128  boolean aFound = false;
2129  while (atrIt.hasNext()) { // check whether is not already presented
2130  AnnotTypeAttr aTA = atrIt.next();
2131  if (aTA.getName().equals(attr.getName())) {
2132  aFound = true;
2133  break;
2134  }
2135  }
2136  if (!aFound) { // if attribute is not presented, add it
2137  type.getAttributes().add(attr);
2138  }
2139  } else {
2140  errorMessage = errorMessage + MessageProvider.getMessage("badPropertyFound") + "<br/>";
2141  continue;
2142  }
2143  } else { // rdf element
2144  if (prName.equalsIgnoreCase("seeAlso")) {
2145  if (!objUri.isEmpty()) {
2146  String comment = prepareCommentToAdding(type.getComment());
2147  type.setComment(comment +
2148  TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SEE_ALSO_COMMENT) + objUri.trim());
2149  }
2150  }
2151  }
2152  // </editor-fold>
2153 
2154  } // end get properties
2155  } // end all classes
2156 
2157 
2158  // <editor-fold defaultstate="collapsed" desc="restrictions">
2159  try {
2160  OWLOntologyWalker walker = new OWLOntologyWalker(Collections.singleton(oModel));
2162  // Now ask the walker to walk over the ontology structure
2163  OWLOntologyWalkerVisitor baseVisitor = (OWLOntologyWalkerVisitor) visitor;
2164  walker.walkStructure(baseVisitor);
2165  // atributes, that was associated to anonymous class becauseof restriction in this class
2166  ArrayList<TypeAttrOnto> ontoAttrsDeleted = new ArrayList<TypeAttrOnto>();
2167 
2168 
2169  // <editor-fold defaultstate="collapsed" desc="minCardinality">
2170  Set<OWLVisitorForRestrictionData.CardinalityData> minCardinalityData = visitor.getMinCardinalityData();
2171  for (OWLVisitorForRestrictionData.CardinalityData data : minCardinalityData) {
2172  if (data.cardinality == 0) { // this is default behaviour, no need to do some changes
2173  continue;
2174  }
2175 
2176  AnnotTypeInfo typeInfo = newTypesMapInfo.get(data.classURI);
2177  if (typeInfo == null) {
2178  continue;
2179  }
2180  AnnotType type = newTypesMap.get(typeInfo.correctedUri);
2181  if (type != null) { // type was found
2182  // determinate, how many object property has
2183  int counter = 0;
2184  Iterator<AnnotTypeAttr> atrIt = type.getAttributes().iterator();
2185  while (atrIt.hasNext()) { // check whether is not already presented
2186  AnnotTypeAttr atr = atrIt.next();
2187  if (atr.getUriInOntology().startsWith(data.propertyURI + ".") ||
2188  atr.getUriInOntology().equalsIgnoreCase(data.propertyURI)) {
2189  counter++;
2190  }
2191  }
2192  if (counter == 0){ // add property
2194  ontoAttrsDeleted, data,
2195  typeInfo.originUri, newTypesMap, newTypesMapInfo, oModel, userGroup);
2196  }
2197  // set information to property
2198  atrIt = type.getAttributes().iterator();
2199  while (atrIt.hasNext()) { // check whether is not already presented
2200  AnnotTypeAttr atr = atrIt.next();
2201  if (atr.getUriInOntology().startsWith(data.propertyURI + ".") ||
2202  atr.getUriInOntology().equalsIgnoreCase(data.propertyURI)) {
2203  String comment = atr.getComment();
2204  if (comment == null) {
2205  comment = "";
2206  }
2207  if (!comment.isEmpty()) {
2208  comment = prepareCommentToAdding(comment);;
2209  }
2210  // property has one object, AnnotTypeAttr has URI in format "property"
2211  if (counter == 1) {
2212  comment += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.MIN_CARDINALITY_ONE_OBJECT_COMMENT_1) + data.cardinality
2214  atr.setRequired(true);
2215  } else { // property has more objects, AnnotTypeAttr has URI in format "property.object"
2216  comment += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.MIN_CARDINALITY_MORE_OBJECT_COMMENT_1) + getNameFromURI(data.propertyURI)
2217  + TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.MIN_CARDINALITY_MORE_OBJECT_COMMENT_2) + data.cardinality
2219  }
2220  atr.setComment(comment);
2221  }
2222  }
2223  }
2224  }
2225 
2226  // </editor-fold>
2227 
2228  // <editor-fold defaultstate="collapsed" desc="maxCardinality">
2229  Set<OWLVisitorForRestrictionData.CardinalityData> maxCardinalityData = visitor.getMaxCardinalityData();
2230  for (OWLVisitorForRestrictionData.CardinalityData data : maxCardinalityData) {
2231  AnnotTypeInfo typeInfo = newTypesMapInfo.get(data.classURI);
2232  if (typeInfo == null) {
2233  continue;
2234  }
2235  AnnotType type = newTypesMap.get(typeInfo.correctedUri);
2236  if (type != null) { // type was found
2237  // determinate, how many object property has
2238  int counter = 0;
2239  Iterator<AnnotTypeAttr> atrIt = type.getAttributes().iterator();
2240  while (atrIt.hasNext()) { // check whether is not already presented
2241  AnnotTypeAttr atr = atrIt.next();
2242  if (atr.getUriInOntology().startsWith(data.propertyURI + ".") ||
2243  atr.getUriInOntology().equalsIgnoreCase(data.propertyURI)) {
2244  counter++;
2245  }
2246  }
2247  if (counter == 0){ // add property
2249  ontoAttrsDeleted, data,
2250  typeInfo.originUri, newTypesMap, newTypesMapInfo, oModel, userGroup);
2251  }
2252  // set information to property
2253  atrIt = type.getAttributes().iterator();
2254  while (atrIt.hasNext()) { // check whether is not already presented
2255  AnnotTypeAttr atr = atrIt.next();
2256  if (atr.getUriInOntology().startsWith(data.propertyURI + ".") ||
2257  atr.getUriInOntology().equalsIgnoreCase(data.propertyURI)) {
2258  if (data.cardinality == 0) { // property is useless
2259  atrIt.remove();
2260  continue;
2261  }
2262  String comment = atr.getComment();
2263  comment = prepareCommentToAdding(comment);
2264  // property has one object, AnnotTypeAttr has URI in format "property"
2265  if (counter == 1) {
2266  comment += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.MAX_CARDINALITY_ONE_OBJECT_COMMENT_1) + data.cardinality
2268  } else { // property has more objects, AnnotTypeAttr has URI in format "property.object"
2269  comment += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.MAX_CARDINALITY_MORE_OBJECT_COMMENT_1) + getNameFromURI(data.propertyURI)
2270  + TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.MAX_CARDINALITY_MORE_OBJECT_COMMENT_2) + data.cardinality
2272  }
2273  atr.setComment(comment);
2274  }
2275  }
2276  }
2277  }
2278 
2279  // </editor-fold>
2280 
2281  // <editor-fold defaultstate="collapsed" desc="exactCardinality">
2282  Set<OWLVisitorForRestrictionData.CardinalityData> exactCardinalityData = visitor.getCardinalityData();
2283  for (OWLVisitorForRestrictionData.CardinalityData data : exactCardinalityData) {
2284  AnnotTypeInfo typeInfo = newTypesMapInfo.get(data.classURI);
2285  if (typeInfo == null) {
2286  continue;
2287  }
2288  AnnotType type = newTypesMap.get(typeInfo.correctedUri);
2289  if (type != null) { // type was found
2290  // determinate, how many object property has
2291  int counter = 0;
2292  Iterator<AnnotTypeAttr> atrIt = type.getAttributes().iterator();
2293  while (atrIt.hasNext()) { // check whether is not already presented
2294  AnnotTypeAttr atr = atrIt.next();
2295  if (atr.getUriInOntology().startsWith(data.propertyURI + ".") ||
2296  atr.getUriInOntology().equalsIgnoreCase(data.propertyURI)) {
2297  counter++;
2298  }
2299  }
2300  if (counter == 0){ // add property
2302  ontoAttrsDeleted, data,
2303  typeInfo.originUri, newTypesMap, newTypesMapInfo, oModel, userGroup);
2304  }
2305  // set information to property
2306  atrIt = type.getAttributes().iterator();
2307  while (atrIt.hasNext()) { // check whether is not already presented
2308  AnnotTypeAttr atr = atrIt.next();
2309  if (atr.getUriInOntology().startsWith(data.propertyURI + ".") ||
2310  atr.getUriInOntology().equalsIgnoreCase(data.propertyURI)) {
2311  if (data.cardinality == 0) { // property is useless
2312  atrIt.remove();
2313  continue;
2314  }
2315  String comment = atr.getComment();
2316  comment = prepareCommentToAdding(comment);
2317  // property has one object, AnnotTypeAttr has URI in format "property"
2318  if (counter == 1) {
2319  atr.setRequired(true);
2320  comment += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.EXACT_CARDINALITY_ONE_OBJECT_COMMENT_1) + data.cardinality
2322  } else { // property has more objects, AnnotTypeAttr has URI in format "property.object"
2323  comment += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.EXACT_CARDINALITY_MORE_OBJECT_COMMENT_1) + getNameFromURI(data.propertyURI)
2324  + TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.EXACT_CARDINALITY_MORE_OBJECT_COMMENT_2) + data.cardinality
2326  }
2327  atr.setComment(comment);
2328  }
2329  }
2330  }
2331  }
2332 
2333  // </editor-fold>
2334 
2335  // <editor-fold defaultstate="collapsed" desc="someValuesFrom">
2336  Set<OWLVisitorForRestrictionData.ValueData> someValuesFromData = visitor.getSomeValuesFromData();
2337  for (OWLVisitorForRestrictionData.ValueData data : someValuesFromData) {
2338  AnnotTypeInfo typeInfo = newTypesMapInfo.get(data.classURI);
2339  if (typeInfo == null) {
2340  continue;
2341  }
2342  AnnotType type = newTypesMap.get(typeInfo.correctedUri);
2343  if (type != null) { // type was found
2344  // determinate, how many object property has
2345  int counter = 0;
2346  boolean onePropertyFromManyFound = false; // if more AnnotTypeAttr from properties are presented, one may have object from restriction
2347  AnnotTypeAttr foundedProperty = null;
2348  Iterator<AnnotTypeAttr> atrIt = type.getAttributes().iterator();
2349  while (atrIt.hasNext()) { // check whether is not already presented
2350  AnnotTypeAttr atr = atrIt.next();
2351  if (atr.getUriInOntology().startsWith(data.propertyURI + ".") ||
2352  atr.getUriInOntology().equalsIgnoreCase(data.propertyURI)) {
2353  counter++;
2354  String propertyObjectUri = atr.getAttributeType().getUriInOntology(); // uri of object of property
2355  if (data.valueURI.equals(propertyObjectUri)) {
2356  onePropertyFromManyFound = true;
2357  foundedProperty = atr;
2358  }
2359  }
2360  }
2361  if (counter == 0) {
2362  if (!typeInfo.wasAnonymous) { // named class (unexcepted behaviour)
2363  continue;
2364  } else {
2365  // try to get object from ontoAttrs
2366  ArrayList<TypeAttrOnto> ontoAtrList = getOntoPropertyMayMove(data.propertyURI, ontoAttrs, ontoAttrsDeleted);
2367  HashSet<String> subjectSetClassURI = new HashSet<String>();
2368  subjectSetClassURI.add(typeInfo.originUri);
2369  if (ontoAtrList != null) {
2370  for (TypeAttrOnto oAtr : ontoAtrList) {
2371  HashSet<String> objectSetClassURI = new HashSet<String>();
2372  if (oAtr.getAttributeType() != null) {
2373  objectSetClassURI.add(oAtr.getAttributeType().getUriInOntology());
2374  } else {
2375  objectSetClassURI.add(data.valueURI);
2376  }
2377  String comment = oAtr.getComment();
2378  processProperties(oAtr.getUriInOntology(), new PropertyReference(),
2379  (comment == null ? "" : comment), subjectSetClassURI, objectSetClassURI, newTypesMap, newTypesMapInfo, ontoAttrs,
2380  userGroup, new HashSet<String>(), new HashSet<String>(), oModel);
2381  }
2382  } else { // unknown object, we set object from someValue-restriction (best information, that we have)
2383  HashSet<String> objectSetClassURI = new HashSet<String>();
2384  objectSetClassURI.add(data.valueURI);
2385  processProperties(data.propertyURI, new PropertyReference(),
2386  "", subjectSetClassURI, objectSetClassURI, newTypesMap, newTypesMapInfo, ontoAttrs,
2387  userGroup, new HashSet<String>(), new HashSet<String>(), oModel);
2388  continue; // information of this restriction is not nessesery to add to comment
2389  }
2390  }
2391  }
2392  // correcting of properties
2393  atrIt = type.getAttributes().iterator();
2394  while (atrIt.hasNext()) { // check whether is not already presented
2395  AnnotTypeAttr atr = atrIt.next();
2396  if (atr.getUriInOntology().startsWith(data.propertyURI + ".") ||
2397  atr.getUriInOntology().equalsIgnoreCase(data.propertyURI)) {
2398  String comment = atr.getComment();
2399  comment = prepareCommentToAdding(comment);
2400  // property has one object, AnnotTypeAttr has URI in format "property"
2401  if (counter == 1) {
2402  comment += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SOME_VALUES_FROM_ONE_OBJECT_COMMENT_1) + getNameFromURI(data.valueURI)
2403  + TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SOME_VALUES_FROM_ONE_OBJECT_COMMENT_2);
2404  atr.setRequired(true);
2405  } else { // property has more objects, AnnotTypeAttr has URI in format "property.object"
2406  if (!onePropertyFromManyFound) {
2407  comment += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SOME_VALUES_FROM_MORE_OBJECT_COMMENT_1) + getNameFromURI(data.propertyURI)
2408  + TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SOME_VALUES_FROM_MORE_OBJECT_COMMENT_2) + getNameFromURI(data.valueURI)
2409  + TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SOME_VALUES_FROM_MORE_OBJECT_COMMENT_3);
2410  } else {
2411  if (atr == foundedProperty) {
2412  comment += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SOME_VALUES_FROM_MORE_OBJECT_COMMENT_1) + getNameFromURI(data.propertyURI)
2413  + TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SOME_VALUES_FROM_MORE_OBJECT_COMMENT_2) + getNameFromURI(data.valueURI)
2414  + TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.SOME_VALUES_FROM_MORE_OBJECT_COMMENT_3);
2415  atr.setRequired(true);
2416  }
2417  }
2418  }
2419  atr.setComment(comment);
2420  }
2421  }
2422  }
2423  }
2424 
2425  // </editor-fold>
2426 
2427  // <editor-fold defaultstate="collapsed" desc="allValuesFrom">
2428  Set<OWLVisitorForRestrictionData.ValueData> allValuesFromData = visitor.getAllValuesFromData();
2429  for (OWLVisitorForRestrictionData.ValueData data : allValuesFromData) {
2430  AnnotTypeInfo typeInfo = newTypesMapInfo.get(data.classURI);
2431  if (typeInfo == null) {
2432  continue;
2433  }
2434  AnnotType type = newTypesMap.get(typeInfo.correctedUri);
2435  if (type != null) { // type was found
2436  // determinate, if object has property
2437  boolean propertyFound = false;
2438  AnnotTypeAttr annotTypeAttr = null;
2439  Iterator<AnnotTypeAttr> atrIt = type.getAttributes().iterator();
2440  while (atrIt.hasNext()) { // check whether is not already presented
2441  AnnotTypeAttr atr = atrIt.next();
2442  if (atr.getUriInOntology().startsWith(data.propertyURI + ".") ||
2443  atr.getUriInOntology().equalsIgnoreCase(data.propertyURI)) {
2444  // remove all AnnotTypeAttr, except first one
2445  if (propertyFound) {
2446  atrIt.remove();
2447  } else {
2448  propertyFound = true;
2449  annotTypeAttr = atr;
2450  }
2451  }
2452  }
2453  if (propertyFound) {
2454  // find new attributeType
2455  AnnotType attributeType = newTypesMap.get(data.valueURI);
2456  if (attributeType == null) { // bad constraints found
2457  continue;
2458  }
2459  // set information to property
2460  annotTypeAttr.setUriInOntology(data.propertyURI);
2461  annotTypeAttr.setName(getNameFromURI(data.propertyURI));
2462  annotTypeAttr.setAttributeType(attributeType);
2463  annotTypeAttr.setSimpleType(null);
2464  } else { // create atribute
2465  ArrayList<TypeAttrOnto> ontoAtrList = getOntoPropertyMayMove(data.propertyURI, ontoAttrs, ontoAttrsDeleted);
2466  HashSet<String> subjectSetClassURI = new HashSet<String>();
2467  subjectSetClassURI.add(typeInfo.originUri);
2468  HashSet<String> objectSetClassURI = new HashSet<String>();
2469  objectSetClassURI.add(data.valueURI);
2470  String comment = (ontoAtrList.isEmpty() ? "" : ontoAtrList.iterator().next().getComment());
2471  processProperties(data.propertyURI, new PropertyReference(),
2472  comment, subjectSetClassURI, objectSetClassURI, newTypesMap, newTypesMapInfo, ontoAttrs,
2473  userGroup, new HashSet<String>(), new HashSet<String>(), oModel);
2474  }
2475  }
2476  }
2477  // </editor-fold>
2478 
2479  // <editor-fold defaultstate="collapsed" desc="hasValue">
2480  Set<OWLVisitorForRestrictionData.HasValueData> hasValueData = visitor.getHasValueData();
2481  for (OWLVisitorForRestrictionData.HasValueData data : hasValueData) {
2482  if (data.individual.isAnonymous()) { // any object can be here
2483  continue;
2484  }
2485  AnnotTypeInfo infoType = newTypesMapInfo.get(data.classURI);
2486  if (infoType == null) {
2487  continue;
2488  }
2489  if (infoType.wasObject) { // object should be instance of class, not instance of another object
2490  continue;
2491  }
2492  AnnotTypeInfo typeInfo = newTypesMapInfo.get(data.classURI);
2493  if (typeInfo == null) {
2494  continue;
2495  }
2496  AnnotType type = newTypesMap.get(typeInfo.correctedUri);
2497  if (type != null) { // type was found
2498  // determinate, if object has property
2499  boolean propertyFound = false;
2500  AnnotTypeAttr annotTypeAttr = null;
2501  Iterator<AnnotTypeAttr> atrIt = type.getAttributes().iterator();
2502  while (atrIt.hasNext()) { // check whether is not already presented
2503  AnnotTypeAttr atr = atrIt.next();
2504  if (atr.getUriInOntology().startsWith(data.propertyURI + ".") ||
2505  atr.getUriInOntology().equalsIgnoreCase(data.propertyURI)) {
2506  // remove all AnnotTypeAttr, except first one
2507  if (propertyFound) {
2508  atrIt.remove();
2509  } else {
2510  propertyFound = true;
2511  annotTypeAttr = atr;
2512  }
2513  }
2514  }
2515  // find object
2516  AnnotType objectType = newTypesMap.get(data.valueURI);
2517  // <editor-fold defaultstate="collapsed" desc="confirm finding object">
2518  boolean selectedObjectFound = false;
2519  if (objectType != null) {
2520  AnnotTypeInfo objectInfo = newTypesMapInfo.get(data.valueURI);
2521  if (objectInfo == null) { // bad restriction in ontology error
2522  errorMessage += MessageProvider.getMessage("unknownOntologyError") + "<br/>";
2523  continue;
2524  }
2525  selectedObjectFound = true;
2526  }
2527  if (!selectedObjectFound) { // if object wasn't found, create it
2528  // create AnnotType from object
2529  createAnnotTypeFromIndividual(oModel, oFactory, newTypes,
2530  newTypesMap, newTypesMapInfo, userGroup, data.individual, type.getName(), 0);
2531  // specification of ancestors
2532  AnnotType individualType = newTypesMap.get(data.valueURI); // created in last command
2533  if (individualType == null) {
2534  errorMessage = MessageProvider.getMessage("unknownOntologyError");
2535  return true;
2536  }
2537  LinkedList<String> superClasses = processSuperClass(oModel, infoType.owlClass);
2538  superClasses.addFirst(infoType.correctedUri);
2539  addSuperClassesToAnnotType(newTypes, newTypesMap, userGroup, individualType, superClasses);
2540  // assign primary ancestor
2541  if (!type.getAncestorTypes().isEmpty()) {
2542  AnnotType anc = individualType.getAncestorTypes().get(0);
2543  individualType.setAncestorType(anc);
2544  }
2545  objectType = individualType;
2546  }
2547  // </editor-fold>
2548  if (propertyFound) {
2549  // set information to property
2550  annotTypeAttr.setUriInOntology(data.propertyURI);
2551  annotTypeAttr.setName(getNameFromURI(data.propertyURI));
2552  annotTypeAttr.setAttributeType(objectType);
2553  annotTypeAttr.setSimpleType(null);
2554  } else { // create atribut
2555  ArrayList<TypeAttrOnto> ontoAtrList = getOntoPropertyMayMove(data.propertyURI, ontoAttrs, ontoAttrsDeleted);
2556  HashSet<String> subjectSetClassURI = new HashSet<String>();
2557  subjectSetClassURI.add(typeInfo.originUri);
2558  HashSet<String> objectSetClassURI = new HashSet<String>();
2559  objectSetClassURI.add(data.valueURI);
2560  String comment = (ontoAtrList.isEmpty() ? "" : ontoAtrList.iterator().next().getComment());
2561  processProperties(data.propertyURI, new PropertyReference(),
2562  comment, subjectSetClassURI, objectSetClassURI, newTypesMap, newTypesMapInfo, ontoAttrs,
2563  userGroup, new HashSet<String>(), new HashSet<String>(), oModel);
2564  }
2565  }
2566  }
2567  // </editor-fold>
2568 
2569  // <editor-fold defaultstate="collapsed" desc="hasSelf">
2570  Set<OWLVisitorForRestrictionData.ValueData> hasSelfData = visitor.getHasSelfData();
2571  for (OWLVisitorForRestrictionData.ValueData data : hasSelfData) {
2572  AnnotTypeInfo infoType = newTypesMapInfo.get(data.classURI);
2573  if (infoType == null) {
2574  continue;
2575  }
2576  if (infoType.wasObject) { // object should be instance of class, not instance of another object
2577  continue;
2578  }
2579  AnnotTypeInfo typeInfo = newTypesMapInfo.get(data.classURI);
2580  if (typeInfo == null) {
2581  continue;
2582  }
2583  AnnotType type = newTypesMap.get(typeInfo.correctedUri);
2584  if (type != null) { // type was found
2585  // determinate, if object has property
2586  boolean propertyFound = false;
2587  AnnotTypeAttr annotTypeAttr = null;
2588  Iterator<AnnotTypeAttr> atrIt = type.getAttributes().iterator();
2589  while (atrIt.hasNext()) { // check whether is not already presented
2590  AnnotTypeAttr atr = atrIt.next();
2591  if (atr.getUriInOntology().startsWith(data.propertyURI + ".") ||
2592  atr.getUriInOntology().equalsIgnoreCase(data.propertyURI) ||
2593  atr.getName().equalsIgnoreCase(getNameFromURI(data.propertyURI))) {
2594  // remove all AnnotTypeAttr, except first one
2595  if (propertyFound) {
2596  atrIt.remove();
2597  } else {
2598  propertyFound = true;
2599  annotTypeAttr = atr;
2600  }
2601  }
2602  }
2603  if (propertyFound) {
2604  // set information to property (set specific object)
2605  getOntoPropertyMayMove(data.propertyURI, ontoAttrs, ontoAttrsDeleted);
2606  annotTypeAttr.setAttributeType(type);
2607  annotTypeAttr.setSimpleType(null);
2608  String comment = annotTypeAttr.getComment();
2609  comment = prepareCommentToAdding(comment);
2610  comment += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.HAS_SELF_COMMENT);
2611  annotTypeAttr.setComment(comment);
2612  } else { // create atribut
2613  ArrayList<TypeAttrOnto> ontoAtrList = getOntoPropertyMayMove(data.propertyURI, ontoAttrs, ontoAttrsDeleted);
2614  HashSet<String> subjectSetClassURI = new HashSet<String>();
2615  subjectSetClassURI.add(typeInfo.originUri);
2616  HashSet<String> objectSetClassURI = new HashSet<String>();
2617  objectSetClassURI.add(typeInfo.originUri);
2618  String comment = (ontoAtrList.isEmpty() ? "" : ontoAtrList.iterator().next().getComment());
2619  comment = prepareCommentToAdding(comment);
2620  comment += TextsFromOWLConstants.getOWLString(lNum,TextsFromOWLConstants.HAS_SELF_COMMENT);
2621  processProperties(data.propertyURI, new PropertyReference(),
2622  comment, subjectSetClassURI, objectSetClassURI, newTypesMap, newTypesMapInfo, ontoAttrs,
2623  userGroup, new HashSet<String>(), new HashSet<String>(), oModel);
2624  }
2625  }
2626  }
2627  // </editor-fold>
2628  } catch (Exception e) { }
2629  // </editor-fold>
2630 
2631 
2632  // <editor-fold defaultstate="collapsed" desc="create name for anonymous class">
2633  // create name for anonymous class
2634  for (OWLClass ontClass : oModel.getClassesInSignature()) { // for all classes
2635  String uri = ontClass.toStringID(); // get class uri
2636  AnnotTypeInfo info = newTypesMapInfo.get(uri);
2637  if (info == null) {
2638  continue;
2639  }
2640  if (!info.wasAnonymous) {
2641  continue;
2642  }
2643  uri = info.correctedUri; // rename uri to acceptable format, if its class is annonymous
2644  String name = getNameFromURI(uri); // get class name
2645  AnnotType type = newTypesMap.get(uri); // get type created for this class
2646  if (type == null) {
2647  errorMessage = MessageProvider.getMessage("unknownOntologyError");
2648  return true;
2649  }
2650  String newURI = getNewNameForAnonymousClass(info, type);
2651  String newName = getNameFromURI(newURI);
2652  type.setUriInOntology(newURI);
2653  type.setName(newName);
2654  newTypesMap.remove(uri);
2655  newTypesMap.put(newURI, type);
2656  }
2657  // </editor-fold>
2658 
2659 
2660  return false;
2661  } // processModelPhase2()
2662 
2663  // </editor-fold>
2664 
2665 
2666 
2667  // <editor-fold defaultstate="collapsed" desc="btnUploadAction">
2668  /**
2669  * Action listener for upload button
2670  *
2671  * @return Returns page outcome (identificator of next page or null to stay here)
2672  */
2673  public String btnUploadAction() {
2674 
2675  ontologyUploaded = true;
2676 
2677  errorMessage = "";
2678  successMessage = "";
2680 
2681  if (uGroup.isEmpty()) {
2682  errorMessage = MessageProvider.getMessage("groupMustBeSet");
2683  return null;
2684  }
2685  // query database for user group
2686  Object[] params = new Object[2]; // parameters for database query
2687  params[0] = "name";
2688  params[1] = uGroup;
2689  List gList = AppBean.getPersistenceManager().queryDB("UserGroup.findByName", params);
2690  UserGroup userGroup = null;
2691  if (gList != null && !gList.isEmpty()) { // if group was found
2692  userGroup = (UserGroup) gList.get(0);
2693  } else {
2694  errorMessage = MessageProvider.getMessage("unknownGroup");
2695  return null;
2696  }
2697 
2698  // Informations about uploaded file
2699  // String fileType = uploadedFile.getContentType();
2700  // String fileNameStr = uploadedFile.getName();
2701  // Long fileSize = uploadedFile.getSize(); // bytes
2702 
2703  if (uploadedFile == null) {
2704  errorMessage = MessageProvider.getMessage("uploadingError");
2705  return null;
2706  }
2707 
2708  // Create writer with file data
2709  StringWriter fWriter = new StringWriter();
2710  try {
2711  IOUtils.copy(uploadedFile.getInputStream(), fWriter);
2712  } catch (IOException ex) {
2713  errorMessage = MessageProvider.getMessage("uploadingError");
2714  return null;
2715  }
2716 
2717  // Create input streams with file data
2718  InputStream is = null;
2719  try {
2720  is = new ByteArrayInputStream(fWriter.toString().getBytes("UTF-8"));
2721  } catch (UnsupportedEncodingException ex) {
2722  errorMessage = MessageProvider.getMessage("uploadingError");
2723  return null;
2724  }
2725 
2726  // Create ontology model
2727  OWLOntologyManager oManager = OWLManager.createOWLOntologyManager();
2728  OWLDataFactory oFactory = OWLManager.getOWLDataFactory();
2729  OWLOntology oModel;
2730  try {
2731  oModel = oManager.loadOntologyFromOntologyDocument(is);
2732  } catch (OWLOntologyCreationException ex) {
2733  errorMessage = errorMessage + MessageProvider.getMessage("unknownOntologyError") + "<br/>";
2734  return null;
2735  }
2736 
2737  if (importLang != null && Localisation.LANGUAGE_CODES.contains(importLang)) {
2738  lNum = Localisation.LANGUAGE_CODES.indexOf(importLang);
2739  } else if (importLang != null && !importLang.isEmpty()) {
2740  errorMessage = errorMessage + MessageProvider.getMessage("unknownImportLanguage") + "<br/>";
2741  return null;
2742  }
2743 
2744  // load imported models - The OWL API do it automatically in contrast to JENA
2745 
2746  // list of new types
2747  ArrayList<AnnotType> newTypes = new ArrayList<AnnotType>();
2748 
2749  // map of new types
2750  Map<String, AnnotType> newTypesMap = new HashMap<String, AnnotType>();
2751 
2752  // list with attributes of unknown types of annotations
2753  ArrayList<TypeAttrOnto> ontoAttrs = new ArrayList<TypeAttrOnto>();
2754 
2755  // list with helper information to AnnotType
2756  Map<String, AnnotTypeInfo> newTypesMapInfo = new HashMap<String, AnnotTypeInfo>();
2757 
2758  // get classes and create types of annotations
2759  if (processModelPhase1(oModel, oFactory, newTypes, newTypesMap, userGroup, newTypesMapInfo)) {
2760  return null; // error occurred
2761  }
2762 
2763  // get properties, create attributes of types of annotations and assign
2764  // ancestors and primary ancestors to types of annotations
2765  if (processModelPhase2(oModel, oFactory, newTypes, newTypesMap, newTypesMapInfo, ontoAttrs, userGroup)) {
2766  return null; // error occurred
2767  }
2768 
2769  // generate URIs
2770  for (Iterator<AnnotType> ntIt = newTypes.iterator(); ntIt.hasNext();) {
2771  AnnotType type = ntIt.next();
2772  String uri = type.getGeneratedURI();
2773  type.setUri(uri);
2774  }
2775 
2776  // types of annotations to update
2777  List<AnnotType> tToUpdate = new ArrayList<AnnotType>(); // old types to update
2778 
2779  // check whether some type is not exists in database
2780  boolean duplicitTypeFound = false;
2781  for (Iterator<AnnotType> ntIt = newTypes.iterator(); ntIt.hasNext();) {
2782  AnnotType type = ntIt.next();
2783  params[0] = "uri";
2784  params[1] = type.getUri();
2785  List tList = AppBean.getPersistenceManager().queryDB("AnnotType.findByUri", params);
2786  if (tList != null && !tList.isEmpty()) { // if type was found
2787  AnnotType typeInDB = (AnnotType) tList.get(0);
2788  if (iMethod == METHOD_0_ERROR) {
2789  errorMessage = errorMessage + MessageProvider.getMessage("typeAlreadyExists1")
2790  + type.getUri() + MessageProvider.getMessage("typeAlreadyExists2") + "<br/>";
2791  } else if (iMethod == METHOD_1_USE) { // method 1 (use old one)
2792  for (Iterator<AnnotType> ntIt2 = newTypes.iterator(); ntIt2.hasNext();) { // replace in others
2793  AnnotType t2 = ntIt2.next();
2794  if (t2.getAncestorType() != null && t2.getAncestorType().getUri().equals(type.getUri())) {
2795  t2.setAncestorType(typeInDB); // replace ancestor
2796  }
2797  List<AnnotType> nAnc = new ArrayList<AnnotType>(); // new list
2798  for (Iterator t2AIt = t2.getAncestorTypes().iterator(); t2AIt.hasNext();) {
2799  AnnotType t2A = (AnnotType) t2AIt.next();
2800  if (t2A.getUri() != null && t2A.getUri().equals(type.getUri())) {
2801  nAnc.add(typeInDB);
2802  } else {
2803  nAnc.add(t2A);
2804  }
2805  }
2806  t2.setAncestorTypes(nAnc); // replace list of ancestors
2807  for (Iterator t2AtIt = t2.getAttributes().iterator(); t2AtIt.hasNext();) {
2808  AnnotTypeAttr t2At = (AnnotTypeAttr)t2AtIt.next();
2809  if (t2At.getAttributeType() != null && t2At.getAttributeType().getUri().equals(type.getUri())) {
2810  t2At.setAttributeType(typeInDB);
2811  }
2812  }
2813  } // replace in others
2814  ntIt.remove(); // remove type (old will be used)
2815  } else if (iMethod == METHOD_2_UPDATE) { // method 2
2816  // update old type
2817  typeInDB.setAncestorType(type.getAncestorType());
2818  typeInDB.setAncestorTypes(type.getAncestorTypes());
2819  typeInDB.setAttributes(new ArrayList<AnnotTypeAttr>(type.getAttributes()));
2820  typeInDB.setComment(type.getComment());
2821  typeInDB.setRestrictedAtt(type.getRestrictedAtt());
2822  typeInDB.setUriInOntology(type.getUriInOntology());
2823 
2824  for (Iterator<AnnotType> ntIt2 = newTypes.iterator(); ntIt2.hasNext();) { // replace in others
2825  AnnotType t2 = ntIt2.next();
2826  if (t2.getAncestorType() != null && t2.getAncestorType().getUri().equals(type.getUri())) {
2827  t2.setAncestorType(typeInDB); // replace ancestor
2828  }
2829  List<AnnotType> nAnc = new ArrayList<AnnotType>(); // new list
2830  for (Iterator t2AIt = t2.getAncestorTypes().iterator(); t2AIt.hasNext();) {
2831  AnnotType t2A = (AnnotType) t2AIt.next();
2832  if (t2A.getUri() != null && t2A.getUri().equals(type.getUri())) {
2833  nAnc.add(typeInDB);
2834  } else {
2835  nAnc.add(t2A);
2836  }
2837  }
2838  t2.setAncestorTypes(nAnc); // replace list of ancestors
2839  for (Iterator t2AtIt = t2.getAttributes().iterator(); t2AtIt.hasNext();) {
2840  AnnotTypeAttr t2At = (AnnotTypeAttr)t2AtIt.next();
2841  if (t2At.getAttributeType() != null && t2At.getAttributeType().getUri().equals(type.getUri())) {
2842  t2At.setAttributeType(typeInDB);
2843  }
2844  }
2845  } // replace in others
2846 
2847  tToUpdate.add(typeInDB);
2848  ntIt.remove(); // remove type (old will be used)
2849  } else { // unknown method
2850  errorMessage = errorMessage + MessageProvider.getMessage("typeAlreadyExists1")
2851  + type.getUri() + MessageProvider.getMessage("typeAlreadyExists2") + "<br/>";
2852  return null;
2853  }
2854  duplicitTypeFound = true;
2855  } // if type was found
2856  } // check whether some type is not exists in database
2857 
2858  if (duplicitTypeFound) { // if some duplicit type found
2859  if (iMethod == METHOD_0_ERROR) {
2860  return null;
2861  }
2862  }
2863 
2864  // attributes from ontology to update
2865  List<TypeAttrOnto> aToUpdate = new ArrayList<TypeAttrOnto>();
2866 
2867  // check whether some attribute is not exists in database
2868  boolean duplicitAttributeFound = false;
2869  for (Iterator<TypeAttrOnto> aFOIt = ontoAttrs.iterator(); aFOIt.hasNext();) {
2870  TypeAttrOnto aFO = aFOIt.next();
2871  Object[] params2 = new Object[4]; // parameters for database query
2872  params2[0] = "name";
2873  params2[1] = aFO.getName();
2874  params2[2] = "groupId";
2875  params2[3] = aFO.getGroup().getId();
2876  List aList = AppBean.getPersistenceManager().queryDB("TypeAttrOnto.findByNameAndGroup", params2);
2877  if (aList != null && !aList.isEmpty()) { // if attribute was found
2878  TypeAttrOnto attrInDB = (TypeAttrOnto) aList.get(0);
2879  if (iMethod == METHOD_0_ERROR) {
2880  errorMessage = errorMessage + MessageProvider.getMessage("attributeAlreadyExists1")
2881  + aFO.getName() + MessageProvider.getMessage("attributeAlreadyExists2") + "<br/>";
2882  } else if (iMethod == METHOD_1_USE) { // method 1 (use old one)
2883  aFOIt.remove();
2884  } else if (iMethod == METHOD_2_UPDATE) { // method 2
2885  // update old attribute
2886  attrInDB.setSimpleType(aFO.getSimpleType());
2887  attrInDB.setAttributeType(aFO.getAttributeType());
2888  attrInDB.setComment(aFO.getComment());
2889  attrInDB.setUriInOntology(aFO.getUriInOntology());
2890 
2891  aToUpdate.add(attrInDB); // add to list
2892  aFOIt.remove();
2893  }
2894  duplicitTypeFound = true;
2895  } // if attribute was found
2896  } // check whether some attribute is not exists in database
2897 
2898  if (duplicitAttributeFound) { // if some duplicit attribute found
2899  if (iMethod == METHOD_0_ERROR) {
2900  return null;
2901  }
2902  }
2903 
2904  // persist types to database
2905  // Relations with existing types can't be saved if it is not update (TODO: Is it needed? If yes, complete it.)
2906  EntityManager em = AppBean.getPersistenceManager().getEM();
2907  EntityTransaction transaction = em.getTransaction();
2908  boolean errorOccurred = false;
2909  try {
2910  transaction.begin();
2911 
2912  // create list without attributes and ansestors and map with types and ancestors
2913  ArrayList<AnnotType> nTWA = new ArrayList<AnnotType>();
2914  Map<String, AnnotType> nTMap = new HashMap<String, AnnotType>();
2915  for (Iterator<AnnotType> ntIt = newTypes.iterator(); ntIt.hasNext();) {
2916  AnnotType type = ntIt.next();
2917  AnnotType nT = new AnnotType(type.getUri(), type.getName(), type.getAncestorType(), type.getGroup());
2918  nT.setAncestorTypes(type.getAncestorTypes());
2919  nT.setAttributes(new ArrayList<AnnotTypeAttr>(type.getAttributes()));
2920  nT.setRestrictedAtt(type.getRestrictedAtt());
2921  nT.setUriInOntology(type.getUriInOntology());
2922  nT.setComment(type.getComment());
2923  type.setAncestorType(null);
2924  type.setAncestorTypes(new ArrayList<AnnotType>());
2925  type.setAttributes(new ArrayList<AnnotTypeAttr>());
2926  nTWA.add(type);
2927  nTMap.put(type.getUri(), nT);
2928  }
2929 
2930  // merge types without attributes and create map with merged types
2931  ArrayList<AnnotType> mergedTypes = new ArrayList<AnnotType>();
2932  Map<String, AnnotType> mTypesMap = new HashMap<String, AnnotType>();
2933  for (Iterator<AnnotType> nTWAIt = nTWA.iterator(); nTWAIt.hasNext();) {
2934  AnnotType type = nTWAIt.next();
2935  type = em.merge(type);
2936  mergedTypes.add(type);
2937  mTypesMap.put(type.getUri(), type);
2938  }
2939 
2940  // fix, add and merge attributes and ancestors
2941  for (Iterator<AnnotType> mIt = mergedTypes.iterator(); mIt.hasNext();) {
2942  AnnotType mType = mIt.next();
2943  AnnotType oType = nTMap.get(mType.getUri()); // get original type
2944 
2945  // attributes
2946  List<AnnotTypeAttr> aList = oType.getAttributes();
2947  for (Iterator<AnnotTypeAttr> aIt = aList.iterator(); aIt.hasNext();) {
2948  AnnotTypeAttr aTA = aIt.next();
2949  AnnotType aTAAT = aTA.getAttributeType();
2950  if (aTAAT != null) { // if it is structured attribute
2951  // replace type with merged one
2952  AnnotType rType = mTypesMap.get(aTAAT.getUri());
2953  if (rType == null) { // it is not new type, it is in database
2954  rType = queryType(aTAAT.getUri(), em);
2955  }
2956  aTA.setAttributeType(rType);
2957  }
2958  // fix back reference to annotation type
2959  aTA.setAnnotationType(mTypesMap.get(aTA.getAnnotationType().getUri()));
2960  }
2961  mType.setAttributes(new ArrayList<AnnotTypeAttr>(aList));
2962 
2963  // primary ancestor
2964  if (oType.getAncestorType() != null) {
2965  // replace type with merged one
2966  AnnotType rType = mTypesMap.get(oType.getAncestorType().getUri());
2967  if (rType == null) { // it is not new type, it is in database
2968  rType = queryType(oType.getAncestorType().getUri(), em);
2969  }
2970  mType.setAncestorType(rType);
2971  }
2972 
2973  // ancestors
2974  ArrayList<AnnotType> newAncestors = new ArrayList<AnnotType>();
2975  for (Iterator<AnnotType> ancIt = oType.getAncestorTypes().iterator(); ancIt.hasNext();) {
2976  AnnotType ancType = ancIt.next();
2977  AnnotType mAnc = mTypesMap.get(ancType.getUri());
2978  if (mAnc == null) { // it is not new type, it is in database
2979  mAnc = queryType(ancType.getUri(), em);
2980  }
2981  if(!newAncestors.contains(mAnc)){
2982  newAncestors.add(mAnc);
2983  }
2984  }
2985  mType.setAncestorTypes(newAncestors);
2986 
2987  mType = em.merge(mType);
2988  } // fix, add and merge attributes and ancestors
2989 
2990  // merge updated types
2991  for (Iterator<AnnotType> tTUIt = tToUpdate.iterator(); tTUIt.hasNext();) {
2992  AnnotType type = tTUIt.next();
2993  AnnotType pType = queryType(type.getUri(), em);
2994  // update informations
2995  pType.setComment(type.getComment());
2996  pType.setRestrictedAtt(type.getRestrictedAtt());
2997  pType.setUriInOntology(type.getUriInOntology());
2998 
2999  Iterator<AnnotTypeAttr> attrIter = pType.getAttributes().iterator();
3000  Iterator<AnnotTypeAttr> newAttrIter = type.getAttributes().iterator();
3001  while (attrIter.hasNext()) { // update attributes
3002  AnnotTypeAttr attr = attrIter.next();
3003  if (!newAttrIter.hasNext()) {
3004  em.remove(attr);
3005  } else {
3006  AnnotTypeAttr newAttr = newAttrIter.next();
3007  attr.setSimpleType(newAttr.getSimpleType());
3008  if (newAttr.getAttributeType() != null) {
3009  attr.setAttributeType(queryType(newAttr.getAttributeType().getUri(), em));
3010  } else {
3011  attr.setAttributeType(null);
3012  }
3013  attr.setName(newAttr.getName());
3014  attr.setComment(newAttr.getComment());
3015  attr.setRequired(newAttr.getRequired());
3016  attr.setUriInOntology(newAttr.getUriInOntology());
3017  }
3018  } // update attributes
3019  // append new attributes
3020  while (newAttrIter.hasNext()) {
3021  AnnotTypeAttr nA = newAttrIter.next();
3022  if (nA.getAttributeType() != null) {
3023  nA.setAttributeType(queryType(nA.getAttributeType().getUri(), em));
3024  }
3025  nA.setAnnotationType(pType);
3026  pType.getAttributes().add(nA);
3027  }
3028 
3029  // update ancestors
3030  List<AnnotType> newAnc = new ArrayList<AnnotType>();
3031  for (Iterator<AnnotType> aIt = type.getAncestorTypes().iterator(); aIt.hasNext();) {
3032  AnnotType aT = aIt.next();
3033  newAnc.add(queryType(aT.getUri(), em));
3034  }
3035  pType.setAncestorTypes(newAnc);
3036 
3037  // update primary ancestor
3038  if (type.getAncestorType() != null) {
3039  pType.setAncestorType(queryType(type.getAncestorType().getUri(), em));
3040  } else {
3041  pType.setAncestorType(null);
3042  }
3043  } // merge updated types
3044 
3045  // Persist attributes of unknown types of annotations
3046  for (Iterator<TypeAttrOnto> oAIt = ontoAttrs.iterator(); oAIt.hasNext();) {
3047  TypeAttrOnto attr = oAIt.next();
3048  // fix references
3049  if (attr.getAttributeType() != null) {
3050  AnnotType aT = mTypesMap.get(attr.getAttributeType().getUri());
3051  attr.setAttributeType(aT);
3052  }
3053  // merge
3054  em.merge(attr);
3055  }
3056 
3057  // Update existing attributes of unknown types of annotations
3058  for (Iterator<TypeAttrOnto> aFOIt = aToUpdate.iterator(); aFOIt.hasNext();) {
3059  TypeAttrOnto aFO = aFOIt.next();
3060  if (aFO.getAttributeType() != null) {
3061  aFO.setAttributeType(queryType(aFO.getAttributeType().getUri(), em));
3062  }
3063  em.merge(aFO);
3064  } // Update existing attributes of unknown types of annotations
3065 
3066  em.flush();
3067  transaction.commit();
3068  } catch (Exception e) {
3069  transaction.rollback();
3070  errorMessage = errorMessage + MessageProvider.getMessage("typePersistingError") + "<br/>";
3071  return null;
3072  } finally {
3073  em.close();
3074  }
3075 
3076  // prepare messages for connected clients
3077  ResponseCreator rc = AppBean.getResponseCreator();
3078  synchronized(AppBean.getSessions()){
3079  Iterator<EditorSession> sesIt = AppBean.getSessions().iterator();
3080  while (sesIt.hasNext()) { // for each client
3081  EditorSession es = sesIt.next();
3082  Flier flier = new Flier();
3083  // create list of added types
3084  for (Iterator<AnnotType> atIt = newTypes.iterator(); atIt.hasNext();) {
3085  AnnotType at = atIt.next();
3086  flier.AddAddedType(at);
3087  }
3088  // create list of changed types
3089  for (Iterator<AnnotType> atIt = tToUpdate.iterator(); atIt.hasNext();) {
3090  AnnotType at = atIt.next();
3091  flier.AddEditedType(at);
3092  }
3093  es.addMessageTS(rc.createCometResponse(flier, es)); // create message
3094  } // for each client
3095  }
3096 
3097  // display message about success
3098  successMessage = MessageProvider.getMessage("uploadSuccessfull");
3099 
3100  return null;
3101  } // btnUploadAction()
3102  // </editor-fold>
3103 
3104 
3105  // <editor-fold defaultstate="collapsed" desc="queryType">
3106  /**
3107  * Query database for type of annotation
3108  *
3109  * @param uri URI of type of annotation
3110  * @param em Entity manager
3111  * @return Returns type of annotation with given URI
3112  * @throws RuntimeException If type of annotation was not found, throws exception
3113  */
3114  private static AnnotType queryType(String uri, EntityManager em) throws RuntimeException {
3115  AnnotType annotType = null;
3116  Object[] params = new Object[2];
3117  params[0] = "uri";
3118  params[1] = uri;
3119  Query q = em.createNamedQuery("AnnotType.findByUri");
3120  for (int p = 0; p < params.length; p = p + 2) {
3121  q.setParameter((String) params[p], params[p + 1]);
3122  }
3123  List aList = q.getResultList();
3124  if (aList != null && !aList.isEmpty()) { // if type was found
3125  annotType = (AnnotType) aList.get(0);
3126  } else { // if type was not found (merge failed)
3127  throw new RuntimeException("New type not found!");
3128  }
3129  return annotType;
3130  } // queryType()
3131  // </editor-fold>
3132 
3133  // <editor-fold defaultstate="collapsed" desc="btnCancelAction">
3134  /**
3135  * Action listener for cancel button
3136  *
3137  * @return Returns page outcome (null to stay here)
3138  */
3139  public String btnCancelAction() {
3140  return null;
3141  }
3142  // </editor-fold>
3143 
3144  // <editor-fold defaultstate="collapsed" desc="get and set function">
3145  /**
3146  * Gets uploaded file
3147  *
3148  * @return Returns uploaded file
3149  */
3150  public UploadedFile getUploadedFile() {
3151  return uploadedFile;
3152  }
3153 
3154  /**
3155  * Sets uploaded file
3156  *
3157  * @param uploadedFile Uploaded file
3158  */
3159  public void setUploadedFile(UploadedFile uploadedFile) {
3160  this.uploadedFile = uploadedFile;
3161  }
3162 
3163  /**
3164  * Gets uploaded file name
3165  *
3166  * @return Returns uploaded file name
3167  */
3168  public String getFileName() {
3169  return fileName;
3170  }
3171 
3172  /**
3173  * Gets error message displayed in form
3174  *
3175  * @return Returns error message displayed in form
3176  */
3177  public String getErrorMessage() {
3178  return errorMessage;
3179  }
3180 
3181  /**
3182  * Sets error message to be displayed in form
3183  *
3184  * @param errorMessage Error message to be displayed in form
3185  */
3186  public void setErrorMessage(String errorMessage) {
3187  this.errorMessage = errorMessage;
3188  }
3189 
3190  /**
3191  * Gets uploading indicator
3192  *
3193  * @return Returns uploading indicator
3194  */
3195  public Boolean getOntologyUploaded() {
3196  return ontologyUploaded;
3197  }
3198 
3199  /**
3200  * Sets uploading indicator
3201  *
3202  * @param ontologyUploaded Uploading indicator
3203  */
3204  public void setOntologyUploaded(Boolean ontologyUploaded) {
3205  this.ontologyUploaded = ontologyUploaded;
3206  }
3207 
3208  /**
3209  * Gets success message displayed in form
3210  *
3211  * @return Returns success message displayed in form
3212  */
3213  public String getSuccessMessage() {
3214  return successMessage;
3215  }
3216 
3217  /**
3218  * Sets success message to be displayed in form
3219  *
3220  * @param successMessage Success message to be displayed in form
3221  */
3222  public void setSuccessMessage(String successMessage) {
3223  this.successMessage = successMessage;
3224  }
3225 
3226  /**
3227  * Gets user group in which uploaded types will be shared
3228  *
3229  * @return Returns user group in which uploaded types will be shared
3230  */
3231  public String getuGroup() {
3232  return uGroup;
3233  }
3234 
3235  /**
3236  * Sets user group in which uploaded types will be shared
3237  *
3238  * @param uGroup User group in which uploaded types will be shared
3239  */
3240  public void setuGroup(String uGroup) {
3241  this.uGroup = uGroup;
3242  }
3243 
3244  /**
3245  * Gets selected import method
3246  *
3247  * @return Returns selected import method
3248  */
3249  public int getiMethod() {
3250  return iMethod;
3251  }
3252 
3253  /**
3254  * Sets selected import method
3255  *
3256  * @param iMethod Selected import method
3257  */
3258  public void setiMethod(int iMethod) {
3259  this.iMethod = iMethod;
3260  }
3261 
3262  /**
3263  * Gets selected import language
3264  *
3265  * @return Returns selected import language
3266  */
3267  public String getImportLang() {
3268  return importLang;
3269  }
3270 
3271  /**
3272  * Sets selected import language
3273  *
3274  * @param iLanguage Selected import language
3275  */
3276  public void setImportLang(String iLanguage) {
3277  this.importLang = iLanguage;
3278  }
3279 
3280  // </editor-fold>
3281 
3282 } // public class UploadOntology
AnnotTypeInfo(String originUri, String correctedUri, OWLClass owlClass, boolean wasObject, boolean wasAnonymous)
Class representing attribute of unknown type of annotation.
static final ArrayList< String > LANGUAGE_CODES
void addInfoAboutCollectionToComment(AnnotType type, HashSet< String > setOfURI, String commentStr1, String commentStr2, String commentStr3)
String addSuperPropertiesToComment(String propertyURI, String comment, Set< String > superClasses)
static final boolean RESTRICT_TYPES_IMPORTED_FROM_ONTO
Definition: Constants.java:86
void getInverseEquivalentPropertyUri(Set< String > processedProperty, OWLObjectProperty property, OWLObjectPropertyExpression expression, OWLOntology oModel, Set< OWLObjectPropertyExpression > inversePropertyURI, Set< OWLObjectPropertyExpression > equivalentPropertyURI)
int addPropertyInAnonymousClassFromCardinalityRestriction(ArrayList< TypeAttrOnto > ontoAttrs, ArrayList< TypeAttrOnto > ontoAttrsDeleted, OWLVisitorForRestrictionData.CardinalityData data, String typeURI, Map< String, AnnotType > newTypesMap, Map< String, AnnotTypeInfo > newTypesMapInfo, OWLOntology oModel, UserGroup userGroup)
Class representing attribute of type of annotation.
void processUnionOfOneOfIntersectionOf(OWLClass ontClass, AnnotType type, OWLOntology oModel)
String deleteNameInURIIfAnonymousProperty(String originURI, BooleanHolder isAnonymous)
void setUploadedFile(UploadedFile uploadedFile)
Singleton for storing global variables.
Definition: AppBean.java:47
Class for getting localized messages from message bundle.
boolean processModelPhase1(OWLOntology oModel, OWLDataFactory oFactory, ArrayList< AnnotType > newTypes, Map< String, AnnotType > newTypesMap, UserGroup userGroup, Map< String, AnnotTypeInfo > newTypesMapInfo)
void addSuperObjectPropertiesToSet(String propertyURI, Set< OWLObjectPropertyExpression > superProperties, Set< String > superClasses)
String getNewNameForAnonymousClass(AnnotTypeInfo info, AnnotType type)
String getStringTypeFromOntologyURI(String stringURI, boolean generateError, BooleanHolder isRequired)
static AnnotType queryType(String uri, EntityManager em)
void setOntologyUploaded(Boolean ontologyUploaded)
Class with reference to OWLObjectProperty or OWLDataProperty.
Class representing user group.
Definition: UserGroup.java:47
boolean processModelPhase2(OWLOntology oModel, OWLDataFactory oFactory, ArrayList< AnnotType > newTypes, Map< String, AnnotType > newTypesMap, Map< String, AnnotTypeInfo > newTypesMapInfo, ArrayList< TypeAttrOnto > ontoAttrs, UserGroup userGroup)
static String getOWLString(int langNum, int stringNum)
void processInverseProperty(OWLOntology oModel, OWLObjectProperty property, Set< OWLClassExpression > objectSetExpression, Set< OWLClassExpression > subjectSetExpression, Set< String > inversePropertiesStringSet)
String getComments(OWLDataFactory oFactory, Set< OWLAnnotation > annotationSet)
void processPropertyWS(String prUri, String prName, String comment, HashSet< String > objectSetClassURI, UserGroup userGroup, ArrayList< TypeAttrOnto > ontoAttrs, Map< String, AnnotType > newTypesMap, boolean isAnonymous)
HashSet< String > processOWLClassExpression(OWLOntology oModel, OWLClassExpression exp)
String editCommentBaseOnType(String originalComment, boolean action, int objectCount, String propertyName, String oneComment, String moreComment1, String moreComment2)
int createAnnotTypeFromIndividual(OWLOntology oModel, OWLDataFactory oFactory, ArrayList< AnnotType > newTypes, Map< String, AnnotType > newTypesMap, Map< String, AnnotTypeInfo > newTypesMapInfo, UserGroup userGroup, OWLIndividual individual, String name, int anonymousIndividualCount)
Class representing type of annotation.
Definition: AnnotType.java:58
void addSuperDataPropertiesToSet(String propertyURI, Set< OWLDataPropertyExpression > superProperties, Set< String > superClasses)
String renameIfAnonymous(String uri, BooleanHolder isAnnonymous)
void processOWLClassExpressionIntersectionOfOneOf(OWLClassExpression exp, HashSet< String > intersectionOfSet, HashSet< String > oneOfSet)
ArrayList< TypeAttrOnto > getOntoPropertyMayMove(String propertyURI, ArrayList< TypeAttrOnto > ontoAttrs, ArrayList< TypeAttrOnto > ontoAttrsDeleted)
Flier with informations for comet handlers.
Definition: Flier.java:31
int processRdfPropertyAxioms(HashSet< String > objectSetClassURI, HashSet< String > subjectSetClassURI, HashSet< String > ancestorSetClassURI, Set< OWLAxiom > allAxioms)
void processProperties(String prUri, PropertyReference propertyReference, String comment, HashSet< String > subjectSetClassURI, HashSet< String > objectSetClassURI, Map< String, AnnotType > newTypesMap, Map< String, AnnotTypeInfo > newTypesMapInfo, ArrayList< TypeAttrOnto > ontoAttrs, UserGroup userGroup, Set< String > superPropertiesStringSet, Set< String > inversePropertiesID, OWLOntology oModel)
void addSuperClassesToAnnotType(ArrayList< AnnotType > newTypes, Map< String, AnnotType > newTypesMap, UserGroup userGroup, AnnotType type, List< String > superClasses)
String procesSpecialPropertyType(String comment, PropertyReference propertyReference, int objectCount, String newPropertyName, OWLOntology oModel)
void noRangePropertyProcess(AnnotType type, String prName, String prUri, String comment)
Class that creates responses and persists data.
Class for additional information about AnnotType.
Backbean for for page for uploading ontology.
LinkedList< String > processSuperClass(OWLOntology oModel, OWLClass ontClass)
AnnotTypeInfo(String originUri, String correctedUri, OWLClass owlClass)
Class responsible for localised strings.
Informations about client session.