fix to ABoxRecomputer's test for whether sameAs reasoning is enabled

This commit is contained in:
brianjlowe 2015-02-11 16:49:30 +02:00
parent ed9b82258d
commit e74f65350f

View file

@ -52,12 +52,12 @@ public class ABoxRecomputer {
private OntModel tboxModel; // asserted and inferred TBox axioms private OntModel tboxModel; // asserted and inferred TBox axioms
private OntModel aboxModel; private OntModel aboxModel;
private Model inferenceModel;
private RDFService rdfService; private RDFService rdfService;
private SimpleReasoner simpleReasoner; private SimpleReasoner simpleReasoner;
private Object lock1 = new Object(); private Object lock1 = new Object();
private volatile boolean recomputing = false; private volatile boolean recomputing = false;
private boolean stopRequested = false; private boolean stopRequested = false;
private boolean handleSameAs = false;
private final int BATCH_SIZE = 100; private final int BATCH_SIZE = 100;
private final int REPORTING_INTERVAL = 1000; private final int REPORTING_INTERVAL = 1000;
@ -75,11 +75,12 @@ public class ABoxRecomputer {
this.tboxModel = tboxModel; this.tboxModel = tboxModel;
this.aboxModel = aboxModel; this.aboxModel = aboxModel;
this.rdfService = rdfService; this.rdfService = rdfService;
this.inferenceModel = RDFServiceGraph.createRDFServiceModel(
new RDFServiceGraph(rdfService, ModelNames.ABOX_INFERENCES));
this.simpleReasoner = simpleReasoner; this.simpleReasoner = simpleReasoner;
this.searchIndexer = searchIndexer; this.searchIndexer = searchIndexer;
recomputing = false; recomputing = false;
stopRequested = false; stopRequested = false;
handleSameAs = simpleReasoner.getSameAsEnabled();
} }
/** /**
@ -102,15 +103,15 @@ public class ABoxRecomputer {
} }
} }
try { try {
if (searchIndexer != null) { if (searchIndexer != null) {
searchIndexer.pause(); searchIndexer.pause();
} }
recomputeABox(); recomputeABox();
} finally { } finally {
if (searchIndexer != null) { if (searchIndexer != null) {
searchIndexer.rebuildIndex(); searchIndexer.rebuildIndex();
searchIndexer.unpause(); searchIndexer.unpause();
} }
synchronized (lock1) { synchronized (lock1) {
recomputing = false; recomputing = false;
} }
@ -183,7 +184,8 @@ public class ABoxRecomputer {
log.trace((System.currentTimeMillis() - start) + " ms to get assertions."); log.trace((System.currentTimeMillis() - start) + " ms to get assertions.");
Model additionalInferences = recomputeIndividual( Model additionalInferences = recomputeIndividual(
individualURI, null, assertions, rebuildModel, RUN_PLUGINS); individualURI, null, assertions, rebuildModel, RUN_PLUGINS);
if (handleSameAs) {
if (simpleReasoner.getSameAsEnabled()) {
Set<String> sameAsInds = getSameAsIndividuals(individualURI); Set<String> sameAsInds = getSameAsIndividuals(individualURI);
for (String sameAsInd : sameAsInds) { for (String sameAsInd : sameAsInds) {
// sameAs for plugins is handled by the SimpleReasoner // sameAs for plugins is handled by the SimpleReasoner
@ -423,8 +425,6 @@ public class ABoxRecomputer {
*/ */
protected void updateInferenceModel(Model rebuildModel, protected void updateInferenceModel(Model rebuildModel,
Collection<String> individuals) throws RDFServiceException { Collection<String> individuals) throws RDFServiceException {
Model inferenceModel = RDFServiceGraph.createRDFServiceModel(
new RDFServiceGraph(rdfService, ModelNames.ABOX_INFERENCES));
Model existing = ModelFactory.createDefaultModel(); Model existing = ModelFactory.createDefaultModel();
for (String individualURI : individuals) { for (String individualURI : individuals) {
Resource subjInd = ResourceFactory.createResource(individualURI); Resource subjInd = ResourceFactory.createResource(individualURI);
@ -432,21 +432,16 @@ public class ABoxRecomputer {
} }
Model retractions = existing.difference(rebuildModel); Model retractions = existing.difference(rebuildModel);
Model additions = rebuildModel.difference(existing); Model additions = rebuildModel.difference(existing);
inferenceModel.enterCriticalSection(Lock.WRITE); long start = System.currentTimeMillis();
try { ChangeSet change = rdfService.manufactureChangeSet();
long start = System.currentTimeMillis(); change.addRemoval(makeN3InputStream(retractions),
ChangeSet change = rdfService.manufactureChangeSet(); RDFService.ModelSerializationFormat.N3, ModelNames.ABOX_INFERENCES);
change.addRemoval(makeN3InputStream(retractions), change.addAddition(makeN3InputStream(additions),
RDFService.ModelSerializationFormat.N3, ModelNames.ABOX_INFERENCES); RDFService.ModelSerializationFormat.N3, ModelNames.ABOX_INFERENCES);
change.addAddition(makeN3InputStream(additions), rdfService.changeSetUpdate(change);
RDFService.ModelSerializationFormat.N3, ModelNames.ABOX_INFERENCES); log.debug((System.currentTimeMillis() - start) +
rdfService.changeSetUpdate(change); " ms to retract " + retractions.size() +
log.debug((System.currentTimeMillis() - start) + " statements and add " + additions.size() + " statements");
" ms to retract " + retractions.size() +
" statements and add " + additions.size() + " statements");
} finally {
inferenceModel.leaveCriticalSection();
}
} }
private InputStream makeN3InputStream(Model m) { private InputStream makeN3InputStream(Model m) {
@ -483,8 +478,8 @@ public class ABoxRecomputer {
if (stmt.getSubject().isURIResource()) { if (stmt.getSubject().isURIResource()) {
String sameAsURI = stmt.getSubject().asResource().getURI(); String sameAsURI = stmt.getSubject().asResource().getURI();
if (!sameAsInds.contains(sameAsURI)) { if (!sameAsInds.contains(sameAsURI)) {
sameAsInds.add(sameAsURI); sameAsInds.add(sameAsURI);
getSameAsIndividuals(sameAsURI, sameAsInds); getSameAsIndividuals(sameAsURI, sameAsInds);
} }
} }
} }