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 = ModelFactory.createOntologyModel(model.getSpecification(), model);
// Note: previously, newOntModel = new OwlModel(model); but the OwlModel extension was not used
// in any particular way, so the new call should be equivalent.
final Ontology ont_ = newOntModel.createOntology(base_);
if ( log.isDebugEnabled() ) {
log.debug("New ontology created with namespace " + ns_ + " base " + base_);
}
newOntModel.setNsPrefix("", ns_);
//////////////////////////////////////////////////////////////////////////
// set new values for the unversioned version:
Map<String, String> newValues = new HashMap<String, String>();
// Set internal attributes, which are updated in the newValues map itself
// so we facilite the processing below:
newValues.put(Omv.uri.getURI(), base_);
if ( version != null ) {
newValues.put(Omv.version.getURI(), version);
}
newValues.put(Omv.creationDate.getURI(), creationDate);
//////////////////////////////////////////////////
// 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 ) {
// not assigned above.
if ( ALTERATE_ANNOTATIONS ) {
// See if it's one of the ones to be modified:
if ( Omv.description.getURI().equals(prd.getURI()) ) {
// transfer modified description:
String description =
"An unversioned ontology containing the latest terms as of the request time, " +
"for the ontology containing: " +st.getObject();
// log.info(" Transferring modified description: " +st.getSubject()+ " :: " +prd+ " :: " +description);
newOntModel.add(ont_, st.getPredicate(), description);
}
else if ( Omv.name.getURI().equals(prd.getURI()) ) {
// transfer modified title:
String title =
"Unversioned form of: " +st.getObject();
// log.info(" Transferring modified title: " +st.getSubject()+ " :: " +prd+ " :: " +title);
newOntModel.add(ont_, st.getPredicate(), title);
}
else {
// transfer as it comes:
// log.info(" Transferring: " +st.getSubject()+ " :: " +prd+ " :: " +st.getObject());
newOntModel.add(ont_, st.getPredicate(), st.getObject());
}
}
else {
// just transfer as it comes:
// log.info(" Transferring: " +st.getSubject()+ " :: " +prd+ " :: " +st.getObject());
newOntModel.add(ont_, st.getPredicate(), st.getObject());
}
}
else {
// log.info(" Not Transferring: " +prd+ " from previous version because new value " +newValue);
}