/* * (non-Javadoc) * @see net.java.treaty.ContractVocabulary#getSuperProperties(java.net.URI) */ public Set<URI> getSuperProperties(URI relationshipOrProperty) throws TreatyException { Set<URI> result; result = new HashSet<URI>(); OntModel model; model = getOntology(); OntProperty property; property = model.getOntProperty(relationshipOrProperty.toString()); for (Iterator<? extends OntProperty> iterator = property.listSuperProperties(false); iterator.hasNext(); ) { try { result.add(new URI(iterator.next().getURI())); } catch (URISyntaxException e) { throw new TreatyException(e); } // end catch. } // end for. return result; }
private void addSuperProperties(UmlClass umlClass, OntProperty property) { List<? extends OntProperty> list = property.listSuperProperties(true).toList(); for (OntProperty superProperty : list) { if (superProperty.getURI().equals(property.getURI())) { continue; } UmlClass superClass = addPropertyClass(superProperty, true); umlClass.addSupertype(superClass); superClass.addSubtype(umlClass); } }
public void setSubPropertyOf(Properties Properties, OntModel ontologyModel) { Iterator<OntProperty> IteratorExtractedProperties = Properties.getExtractedProperty().iterator(); while (IteratorExtractedProperties.hasNext()) { OntProperty property = (OntProperty) IteratorExtractedProperties.next(); String URI = property.getURI(); if (URI != null) { try { ExtendedIterator<OntProperty> itSup = (ExtendedIterator<OntProperty>) property.listSuperProperties(true); while (itSup.hasNext()) { OntProperty propertySup = itSup.next(); String URISUP = propertySup.getURI(); if (URISUP != null) { addSubPropertyOfRelation(property, propertySup); } } } catch (Exception e) { // SPARQL Query for SubProperties String queryString = "PREFIX rdfs:<" + RDFS.getURI() + ">" + "PREFIX ont:<" + property.getNameSpace() + ">" + "SELECT ?obj " + "WHERE {" + " ont:" + property.getLocalName() + " rdfs:subPropertyOf ?obj" + " }"; // Execute Query Query query = QueryFactory.create(queryString); QueryExecution qexec = QueryExecutionFactory.create(query, ontologyModel); try { ResultSet results = qexec.execSelect(); // Temporary Model in Order to Construct Node for External Property OntModel ontologyTempModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, null); // Extract Relation for (; results.hasNext(); ) { QuerySolution soln = results.nextSolution(); Resource obj = soln.getResource("obj"); String URIObj = obj.getURI(); // Get SubPropertyOf all Property different from the current one if (URIObj != null && property.getURI() != URIObj) { OntProperty propertySup = ontologyTempModel.createOntProperty(URIObj); // Save SubPropertyOf Relation (property SubPropertyOf PropertySub) addSubPropertyOfRelation(property, propertySup); } } } finally { qexec.close(); } } } } }