fix to ABoxRecomputer's test for whether sameAs reasoning is enabled
This commit is contained in:
parent
ed9b82258d
commit
e74f65350f
1 changed files with 30 additions and 35 deletions
|
@ -47,17 +47,17 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
public class ABoxRecomputer {
|
public class ABoxRecomputer {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ABoxRecomputer.class);
|
private static final Log log = LogFactory.getLog(ABoxRecomputer.class);
|
||||||
|
|
||||||
private final SearchIndexer searchIndexer;
|
private final SearchIndexer searchIndexer;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -175,7 +176,7 @@ public class ABoxRecomputer {
|
||||||
|
|
||||||
private static final boolean RUN_PLUGINS = true;
|
private static final boolean RUN_PLUGINS = true;
|
||||||
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) throws RDFServiceException {
|
Model rebuildModel) throws RDFServiceException {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
@ -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
|
||||||
|
@ -201,7 +203,7 @@ public class ABoxRecomputer {
|
||||||
}
|
}
|
||||||
return additionalInferences;
|
return additionalInferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds inferences to temporary rebuildmodel
|
* Adds inferences to temporary rebuildmodel
|
||||||
* @param individualURI
|
* @param individualURI
|
||||||
|
@ -340,7 +342,7 @@ public class ABoxRecomputer {
|
||||||
queryStr, RDFService.ModelSerializationFormat.N3)
|
queryStr, RDFService.ModelSerializationFormat.N3)
|
||||||
, RDFService.ModelSerializationFormat.N3);
|
, RDFService.ModelSerializationFormat.N3);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Model rewriteInferences(Model inferences, String aliasURI) {
|
private Model rewriteInferences(Model inferences, String aliasURI) {
|
||||||
if (aliasURI == null) {
|
if (aliasURI == null) {
|
||||||
return inferences;
|
return inferences;
|
||||||
|
@ -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) {
|
||||||
|
@ -454,7 +449,7 @@ public class ABoxRecomputer {
|
||||||
m.write(out, "N3");
|
m.write(out, "N3");
|
||||||
return new ByteArrayInputStream(out.toByteArray());
|
return new ByteArrayInputStream(out.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> getSameAsIndividuals(String individualURI) {
|
private Set<String> getSameAsIndividuals(String individualURI) {
|
||||||
HashSet<String> sameAsInds = new HashSet<String>();
|
HashSet<String> sameAsInds = new HashSet<String>();
|
||||||
sameAsInds.add(individualURI);
|
sameAsInds.add(individualURI);
|
||||||
|
@ -462,7 +457,7 @@ public class ABoxRecomputer {
|
||||||
sameAsInds.remove(individualURI);
|
sameAsInds.remove(individualURI);
|
||||||
return sameAsInds;
|
return sameAsInds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getSameAsIndividuals(String individualURI, Set<String> sameAsInds) {
|
private void getSameAsIndividuals(String individualURI, Set<String> sameAsInds) {
|
||||||
Model m = RDFServiceGraph.createRDFServiceModel(new RDFServiceGraph(rdfService));
|
Model m = RDFServiceGraph.createRDFServiceModel(new RDFServiceGraph(rdfService));
|
||||||
Resource individual = ResourceFactory.createResource(individualURI);
|
Resource individual = ResourceFactory.createResource(individualURI);
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue