Merge branch 'maint-rel-1.6' into develop

This commit is contained in:
brianjlowe 2013-12-04 16:34:38 -05:00
commit 6637a54252
9 changed files with 144 additions and 148 deletions

View file

@ -107,6 +107,9 @@ public class ABoxRecomputer {
} }
} }
// don't check for existing inferences in the rebuild model
private boolean DO_CHECK = true;
/* /*
* Recompute the entire ABox inference graph. The new * Recompute the entire ABox inference graph. The new
* inference graph is built in a separate model and * inference graph is built in a separate model and
@ -132,11 +135,13 @@ public class ABoxRecomputer {
log.info("Recomputing inferences for " + individuals.size() + " individuals"); log.info("Recomputing inferences for " + individuals.size() + " individuals");
long start = System.currentTimeMillis();
for (String individualURI : individuals) { for (String individualURI : individuals) {
Resource individual = ResourceFactory.createResource(individualURI); Resource individual = ResourceFactory.createResource(individualURI);
try { try {
addedABoxTypeAssertion(individual, inferenceRebuildModel, unknownTypes); addedABoxTypeAssertion(individual, inferenceRebuildModel, unknownTypes, DO_CHECK);
simpleReasoner.setMostSpecificTypes(individual, inferenceRebuildModel, unknownTypes); simpleReasoner.setMostSpecificTypes(individual, inferenceRebuildModel, unknownTypes);
List<ReasonerPlugin> pluginList = simpleReasoner.getPluginList(); List<ReasonerPlugin> pluginList = simpleReasoner.getPluginList();
if (pluginList.size() > 0) { if (pluginList.size() > 0) {
@ -165,8 +170,11 @@ public class ABoxRecomputer {
} }
numStmts++; numStmts++;
if ((numStmts % 10000) == 0) { if ((numStmts % 1000) == 0) {
log.info("Still computing class subsumption ABox inferences..."); log.info("Still computing class subsumption ABox inferences ("
+ numStmts + "/" + individuals.size() + " individuals)");
log.info((System.currentTimeMillis() - start) / 1000 + " ms per individual");
start = System.currentTimeMillis();
} }
if (stopRequested) { if (stopRequested) {
@ -275,7 +283,7 @@ public class ABoxRecomputer {
log.info("Finished computing sameAs ABox inferences"); log.info("Finished computing sameAs ABox inferences");
try { try {
if (updateInferenceModel(inferenceRebuildModel)) { if (updateInferenceModel(inferenceRebuildModel, individuals)) {
log.info("a stopRequested signal was received during updateInferenceModel. Halting Processing."); log.info("a stopRequested signal was received during updateInferenceModel. Halting Processing.");
return; return;
} }
@ -366,7 +374,13 @@ public class ABoxRecomputer {
} }
protected void addedABoxTypeAssertion(Resource individual, Model inferenceModel, HashSet<String> unknownTypes) { protected void addedABoxTypeAssertion(Resource individual, Model inferenceModel,
HashSet<String> unknownTypes) {
addedABoxTypeAssertion(individual, inferenceModel, unknownTypes, true);
}
protected void addedABoxTypeAssertion(Resource individual, Model inferenceModel,
HashSet<String> unknownTypes, boolean checkRedundancy) {
StmtIterator iter = null; StmtIterator iter = null;
@ -376,7 +390,8 @@ public class ABoxRecomputer {
while (iter.hasNext()) { while (iter.hasNext()) {
Statement stmt = iter.next(); Statement stmt = iter.next();
simpleReasoner.addedABoxTypeAssertion(stmt, inferenceModel, unknownTypes); simpleReasoner.addedABoxTypeAssertion(
stmt, inferenceModel, unknownTypes, checkRedundancy);
} }
} finally { } finally {
if (iter != null) { if (iter != null) {
@ -388,121 +403,68 @@ public class ABoxRecomputer {
/* /*
* reconcile a set of inferences into the application inference model * reconcile a set of inferences into the application inference model
*/ */
protected boolean updateInferenceModel(Model inferenceRebuildModel) { protected boolean updateInferenceModel(Model inferenceRebuildModel,
Collection<String> individuals) {
log.info("Updating ABox inference model"); log.info("Updating ABox inference model");
Iterator<Statement> iter = null;
// Remove everything from the current inference model that is not // Remove everything from the current inference model that is not
// in the recomputed inference model // in the recomputed inference model
int num = 0; int num = 0;
scratchpadModel.enterCriticalSection(Lock.WRITE); scratchpadModel.enterCriticalSection(Lock.WRITE);
scratchpadModel.removeAll(); scratchpadModel.removeAll();
log.info("Updating ABox inference model (checking for outdated inferences)"); Model rebuild = ModelFactory.createDefaultModel();
try { Model existing = ModelFactory.createDefaultModel();
inferenceModel.enterCriticalSection(Lock.READ);
long start = System.currentTimeMillis();
for (String individualURI : individuals) {
rebuild.removeAll();
existing.removeAll();
Resource subjInd = ResourceFactory.createResource(individualURI);
inferenceModel.enterCriticalSection(Lock.READ);
try { try {
iter = listModelStatements(inferenceModel, JenaDataSourceSetupBase.JENA_INF_MODEL); existing.add(inferenceModel.listStatements(subjInd, null, (RDFNode) null));
while (iter.hasNext()) { } finally {
Statement stmt = iter.next(); inferenceModel.leaveCriticalSection();
if (!inferenceRebuildModel.contains(stmt)) { }
scratchpadModel.add(stmt); inferenceRebuildModel.enterCriticalSection(Lock.READ);
try {
rebuild.add(inferenceRebuildModel.listStatements(subjInd, null, (RDFNode) null));
} finally {
inferenceRebuildModel.leaveCriticalSection();
}
Model retractions = existing.difference(rebuild);
Model additions = rebuild.difference(existing);
inferenceModel.enterCriticalSection(Lock.WRITE);
try {
inferenceModel.remove(retractions);
inferenceModel.add(additions);
} finally {
inferenceModel.leaveCriticalSection();
}
inferenceRebuildModel.enterCriticalSection(Lock.WRITE);
try {
inferenceRebuildModel.remove(rebuild);
} finally {
inferenceRebuildModel.leaveCriticalSection();
} }
num++; num++;
if ((num % 10000) == 0) { if ((num % 1000) == 0) {
log.info("Still updating ABox inference model (checking for outdated inferences)..."); log.info("Still updating ABox inference model (" +
+ num + "/" + individuals.size() + " individuals)");
log.info((System.currentTimeMillis() - start) / 1000 + " ms per individual");
start = System.currentTimeMillis();
} }
if (stopRequested) { if (stopRequested) {
return true; return true;
}
}
} finally {
// if (iter != null) {
// iter.close();
// }
inferenceModel.leaveCriticalSection();
} }
try {
iter = listModelStatements(scratchpadModel, SimpleReasonerSetup.JENA_INF_MODEL_SCRATCHPAD);
while (iter.hasNext()) {
Statement stmt = iter.next();
// skip statements with blank nodes to avoid excessive deletion
if (stmt.getSubject().isAnon() || stmt.getObject().isAnon()) {
continue;
}
inferenceModel.enterCriticalSection(Lock.WRITE);
try {
inferenceModel.remove(stmt);
} finally {
inferenceModel.leaveCriticalSection();
}
}
} finally {
// if (iter != null) {
// iter.close();
// }
}
// Add everything from the recomputed inference model that is not already
// in the current inference model to the current inference model.
try {
scratchpadModel.removeAll();
log.info("Updating ABox inference model (adding any new inferences)");
iter = listModelStatements(inferenceRebuildModel, SimpleReasonerSetup.JENA_INF_MODEL_REBUILD);
while (iter.hasNext()) {
Statement stmt = iter.next();
inferenceModel.enterCriticalSection(Lock.READ);
try {
if (!inferenceModel.contains(stmt)) {
scratchpadModel.add(stmt);
}
} finally {
inferenceModel.leaveCriticalSection();
}
num++;
if ((num % 10000) == 0) {
log.info("Still updating ABox inference model (adding any new inferences)...");
}
if (stopRequested) {
return true;
}
}
} finally {
// if (iter != null) {
// iter.close();
// }
}
iter = listModelStatements(scratchpadModel, SimpleReasonerSetup.JENA_INF_MODEL_SCRATCHPAD);
try {
while (iter.hasNext()) {
Statement stmt = iter.next();
inferenceModel.enterCriticalSection(Lock.WRITE);
try {
inferenceModel.add(stmt);
} finally {
inferenceModel.leaveCriticalSection();
}
}
} finally {
// if (iter != null) {
// iter.close();
// }
}
} finally {
scratchpadModel.removeAll();
scratchpadModel.leaveCriticalSection();
} }
log.info("ABox inference model updated"); log.info("ABox inference model updated");

View file

@ -12,6 +12,8 @@ public interface ReasonerPlugin {
public boolean isInterestedInRemovedStatement(Statement stmt); public boolean isInterestedInRemovedStatement(Statement stmt);
public boolean isConfigurationOnlyPlugin();
public void addedABoxStatement(Statement stmt, public void addedABoxStatement(Statement stmt,
Model aboxAssertionsModel, Model aboxAssertionsModel,
Model aboxInferencesModel, Model aboxInferencesModel,

View file

@ -162,6 +162,10 @@ public class SimpleReasoner extends StatementListener {
this.doSameAs = tf; this.doSameAs = tf;
} }
public boolean getSameAsEnabled() {
return this.doSameAs;
}
/* /*
* Performs incremental ABox reasoning based * Performs incremental ABox reasoning based
* on the addition of a new statement * on the addition of a new statement
@ -343,6 +347,12 @@ public class SimpleReasoner extends StatementListener {
changedTBoxStatement(stmt, false); changedTBoxStatement(stmt, false);
} }
protected void addedABoxTypeAssertion(Statement stmt,
Model inferenceModel,
HashSet<String> unknownTypes) {
addedABoxTypeAssertion(stmt, inferenceModel, unknownTypes, true);
}
/** /**
* Performs incremental reasoning based on a new type assertion * Performs incremental reasoning based on a new type assertion
* added to the ABox (assertion that an individual is of a certain * added to the ABox (assertion that an individual is of a certain
@ -353,7 +363,8 @@ public class SimpleReasoner extends StatementListener {
*/ */
protected void addedABoxTypeAssertion(Statement stmt, protected void addedABoxTypeAssertion(Statement stmt,
Model inferenceModel, Model inferenceModel,
HashSet<String> unknownTypes) { HashSet<String> unknownTypes,
boolean checkRedundancy) {
tboxModel.enterCriticalSection(Lock.READ); tboxModel.enterCriticalSection(Lock.READ);
try { try {
@ -379,7 +390,7 @@ public class SimpleReasoner extends StatementListener {
Statement infStmt = Statement infStmt =
ResourceFactory.createStatement(stmt.getSubject(), ResourceFactory.createStatement(stmt.getSubject(),
RDF.type, parentClass); RDF.type, parentClass);
addInference(infStmt,inferenceModel,true); addInference(infStmt, inferenceModel, true, checkRedundancy);
} }
} }
} else { } else {
@ -1189,13 +1200,20 @@ public class SimpleReasoner extends StatementListener {
addInference(infStmt,inferenceModel,true); addInference(infStmt,inferenceModel,true);
} }
protected void addInference(Statement infStmt, Model inferenceModel, boolean handleSameAs) { protected void addInference(Statement infStmt, Model inferenceModel,
boolean handleSameAs) {
addInference(infStmt, inferenceModel, handleSameAs, true);
}
protected void addInference(Statement infStmt, Model inferenceModel,
boolean handleSameAs, boolean checkRedundancy) {
aboxModel.enterCriticalSection(Lock.READ); aboxModel.enterCriticalSection(Lock.READ);
try { try {
inferenceModel.enterCriticalSection(Lock.WRITE); inferenceModel.enterCriticalSection(Lock.WRITE);
try { try {
if (!inferenceModel.contains(infStmt) && !aboxModel.contains(infStmt)) { if (!checkRedundancy
|| (!inferenceModel.contains(infStmt) && !aboxModel.contains(infStmt))) {
inferenceModel.add(infStmt); inferenceModel.add(infStmt);
} }
@ -1732,8 +1750,6 @@ public class SimpleReasoner extends StatementListener {
} }
} }
/** /**
* Utility method for logging * Utility method for logging
*/ */

View file

@ -15,7 +15,7 @@ import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
/** /**
* Disables sameAs in associated SimpleReasoner. * Disables sameAs in associated SimpleReasoner.
*/ */
public abstract class DisableSameAs implements ReasonerPlugin { public class DisableSameAs implements ReasonerPlugin {
private static final Log log = LogFactory.getLog(DisableSameAs.class); private static final Log log = LogFactory.getLog(DisableSameAs.class);
@ -27,6 +27,10 @@ public abstract class DisableSameAs implements ReasonerPlugin {
log.info("owl:sameAs disabled in SimpleReasoner."); log.info("owl:sameAs disabled in SimpleReasoner.");
} }
public boolean isConfigurationOnlyPlugin() {
return true;
}
public SimpleReasoner getSimpleReasoner() { public SimpleReasoner getSimpleReasoner() {
return this.simpleReasoner; return this.simpleReasoner;
} }

View file

@ -62,6 +62,10 @@ public abstract class SimpleBridgingRule implements ReasonerPlugin {
} }
public boolean isConfigurationOnlyPlugin() {
return false;
}
public boolean isInterestedInAddedStatement(Statement stmt) { public boolean isInterestedInAddedStatement(Statement stmt) {
return isRelevantPredicate(stmt); return isRelevantPredicate(stmt);
} }

View file

@ -36,6 +36,10 @@ public abstract class SimplePropertyAndTypeRule implements ReasonerPlugin {
INFERRED_PROP = ResourceFactory.createProperty(inferredProp); INFERRED_PROP = ResourceFactory.createProperty(inferredProp);
} }
public boolean isConfigurationOnlyPlugin() {
return false;
}
public boolean isInterestedInAddedStatement(Statement stmt) { public boolean isInterestedInAddedStatement(Statement stmt) {
return (RDF.type.equals(stmt.getPredicate()) || isRelevantPredicate(stmt)); return (RDF.type.equals(stmt.getPredicate()) || isRelevantPredicate(stmt));
} }

View file

@ -104,7 +104,10 @@ public class SimpleReasonerSetup implements ServletContextListener {
ReasonerPlugin plugin = (ReasonerPlugin) Class.forName( ReasonerPlugin plugin = (ReasonerPlugin) Class.forName(
classname).getConstructors()[0].newInstance(); classname).getConstructors()[0].newInstance();
plugin.setSimpleReasoner(simpleReasoner); plugin.setSimpleReasoner(simpleReasoner);
if (!plugin.isConfigurationOnlyPlugin()) {
pluginList.add(plugin); pluginList.add(plugin);
log.info("adding reasoner plugin " + plugin.getClass().getName());
}
} catch(Throwable t) { } catch(Throwable t) {
ss.info(this, "Could not instantiate reasoner plugin " + classname); ss.info(this, "Could not instantiate reasoner plugin " + classname);
} }

View file

@ -14,6 +14,7 @@ import com.hp.hpl.jena.ontology.OntProperty;
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;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.OWL;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
@ -431,10 +432,10 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
tBox.register(simpleReasonerTBoxListener); tBox.register(simpleReasonerTBoxListener);
// add abox data // add abox data
Resource a = aBox.createResource("http://test.vivo/a"); Resource a = aBox.createIndividual("http://test.vivo/a", OWL.Thing);
Resource b = aBox.createResource("http://test.vivo/b"); Resource b = aBox.createIndividual("http://test.vivo/b", OWL.Thing);
Resource c = aBox.createResource("http://test.vivo/c"); Resource c = aBox.createIndividual("http://test.vivo/c", OWL.Thing);
Resource d = aBox.createResource("http://test.vivo/d"); Resource d = aBox.createIndividual("http://test.vivo/d", OWL.Thing);
aBox.add(a,P,b); aBox.add(a,P,b);
aBox.add(c,P,d); aBox.add(c,P,d);
@ -496,8 +497,8 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
tBox.register(simpleReasonerTBoxListener); tBox.register(simpleReasonerTBoxListener);
// add statements to the abox and verify inference // add statements to the abox and verify inference
Resource c = aBox.createResource("http://test.vivo/c"); Resource c = aBox.createIndividual("http://test.vivo/c", OWL.Thing);
Resource d = aBox.createResource("http://test.vivo/d"); Resource d = aBox.createIndividual("http://test.vivo/d", OWL.Thing);
aBox.add(c,P,d); aBox.add(c,P,d);
Assert.assertTrue(inf.contains(d,Q,c)); Assert.assertTrue(inf.contains(d,Q,c));
@ -555,10 +556,10 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
aBox.register(simpleReasoner); aBox.register(simpleReasoner);
// abox statements // abox statements
Resource a = aBox.createResource("http://test.vivo/a"); Resource a = aBox.createIndividual("http://test.vivo/a", OWL.Thing);
Resource b = aBox.createResource("http://test.vivo/b"); Resource b = aBox.createIndividual("http://test.vivo/b", OWL.Thing);
Resource c = aBox.createResource("http://test.vivo/c"); Resource c = aBox.createIndividual("http://test.vivo/c", OWL.Thing);
Resource d = aBox.createResource("http://test.vivo/d"); Resource d = aBox.createIndividual("http://test.vivo/d", OWL.Thing);
aBox.add(a,P,b); aBox.add(a,P,b);
aBox.add(c,X,d); aBox.add(c,X,d);

View file

@ -782,10 +782,10 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
aBox.register(simpleReasoner); aBox.register(simpleReasoner);
// Individuals a, b, c and d // Individuals a, b, c and d
Resource a = aBox.createResource("http://test.vivo/a"); Resource a = aBox.createIndividual("http://test.vivo/a", OWL.Thing);
Resource b = aBox.createResource("http://test.vivo/b"); Resource b = aBox.createIndividual("http://test.vivo/b", OWL.Thing);
Resource c = aBox.createResource("http://test.vivo/c"); Resource c = aBox.createIndividual("http://test.vivo/c", OWL.Thing);
Resource d = aBox.createResource("http://test.vivo/d"); Resource d = aBox.createIndividual("http://test.vivo/d", OWL.Thing);
aBox.add(a,P,c); aBox.add(a,P,c);
aBox.add(a,S,literal1); aBox.add(a,S,literal1);