incremental development for NIHVIVO-1286
This commit is contained in:
parent
8a5d4ccec4
commit
89d6ae5ab7
3 changed files with 65 additions and 62 deletions
|
@ -96,7 +96,11 @@ public class ABoxUpdater {
|
||||||
addClass(change);
|
addClass(change);
|
||||||
break;
|
break;
|
||||||
case DELETE:
|
case DELETE:
|
||||||
|
if ("Delete".equals(change.getNotes())) {
|
||||||
deleteClass(change);
|
deleteClass(change);
|
||||||
|
} else {
|
||||||
|
renameClassToParent(change);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case RENAME:
|
case RENAME:
|
||||||
renameClass(change);
|
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)");
|
: ((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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class DateTimeMigration {
|
||||||
|
|
||||||
if (additions.size() > 0) {
|
if (additions.size() > 0) {
|
||||||
long count = additions.size() / 2;
|
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 {
|
} finally {
|
||||||
aboxModel.leaveCriticalSection();
|
aboxModel.leaveCriticalSection();
|
||||||
|
@ -130,7 +130,7 @@ public class DateTimeMigration {
|
||||||
*/
|
*/
|
||||||
public void updateLiterals() throws IOException {
|
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 yearFormat = new SimpleDateFormat("yyyy");
|
||||||
DateFormat yearMonthFormat = new SimpleDateFormat("yyyy-mm");
|
DateFormat yearMonthFormat = new SimpleDateFormat("yyyy-mm");
|
||||||
DateFormat yearMonthDayFormat = new SimpleDateFormat("yyyy-mm-dd");
|
DateFormat yearMonthDayFormat = new SimpleDateFormat("yyyy-mm-dd");
|
||||||
|
@ -196,7 +196,7 @@ public class DateTimeMigration {
|
||||||
record.recordAdditions(additions);
|
record.recordAdditions(additions);
|
||||||
|
|
||||||
if (additions.size() > 0) {
|
if (additions.size() > 0) {
|
||||||
logger.log(additions.size() + " date/time assertions" +
|
logger.log(additions.size() + " date/time assertion" +
|
||||||
((additions.size() > 1) ? "s" : "") +
|
((additions.size() > 1) ? "s" : "") +
|
||||||
" were updated to the 1.2 representation.");
|
" were updated to the 1.2 representation.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,6 @@ public class OntologyUpdater {
|
||||||
|
|
||||||
performSparqlConstructAdditions(settings.getSparqlConstructAdditionsDir(), settings.getOntModelSelector().getABoxModel());
|
performSparqlConstructAdditions(settings.getSparqlConstructAdditionsDir(), settings.getOntModelSelector().getABoxModel());
|
||||||
performSparqlConstructRetractions(settings.getSparqlConstructDeletionsDir(), settings.getOntModelSelector().getABoxModel());
|
performSparqlConstructRetractions(settings.getSparqlConstructDeletionsDir(), settings.getOntModelSelector().getABoxModel());
|
||||||
performSparqlConstructAdditions(settings.getSparqlConstructAdditionsPass2Dir(), settings.getOntModelSelector().getABoxModel());
|
|
||||||
|
|
||||||
DateTimeMigration dtMigration = new DateTimeMigration(settings.getOntModelSelector().getABoxModel(), logger, record);
|
DateTimeMigration dtMigration = new DateTimeMigration(settings.getOntModelSelector().getABoxModel(), logger, record);
|
||||||
dtMigration.updateABox();
|
dtMigration.updateABox();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue