miscellaneous small updates made while testing the 1.0 to 1.1 upgrade process.

This commit is contained in:
sjm222 2010-07-12 01:41:44 +00:00
parent 4241506730
commit 42b0b79377
4 changed files with 95 additions and 96 deletions

View file

@ -110,7 +110,7 @@ public class ABoxUpdater {
/**
*
* Update a knowledge based on a class rename in the ontology. All references to the
* Update the knowledge base for a class rename in the ontology. All references to the
* old class URI in either the subject or the object position of a statement are
* changed to use the new class URI.
*
@ -212,7 +212,7 @@ public class ABoxUpdater {
/**
*
* Examine a knowledge based on a class addition to the ontology and
* Examine the knowledge base for a class addition to the ontology and
* add messages to the change log indicating where manual review is
* recommended. If the added class has a direct parent in the new ontology
* that is not OWL.Thing, and if the knowledge base contains individuals
@ -275,6 +275,7 @@ public class ABoxUpdater {
}
}
/**
*
* Update a knowledge base to account for a class deletion in the ontology.
@ -328,6 +329,7 @@ public class ABoxUpdater {
renameClass(chg);
}
public void processPropertyChanges(List<AtomicOntologyChange> changes) throws IOException {
Iterator<AtomicOntologyChange> propItr = changes.iterator();
while(propItr.hasNext()){
@ -452,7 +454,7 @@ public class ABoxUpdater {
record.recordRetractions(renamePropRetractModel);
if (renamePropRetractModel.size() > 0) {
logger.log(renamePropRetractModel.size() + " statment" +
logger.log(renamePropRetractModel.size() + " statement" +
((renamePropRetractModel.size() > 1) ? "s" : "") +
" with predicate " + propObj.getSourceURI() + " " +
((renamePropRetractModel.size() > 1) ? "were" : "was")

View file

@ -2,7 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.ontology.update;
import com.hp.hpl.jena.ontology.OntModel;
/**
*
* We need to document what is in source and destinationURI for each

View file

@ -12,14 +12,8 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
@ -27,9 +21,6 @@ import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
@ -45,9 +36,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
*/
public class OntologyUpdater {
private final Log log = LogFactory.getLog(OntologyUpdater.class);
//private final Log log = LogFactory.getLog(OntologyUpdater.class);
private OntologyUpdateSettings settings;
private OntologyChangeLogger logger;
@ -55,10 +44,8 @@ public class OntologyUpdater {
public OntologyUpdater(OntologyUpdateSettings settings) {
this.settings = settings;
this.logger = new SimpleOntologyChangeLogger(settings.getLogFile(),
settings.getErrorLogFile());
this.record = new SimpleOntologyChangeRecord(
settings.getAddedDataFile(), settings.getRemovedDataFile());
this.logger = new SimpleOntologyChangeLogger(settings.getLogFile(), settings.getErrorLogFile());
this.record = new SimpleOntologyChangeRecord(settings.getAddedDataFile(), settings.getRemovedDataFile());
}
public boolean update() throws IOException {
@ -67,8 +54,14 @@ public class OntologyUpdater {
boolean updateRequired = updateRequired();
if (updateRequired) {
performUpdate();
try {
performUpdate();
} catch (Exception e) {
logger.logError(e.getMessage());
e.printStackTrace();
}
if (!logger.errorsWritten()) {
// add assertions to the knowledge base showing that the
// update was successful, so we don't need to run it again.
@ -78,6 +71,7 @@ public class OntologyUpdater {
record.writeChanges();
logger.closeLogs();
}
return updateRequired;
@ -86,20 +80,17 @@ public class OntologyUpdater {
private void performUpdate() throws IOException {
performSparqlConstructs(settings.getSparqlConstructsDir(),
settings.getOntModelSelector().getABoxModel());
performSparqlConstructs(settings.getSparqlConstructsDir(), settings.getOntModelSelector().getABoxModel());
List<AtomicOntologyChange> rawChanges = getAtomicOntologyChanges();
AtomicOntologyChangeLists changes =
new AtomicOntologyChangeLists(rawChanges,
settings.getNewTBoxModel(),
settings.getOldTBoxModel());
//process the TBox before the ABox
updateTBoxAnnotations();
updateABox(changes);
AtomicOntologyChangeLists changes = new AtomicOntologyChangeLists(rawChanges,
settings.getNewTBoxModel(),
settings.getOldTBoxModel());
//process the TBox before the ABox
updateTBoxAnnotations();
updateABox(changes);
}
@ -195,7 +186,8 @@ public class OntologyUpdater {
private void updateABox(AtomicOntologyChangeLists changes)
throws IOException {
// TODO get models from somewhere
OntModel oldTBoxModel = settings.getOldTBoxModel();
OntModel newTBoxModel = settings.getNewTBoxModel();
OntModel ABoxModel = settings.getOntModelSelector().getABoxModel();
@ -204,7 +196,7 @@ public class OntologyUpdater {
settings.getNewTBoxAnnotationsModel(), logger, record);
aboxUpdater.processPropertyChanges(changes.getAtomicPropertyChanges());
aboxUpdater.processClassChanges(changes.getAtomicClassChanges());
// run additional SPARQL CONSTRUCTS
}
private void updateTBoxAnnotations() throws IOException {
@ -255,6 +247,7 @@ public class OntologyUpdater {
private void assertSuccess() throws FileNotFoundException, IOException {
try {
Model m = settings.getOntModelSelector().getApplicationMetadataModel();
File successAssertionsFile =
new File(settings.getSuccessAssertionsFile());
@ -292,35 +285,33 @@ public class OntologyUpdater {
OntModel oldTboxModel) throws IOException {
Iterator<AtomicOntologyChange> listItr = changeList.iterator();
while(listItr.hasNext()){
while(listItr.hasNext()) {
AtomicOntologyChange changeObj = listItr.next();
if(changeObj.getSourceURI() != null){
if(oldTboxModel.getOntProperty(changeObj.
getSourceURI()) != null){
if (changeObj.getSourceURI() != null){
if (oldTboxModel.getOntProperty(changeObj.getSourceURI()) != null){
atomicPropertyChanges.add(changeObj);
}
else if(oldTboxModel.getOntClass(changeObj.
getSourceURI()) != null) {
else if (oldTboxModel.getOntClass(changeObj.getSourceURI()) != null) {
atomicClassChanges.add(changeObj);
}
else{
logger.logError("Source URI is neither a Property" +
" nor a Class. " + "Change Object skipped");
" nor a Class. " + "Change Object skipped for sourceURI: " + changeObj.getSourceURI());
}
}
else if(changeObj.getDestinationURI() != null){
if(newTboxModel.getOntProperty(changeObj.
getDestinationURI()) != null){
if (newTboxModel.getOntProperty(changeObj.getDestinationURI()) != null) {
atomicPropertyChanges.add(changeObj);
}
else if(newTboxModel.getOntClass(changeObj.
getDestinationURI()) != null){
} else if(newTboxModel.getOntClass(changeObj.
getDestinationURI()) != null) {
atomicClassChanges.add(changeObj);
}
else{
} else{
logger.logError("Destination URI is neither a Property" +
" nor a Class. " + "Change Object skipped");
" nor a Class. " + "Change Object skipped for destinationURI: " + changeObj.getDestinationURI());
}
}
else{

View file

@ -22,8 +22,8 @@ import com.hp.hpl.jena.shared.Lock;
*/
public class TBoxUpdater {
private OntModel oldTboxModel;
private OntModel newTboxModel;
private OntModel oldTboxAnnotationsModel;
private OntModel newTboxAnnotationsModel;
private OntModel siteModel;
private OntologyChangeLogger logger;
private OntologyChangeRecord record;
@ -32,8 +32,8 @@ public class TBoxUpdater {
*
* Constructor
*
* @param oldTboxModel - previous version of the ontology
* @param newTboxModel - new version of the ontology
* @param oldTboxAnnotationsModel - previous version of the annotations in the ontology
* @param newTboxAnnotationsModel - new version of the annotations in the ontology
* @param siteModel - the knowledge base to be updated
* @param logger - for writing to the change log
* and the error log.
@ -41,14 +41,14 @@ public class TBoxUpdater {
* and the retractions model.
*
*/
public TBoxUpdater(OntModel oldTboxModel,
OntModel newTboxModel,
public TBoxUpdater(OntModel oldTboxAnnotationsModel,
OntModel newTboxAnnotationsModel,
OntModel siteModel,
OntologyChangeLogger logger,
OntologyChangeRecord record) {
this.oldTboxModel = oldTboxModel;
this.newTboxModel = newTboxModel;
this.oldTboxAnnotationsModel = oldTboxAnnotationsModel;
this.newTboxAnnotationsModel = newTboxAnnotationsModel;
this.siteModel = siteModel;
this.logger = logger;
this.record = record;
@ -56,12 +56,12 @@ public class TBoxUpdater {
/**
*
* Update a knowledge base to align with changes vitro annotation property default
* Update a knowledge base to align with changes to vitro annotation property default
* values in a new version of the ontology. The two versions of the ontology and the
* knowledge base to be updated are provided in the class constructor and are
* referenced via class level variables.
*
* If the default value (i.e. the value that is provided in the vivo-core-
* If the default value (i.e. the value that is provided in the vivo-core
* annotations files) of a vitro annotation property has been changed for a vivo
* core class, and that default value has not been changed in the site knowledge
* base, then update the value in the site knowledge base to be the new default.
@ -76,7 +76,7 @@ public class TBoxUpdater {
* Writes to the change log file, the error log file, and the incremental change
* knowledge base.
*
* Note: as specified, this method for now assume that no new vitro annotation
* Note: as specified, this method for now assumes that no new vitro annotation
* properties have been introduced. This should be updated for future versions.
*/
public void updateVitroPropertyDefaultValues() throws IOException {
@ -92,8 +92,8 @@ public class TBoxUpdater {
// if the default has changed in the new version of the ontology AND if
// the site hasn't overidden the previous default in their knowledge base.
StmtIterator iter = oldTboxModel.listStatements();
StmtIterator iter = oldTboxAnnotationsModel.listStatements();
int stmtCount = 0;
while (iter.hasNext()) {
@ -103,43 +103,53 @@ public class TBoxUpdater {
Resource subject = stmt.getSubject();
Property predicate = stmt.getPredicate();
RDFNode oldObject = stmt.getObject();
NodeIterator newObjects = newTboxAnnotationsModel.listObjectsOfProperty(subject, predicate);
NodeIterator objects = newTboxModel.listObjectsOfProperty(subject, predicate);
if ((objects == null) || (!objects.hasNext()) ) {
if ((newObjects == null) || (!newObjects.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() +
RDFNode newObject = newObjects.next();
int i = 1;
while (newObjects.hasNext()) {
i++;
newObjects.next();
}
if (i > 1) {
logger.log("WARNING: found " + i +
" statements with subject = " + subject.getURI() +
" and property = " + predicate.getURI() +
" in the new version of the ontology. (maximum of one is expected)");
" in the new version of the annotations ontology. (maximum of one is expected)");
continue;
}
if (!newObject.equals(oldObject)) {
objects = siteModel.listObjectsOfProperty(subject,predicate);
NodeIterator siteObjects = siteModel.listObjectsOfProperty(subject,predicate);
if (!objects.hasNext()) {
if (siteObjects == null || !siteObjects.hasNext()) {
continue;
}
RDFNode siteObject = objects.next();
if (objects.hasNext()) {
logger.logError("Warning: found " + objects.toList().size() +
RDFNode siteObject = siteObjects.next();
i = 1;
while (siteObjects.hasNext()) {
i++;
siteObjects.next();
}
if (i > 1) {
logger.log("WARNING: found " + i +
" 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;
" in the site annotations model. (maximum of one is expected). ");
continue;
}
if (siteObject.equals(oldObject)) {
try {
StmtIterator it = siteModel.listStatements(subject, predicate, (RDFNode)null);
@ -169,7 +179,7 @@ public class TBoxUpdater {
}
}
}
Model actualAdditions = additions.difference(retractions);
siteModel.add(actualAdditions);
record.recordAdditions(actualAdditions);
@ -180,7 +190,7 @@ public class TBoxUpdater {
// log summary of changes
if (actualAdditions.size() > 0) {
logger.log("Updated the default vitro annotation value for " +
actualAdditions.size() + " statments in the knowledge base.");
actualAdditions.size() + " statements in the knowledge base.");
}
long numRemoved = actualRetractions.size() - actualAdditions.size();
@ -193,15 +203,22 @@ public class TBoxUpdater {
// into the site model.
//
Model newAnnotationSettings = newTboxModel.difference(oldTboxModel);
Model newAnnotationSettings = newTboxAnnotationsModel.difference(oldTboxAnnotationsModel);
Model newAnnotationSettingsToAdd = ModelFactory.createDefaultModel();
StmtIterator newStmtIt = newAnnotationSettings.listStatements();
while (newStmtIt.hasNext()) {
Statement stmt = newStmtIt.next();
if (!siteModel.contains(stmt)) {
newAnnotationSettingsToAdd.add(stmt);
// TODO remove this for production
logger.log( "adding Statement: subject = " + stmt.getSubject().getURI() +
" property = " + stmt.getPredicate().getURI() +
" object = " + (stmt.getObject().isLiteral() ? ((Literal)stmt.getObject()).getLexicalForm()
: ((Resource)stmt.getObject()).getURI()));
}
}
siteModel.add(newAnnotationSettingsToAdd);
record.recordAdditions(newAnnotationSettingsToAdd);
@ -213,16 +230,6 @@ public class TBoxUpdater {
"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
while (iter.hasNext()) {
Statement statement = iter.next();
logger.log( "added Statement: subject = " + statement.getSubject().getURI() +
" property = " + statement.getPredicate().getURI() +
" object = " + (statement.getObject().isLiteral() ? ((Resource)statement.getObject()).getURI()
: ((Literal)statement.getObject()).getLexicalForm()));
}
} finally {
siteModel.leaveCriticalSection();