merging in 1.1 branch changes

This commit is contained in:
sjm222 2010-08-03 14:25:31 +00:00
parent 8bef6badf4
commit 802e5bc1ab
3 changed files with 88 additions and 33 deletions

View file

@ -267,7 +267,7 @@ public class ABoxUpdater {
if (count > 0) { if (count > 0) {
//TODO - take out the detailed logging after our internal testing is completed. //TODO - take out the detailed logging after our internal testing is completed.
logger.log("There " + ((count > 1) ? "are" : "is") + " " + count + " individuals in the model that are of type " + parentOfAddedClass.getURI() + "," + logger.log("There " + ((count > 1) ? "are" : "is") + " " + count + " individual" + ((count > 1) ? "s" : "") + " in the model that " + ((count > 1) ? "are" : "is") + " of type " + parentOfAddedClass.getURI() + "," +
" and a new subclass of that class has been added: " + addedClass.getURI() + ". " + " and a new subclass of that class has been added: " + addedClass.getURI() + ". " +
"Please review " + ((count > 1) ? "these" : "this") + " individual" + ((count > 1) ? "s" : "") + " to see whether " + ((count > 1) ? "they" : "it") + " should be of type: " + addedClass.getURI() ); "Please review " + ((count > 1) ? "these" : "this") + " individual" + ((count > 1) ? "s" : "") + " to see whether " + ((count > 1) ? "they" : "it") + " should be of type: " + addedClass.getURI() );
} }

View file

@ -81,6 +81,7 @@ public class OntologyUpdater {
private void performUpdate() throws IOException { private void performUpdate() throws IOException {
performSparqlConstructAdditions(settings.getSparqlConstructAdditionsDir(), settings.getOntModelSelector().getABoxModel()); performSparqlConstructAdditions(settings.getSparqlConstructAdditionsDir(), settings.getOntModelSelector().getABoxModel());
performSparqlConstructRetractions(settings.getSparqlConstructDeletionsDir(), settings.getOntModelSelector().getABoxModel());
List<AtomicOntologyChange> rawChanges = getAtomicOntologyChanges(); List<AtomicOntologyChange> rawChanges = getAtomicOntologyChanges();
@ -128,9 +129,38 @@ public class OntologyUpdater {
aboxModel.leaveCriticalSection(); aboxModel.leaveCriticalSection();
} }
} }
private void performSparqlConstructRetractions(String sparqlConstructDir, OntModel aboxModel) throws IOException {
Model retractions = performSparqlConstructs(sparqlConstructDir, aboxModel);
if (retractions == null) {
return;
}
aboxModel.enterCriticalSection(Lock.WRITE);
try {
Model actualRetractions = ModelFactory.createDefaultModel();
StmtIterator stmtIt = retractions.listStatements();
while (stmtIt.hasNext()) {
Statement stmt = stmtIt.nextStatement();
if (aboxModel.contains(stmt)) {
actualRetractions.add(stmt);
}
}
aboxModel.remove(actualRetractions);
if (actualRetractions.size() > 0) {
logger.log("Removed " + actualRetractions.size() + " statement"
+ ((actualRetractions.size() > 1) ? "s" : "") +
" using SPARQL CONSTRUCT queries.");
}
record.recordRetractions(actualRetractions);
} finally {
aboxModel.leaveCriticalSection();
}
}
/** /**
* Performs a set of arbitrary SPARQL CONSTRUCT queries on the * Performs a set of arbitrary SPARQL CONSTRUCT queries on the

View file

@ -31,6 +31,7 @@ public class TBoxUpdater {
private OntModel siteModel; private OntModel siteModel;
private OntologyChangeLogger logger; private OntologyChangeLogger logger;
private OntologyChangeRecord record; private OntologyChangeRecord record;
private boolean detailLogs = false;
/** /**
* *
@ -160,14 +161,37 @@ public class TBoxUpdater {
continue; continue;
} }
if (!newObject.equals(oldObject)) { // If a subject-property pair occurs in the old annotation TBox and the new annotations
// TBox, but not in the site model, then it is considered an erroneous deletion and
// the value from the new TBox is added into the site model.
// sjm: 7-16-2010. We want this here now to add back in annotations mistakenly dropped
// in the .9 to 1.0 migration, but I'm not sure we would want this here permanently.
// Shouldn't a site be allowed to delete annotations if they want to?
NodeIterator siteObjects = siteModel.listObjectsOfProperty(subject,predicate); NodeIterator siteObjects = siteModel.listObjectsOfProperty(subject,predicate);
RDFNode siteObject = null; if (siteObjects == null || !siteObjects.hasNext()) {
try {
additions.add(subject, predicate, newObject);
if (siteObjects != null && siteObjects.hasNext()) { if (detailLogs) {
logger.log( "adding Statement: subject = " + subject.getURI() +
" property = " + predicate.getURI() +
" object = " + (newObject.isLiteral() ? ((Literal)newObject).getLexicalForm()
: ((Resource)newObject).getURI()));
}
} catch (Exception e) {
logger.logError("Error trying to add statement with property " + predicate.getURI() +
" of class = " + subject.getURI() + " in the knowledge base:\n" + e.getMessage());
}
siteObject = siteObjects.next(); continue;
}
if (!newObject.equals(oldObject)) {
RDFNode siteObject = siteObjects.next();
i = 1; i = 1;
while (siteObjects.hasNext()) { while (siteObjects.hasNext()) {
@ -182,9 +206,8 @@ public class TBoxUpdater {
" in the site annotations model. (maximum of one is expected). "); " in the site annotations model. (maximum of one is expected). ");
continue; continue;
} }
}
if (siteObject == null || siteObject.equals(oldObject)) { if (siteObject.equals(oldObject)) {
try { try {
StmtIterator it = siteModel.listStatements(subject, predicate, (RDFNode)null); StmtIterator it = siteModel.listStatements(subject, predicate, (RDFNode)null);
while (it.hasNext()) { while (it.hasNext()) {
@ -199,6 +222,7 @@ public class TBoxUpdater {
try { try {
additions.add(subject, predicate, newObject); additions.add(subject, predicate, newObject);
if (detailLogs) {
logger.log("Changed the value of property " + predicate.getURI() + logger.log("Changed the value of property " + predicate.getURI() +
" of subject = " + subject.getURI() + " of subject = " + subject.getURI() +
" from " + " from " +
@ -206,6 +230,7 @@ public class TBoxUpdater {
" to " + " to " +
(newObject.isResource() ? ((Resource)newObject).getURI() : ((Literal)newObject).getLexicalForm()) + (newObject.isResource() ? ((Resource)newObject).getURI() : ((Literal)newObject).getLexicalForm()) +
" in the knowledge base:\n"); " in the knowledge base:\n");
}
} catch (Exception e) { } catch (Exception e) {
logger.logError("Error trying to change the value of property " + predicate.getURI() + logger.logError("Error trying to change the value of property " + predicate.getURI() +
" of class = " + subject.getURI() + " in the knowledge base:\n" + e.getMessage()); " of class = " + subject.getURI() + " in the knowledge base:\n" + e.getMessage());
@ -230,7 +255,7 @@ public class TBoxUpdater {
long numRemoved = actualRetractions.size() - actualAdditions.size(); long numRemoved = actualRetractions.size() - actualAdditions.size();
if (numRemoved > 0) { if (numRemoved > 0) {
logger.log("Removed " + numRemoved + logger.log("Removed " + numRemoved +
" superfluous vitro annotation property setting" + ((numRemoved > 1) ? "s" : "") + " from the knowledge base."); " outdated vitro annotation property setting" + ((numRemoved > 1) ? "s" : "") + " from the knowledge base.");
} }
// Copy annotation property settings that were introduced in the new ontology // Copy annotation property settings that were introduced in the new ontology
@ -245,19 +270,19 @@ public class TBoxUpdater {
if (!siteModel.contains(stmt)) { if (!siteModel.contains(stmt)) {
newAnnotationSettingsToAdd.add(stmt); newAnnotationSettingsToAdd.add(stmt);
// TODO remove this for production if (detailLogs) {
logger.log( "adding Statement: subject = " + stmt.getSubject().getURI() + logger.log( "adding Statement: subject = " + stmt.getSubject().getURI() +
" property = " + stmt.getPredicate().getURI() + " property = " + stmt.getPredicate().getURI() +
" object = " + (stmt.getObject().isLiteral() ? ((Literal)stmt.getObject()).getLexicalForm() " object = " + (stmt.getObject().isLiteral() ? ((Literal)stmt.getObject()).getLexicalForm()
: ((Resource)stmt.getObject()).getURI())); : ((Resource)stmt.getObject()).getURI()));
} }
} }
}
siteModel.add(newAnnotationSettingsToAdd); siteModel.add(newAnnotationSettingsToAdd);
record.recordAdditions(newAnnotationSettingsToAdd); record.recordAdditions(newAnnotationSettingsToAdd);
// log the additions // log the additions - summary
//summary
if (newAnnotationSettingsToAdd.size() > 0) { if (newAnnotationSettingsToAdd.size() > 0) {
boolean plural = (newAnnotationSettingsToAdd.size() > 1); boolean plural = (newAnnotationSettingsToAdd.size() > 1);
logger.log("Added " + newAnnotationSettingsToAdd.size() + " new annotation property setting" + (plural ? "s" : "") + " to the knowledge base. This includes " + logger.log("Added " + newAnnotationSettingsToAdd.size() + " new annotation property setting" + (plural ? "s" : "") + " to the knowledge base. This includes " +