incremental development for NIHVIVO-1286
This commit is contained in:
parent
b52832208d
commit
98d569d3fa
4 changed files with 96 additions and 23 deletions
|
@ -634,17 +634,14 @@ public class ABoxUpdater {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logChange(Statement statement, boolean add) throws IOException {
|
public void logChange(Statement statement, boolean add) throws IOException {
|
||||||
logger.log( (add ? "Added " : "Removed") + "Statement: subject = " + statement.getSubject().getURI() +
|
logger.log( (add ? "Added" : "Removed") + stmtString(statement));
|
||||||
" property = " + statement.getPredicate().getURI() +
|
|
||||||
" object = " + (statement.getObject().isLiteral() ? ((Literal)statement.getObject()).getLexicalForm()
|
|
||||||
: ((Resource)statement.getObject()).getURI()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String stmtString(Statement statement) {
|
public static String stmtString(Statement statement) {
|
||||||
return " subject = " + statement.getSubject().getURI() +
|
return " [subject = " + statement.getSubject().getURI() +
|
||||||
" property = " + statement.getPredicate().getURI() +
|
"] [property = " + statement.getPredicate().getURI() +
|
||||||
" object = " + (statement.getObject().isLiteral() ? ((Literal)statement.getObject()).getLexicalForm() + " (Literal)"
|
"] [object = " + (statement.getObject().isLiteral() ? ((Literal)statement.getObject()).getLexicalForm() + " (Literal)"
|
||||||
: ((Resource)statement.getObject()).getURI() + " (Resource)");
|
: ((Resource)statement.getObject()).getURI() + " (Resource)") + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,7 @@ public class DateTimeMigration {
|
||||||
newStmt = ResourceFactory.createStatement(stmt.getSubject(), stmt.getPredicate(), getDateTimeLiteral(date) );
|
newStmt = ResourceFactory.createStatement(stmt.getSubject(), stmt.getPredicate(), getDateTimeLiteral(date) );
|
||||||
} catch (ParseException pe) {
|
} catch (ParseException pe) {
|
||||||
logger.log("Parse Exception for year literal: " + stmt.getObject().asLiteral().getLexicalForm() +
|
logger.log("Parse Exception for year literal: " + stmt.getObject().asLiteral().getLexicalForm() +
|
||||||
". The following statement has been removed from the knowledge base " + stmtString(stmt));
|
". The following statement has been removed from the knowledge base " + ABoxUpdater.stmtString(stmt));
|
||||||
}
|
}
|
||||||
} else if (ymPrecisionURI.equals(precision)) {
|
} else if (ymPrecisionURI.equals(precision)) {
|
||||||
try {
|
try {
|
||||||
|
@ -183,7 +183,7 @@ public class DateTimeMigration {
|
||||||
newStmt = ResourceFactory.createStatement(stmt.getSubject(), stmt.getPredicate(), getDateTimeLiteral(date) );
|
newStmt = ResourceFactory.createStatement(stmt.getSubject(), stmt.getPredicate(), getDateTimeLiteral(date) );
|
||||||
} catch (ParseException pe) {
|
} catch (ParseException pe) {
|
||||||
logger.log("Parse Exception for yearMonth literal: " + stmt.getObject().asLiteral().getLexicalForm() +
|
logger.log("Parse Exception for yearMonth literal: " + stmt.getObject().asLiteral().getLexicalForm() +
|
||||||
". The following statement has been removed from the knowledge base " + stmtString(stmt));
|
". The following statement has been removed from the knowledge base " + ABoxUpdater.stmtString(stmt));
|
||||||
}
|
}
|
||||||
} else if (ymdPrecisionURI.equals(precision)) {
|
} else if (ymdPrecisionURI.equals(precision)) {
|
||||||
try {
|
try {
|
||||||
|
@ -191,14 +191,14 @@ public class DateTimeMigration {
|
||||||
newStmt = ResourceFactory.createStatement(stmt.getSubject(), stmt.getPredicate(), getDateTimeLiteral(date) );
|
newStmt = ResourceFactory.createStatement(stmt.getSubject(), stmt.getPredicate(), getDateTimeLiteral(date) );
|
||||||
} catch (ParseException pe) {
|
} catch (ParseException pe) {
|
||||||
logger.log("Parse Exception for yearMonthDay literal: " + stmt.getObject().asLiteral().getLexicalForm() +
|
logger.log("Parse Exception for yearMonthDay literal: " + stmt.getObject().asLiteral().getLexicalForm() +
|
||||||
". The following statement has been removed from the knowledge base " + stmtString(stmt));
|
". The following statement has been removed from the knowledge base " + ABoxUpdater.stmtString(stmt));
|
||||||
}
|
}
|
||||||
} else if (ymdtPrecisionURI.equals(precision)) {
|
} else if (ymdtPrecisionURI.equals(precision)) {
|
||||||
logger.log("WARNING: unhandled precision found for individual " + stmt.getSubject().getURI() + ": " + precision +
|
logger.log("WARNING: unhandled precision found for individual " + stmt.getSubject().getURI() + ": " + precision +
|
||||||
". The following statement has been removed from the knowledge base " + stmtString(stmt));
|
". The following statement has been removed from the knowledge base " + ABoxUpdater.stmtString(stmt));
|
||||||
} else {
|
} else {
|
||||||
logger.log("WARNING: unrecognized precision found for individual " + stmt.getSubject().getURI() + ": " + precision +
|
logger.log("WARNING: unrecognized precision found for individual " + stmt.getSubject().getURI() + ": " + precision +
|
||||||
". The following statement has been removed from the knowledge base " + stmtString(stmt));
|
". The following statement has been removed from the knowledge base " + ABoxUpdater.stmtString(stmt));
|
||||||
}
|
}
|
||||||
|
|
||||||
retractions.add(stmt);
|
retractions.add(stmt);
|
||||||
|
@ -256,11 +256,4 @@ public class DateTimeMigration {
|
||||||
String dateString = dt.toString().substring(0, dt.toString().length()-1);
|
String dateString = dt.toString().substring(0, dt.toString().length()-1);
|
||||||
return ResourceFactory.createTypedLiteral(dateString, XSDDatatype.XSDdateTime);
|
return ResourceFactory.createTypedLiteral(dateString, XSDDatatype.XSDdateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String stmtString(Statement statement) {
|
|
||||||
return " subject = " + statement.getSubject().getURI() +
|
|
||||||
" property = " + statement.getPredicate().getURI() +
|
|
||||||
" object = " + (statement.getObject().isLiteral() ? ((Literal)statement.getObject()).getLexicalForm() + " (Literal)"
|
|
||||||
: ((Resource)statement.getObject()).getURI() + " (Resource)");
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -243,9 +243,13 @@ public class OntologyUpdater {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTBoxAnnotations() throws IOException {
|
private void updateTBoxAnnotations() throws IOException {
|
||||||
(new TBoxUpdater(settings.getOldTBoxAnnotationsModel(),
|
|
||||||
|
TBoxUpdater tboxUpdater = new TBoxUpdater(settings.getOldTBoxAnnotationsModel(),
|
||||||
settings.getNewTBoxAnnotationsModel(),
|
settings.getNewTBoxAnnotationsModel(),
|
||||||
settings.getOntModelSelector().getABoxModel(), logger, record)).updateVitroPropertyDefaultValues();
|
settings.getOntModelSelector().getABoxModel(), logger, record);
|
||||||
|
|
||||||
|
tboxUpdater.updateVitroPropertyDefaultValues();
|
||||||
|
tboxUpdater.updateVitroAnnotationsModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,7 +5,9 @@ package edu.cornell.mannlib.vitro.webapp.ontology.update;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.ontology.DatatypeProperty;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
@ -16,6 +18,7 @@ import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
import com.hp.hpl.jena.rdf.model.Statement;
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
@ -33,6 +36,11 @@ public class TBoxUpdater {
|
||||||
private OntologyChangeRecord record;
|
private OntologyChangeRecord record;
|
||||||
private boolean detailLogs = false;
|
private boolean detailLogs = false;
|
||||||
|
|
||||||
|
private static final String classGroupURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#ClassGroup";
|
||||||
|
private Resource classGroupClass = (ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM)).createResource(classGroupURI);
|
||||||
|
private static final String inClassGroupURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#inClassGroup";
|
||||||
|
private Property inClassGroupProp = (ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM)).createProperty(inClassGroupURI);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -297,4 +305,75 @@ public class TBoxUpdater {
|
||||||
siteModel.leaveCriticalSection();
|
siteModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Update a knowledge base to align with changes to the vitro annotation model
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Currently, this method only handles deletions of a ClassGroup
|
||||||
|
*
|
||||||
|
* Writes to the change log file, the error log file, and the incremental change
|
||||||
|
* knowledge base.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void updateVitroAnnotationsModel() throws IOException {
|
||||||
|
|
||||||
|
// for each ClassGroup in the old vitro annotations model: if it is not in
|
||||||
|
// the new vitro annotations model and the site has no classes asserted to
|
||||||
|
// be in that class group then delete it.
|
||||||
|
// TODO: the site will have classes asserted to be in it if we have switched
|
||||||
|
// the default assignment in the new version but haven't migration yet. How
|
||||||
|
// to handle this?
|
||||||
|
|
||||||
|
siteModel.enterCriticalSection(Lock.WRITE);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Model retractions = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
StmtIterator iter = oldTboxAnnotationsModel.listStatements((Resource) null, RDF.type, classGroupClass);
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Statement stmt = iter.next();
|
||||||
|
|
||||||
|
if (!newTboxAnnotationsModel.contains(stmt) && !usesGroup(siteModel, stmt.getSubject())) {
|
||||||
|
count++;
|
||||||
|
retractions.add(siteModel.listStatements(stmt.getSubject(),(Property) null,(RDFNode)null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (retractions.size() > 0) {
|
||||||
|
siteModel.remove(retractions);
|
||||||
|
record.recordRetractions(retractions);
|
||||||
|
|
||||||
|
// log summary of changes
|
||||||
|
if (retractions.size() > 0) {
|
||||||
|
logger.log("Removed " + count + " Class Group" + (count > 1 ? "s" : "") + " from the annotations model.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
siteModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we were going to handle add, this is the logic:
|
||||||
|
// for each ClassGroup in new old vitro annotations model: if it is not in
|
||||||
|
// the old vitro annotations and it is not in the site model, then
|
||||||
|
// add it.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean usesGroup(Model model, Resource theClassGroup) throws IOException {
|
||||||
|
|
||||||
|
model.enterCriticalSection(Lock.READ);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return (model.contains((Resource) null, inClassGroupProp, theClassGroup) ? true : false);
|
||||||
|
} finally {
|
||||||
|
model.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue