incremental development for NIHVIVO-1286

This commit is contained in:
sjm222 2011-01-05 12:11:27 +00:00
parent 8a5d4ccec4
commit 89d6ae5ab7
3 changed files with 65 additions and 62 deletions

View file

@ -96,7 +96,11 @@ public class ABoxUpdater {
addClass(change);
break;
case DELETE:
deleteClass(change);
if ("Delete".equals(change.getNotes())) {
deleteClass(change);
} else {
renameClassToParent(change);
}
break;
case RENAME:
renameClass(change);
@ -275,6 +279,62 @@ public class ABoxUpdater {
}
}
/**
*
* Update a knowledge base to account for a class deletion in the ontology.
* All references to the deleted class URI in either the subject or the object
* position of a statement are changed to use the closest available parent of
* the deleted class from the previous ontology that remains in the new version
* of the ontology. Note that the closest available parent may be owl:Thing.
* If the deleted class has more than one closest available parent, then
* change individuals that were asserted to be of the deleted class to be
* asserted to be of both parent classes.
*
* @param change - an AtomicOntologyChange object representing a class
* delete operation.
*
*/
public void renameClassToParent(AtomicOntologyChange change) throws IOException {
logger.log("Processing a class migration to parent for deleted class " + change.getSourceURI());
OntClass deletedClass = oldTboxModel.getOntClass(change.getSourceURI());
if (deletedClass == null) {
logger.log("WARNING: didn't find the deleted class " + change.getSourceURI() + " in the old model. Skipping updates for this deletion");
return;
}
List<OntClass> classList = deletedClass.listSuperClasses(true).toList();
List<OntClass> namedClassList = new ArrayList<OntClass>();
for (OntClass ontClass : classList) {
if (!ontClass.isAnon()) {
namedClassList.add(ontClass);
}
}
OntClass parent = (!namedClassList.isEmpty())
? namedClassList.get(0)
: OWL_THING;
OntClass replacementClass = newTboxModel.getOntClass(parent.getURI());
while (replacementClass == null) {
parent = parent.getSuperClass();
if (parent == null) {
replacementClass = OWL_THING;
} else {
replacementClass = newTboxModel.getOntClass(parent.getURI());
}
}
//log summary of changes
logger.log("Class " + deletedClass.getURI() + " has been deleted. Any references to it in the knowledge base have been changed to " + replacementClass.getURI());
AtomicOntologyChange chg = new AtomicOntologyChange(deletedClass.getURI(), replacementClass.getURI(), AtomicChangeType.RENAME, change.getNotes());
renameClass(chg);
}
/**
*
@ -587,60 +647,4 @@ public class ABoxUpdater {
: ((Resource)statement.getObject()).getURI() + " (Resource)");
}
/**
*
* Update a knowledge base to account for a class deletion in the ontology.
* All references to the deleted class URI in either the subject or the object
* position of a statement are changed to use the closest available parent of
* the deleted class from the previous ontology that remains in the new version
* of the ontology. Note that the closest available parent may be owl:Thing.
* If the deleted class has more than one closest available parent, then
* change individuals that were asserted to be of the deleted class to be
* asserted to be of both parent classes.
*
* @param change - an AtomicOntologyChange object representing a class
* delete operation.
*
*/
public void obsolete_deleteClass(AtomicOntologyChange change) throws IOException {
logger.log("Processing a class deletion of class " + change.getSourceURI());
OntClass deletedClass = oldTboxModel.getOntClass(change.getSourceURI());
if (deletedClass == null) {
logger.log("WARNING: didn't find the deleted class " + change.getSourceURI() + " in the old model. Skipping updates for this deletion");
return;
}
List<OntClass> classList = deletedClass.listSuperClasses(true).toList();
List<OntClass> namedClassList = new ArrayList<OntClass>();
for (OntClass ontClass : classList) {
if (!ontClass.isAnon()) {
namedClassList.add(ontClass);
}
}
OntClass parent = (!namedClassList.isEmpty())
? namedClassList.get(0)
: OWL_THING;
OntClass replacementClass = newTboxModel.getOntClass(parent.getURI());
while (replacementClass == null) {
parent = parent.getSuperClass();
if (parent == null) {
replacementClass = OWL_THING;
} else {
replacementClass = newTboxModel.getOntClass(parent.getURI());
}
}
//log summary of changes
logger.log("Class " + deletedClass.getURI() + " has been deleted. Any references to it in the knowledge base have been changed to " + replacementClass.getURI());
AtomicOntologyChange chg = new AtomicOntologyChange(deletedClass.getURI(), replacementClass.getURI(), AtomicChangeType.RENAME, change.getNotes());
renameClass(chg);
}
}

View file

@ -117,7 +117,7 @@ public class DateTimeMigration {
if (additions.size() > 0) {
long count = additions.size() / 2;
logger.log(count + "Academic Term and/or Year statement" + ((count > 1) ? "s" : "") + " were updated to use dateTimeInterval instead");
logger.log(count + "Academic Term and/or Year assertion" + ((count > 1) ? "s" : "") + " were updated to use dateTimeInterval instead");
}
} finally {
aboxModel.leaveCriticalSection();
@ -130,7 +130,7 @@ public class DateTimeMigration {
*/
public void updateLiterals() throws IOException {
// note: not handling timezones - they are not expected to be in the 1.1.1 data
//TODO: look into java locale note: not handling timezones - they are not expected to be in the 1.1.1 data
DateFormat yearFormat = new SimpleDateFormat("yyyy");
DateFormat yearMonthFormat = new SimpleDateFormat("yyyy-mm");
DateFormat yearMonthDayFormat = new SimpleDateFormat("yyyy-mm-dd");
@ -196,7 +196,7 @@ public class DateTimeMigration {
record.recordAdditions(additions);
if (additions.size() > 0) {
logger.log(additions.size() + " date/time assertions" +
logger.log(additions.size() + " date/time assertion" +
((additions.size() > 1) ? "s" : "") +
" were updated to the 1.2 representation.");
}

View file

@ -81,8 +81,7 @@ public class OntologyUpdater {
performSparqlConstructAdditions(settings.getSparqlConstructAdditionsDir(), settings.getOntModelSelector().getABoxModel());
performSparqlConstructRetractions(settings.getSparqlConstructDeletionsDir(), settings.getOntModelSelector().getABoxModel());
performSparqlConstructAdditions(settings.getSparqlConstructAdditionsPass2Dir(), settings.getOntModelSelector().getABoxModel());
DateTimeMigration dtMigration = new DateTimeMigration(settings.getOntModelSelector().getABoxModel(), logger, record);
dtMigration.updateABox();