passes sameAs unit tests

This commit is contained in:
brianjlowe 2015-12-10 18:34:54 +02:00
parent a4649a7751
commit f0992605ce
2 changed files with 24 additions and 36 deletions

View file

@ -158,7 +158,7 @@ public class ABoxRecomputer {
String individualURI = individuals.poll(); String individualURI = individuals.poll();
try { try {
additionalInferences.add(recomputeIndividual( additionalInferences.add(recomputeIndividual(
individualURI, rebuildModel, caches)); individualURI, rebuildModel, caches, individuals));
numInds++; numInds++;
individualsInBatch.add(individualURI); individualsInBatch.add(individualURI);
boolean batchFilled = (numInds % BATCH_SIZE) == 0; boolean batchFilled = (numInds % BATCH_SIZE) == 0;
@ -202,13 +202,14 @@ public class ABoxRecomputer {
private static final boolean SKIP_PLUGINS = !RUN_PLUGINS; private static final boolean SKIP_PLUGINS = !RUN_PLUGINS;
private Model recomputeIndividual(String individualURI, private Model recomputeIndividual(String individualURI,
Model rebuildModel, TypeCaches caches) throws RDFServiceException { Model rebuildModel, TypeCaches caches, Queue<String> individualQueue)
throws RDFServiceException {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
Model assertions = getAssertions(individualURI); Model assertions = getAssertions(individualURI);
log.debug((System.currentTimeMillis() - start) + " ms to get assertions."); log.debug((System.currentTimeMillis() - start) + " ms to get assertions.");
long prevRebuildSize = (simpleReasoner.getSameAsEnabled()) ? rebuildModel.size() : 0;
Model additionalInferences = recomputeIndividual( Model additionalInferences = recomputeIndividual(
individualURI, null, assertions, rebuildModel, caches, RUN_PLUGINS); individualURI, null, assertions, rebuildModel, caches, RUN_PLUGINS);
if (simpleReasoner.getSameAsEnabled()) { if (simpleReasoner.getSameAsEnabled()) {
Set<String> sameAsInds = getSameAsIndividuals(individualURI); Set<String> sameAsInds = getSameAsIndividuals(individualURI);
for (String sameAsInd : sameAsInds) { for (String sameAsInd : sameAsInds) {
@ -221,10 +222,18 @@ public class ABoxRecomputer {
Resource indRes = ResourceFactory.createResource(individualURI); Resource indRes = ResourceFactory.createResource(individualURI);
Resource sameAsIndRes = ResourceFactory.createResource(sameAsInd); Resource sameAsIndRes = ResourceFactory.createResource(sameAsInd);
if(!assertions.contains(indRes, OWL.sameAs, sameAsIndRes)) { if(!assertions.contains(indRes, OWL.sameAs, sameAsIndRes)) {
if(!rebuildModel.contains(indRes, OWL.sameAs, sameAsIndRes)) {
individualQueue.add(sameAsInd);
rebuildModel.add(indRes, OWL.sameAs, sameAsIndRes); rebuildModel.add(indRes, OWL.sameAs, sameAsIndRes);
} }
} }
} }
if(rebuildModel.size() - prevRebuildSize > 0) {
for (String sameAsInd : sameAsInds) {
individualQueue.add(sameAsInd);
}
}
}
return additionalInferences; return additionalInferences;
} }
@ -528,7 +537,7 @@ public class ABoxRecomputer {
return new ByteArrayInputStream(out.toByteArray()); return new ByteArrayInputStream(out.toByteArray());
} }
private Set<String> getSameAsIndividuals(String individualURI) { public Set<String> getSameAsIndividuals(String individualURI) {
HashSet<String> sameAsInds = new HashSet<String>(); HashSet<String> sameAsInds = new HashSet<String>();
sameAsInds.add(individualURI); sameAsInds.add(individualURI);
getSameAsIndividuals(individualURI, sameAsInds); getSameAsIndividuals(individualURI, sameAsInds);
@ -540,7 +549,6 @@ public class ABoxRecomputer {
try { try {
final List<String> addedURIs = new ArrayList<String>(); final List<String> addedURIs = new ArrayList<String>();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("SELECT\n") builder.append("SELECT\n")
.append(" ?object\n") .append(" ?object\n")
.append("WHERE {\n") .append("WHERE {\n")
@ -553,7 +561,6 @@ public class ABoxRecomputer {
.append(" } \n") .append(" } \n")
.append(" FILTER (?g != <" + ModelNames.ABOX_INFERENCES + ">)\n") .append(" FILTER (?g != <" + ModelNames.ABOX_INFERENCES + ">)\n")
.append("}\n"); .append("}\n");
rdfService.sparqlSelectQuery(builder.toString(), new ResultSetConsumer() { rdfService.sparqlSelectQuery(builder.toString(), new ResultSetConsumer() {
@Override @Override
protected void processQuerySolution(QuerySolution qs) { protected void processQuerySolution(QuerySolution qs) {
@ -564,32 +571,6 @@ public class ABoxRecomputer {
} }
} }
}); });
for (String indUri : addedURIs) {
getSameAsIndividuals(indUri, sameAsInds);
}
addedURIs.clear();
builder = new StringBuilder();
builder.append("SELECT\n")
.append(" ?subject\n")
.append("WHERE\n")
.append("{\n")
.append(" ?subject <" + OWL.sameAs + "> <" + individualUri + "> .\n")
.append("}\n");
rdfService.sparqlSelectQuery(builder.toString(), new ResultSetConsumer() {
@Override
protected void processQuerySolution(QuerySolution qs) {
Resource object = qs.getResource("subject");
if (object != null && !sameAsInds.contains(object.getURI())) {
sameAsInds.add(object.getURI());
addedURIs.add(object.getURI());
}
}
});
for (String indUri : addedURIs) { for (String indUri : addedURIs) {
getSameAsIndividuals(indUri, sameAsInds); getSameAsIndividuals(indUri, sameAsInds);
} }

View file

@ -198,8 +198,6 @@ public class SimpleReasoner extends StatementListener {
} }
} }
private static final int SAFETY_VALVE = 1000000; // one million individuals
private void recomputeIndividuals() { private void recomputeIndividuals() {
if(recomputer.isRecomputing()) { if(recomputer.isRecomputing()) {
return; return;
@ -250,6 +248,16 @@ public class SimpleReasoner extends StatementListener {
@Override @Override
public void removedStatement(Statement stmt) { public void removedStatement(Statement stmt) {
doPlugins(ModelUpdate.Operation.RETRACT,stmt); doPlugins(ModelUpdate.Operation.RETRACT,stmt);
if(doSameAs && OWL.sameAs.equals(stmt.getPredicate())) {
if (stmt.getSubject().isURIResource()) {
individualURIqueue.addAll(this.recomputer.getSameAsIndividuals(
stmt.getSubject().getURI()));
}
if (stmt.getObject().isURIResource()) {
individualURIqueue.addAll(this.recomputer.getSameAsIndividuals(
stmt.getObject().asResource().getURI()));
}
}
listenToStatement(stmt); listenToStatement(stmt);
// try { // try {
// handleRemovedStatement(stmt); // handleRemovedStatement(stmt);
@ -1954,5 +1962,4 @@ public class SimpleReasoner extends StatementListener {
} }
} }