improvements and bugfixes for NIHVIVO-205 ontology upgrade

This commit is contained in:
bjl23 2010-04-02 16:10:14 +00:00
parent 36ab5f8357
commit 819f05039d
7 changed files with 222 additions and 158 deletions

View file

@ -3,11 +3,13 @@
package edu.cornell.mannlib.vitro.webapp.ontology.update;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
@ -36,6 +38,9 @@ public class ABoxUpdater {
private OntModel aboxModel;
private OntologyChangeLogger logger;
private OntologyChangeRecord record;
private OntClass OWL_THING = (ModelFactory
.createOntologyModel(OntModelSpec.OWL_MEM))
.createClass(OWL.Thing.getURI());
/**
*
@ -127,10 +132,9 @@ public class ABoxUpdater {
// Change class references in the subjects of statements
StmtIterator iter = aboxModel.listStatements(oldClass, (Property) null, (RDFNode) null);
//log summary of changes
logger.log("Changing " + iter.toList().size() + " subject referernces to the " + oldClass.getURI() + " class to be " + newClass.getURI());
while (iter.hasNext()) {
int count = 0;
while (iter.hasNext()) {
count++;
Statement oldStatement = iter.next();
Statement newStatement = ResourceFactory.createStatement(newClass, oldStatement.getPredicate(), oldStatement.getObject());
retractions.add(oldStatement);
@ -138,14 +142,18 @@ public class ABoxUpdater {
logChange(oldStatement, false);
logChange(newStatement,true);
}
//log summary of changes
if (count > 0) {
logger.log("Changing " + count + " subject referernces to the " + oldClass.getURI() + " class to be " + newClass.getURI());
}
// Change class references in the objects of statements
iter = aboxModel.listStatements((Resource) null, (Property) null, oldClass);
//log summary of changes
logger.log("Changing " + iter.toList().size() + " object referernces to the " + oldClass.getURI() + " class to be " + newClass.getURI());
while (iter.hasNext()) {
count = 0;
while (iter.hasNext()) {
count++;
Statement oldStatement = iter.next();
Statement newStatement = ResourceFactory.createStatement(oldStatement.getSubject(), oldStatement.getPredicate(), newClass);
retractions.add(oldStatement);
@ -155,6 +163,11 @@ public class ABoxUpdater {
logChanges(oldStatement, newStatement);
}
//log summary of changes
if (count > 0) {
logger.log("Changing " + count + " object referernces to the " + oldClass.getURI() + " class to be " + newClass.getURI());
}
aboxModel.remove(retractions);
record.recordRetractions(retractions);
aboxModel.add(additions);
@ -191,7 +204,18 @@ public class ABoxUpdater {
return;
}
ExtendedIterator<OntClass> classIter = addedClass.listSuperClasses(true);
List<OntClass> classList = addedClass.listSuperClasses(true).toList();
List<OntClass> namedClassList = new ArrayList<OntClass>();
for (OntClass ontClass : classList) {
if (!ontClass.isAnon()) {
namedClassList.add(ontClass);
}
}
if (namedClassList.isEmpty()) {
namedClassList.add(OWL_THING);
}
Iterator<OntClass> classIter = namedClassList.iterator();
while (classIter.hasNext()) {
OntClass parentOfAddedClass = classIter.next();
@ -209,11 +233,13 @@ public class ABoxUpdater {
indList += "\n\t" + stmt.getSubject().getURI();
}
//TODO - take out the detailed logging after our internal testing is completed.
logger.log("There are " + count + " individuals in the model that are of type " + parentOfAddedClass.getURI() + "," +
" and a new subclass of that class has been added: " + addedClass.getURI() + ". " +
"Please review the following individuals to see whether they should be of type: " + addedClass.getURI() + ":" +
indList );
if (count > 0) {
//TODO - take out the detailed logging after our internal testing is completed.
logger.log("There are " + count + " individuals in the model that are of type " + parentOfAddedClass.getURI() + "," +
" and a new subclass of that class has been added: " + addedClass.getURI() + ". " +
"Please review the following individuals to see whether they should be of type: " + addedClass.getURI() + ":" +
indList );
}
}
}
}
@ -246,7 +272,17 @@ public class ABoxUpdater {
return;
}
OntClass parent = deletedClass.getSuperClass();
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) {
@ -255,7 +291,7 @@ public class ABoxUpdater {
}
//log summary of changes
logger.log("CLass " + deletedClass.getURI() + " has been deleted. Any references to it in the knowledge base will be changed to " +
logger.log("Class " + deletedClass.getURI() + " has been deleted. Any references to it in the knowledge base will be changed to " +
replacementClass.getURI());
AtomicOntologyChange chg = new AtomicOntologyChange(deletedClass.getURI(), replacementClass.getURI(), AtomicChangeType.RENAME);
@ -281,37 +317,50 @@ public class ABoxUpdater {
private void addProperty(AtomicOntologyChange propObj) throws IOException{
OntProperty tempProperty = newTboxModel.getOntProperty
(propObj.getDestinationURI()).getSuperProperty();
(propObj.getDestinationURI());
if (tempProperty == null) {
logger.logError("Unable to find property " +
propObj.getDestinationURI() +
" in newTBoxModel");
return;
}
OntProperty superProperty = tempProperty.getSuperProperty();
if (superProperty == null) {
return;
}
int count = aboxModel.listStatements(
(Resource) null, tempProperty, (RDFNode) null).toSet().size();
logger.log("The Property " + tempProperty.getURI() +
"which occurs " + count + "times in database has " +
"a new subProperty " + propObj.getDestinationURI() +
"added to Core 1.0");
logger.log("Please review accordingly");
(Resource) null, superProperty, (RDFNode) null).toSet().size();
if (count > 0) {
logger.log("The Property " + superProperty.getURI() +
" which occurs " + count + " times in database has " +
"a new subProperty " + propObj.getDestinationURI() +
" in the new ontology version. ");
logger.log("Please review accordingly.");
}
}
private void deleteProperty(AtomicOntologyChange propObj) throws IOException{
OntProperty deletedProperty = oldTboxModel.getOntProperty(propObj.getSourceURI());
if (deletedProperty == null) {
// TODO - log
logger.logError("expected to find property "
+ propObj.getSourceURI() + " in oldTBoxModel");
return;
}
OntProperty replacementProperty = null;
OntProperty parent = deletedProperty.getSuperProperty();
OntProperty replacementProperty = newTboxModel.getOntProperty(parent.getURI());
while (replacementProperty == null) {
parent = parent.getSuperProperty();
if (parent == null) {
break;
}
replacementProperty = newTboxModel.getOntProperty(parent.getURI());
}
if (parent != null) {
replacementProperty = newTboxModel.getOntProperty(parent.getURI());
while (replacementProperty == null) {
parent = parent.getSuperProperty();
if (parent == null) {
break;
}
replacementProperty = newTboxModel.getOntProperty(parent.getURI());
}
}
Model deletePropModel = ModelFactory.createDefaultModel();
@ -325,9 +374,11 @@ public class ABoxUpdater {
aboxModel.leaveCriticalSection();
}
record.recordRetractions(deletePropModel);
logger.log(deletePropModel.size() + " statements using " +
propObj.getSourceURI() + " were removed. " +
" Please refer to the removed data model");
if (deletePropModel.size() > 0) {
logger.log(deletePropModel.size() + " statements using " +
propObj.getSourceURI() + " were removed. " +
" Please refer to the removed data model");
}
} else {
AtomicOntologyChange chg = new AtomicOntologyChange(deletedProperty.getURI(), replacementProperty.getURI(), AtomicChangeType.RENAME);
renameProperty(chg);
@ -341,7 +392,8 @@ public class ABoxUpdater {
OntProperty newProperty = newTboxModel.getOntProperty(propObj.getDestinationURI());
if (oldProperty == null || newProperty == null) {
// TODO - log
logger.logError(" expects non-null old property and new property "
+ "URIs");
return;
}
@ -369,10 +421,12 @@ public class ABoxUpdater {
record.recordAdditions(renamePropAddModel);
record.recordRetractions(renamePropRetractModel);
logger.log(renamePropRetractModel.size() + " statments using " +
"property " + propObj.getSourceURI() + " were changed to use " +
propObj.getDestinationURI() + " instead. Please refer to the " +
"removed data model and the added data model.");
if (renamePropRetractModel.size() > 0) {
logger.log(renamePropRetractModel.size() + " statments using " +
"property " + propObj.getSourceURI() + " were changed to use " +
propObj.getDestinationURI() + " instead. Please refer to the " +
"removed data model and the added data model.");
}
}

View file

@ -24,6 +24,12 @@ import java.util.ArrayList;
public class OntologyChangeParser {
private OntologyChangeLogger logger;
public OntologyChangeParser(OntologyChangeLogger logger) {
this.logger = logger;
}
/**
* @param args
* @throws IOException
@ -32,6 +38,8 @@ public class OntologyChangeParser {
@SuppressWarnings({ "unchecked", "null", "static-access" })
public ArrayList<AtomicOntologyChange> parseFile(String diffPath) throws IOException{
logger.log("Parsing PromptDiff file at " + diffPath);
AtomicOntologyChange changeObj;
ArrayList<AtomicOntologyChange> changeObjects = new ArrayList<AtomicOntologyChange>();
int countColumns = 0;
@ -42,56 +50,44 @@ public class OntologyChangeParser {
StringTokenizer stArr = null;
FileInputStream in = new FileInputStream(new File(diffPath));
CSVReader readFile = new SimpleReader();
readFile.setSeperator('\t');
List<String[]> rows = readFile.parse(in);
for(int rowNum = 0; rowNum < rows.size(); rowNum++){
String[] cols = rows.get(rowNum);
for(int col =0; col < cols.length; col++){
String column = cols[col].trim();
stArr = new StringTokenizer(column," ");
countColumns = stArr.countTokens();
if (cols.length != 5) {
logger.logError("Invalid PromptDiff data at row " + (rowNum + 1)
+ ". Expected 5 columns; found " + cols.length );
} else {
changeObj = new AtomicOntologyChange();
if(countColumns == 4){
URI = stArr.nextToken();
rename = stArr.nextToken();
String check = stArr.nextToken();
if(check.equalsIgnoreCase("Add")){
AtomicChangeType atomicChangeType = changeObj.getAtomicChangeType();
changeObj.setAtomicChangeType(atomicChangeType.ADD);
changeObj.setDestinationURI(URI);
changeObjects.add(changeObj);
}
else{
AtomicChangeType atomicChangeType = changeObj.getAtomicChangeType();
changeObj.setAtomicChangeType(atomicChangeType.DELETE);
changeObj.setSourceURI(URI);
changeObjects.add(changeObj);
}
}
else{
sourceURI = stArr.nextToken();
destinationURI = stArr.nextToken();
AtomicChangeType atomicChangeType = changeObj.getAtomicChangeType();
changeObj.setAtomicChangeType(atomicChangeType.RENAME);
changeObj.setSourceURI(sourceURI);
changeObj.setDestinationURI(destinationURI);
changeObjects.add(changeObj);
}
if (cols[0] != null && cols[0].length() > 0) {
changeObj.setSourceURI(cols[0]);
}
if (cols[1] != null && cols[1].length() > 0) {
changeObj.setDestinationURI(cols[1]);
}
if ("Yes".equals(cols[2])) {
changeObj.setAtomicChangeType(AtomicChangeType.RENAME);
} else if ("Delete".equals(cols[3])) {
changeObj.setAtomicChangeType(AtomicChangeType.DELETE);
} else if ("Add".equals(cols[3])) {
changeObj.setAtomicChangeType(AtomicChangeType.ADD);
} else {
logger.logError("Invalid rename or change type data: '" +
cols[2] + " " + cols[3] + "'");
}
changeObjects.add(changeObj);
}
}
if (changeObjects.size() == 0) {
logger.log("did not find any changes in PromptDiff output file.");
}
return changeObjects;
}

View file

@ -9,6 +9,7 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@ -87,7 +88,7 @@ public class OntologyUpdater {
updateTBoxAnnotations();
// perform additional additions and retractions
logger.closeLogs();
}
/**
@ -158,7 +159,8 @@ public class OntologyUpdater {
private List<AtomicOntologyChange> getAtomicOntologyChanges()
throws IOException {
return (new OntologyChangeParser()).parseFile(settings.getDiffFile());
return (new OntologyChangeParser(logger))
.parseFile(settings.getDiffFile());
}
@ -166,9 +168,9 @@ public class OntologyUpdater {
private void updateABox(AtomicOntologyChangeLists changes)
throws IOException {
// TODO get models from somewhere
OntModel oldTBoxModel = null;
OntModel newTBoxModel = null;
OntModel ABoxModel = null;
OntModel oldTBoxModel = settings.getOldTBoxModel();
OntModel newTBoxModel = settings.getNewTBoxModel();
OntModel ABoxModel = settings.getOntModelSelector().getABoxModel();
ABoxUpdater aboxUpdater = new ABoxUpdater(
oldTBoxModel, newTBoxModel, ABoxModel, logger, record);
aboxUpdater.processPropertyChanges(changes.getAtomicPropertyChanges());
@ -252,19 +254,20 @@ public class OntologyUpdater {
*/
private class AtomicOntologyChangeLists {
private List<AtomicOntologyChange> atomicClassChanges;
private List<AtomicOntologyChange> atomicClassChanges =
new ArrayList<AtomicOntologyChange>();
private List<AtomicOntologyChange> atomicPropertyChanges;
private List<AtomicOntologyChange> atomicPropertyChanges =
new ArrayList<AtomicOntologyChange>();
public AtomicOntologyChangeLists (
List<AtomicOntologyChange> changeList, OntModel newTboxModel,
OntModel oldTboxModel) throws IOException {
String str = null;
Iterator<AtomicOntologyChange> listItr = changeList.iterator();
while(listItr.hasNext()){
AtomicOntologyChange changeObj = listItr.next();
if(!changeObj.getSourceURI().equals(str)){
if(changeObj.getSourceURI() != null){
if(oldTboxModel.getOntProperty(changeObj.
getSourceURI()) != null){
atomicPropertyChanges.add(changeObj);
@ -279,7 +282,7 @@ public class OntologyUpdater {
}
}
else if(!changeObj.getDestinationURI().equals(str)){
else if(changeObj.getDestinationURI() != null){
if(newTboxModel.getOntProperty(changeObj.
getDestinationURI()) != null){
atomicPropertyChanges.add(changeObj);
@ -298,7 +301,7 @@ public class OntologyUpdater {
+ "Change Object skipped" );
}
}
logger.log("Property and Class change Object lists seperated");
//logger.log("Property and Class change Object lists separated");
}
public List<AtomicOntologyChange> getAtomicClassChanges() {

View file

@ -33,6 +33,7 @@ public class SimpleOntologyChangeLogger implements OntologyChangeLogger {
String methodName = ((StackTraceElement)elements[1]).getMethodName();
logWriter.write(className + "." + methodName + ": " + logMessage + "\n");
logWriter.flush();
}
public void logError(String errorMessage) throws IOException {
@ -45,6 +46,7 @@ public class SimpleOntologyChangeLogger implements OntologyChangeLogger {
int lineNumber = ((StackTraceElement)elements[1]).getLineNumber();
errorWriter.write(className + "." + methodName + " line " + lineNumber + ": " + errorMessage + "\n");
errorWriter.flush();
}
public void closeLogs() throws IOException {

View file

@ -3,6 +3,8 @@ package edu.cornell.mannlib.vitro.webapp.ontology.update;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -25,12 +27,16 @@ public class SimpleOntologyChangeRecord implements OntologyChangeRecord {
public SimpleOntologyChangeRecord(
String additionsFile, String retractionsFile) {
this.additionsFile = new File(additionsFile);
if (!this.additionsFile.exists()) {
throw new RuntimeException(this.getClass().getName() +
try {
FileWriter test = new FileWriter(additionsFile);
} catch (IOException ioe) {
throw new RuntimeException(this.getClass().getName() +
" unable to create required file at " + additionsFile);
}
}
this.retractionsFile = new File(retractionsFile);
if (!this.retractionsFile.exists()) {
try {
FileWriter test = new FileWriter(retractionsFile);
} catch (IOException ioe) {
throw new RuntimeException(this.getClass().getName() +
" unable to create required file at " + retractionsFile);
}

View file

@ -103,35 +103,35 @@ public class TBoxUpdater {
NodeIterator objects = newTboxModel.listObjectsOfProperty(subject, predicate);
if ((objects == null) || (objects.toList().size() == 0) ) {
logger.logError("Error: found a statement for subject = " + subject.getURI() +
" and property = " + predicate.getURI() +
" in the old version but not the new version of the ontology.");
continue;
} else if (objects.toList().size() > 1) {
if ((objects == null) || (!objects.hasNext()) ) {
retractions.add(siteModel.listStatements(subject, predicate, (RDFNode) null));
//logger.log("Error: found a statement for subject = " + subject.getURI() +
// " and property = " + predicate.getURI() +
// " in the old version but not the new version of the ontology.");
continue;
}
RDFNode newObject = objects.next();
if (objects.hasNext()) {
logger.logError("Error: found " + objects.toList().size() +
" statements with subject = " + subject.getURI() +
" and property = " + predicate.getURI() +
" in the new version of the ontology. (maximum of one is expected)");
continue;
continue;
}
RDFNode newObject = objects.next();
if (!newObject.equals(oldObject)) {
objects = siteModel.listObjectsOfProperty(subject,predicate);
if (objects.toList().size() > 1) {
RDFNode siteObject = objects.next();
if (objects.hasNext()) {
logger.logError("Warning: found " + objects.toList().size() +
" statements with subject = " + subject.getURI() +
" and property = " + predicate.getURI() +
" in the site model (maximum of one is expected). +" +
" did not perform any update on this property");
continue;
continue;
}
RDFNode siteObject = objects.next();
if (!siteObject.equals(oldObject)) {
try {
@ -149,11 +149,11 @@ public class TBoxUpdater {
additions.add(subject, predicate, newObject);
logger.log("Changed the value of property " + predicate.getURI() +
" of class = " + subject.getURI() +
" of subject = " + subject.getURI() +
" from " +
(newObject.isLiteral() ? ((Resource)oldObject).getURI() : ((Literal)oldObject).getLexicalForm()) +
(oldObject.isResource() ? ((Resource)oldObject).getURI() : ((Literal)oldObject).getLexicalForm()) +
" to " +
(newObject.isLiteral() ? ((Resource)newObject).getURI() : ((Literal)newObject).getLexicalForm()) +
(newObject.isResource() ? ((Resource)newObject).getURI() : ((Literal)newObject).getLexicalForm()) +
" in the knowledge base:\n");
} catch (Exception e) {
logger.logError("Error trying to change the value of property " + predicate.getURI() +

View file

@ -44,7 +44,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
private final String DATA_DIR = "/WEB-INF/ontologies/update/";
private final String LOG_DIR = "logs/";
private final String REMOVED_DATA_DIR = "removedData/";
private final String CHANGED_DATA_DIR = "changedData/";
private final String ASK_QUERY_FILE = DATA_DIR + "ask.sparql";
private final String SUCCESS_ASSERTIONS_FILE = DATA_DIR + "success.n3";
private final String SUCCESS_RDF_FORMAT = "N3";
@ -53,8 +53,10 @@ public class UpdateKnowledgeBase implements ServletContextListener {
"knowledgeBaseUpdate.log";
private final String ERROR_LOG_FILE = DATA_DIR + LOG_DIR +
"knowledgeBaseUpdate.error.log";
private final String REMOVED_DATA_FILE = DATA_DIR + REMOVED_DATA_DIR +
private final String REMOVED_DATA_FILE = DATA_DIR + CHANGED_DATA_DIR +
"removedData.rdf";
private final String ADDED_DATA_FILE = DATA_DIR + CHANGED_DATA_DIR +
"addedData.rdf";
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/";
@ -63,53 +65,54 @@ public class UpdateKnowledgeBase implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
// TODO remove when ready
if (true) {
return;
}
ServletContext ctx = sce.getServletContext();
OntModelSelector oms = new SimpleOntModelSelector(
(OntModel) sce.getServletContext().getAttribute(
JenaBaseDao.ASSERTIONS_ONT_MODEL_ATTRIBUTE_NAME));
OntologyUpdateSettings settings = new OntologyUpdateSettings();
settings.setAskQueryFile(ctx.getRealPath(ASK_QUERY_FILE));
settings.setDataDir(ctx.getRealPath(DATA_DIR));
settings.setSparqlConstructsDir(ctx.getRealPath(SPARQL_CONSTRUCTS_DIR));
settings.setDiffFile(ctx.getRealPath(DIFF_FILE));
settings.setSuccessAssertionsFile(
ctx.getRealPath(SUCCESS_ASSERTIONS_FILE));
settings.setSuccessRDFFormat(ctx.getRealPath(SUCCESS_RDF_FORMAT));
settings.setLogFile(ctx.getRealPath(LOG_FILE));
settings.setErrorLogFile(ctx.getRealPath(ERROR_LOG_FILE));
settings.setRemovedDataFile(ctx.getRealPath(REMOVED_DATA_FILE));
WebappDaoFactory wadf = (WebappDaoFactory) ctx.getAttribute("webappDaoFactory");
settings.setDefaultNamespace(wadf.getDefaultNamespace());
OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_MODEL_DIR));
settings.setOldTBoxModel(oldTBoxModel);
settings.setNewTBoxModel(oms.getTBoxModel());
OntModel oldTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_ANNOTATIONS_DIR));
settings.setOldTBoxAnnotationsModel(oldTBoxAnnotationsModel);
OntModel newTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(NEW_TBOX_ANNOTATIONS_DIR));
settings.setNewTBoxAnnotationsModel(newTBoxAnnotationsModel);
try {
doMiscAppMetadataReplacements(ctx.getRealPath(MISC_REPLACEMENTS_FILE), oms);
(new OntologyUpdater(settings)).update();
} catch (IOException ioe) {
String errMsg = "IOException updating knowledge base " +
"for ontology changes: ";
// Tomcat doesn't always seem to print exceptions thrown from
// context listeners
System.out.println(errMsg);
ioe.printStackTrace();
throw new RuntimeException(errMsg, ioe);
}
ServletContext ctx = sce.getServletContext();
OntModelSelector oms = new SimpleOntModelSelector(
(OntModel) sce.getServletContext().getAttribute(
JenaBaseDao.ASSERTIONS_ONT_MODEL_ATTRIBUTE_NAME));
OntologyUpdateSettings settings = new OntologyUpdateSettings();
settings.setAskQueryFile(ctx.getRealPath(ASK_QUERY_FILE));
settings.setDataDir(ctx.getRealPath(DATA_DIR));
settings.setSparqlConstructsDir(ctx.getRealPath(SPARQL_CONSTRUCTS_DIR));
settings.setDiffFile(ctx.getRealPath(DIFF_FILE));
settings.setSuccessAssertionsFile(
ctx.getRealPath(SUCCESS_ASSERTIONS_FILE));
settings.setSuccessRDFFormat(ctx.getRealPath(SUCCESS_RDF_FORMAT));
settings.setLogFile(ctx.getRealPath(LOG_FILE));
settings.setErrorLogFile(ctx.getRealPath(ERROR_LOG_FILE));
settings.setAddedDataFile(ctx.getRealPath(ADDED_DATA_FILE));
settings.setRemovedDataFile(ctx.getRealPath(REMOVED_DATA_FILE));
WebappDaoFactory wadf = (WebappDaoFactory) ctx.getAttribute("webappDaoFactory");
settings.setDefaultNamespace(wadf.getDefaultNamespace());
settings.setOntModelSelector(oms);
OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_MODEL_DIR));
settings.setOldTBoxModel(oldTBoxModel);
settings.setNewTBoxModel(oms.getTBoxModel());
OntModel oldTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_ANNOTATIONS_DIR));
settings.setOldTBoxAnnotationsModel(oldTBoxAnnotationsModel);
OntModel newTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(NEW_TBOX_ANNOTATIONS_DIR));
settings.setNewTBoxAnnotationsModel(newTBoxAnnotationsModel);
try {
doMiscAppMetadataReplacements(ctx.getRealPath(MISC_REPLACEMENTS_FILE), oms);
(new OntologyUpdater(settings)).update();
} catch (IOException ioe) {
String errMsg = "IOException updating knowledge base " +
"for ontology changes: ";
// Tomcat doesn't always seem to print exceptions thrown from
// context listeners
System.out.println(errMsg);
ioe.printStackTrace();
throw new RuntimeException(errMsg, ioe);
}
} catch (Throwable t) {
t.printStackTrace();
}
}