use of org.geneontology.minerva.UndoAwareMolecularModelManager.UndoMetadata in project minerva by geneontology.
the class DataPropertyTest method testDataProperyRenderer.
@Test
public void testDataProperyRenderer() throws Exception {
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
OWLOntology ontology = m.createOntology(IRI.generateDocumentIRI());
final IRI clsIRI = IRI.generateDocumentIRI();
final IRI propIRI = IRI.generateDocumentIRI();
// create a test ontology with one data property and one class
OWLDataFactory f = m.getOWLDataFactory();
OWLDataProperty prop = f.getOWLDataProperty(propIRI);
m.addAxiom(ontology, f.getOWLDeclarationAxiom(prop));
m.addAxiom(ontology, f.getOWLAnnotationAssertionAxiom(propIRI, f.getOWLAnnotation(f.getRDFSLabel(), f.getOWLLiteral("fake-data-property"))));
OWLClass cls = f.getOWLClass(clsIRI);
m.addAxiom(ontology, f.getOWLDeclarationAxiom(cls));
m.addAxiom(ontology, f.getOWLAnnotationAssertionAxiom(clsIRI, f.getOWLAnnotation(f.getRDFSLabel(), f.getOWLLiteral("fake-cls"))));
// graph and m3
final UndoMetadata metadata = new UndoMetadata("foo-user");
UndoAwareMolecularModelManager m3 = createM3(ontology);
final ModelContainer model = m3.generateBlankModel(metadata);
final OWLNamedIndividual individual = m3.createIndividual(model, cls, metadata);
m3.addDataProperty(model, individual, prop, f.getOWLLiteral(10), metadata);
MolecularModelJsonRenderer r = new MolecularModelJsonRenderer(model, null, curieHandler);
final JsonModel jsonModel = r.renderModel();
assertEquals(1, jsonModel.individuals.length);
assertEquals(1, jsonModel.individuals[0].annotations.length);
{
JsonAnnotation ann = jsonModel.individuals[0].annotations[0];
assertEquals(propIRI.toString(), ann.key);
assertEquals("10", ann.value);
assertEquals("xsd:integer", ann.valueType);
}
m3.dispose();
}
use of org.geneontology.minerva.UndoAwareMolecularModelManager.UndoMetadata in project minerva by geneontology.
the class DataPropertyTest method testDataPropertyBatch.
@Test
public void testDataPropertyBatch() throws Exception {
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
OWLOntology ontology = m.createOntology(IRI.generateDocumentIRI());
final IRI clsIRI = IRI.create("http://purl.obolibrary.org/obo/GO_0001");
final IRI propIRI = IRI.create("http://purl.obolibrary.org/obo/RO_0001");
// create a test ontology with one data property and one class
OWLDataFactory f = m.getOWLDataFactory();
OWLDataProperty prop = f.getOWLDataProperty(propIRI);
m.addAxiom(ontology, f.getOWLDeclarationAxiom(prop));
m.addAxiom(ontology, f.getOWLAnnotationAssertionAxiom(propIRI, f.getOWLAnnotation(f.getRDFSLabel(), f.getOWLLiteral("fake-data-property"))));
OWLClass cls = f.getOWLClass(clsIRI);
m.addAxiom(ontology, f.getOWLDeclarationAxiom(cls));
m.addAxiom(ontology, f.getOWLAnnotationAssertionAxiom(clsIRI, f.getOWLAnnotation(f.getRDFSLabel(), f.getOWLLiteral("fake-cls"))));
// graph and m3
UndoAwareMolecularModelManager m3 = createM3(ontology);
// handler
InferenceProviderCreator ipc = null;
JsonOrJsonpBatchHandler handler = new JsonOrJsonpBatchHandler(m3, "development", ipc, null, null);
// empty model
final ModelContainer model = m3.generateBlankModel(new UndoMetadata("foo-user"));
// create individual with annotations, including one data property
M3Request r1 = BatchTestTools.addIndividual(curieHandler.getCuri(model.getModelId()), "GO:0001");
r1.arguments.values = new JsonAnnotation[2];
r1.arguments.values[0] = new JsonAnnotation();
r1.arguments.values[0].key = AnnotationShorthand.comment.name();
r1.arguments.values[0].value = "foo-comment";
r1.arguments.values[1] = new JsonAnnotation();
r1.arguments.values[1].key = curieHandler.getCuri(propIRI);
r1.arguments.values[1].value = "10";
r1.arguments.values[1].valueType = "xsd:integer";
M3BatchResponse response1 = exec(handler, Collections.singletonList(r1));
final String individualsId;
// check for data property as annotation
{
assertEquals(1, response1.data.individuals.length);
JsonOwlIndividual i = response1.data.individuals[0];
assertEquals(4, i.annotations.length);
individualsId = i.id;
JsonAnnotation dataPropAnnotation = null;
for (JsonAnnotation ann : i.annotations) {
if (curieHandler.getCuri(propIRI).equals(ann.key)) {
dataPropAnnotation = ann;
}
}
assertNotNull(dataPropAnnotation);
}
assertNotNull(individualsId);
// check underlying owl model for usage of OWLDataProperty
{
Set<OWLDataPropertyAssertionAxiom> axioms = model.getAboxOntology().getAxioms(AxiomType.DATA_PROPERTY_ASSERTION);
assertEquals(1, axioms.size());
OWLDataPropertyAssertionAxiom ax = axioms.iterator().next();
OWLLiteral literal = ax.getObject();
assertEquals(prop, ax.getProperty());
assertEquals(f.getOWLLiteral(10), literal);
}
// delete data property
M3Request r2 = new M3Request();
r2.entity = Entity.individual;
r2.operation = Operation.removeAnnotation;
r2.arguments = new M3Argument();
r2.arguments.individual = individualsId;
r2.arguments.modelId = curieHandler.getCuri(model.getModelId());
r2.arguments.values = new JsonAnnotation[1];
r2.arguments.values[0] = new JsonAnnotation();
r2.arguments.values[0].key = propIRI.toString();
r2.arguments.values[0].value = "10";
r2.arguments.values[0].valueType = "xsd:integer";
M3BatchResponse response2 = exec(handler, Collections.singletonList(r2));
// check for deleted property as annotation
{
assertEquals(1, response2.data.individuals.length);
JsonOwlIndividual i = response2.data.individuals[0];
assertEquals(3, i.annotations.length);
}
m3.dispose();
}
use of org.geneontology.minerva.UndoAwareMolecularModelManager.UndoMetadata in project minerva by geneontology.
the class JsonOrJsonpBatchHandler method m3Batch.
private M3BatchResponse m3Batch(M3BatchResponse response, M3Request[] requests, String userId, Set<String> providerGroups, boolean useReasoner, boolean isPrivileged) throws InsufficientPermissionsException, Exception {
userId = normalizeUserId(userId);
UndoMetadata token = new UndoMetadata(userId);
final BatchHandlerValues values = new BatchHandlerValues();
for (M3Request request : requests) {
requireNotNull(request, "request");
requireNotNull(request.entity, "entity");
requireNotNull(request.operation, "operation");
final Entity entity = request.entity;
final Operation operation = request.operation;
checkPermissions(entity, operation, isPrivileged);
// individual
if (Entity.individual == entity) {
String error = handleRequestForIndividual(request, operation, userId, providerGroups, token, values);
if (error != null) {
return error(response, error, null);
}
} else // edge
if (Entity.edge == entity) {
String error = handleRequestForEdge(request, operation, userId, providerGroups, token, values);
if (error != null) {
return error(response, error, null);
}
} else // model
if (Entity.model == entity) {
String error = handleRequestForModel(request, response, operation, userId, providerGroups, token, values);
if (error != null) {
return error(response, error, null);
}
} else // meta (e.g. relations, model ids, evidence)
if (Entity.meta == entity) {
if (Operation.get == operation) {
if (values.nonMeta) {
// can only be used with other "meta" operations in batch mode, otherwise it would lead to conflicts in the returned signal
return error(response, "Get meta entity can only be combined with other meta operations.", null);
}
getMeta(response, userId, providerGroups);
} else if (Operation.exportAll == operation) {
exportAllModels();
response.messageType = "success";
response.signal = "meta";
response.message = "Dumped all models to folder";
return response;
} else if (Operation.sparql == operation) {
handleSPARQLRequest(request, response);
} else {
return error(response, "Unknown operation: " + operation, null);
}
} else {
return error(response, "Unknown entity: " + entity, null);
}
}
if (M3BatchResponse.SIGNAL_META.equals(response.signal)) {
return response;
}
if (values.model == null) {
return error(response, "Empty batch calls are not supported, at least one request is required.", null);
}
// update reasoner
// report state
InferenceProvider inferenceProvider = null;
boolean isConsistent = true;
boolean isConformant = true;
if (inferenceProviderCreator != null && useReasoner) {
inferenceProvider = inferenceProviderCreator.create(values.model);
isConsistent = inferenceProvider.isConsistent();
response.setReasoned(true);
// to ensure that all individuals are in the response
values.renderBulk = true;
org.geneontology.minerva.validation.ValidationResultSet validations = inferenceProvider.getValidation_results();
isConformant = validations.allConformant();
}
// create response.data
response.data = new ResponseData();
// final MolecularModelJsonRenderer renderer = createModelRenderer(values.model, externalLookupService, inferenceProvider, curieHandler);
// working towards zero use of external look up service.. which is both slow and confusing.
final MolecularModelJsonRenderer renderer = createModelRenderer(values.model, m3.getGolego_repo(), inferenceProvider, curieHandler);
if (values.renderBulk) {
// render complete model
JsonModel jsonModel = renderer.renderModel();
initResponseData(jsonModel, response.data);
response.signal = M3BatchResponse.SIGNAL_REBUILD;
} else {
response.signal = M3BatchResponse.SIGNAL_MERGE;
// render individuals
if (values.relevantIndividuals.isEmpty() == false) {
Pair<JsonOwlIndividual[], JsonOwlFact[]> pair = renderer.renderIndividuals(values.relevantIndividuals);
response.data.individuals = pair.getLeft();
response.data.facts = pair.getRight();
}
// add model annotations
response.data.annotations = MolecularModelJsonRenderer.renderModelAnnotations(values.model.getAboxOntology(), curieHandler);
response.data.modelId = curieHandler.getCuri(values.model.getModelId());
}
// add other infos to data
if (!isConsistent) {
response.data.inconsistentFlag = Boolean.TRUE;
}
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;
if (response.message == null) {
response.message = "success";
}
return response;
}
use of org.geneontology.minerva.UndoAwareMolecularModelManager.UndoMetadata in project minerva by geneontology.
the class UndoAwareMolecularModelManagerTest method testUndoRedo.
@Test
public void testUndoRedo() throws Exception {
OWLOntology tbox = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(this.getClass().getResourceAsStream("/go-mgi-signaling-test.obo"));
m3 = new UndoAwareMolecularModelManager(tbox, curieHandler, "http://testmodel.geneontology.org/", folder.newFile().getAbsolutePath(), null, go_lego_journal_file, true);
String userId = "test-user-id";
ModelContainer model = m3.generateBlankModel(null);
// GO:0001158 ! enhancer sequence-specific DNA binding
OWLNamedIndividual bindingIdividual = m3.createIndividual(model.getModelId(), "GO:0001158", null, new UndoMetadata(userId));
String bindingId = bindingIdividual.getIRI().toString();
// BFO:0000066 GO:0005654 ! occurs_in nucleoplasm
m3.addType(model.getModelId(), bindingId, "BFO:0000066", "GO:0005654", new UndoMetadata(userId));
MolecularModelJsonRenderer renderer = new MolecularModelJsonRenderer(model, null, curieHandler);
JsonOwlIndividual render1 = renderer.renderObject(bindingIdividual);
assertEquals(2, render1.type.length);
// check event count
Pair<List<ChangeEvent>, List<ChangeEvent>> undoRedoEvents = m3.getUndoRedoEvents(model.getModelId());
List<ChangeEvent> undoEvents = undoRedoEvents.getLeft();
List<ChangeEvent> redoEvents = undoRedoEvents.getRight();
assertEquals(0, redoEvents.size());
assertEquals(2, undoEvents.size());
// undo
assertTrue(m3.undo(model, userId));
JsonOwlIndividual render2 = renderer.renderObject(bindingIdividual);
assertEquals(1, render2.type.length);
// redo
assertTrue(m3.redo(model, userId));
JsonOwlIndividual render3 = renderer.renderObject(bindingIdividual);
assertEquals(2, render3.type.length);
// undo again
assertTrue(m3.undo(model, userId));
JsonOwlIndividual render4 = renderer.renderObject(bindingIdividual);
assertEquals(1, render4.type.length);
// add new type
// GO:0001664 ! G-protein coupled receptor binding
m3.addType(model.getModelId(), bindingId, "GO:0001664", new UndoMetadata(userId));
// redo again, should fail
assertFalse(m3.redo(model, userId));
if (m3 != null) {
m3.dispose();
}
}
Aggregations