[VIVO-1031] Minor improvements to remove RDFServiceGraph usage from reinferencer.
This commit is contained in:
parent
5d6f4dada7
commit
1832bba831
1 changed files with 39 additions and 21 deletions
|
@ -57,7 +57,6 @@ 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();
|
||||||
|
@ -70,7 +69,6 @@ public class ABoxRecomputer {
|
||||||
/**
|
/**
|
||||||
* @param tboxModel - input. This model contains both asserted and inferred TBox axioms
|
* @param tboxModel - input. This model contains both asserted and inferred TBox axioms
|
||||||
* @param aboxModel - input. This model contains asserted ABox statements
|
* @param aboxModel - input. This model contains asserted ABox statements
|
||||||
* @param inferenceModel - output. This is the model in which inferred (materialized) ABox statements are maintained (added or retracted).
|
|
||||||
*/
|
*/
|
||||||
public ABoxRecomputer(OntModel tboxModel,
|
public ABoxRecomputer(OntModel tboxModel,
|
||||||
OntModel aboxModel,
|
OntModel aboxModel,
|
||||||
|
@ -80,8 +78,6 @@ 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;
|
||||||
|
@ -377,10 +373,10 @@ public class ABoxRecomputer {
|
||||||
" UNION \n" +
|
" UNION \n" +
|
||||||
" { ?inv <" + OWL.inverseOf.getURI() + "> ?prop } \n" +
|
" { ?inv <" + OWL.inverseOf.getURI() + "> ?prop } \n" +
|
||||||
"} \n";
|
"} \n";
|
||||||
return RDFServiceUtils.parseModel(
|
|
||||||
rdfService.sparqlConstructQuery(
|
Model model = ModelFactory.createDefaultModel();
|
||||||
queryStr, RDFService.ModelSerializationFormat.N3)
|
rdfService.sparqlConstructQuery(queryStr, model);
|
||||||
, RDFService.ModelSerializationFormat.N3);
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Model rewriteInferences(Model inferences, String aliasURI) {
|
private Model rewriteInferences(Model inferences, String aliasURI) {
|
||||||
|
@ -460,6 +456,23 @@ public class ABoxRecomputer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void addInferenceStatementsFor(String individualUri, Model addTo) throws RDFServiceException {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("CONSTRUCT\n")
|
||||||
|
.append("{\n")
|
||||||
|
.append(" <" + individualUri + "> ?p ?o .\n")
|
||||||
|
.append("}\n")
|
||||||
|
.append("WHERE\n")
|
||||||
|
.append("{\n")
|
||||||
|
.append(" GRAPH <").append(ModelNames.ABOX_INFERENCES).append(">\n")
|
||||||
|
.append(" {\n")
|
||||||
|
.append(" <" + individualUri + "> ?p ?o .\n")
|
||||||
|
.append(" }\n")
|
||||||
|
.append("}\n");
|
||||||
|
|
||||||
|
rdfService.sparqlConstructQuery(builder.toString(), addTo);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* reconcile a set of inferences into the application inference model
|
* reconcile a set of inferences into the application inference model
|
||||||
*/
|
*/
|
||||||
|
@ -467,21 +480,26 @@ public class ABoxRecomputer {
|
||||||
Collection<String> individuals) throws RDFServiceException {
|
Collection<String> individuals) throws RDFServiceException {
|
||||||
Model existing = ModelFactory.createDefaultModel();
|
Model existing = ModelFactory.createDefaultModel();
|
||||||
for (String individualURI : individuals) {
|
for (String individualURI : individuals) {
|
||||||
Resource subjInd = ResourceFactory.createResource(individualURI);
|
addInferenceStatementsFor(individualURI, existing);
|
||||||
existing.add(inferenceModel.listStatements(subjInd, null, (RDFNode) null));
|
|
||||||
}
|
}
|
||||||
Model retractions = existing.difference(rebuildModel);
|
Model retractions = existing.difference(rebuildModel);
|
||||||
Model additions = rebuildModel.difference(existing);
|
Model additions = rebuildModel.difference(existing);
|
||||||
long start = System.currentTimeMillis();
|
if (additions.size() > 0 || retractions.size() > 0) {
|
||||||
ChangeSet change = rdfService.manufactureChangeSet();
|
long start = System.currentTimeMillis();
|
||||||
change.addRemoval(makeN3InputStream(retractions),
|
ChangeSet change = rdfService.manufactureChangeSet();
|
||||||
RDFService.ModelSerializationFormat.N3, ModelNames.ABOX_INFERENCES);
|
if (retractions.size() > 0) {
|
||||||
change.addAddition(makeN3InputStream(additions),
|
change.addRemoval(makeN3InputStream(retractions),
|
||||||
RDFService.ModelSerializationFormat.N3, ModelNames.ABOX_INFERENCES);
|
RDFService.ModelSerializationFormat.N3, ModelNames.ABOX_INFERENCES);
|
||||||
rdfService.changeSetUpdate(change);
|
}
|
||||||
log.debug((System.currentTimeMillis() - start) +
|
if (additions.size() > 0) {
|
||||||
" ms to retract " + retractions.size() +
|
change.addAddition(makeN3InputStream(additions),
|
||||||
" statements and add " + additions.size() + " statements");
|
RDFService.ModelSerializationFormat.N3, ModelNames.ABOX_INFERENCES);
|
||||||
|
}
|
||||||
|
rdfService.changeSetUpdate(change);
|
||||||
|
log.debug((System.currentTimeMillis() - start) +
|
||||||
|
" ms to retract " + retractions.size() +
|
||||||
|
" statements and add " + additions.size() + " statements");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream makeN3InputStream(Model m) {
|
private InputStream makeN3InputStream(Model m) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue