improvements and bugfixes for NIHVIVO-205 ontology upgrade
This commit is contained in:
parent
03a2a13a37
commit
71a6fccd64
5 changed files with 43 additions and 26 deletions
|
@ -72,18 +72,19 @@
|
|||
<listener-class>edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetup</listener-class>
|
||||
</listener>
|
||||
|
||||
<!-- Invokes process to perform updates to align with ontology changes if needed -->
|
||||
<!-- Needs to run before submodels are attached and Pellet is set up -->
|
||||
|
||||
<listener>
|
||||
<listener-class>edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase</listener-class>
|
||||
</listener>
|
||||
|
||||
<!-- Attaching submodels permits extra RDF files to be made visible without storing the data in the DB. -->
|
||||
|
||||
<listener>
|
||||
<listener-class>edu.cornell.mannlib.vitro.webapp.servlet.setup.AttachSubmodels</listener-class>
|
||||
</listener>
|
||||
|
||||
<!-- Invokes process to perform updates to align with ontology changes if needed -->
|
||||
|
||||
<listener>
|
||||
<listener-class>edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase</listener-class>
|
||||
</listener>
|
||||
|
||||
<!-- Pellet setup enables reasoning. Inferences are cached in a separate DB graph. -->
|
||||
<!-- Changing the class name sets the kindss of inferences that are materialized. -->
|
||||
<!-- See documentation for details. -->
|
||||
|
|
|
@ -84,7 +84,7 @@ public class OntologyUpdater {
|
|||
|
||||
AtomicOntologyChangeLists changes =
|
||||
new AtomicOntologyChangeLists(rawChanges,
|
||||
settings.getOntModelSelector().getTBoxModel(),
|
||||
settings.getNewTBoxModel(),
|
||||
settings.getOldTBoxModel());
|
||||
|
||||
//updateTBox(changes);
|
||||
|
@ -186,7 +186,7 @@ public class OntologyUpdater {
|
|||
private void updateTBoxAnnotations() throws IOException {
|
||||
(new TBoxUpdater(settings.getOldTBoxAnnotationsModel(),
|
||||
settings.getNewTBoxAnnotationsModel(),
|
||||
settings.getOntModelSelector().getTBoxModel(), logger, record))
|
||||
settings.getOntModelSelector().getABoxModel(), logger, record))
|
||||
.updateVitroPropertyDefaultValues();
|
||||
}
|
||||
|
||||
|
|
|
@ -46,12 +46,16 @@ public class SimpleOntologyChangeRecord implements OntologyChangeRecord {
|
|||
|
||||
public void recordAdditions(Model incrementalAdditions) {
|
||||
additionsModel.add(incrementalAdditions);
|
||||
write(additionsModel, additionsFile);
|
||||
if (additionsModel.size() > 0) {
|
||||
write(additionsModel, additionsFile);
|
||||
}
|
||||
}
|
||||
|
||||
public void recordRetractions(Model incrementalRetractions) {
|
||||
retractionsModel.add(incrementalRetractions);
|
||||
write(retractionsModel, retractionsFile);
|
||||
if (retractionsModel.size() > 0) {
|
||||
write(retractionsModel, retractionsFile);
|
||||
}
|
||||
}
|
||||
|
||||
private void write(Model model, File file) {
|
||||
|
|
|
@ -122,7 +122,11 @@ public class TBoxUpdater {
|
|||
|
||||
if (!newObject.equals(oldObject)) {
|
||||
objects = siteModel.listObjectsOfProperty(subject,predicate);
|
||||
|
||||
|
||||
if (!objects.hasNext()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RDFNode siteObject = objects.next();
|
||||
if (objects.hasNext()) {
|
||||
logger.logError("Warning: found " + objects.toList().size() +
|
||||
|
@ -163,18 +167,18 @@ public class TBoxUpdater {
|
|||
}
|
||||
}
|
||||
|
||||
siteModel.add(additions);
|
||||
record.recordAdditions(additions);
|
||||
siteModel.remove(retractions);
|
||||
record.recordRetractions(retractions);
|
||||
Model actualAdditions = additions.difference(retractions);
|
||||
siteModel.add(actualAdditions);
|
||||
record.recordAdditions(actualAdditions);
|
||||
Model actualRetractions = retractions.difference(additions);
|
||||
siteModel.remove(actualRetractions);
|
||||
record.recordRetractions(actualRetractions);
|
||||
|
||||
// log summary of changes
|
||||
StmtIterator addedIter = additions.listStatements();
|
||||
logger.log("Updated the default vitro annotation value for " +
|
||||
addedIter.toList().size() + " statments in the knowledge base.");
|
||||
actualAdditions.size() + " statments in the knowledge base.");
|
||||
|
||||
StmtIterator removedIter = retractions.listStatements();
|
||||
int numRemoved = removedIter.toList().size() - addedIter.toList().size();
|
||||
long numRemoved = actualRetractions.size() - actualAdditions.size();
|
||||
logger.log("Removed " + numRemoved +
|
||||
" superfluous vitro annotation property settings from the knowledge base.");
|
||||
|
||||
|
@ -183,15 +187,21 @@ public class TBoxUpdater {
|
|||
//
|
||||
|
||||
Model newAnnotationSettings = newTboxModel.difference(oldTboxModel);
|
||||
siteModel.add(newAnnotationSettings);
|
||||
record.recordAdditions(newAnnotationSettings);
|
||||
Model newAnnotationSettingsToAdd = ModelFactory.createDefaultModel();
|
||||
StmtIterator newStmtIt = newAnnotationSettings.listStatements();
|
||||
while (newStmtIt.hasNext()) {
|
||||
Statement stmt = newStmtIt.next();
|
||||
if (!siteModel.contains(stmt)) {
|
||||
newAnnotationSettingsToAdd.add(stmt);
|
||||
}
|
||||
}
|
||||
siteModel.add(newAnnotationSettingsToAdd);
|
||||
record.recordAdditions(newAnnotationSettingsToAdd);
|
||||
|
||||
// log the additions
|
||||
iter = newAnnotationSettings.listStatements();
|
||||
|
||||
//summary
|
||||
logger.log("Added " + iter.toList().size() + " new annotation property settings to the knowledge base. This includes " +
|
||||
"exsiting annotation properties applied to exsiting classes where they weren't applied before, or existing " +
|
||||
logger.log("Added " + newAnnotationSettingsToAdd.size() + " new annotation property settings to the knowledge base. This includes " +
|
||||
"existing annotation properties applied to existing classes where they weren't applied before, or existing " +
|
||||
"properties applied to new classes. No new annotation properties have been introduced.");
|
||||
//details
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
private final String SPARQL_CONSTRUCTS_DIR = DATA_DIR + "sparqlConstructs/";
|
||||
private final String MISC_REPLACEMENTS_FILE = DATA_DIR + "miscReplacements.rdf";
|
||||
private final String OLD_TBOX_MODEL_DIR = DATA_DIR + "oldVersion/";
|
||||
private final String NEW_TBOX_MODEL_DIR = "/WEB-INF/submodels/";
|
||||
private final String OLD_TBOX_ANNOTATIONS_DIR = DATA_DIR + "oldAnnotations/";
|
||||
private final String NEW_TBOX_ANNOTATIONS_DIR = "/WEB-INF/ontologies/user";
|
||||
|
||||
|
@ -91,7 +92,8 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
settings.setOntModelSelector(oms);
|
||||
OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_MODEL_DIR));
|
||||
settings.setOldTBoxModel(oldTBoxModel);
|
||||
settings.setNewTBoxModel(oms.getTBoxModel());
|
||||
OntModel newTBoxModel = loadModelFromDirectory(ctx.getRealPath(NEW_TBOX_MODEL_DIR));
|
||||
settings.setNewTBoxModel(newTBoxModel);
|
||||
OntModel oldTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_ANNOTATIONS_DIR));
|
||||
settings.setOldTBoxAnnotationsModel(oldTBoxAnnotationsModel);
|
||||
OntModel newTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(NEW_TBOX_ANNOTATIONS_DIR));
|
||||
|
|
Loading…
Add table
Reference in a new issue