private void buildPropertyClasses(Frame frame) { for (Field field : frame.getDeclaredFields()) { OntResource type = field.getType(); if (type.canAs(OntProperty.class)) { String uri = type.getURI(); UmlClass umlClass = addPropertyClass(type, true); } } }
private void buildClass(Frame frame) { String uri = frame.getUri(); UmlClass umlClass = new UmlClass(frame, this); uri2Class.put(uri, umlClass); for (Field field : frame.getDeclaredFields()) { RdfType fieldType = field.getRdfType(); if (fieldType.canAsDatatype()) { umlClass.add(field); } } }
private void addField(OntResource type, OntProperty p, OntProperty ancestor) { int minCardinality = 0; int maxCardinality = -1; OntResource range = null; String typeURI = type.getURI(); if (typeURI == null) { // We only add fields to named types. return; } // Do not add abstract properties. if (isAbstract(p)) return; Frame frame = manager.getFrameByUri(typeURI); if (frame == null) { if (isStandard(typeURI)) return; logger.warn( "Ignoring property " + p.getLocalName() + " on class " + type.getLocalName() + ": frame not found"); return; } if (frame.getDeclaredFieldByPropertyURI(p.getURI()) != null) return; if (p.hasRDFType(OWL.FunctionalProperty)) { maxCardinality = 1; } OntClass restriction = frame.getRestriction(p.getURI()); range = p.getRange(); if (range == null && ancestor != null) { range = ancestor.getRange(); } if (range == null) { // logger.warn("Ignoring property " + p.getLocalName() + " on class " + // type.getLocalName() + ": range not defined"); // return; range = THING; } if (restriction != null) { Resource onClass = restriction.getPropertyResourceValue(OWL2.onClass); if (onClass != null) { range = onClass.as(OntResource.class); if (restriction.hasProperty(OWL2.minQualifiedCardinality)) { minCardinality = restriction.getProperty(OWL2.minQualifiedCardinality).getInt(); } if (restriction.hasProperty(OWL2.maxQualifiedCardinality)) { maxCardinality = restriction.getProperty(OWL2.maxQualifiedCardinality).getInt(); } } else { if (restriction.hasProperty(OWL.minCardinality)) { minCardinality = restriction.getProperty(OWL.minCardinality).getInt(); } if (restriction.hasProperty(OWL.maxCardinality)) { maxCardinality = restriction.getProperty(OWL.maxCardinality).getInt(); } } } Field field = null; String rangeURI = range.getURI(); if (rangeURI == null) { field = createListField(frame, p, range); if (field == null) { logger.warn( "Ignoring property " + p.getLocalName() + " on class " + type.getLocalName() + ": range has no URI"); return; } } else { field = new Field(frame, p, range, minCardinality, maxCardinality); if (field.getRdfType() == null) { logger.warn( "Failed to create RdfType for field " + field.getLocalName() + " of type " + field.getType().getURI()); } } Resource rawInverse = p.getPropertyResourceValue(OWL.inverseOf); if (rawInverse != null && rawInverse.canAs(OntProperty.class)) { field.setInverseOf(rawInverse.as(OntProperty.class)); } frame.getDeclaredFields().add(field); }
private void addFieldFromRestriction( Map<String, Field> fieldMap, Frame frame, OntClass restriction) { int minCardinality = 0; int maxCardinality = -1; OntResource range = null; Resource resource = restriction.getPropertyResourceValue(OWL2.onProperty); String uri = resource.getURI(); Field priorField = fieldMap.get(uri); if (priorField != null) { maxCardinality = priorField.getMaxCardinality(); } OntProperty property = null; if (restriction.getPropertyResourceValue(OWL2.onProperty).canAs(OntProperty.class)) { property = resource.as(OntProperty.class); } else { property = model.createOntProperty(resource.getURI()); } if (property != null && property.canAs(FunctionalProperty.class)) { maxCardinality = 1; } if (restriction.hasProperty(OWL.minCardinality)) { minCardinality = restriction.getProperty(OWL.minCardinality).getInt(); } if (restriction.hasProperty(OWL.maxCardinality)) { maxCardinality = restriction.getProperty(OWL.maxCardinality).getInt(); } Resource valueType = restriction.getPropertyResourceValue(OWL.allValuesFrom); if (valueType != null) { range = valueType.as(OntResource.class); } Resource hasValue = restriction.getPropertyResourceValue(OWL.hasValue); NamedIndividual individualValue = null; if (hasValue != null && hasValue.getURI() != null) { String individualURI = hasValue.getURI(); individualValue = new NamedIndividual(hasValue.as(OntResource.class)); } // Resource onClass = restriction.getPropertyResourceValue(OWL2.onClass); // if (onClass != null) { // range = onClass.as(OntResource.class); // if (restriction.hasProperty(OWL2.minQualifiedCardinality)) { // minCardinality = restriction.getProperty(OWL2.minQualifiedCardinality).getInt(); // } // if (restriction.hasProperty(OWL2.maxQualifiedCardinality)) { // maxCardinality = restriction.getProperty(OWL2.maxQualifiedCardinality).getInt(); // } // // } else { // if (restriction.hasProperty(OWL.minCardinality)) { // minCardinality = restriction.getProperty(OWL.minCardinality).getInt(); // } // if (restriction.hasProperty(OWL.maxCardinality)) { // maxCardinality = restriction.getProperty(OWL.maxCardinality).getInt(); // } // } if (range == null) { Resource value = property.getPropertyResourceValue(RDFS.range); if (value == null) { logger.warn( "Ignoring field " + resource.getLocalName() + " on class " + frame.getLocalName() + ": the range is not defined."); return; } range = property.getPropertyResourceValue(RDFS.range).as(OntResource.class); } String comment = restriction.getComment(null); if (priorField != null && priorField.getDeclaringFrame() == frame) { priorField.setComment(comment); priorField.setMinCardinality(minCardinality); priorField.setMaxCardinality(maxCardinality); priorField.setValueRestriction(individualValue); return; } Field field = new Field(frame, property, range, minCardinality, maxCardinality); field.setComment(comment); field.setValueRestriction(individualValue); fieldMap.put(uri, field); frame.getDeclaredFields().add(field); }
private void addChildren(UmlClass umlClass, Frame frame) { List<UmlAssociation> parentList = new ArrayList<UmlAssociation>(); for (Field field : frame.getDeclaredFields()) { RdfType fieldType = field.getRdfType(); Field inverseField = field.getInverseField(); UmlClass otherClass = null; if (fieldType.canAsFrame()) { otherClass = getUmlClassByURI(fieldType.getUri()); } else if (fieldType.canAsListType()) { otherClass = getUmlClassByURI(fieldType.asListType().getElementType().getUri()); } if (otherClass != null) { InverseProperty inverse = field.getInverseProperty(); Encapsulation inverseEncapsulation = inverseField == null ? inverse.getEncapsulation() : inverseField.getEncapsulation(); Encapsulation encapsulation = field.getEncapsulation(); if (encapsulation == Encapsulation.NONE && inverseEncapsulation != Encapsulation.NONE) { // // The other class is the parent UmlAssociationEnd end0 = new UmlAssociationEnd(umlClass); end0.setMultiplicity(inverse.getMultiplicity()); defineEnd(end0, inverseField, encapsulation); UmlAssociationEnd end1 = new UmlAssociationEnd(otherClass); defineEnd(end1, field, inverseEncapsulation); UmlAssociation assoc = new UmlAssociation(end0, end1); otherClass.addChild(assoc); parentList.add(assoc); } else { UmlAssociationEnd end0 = new UmlAssociationEnd(umlClass); UmlAssociationEnd end1 = new UmlAssociationEnd(otherClass); defineEnd(end0, inverseField, encapsulation); defineEnd(end1, field, inverseEncapsulation); UmlAssociation assoc = new UmlAssociation(end0, end1); umlClass.addChild(assoc); parentList.add(assoc); } } else { // TODO: handle other conditions } } addParentList(umlClass, parentList); }