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-class>edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetup</listener-class>
|
||||||
</listener>
|
</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. -->
|
<!-- Attaching submodels permits extra RDF files to be made visible without storing the data in the DB. -->
|
||||||
|
|
||||||
<listener>
|
<listener>
|
||||||
<listener-class>edu.cornell.mannlib.vitro.webapp.servlet.setup.AttachSubmodels</listener-class>
|
<listener-class>edu.cornell.mannlib.vitro.webapp.servlet.setup.AttachSubmodels</listener-class>
|
||||||
</listener>
|
</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. -->
|
<!-- Pellet setup enables reasoning. Inferences are cached in a separate DB graph. -->
|
||||||
<!-- Changing the class name sets the kindss of inferences that are materialized. -->
|
<!-- Changing the class name sets the kindss of inferences that are materialized. -->
|
||||||
<!-- See documentation for details. -->
|
<!-- See documentation for details. -->
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class OntologyUpdater {
|
||||||
|
|
||||||
AtomicOntologyChangeLists changes =
|
AtomicOntologyChangeLists changes =
|
||||||
new AtomicOntologyChangeLists(rawChanges,
|
new AtomicOntologyChangeLists(rawChanges,
|
||||||
settings.getOntModelSelector().getTBoxModel(),
|
settings.getNewTBoxModel(),
|
||||||
settings.getOldTBoxModel());
|
settings.getOldTBoxModel());
|
||||||
|
|
||||||
//updateTBox(changes);
|
//updateTBox(changes);
|
||||||
|
@ -186,7 +186,7 @@ public class OntologyUpdater {
|
||||||
private void updateTBoxAnnotations() throws IOException {
|
private void updateTBoxAnnotations() throws IOException {
|
||||||
(new TBoxUpdater(settings.getOldTBoxAnnotationsModel(),
|
(new TBoxUpdater(settings.getOldTBoxAnnotationsModel(),
|
||||||
settings.getNewTBoxAnnotationsModel(),
|
settings.getNewTBoxAnnotationsModel(),
|
||||||
settings.getOntModelSelector().getTBoxModel(), logger, record))
|
settings.getOntModelSelector().getABoxModel(), logger, record))
|
||||||
.updateVitroPropertyDefaultValues();
|
.updateVitroPropertyDefaultValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,13 +46,17 @@ public class SimpleOntologyChangeRecord implements OntologyChangeRecord {
|
||||||
|
|
||||||
public void recordAdditions(Model incrementalAdditions) {
|
public void recordAdditions(Model incrementalAdditions) {
|
||||||
additionsModel.add(incrementalAdditions);
|
additionsModel.add(incrementalAdditions);
|
||||||
|
if (additionsModel.size() > 0) {
|
||||||
write(additionsModel, additionsFile);
|
write(additionsModel, additionsFile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void recordRetractions(Model incrementalRetractions) {
|
public void recordRetractions(Model incrementalRetractions) {
|
||||||
retractionsModel.add(incrementalRetractions);
|
retractionsModel.add(incrementalRetractions);
|
||||||
|
if (retractionsModel.size() > 0) {
|
||||||
write(retractionsModel, retractionsFile);
|
write(retractionsModel, retractionsFile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void write(Model model, File file) {
|
private void write(Model model, File file) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -123,6 +123,10 @@ public class TBoxUpdater {
|
||||||
if (!newObject.equals(oldObject)) {
|
if (!newObject.equals(oldObject)) {
|
||||||
objects = siteModel.listObjectsOfProperty(subject,predicate);
|
objects = siteModel.listObjectsOfProperty(subject,predicate);
|
||||||
|
|
||||||
|
if (!objects.hasNext()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
RDFNode siteObject = objects.next();
|
RDFNode siteObject = objects.next();
|
||||||
if (objects.hasNext()) {
|
if (objects.hasNext()) {
|
||||||
logger.logError("Warning: found " + objects.toList().size() +
|
logger.logError("Warning: found " + objects.toList().size() +
|
||||||
|
@ -163,18 +167,18 @@ public class TBoxUpdater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
siteModel.add(additions);
|
Model actualAdditions = additions.difference(retractions);
|
||||||
record.recordAdditions(additions);
|
siteModel.add(actualAdditions);
|
||||||
siteModel.remove(retractions);
|
record.recordAdditions(actualAdditions);
|
||||||
record.recordRetractions(retractions);
|
Model actualRetractions = retractions.difference(additions);
|
||||||
|
siteModel.remove(actualRetractions);
|
||||||
|
record.recordRetractions(actualRetractions);
|
||||||
|
|
||||||
// log summary of changes
|
// log summary of changes
|
||||||
StmtIterator addedIter = additions.listStatements();
|
|
||||||
logger.log("Updated the default vitro annotation value for " +
|
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();
|
long numRemoved = actualRetractions.size() - actualAdditions.size();
|
||||||
int numRemoved = removedIter.toList().size() - addedIter.toList().size();
|
|
||||||
logger.log("Removed " + numRemoved +
|
logger.log("Removed " + numRemoved +
|
||||||
" superfluous vitro annotation property settings from the knowledge base.");
|
" superfluous vitro annotation property settings from the knowledge base.");
|
||||||
|
|
||||||
|
@ -183,15 +187,21 @@ public class TBoxUpdater {
|
||||||
//
|
//
|
||||||
|
|
||||||
Model newAnnotationSettings = newTboxModel.difference(oldTboxModel);
|
Model newAnnotationSettings = newTboxModel.difference(oldTboxModel);
|
||||||
siteModel.add(newAnnotationSettings);
|
Model newAnnotationSettingsToAdd = ModelFactory.createDefaultModel();
|
||||||
record.recordAdditions(newAnnotationSettings);
|
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
|
// log the additions
|
||||||
iter = newAnnotationSettings.listStatements();
|
|
||||||
|
|
||||||
//summary
|
//summary
|
||||||
logger.log("Added " + iter.toList().size() + " new annotation property settings to the knowledge base. This includes " +
|
logger.log("Added " + newAnnotationSettingsToAdd.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 " +
|
"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.");
|
"properties applied to new classes. No new annotation properties have been introduced.");
|
||||||
//details
|
//details
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
private final String SPARQL_CONSTRUCTS_DIR = DATA_DIR + "sparqlConstructs/";
|
private final String SPARQL_CONSTRUCTS_DIR = DATA_DIR + "sparqlConstructs/";
|
||||||
private final String MISC_REPLACEMENTS_FILE = DATA_DIR + "miscReplacements.rdf";
|
private final String MISC_REPLACEMENTS_FILE = DATA_DIR + "miscReplacements.rdf";
|
||||||
private final String OLD_TBOX_MODEL_DIR = DATA_DIR + "oldVersion/";
|
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 OLD_TBOX_ANNOTATIONS_DIR = DATA_DIR + "oldAnnotations/";
|
||||||
private final String NEW_TBOX_ANNOTATIONS_DIR = "/WEB-INF/ontologies/user";
|
private final String NEW_TBOX_ANNOTATIONS_DIR = "/WEB-INF/ontologies/user";
|
||||||
|
|
||||||
|
@ -91,7 +92,8 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
settings.setOntModelSelector(oms);
|
settings.setOntModelSelector(oms);
|
||||||
OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_MODEL_DIR));
|
OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_MODEL_DIR));
|
||||||
settings.setOldTBoxModel(oldTBoxModel);
|
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));
|
OntModel oldTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_ANNOTATIONS_DIR));
|
||||||
settings.setOldTBoxAnnotationsModel(oldTBoxAnnotationsModel);
|
settings.setOldTBoxAnnotationsModel(oldTBoxAnnotationsModel);
|
||||||
OntModel newTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(NEW_TBOX_ANNOTATIONS_DIR));
|
OntModel newTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(NEW_TBOX_ANNOTATIONS_DIR));
|
||||||
|
|
Loading…
Add table
Reference in a new issue