if ( ontRes != null ) {
prexistStatements = new ArrayList<Statement>();
log.info("Getting pre-existing properties for OWL.Ontology individual: " +ontRes.getURI());
StmtIterator iter = ontRes.listProperties();
while ( iter.hasNext() ) {
Statement st = iter.nextStatement();
prexistStatements.add(st);
}
}
// The new OntModel that will contain the pre-existing attributes (if any),
// plus the new and updated attributes:
final OntModel newOntModel = _createOntModel(model);
final Ontology ont_ = newOntModel.createOntology(base_);
log.info("New ontology created with namespace " + ns_ + " base " + base_);
newOntModel.setNsPrefix("", ns_);
// set preferred prefixes:
Map<String, String> preferredPrefixMap = MdHelper.getPreferredPrefixMap();
for ( String uri : preferredPrefixMap.keySet() ) {
String prefix = preferredPrefixMap.get(uri);
newOntModel.setNsPrefix(prefix, uri);
}
// Set internal attributes, which are updated in the newValues map itself
// so we facilite the processing below:
newValues.put(Omv.version.getURI(), version);
newValues.put(Omv.creationDate.getURI(), creationDate);
// set some properties from the explicit values
newValues.put(OmvMmi.origMaintainerCode.getURI(), orgAbbreviation);
//////////////////////////////////////////////////
// transfer any preexisting attributes, and then remove all properties from
// pre-existing ontRes so just the new OntModel gets added.
if ( ontRes != null ) {
for ( Statement st : prexistStatements ) {
Property prd = st.getPredicate();
//
// Do not tranfer pre-existing/pre-assigned-above attributes
//
String newValue = newValues.get(prd.getURI());
if ( newValue == null || newValue.trim().length() == 0 ) {
log.info(" Transferring: " +st.getSubject()+ " :: " +prd+ " :: " +st.getObject());
newOntModel.add(ont_, prd, st.getObject());
}
else {
log.info(" Removing pre-existing values for predicate: " +prd+ " because of new value " +newValue);
newOntModel.removeAll(ont_, prd, null);
}