Skip to content

Commit

Permalink
Added a basic robot diff operation to minerva m3batchhandler
Browse files Browse the repository at this point in the history
  • Loading branch information
goodb committed Oct 29, 2020
1 parent dcaaf3e commit 0aa9214
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
5 changes: 5 additions & 0 deletions minerva-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,10 @@
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>org.obolibrary.robot</groupId>
<artifactId>robot-core</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public void loadModel(IRI modelId, boolean isOverride) throws OWLOntologyCreatio


@Override
protected OWLOntology loadModelABox(IRI modelId) throws OWLOntologyCreationException {
public OWLOntology loadModelABox(IRI modelId) throws OWLOntologyCreationException {
LOG.info("Load model abox: " + modelId + " from database");
try {
BigdataSailRepositoryConnection connection = repo.getReadOnlyConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ else if (Entity.meta == entity) {
if(!isConformant) {
response.data.validation_results = inferenceProvider.getValidation_results();
}
response.data.diffResult = values.diffResult;
response.data.modifiedFlag = Boolean.valueOf(values.model.isModified());
// These are required for an "okay" response.
response.messageType = M3BatchResponse.MESSAGE_TYPE_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.gson.annotations.SerializedName;
import org.geneontology.minerva.json.*;
import org.geneontology.minerva.validation.ValidationResultSet;
import org.geneontology.owl.differ.Differ;

import javax.ws.rs.*;
import java.util.List;
Expand Down Expand Up @@ -63,6 +64,9 @@ public static enum Operation {
@SerializedName("reset")
resetModel,

@SerializedName("diff")
diffModel,

@SerializedName("update-imports")
updateImports,

Expand Down Expand Up @@ -114,6 +118,10 @@ public static class ResponseData extends JsonModel {
@SerializedName("modified-p")
public Boolean modifiedFlag;

//TODO starting out here with raw result from robot
@SerializedName("diff-result")
public String diffResult;

public Object undo;
public Object redo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@
import org.geneontology.minerva.server.handler.M3BatchHandler.Operation;
import org.geneontology.minerva.server.handler.OperationsTools.MissingParameterException;
import org.geneontology.minerva.server.validation.BeforeSaveModelValidator;
import org.geneontology.owl.differ.Differ;
import org.geneontology.rules.engine.WorkingMemory;
import org.obolibrary.robot.DiffOperation;
import org.obolibrary.robot.IOHelper;
import org.openrdf.query.*;
import org.openrdf.repository.RepositoryException;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.rio.RDFWriter;
import org.openrdf.rio.Rio;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.model.parameters.OntologyCopy;
import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.util.*;

import static org.geneontology.minerva.server.handler.OperationsTools.requireNotNull;
Expand Down Expand Up @@ -78,7 +83,8 @@ static class BatchHandlerValues implements VariableResolver {
boolean nonMeta = false;
ModelContainer model = null;
Map<String, OWLNamedIndividual> individualVariable = new HashMap<>();

String diffResult = null;

@Override
public boolean notVariable(String id) {
return individualVariable.containsKey(id) == false;
Expand Down Expand Up @@ -507,6 +513,26 @@ else if (Operation.resetModel == operation) {
//reset model values
values.model = checkModelId(null, request);
values.renderBulk = true;
}else if (Operation.diffModel == operation) {
values.nonMeta = true;
requireNotNull(request.arguments, "request.arguments");
//this won't change
values.model = checkModelId(values.model, request);
IRI model_iri = values.model.getModelId();
//run diff
OWLOntologyManager man1 = OWLManager.createOWLOntologyManager();
OWLOntology active_ontology = man1.copyOntology(values.model.getAboxOntology(), OntologyCopy.DEEP);
OWLOntology stored_ontology = m3.loadModelABox(model_iri);
//TODO refine representation of diff result..
StringWriter writer = new StringWriter();
// boolean actual = DiffOperation.compare(active_ontology, stored_ontology, writer);
Map<String, String> options = new HashMap<>();
options.put("labels", "true");
options.put("format", "html");
DiffOperation.compare(active_ontology, stored_ontology, new IOHelper(), writer, options);
values.diffResult = writer.toString();
writer.close();
values.renderBulk = true;
}
else if (Operation.undo == operation) {
values.nonMeta = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ public void testModelReset() throws Exception {
Set<OWLAxiom> mid_axioms = midModel.getABoxAxioms(null);
assertFalse(mid_axioms.equals(start_axioms));

//test diff command for comparison
r = new M3Request();
r.entity = Entity.model;
r.operation = Operation.diffModel;
r.arguments = new M3Argument();
r.arguments.modelId = modelId;
M3BatchResponse diffresp = executeBatch(r);
String dr = diffresp.data.diffResult;
assertFalse(dr.equals("Ontologies are identical\n"));

//now reset the model
r = new M3Request();
r.entity = Entity.model;
Expand All @@ -158,6 +168,16 @@ public void testModelReset() throws Exception {
OWLOntology endModel = man3.copyOntology(models.getModelAbox(IRI.create(modelId)), OntologyCopy.DEEP);
Set<OWLAxiom> end_axioms = endModel.getABoxAxioms(null);
assertTrue(start_axioms.equals(end_axioms));

//test diff command for comparison
r = new M3Request();
r.entity = Entity.model;
r.operation = Operation.diffModel;
r.arguments = new M3Argument();
r.arguments.modelId = modelId;
diffresp = executeBatch(r);
dr = diffresp.data.diffResult;
assertTrue(dr.equals("Ontologies are identical\n"));
}

@Test
Expand Down

0 comments on commit 0aa9214

Please sign in to comment.