Search in sources :

Example 1 with ModelContainer

use of org.geneontology.minerva.ModelContainer 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();
}
Also used : UndoAwareMolecularModelManager(org.geneontology.minerva.UndoAwareMolecularModelManager) ModelContainer(org.geneontology.minerva.ModelContainer) UndoMetadata(org.geneontology.minerva.UndoAwareMolecularModelManager.UndoMetadata) Test(org.junit.Test)

Example 2 with ModelContainer

use of org.geneontology.minerva.ModelContainer 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();
}
Also used : Set(java.util.Set) UndoAwareMolecularModelManager(org.geneontology.minerva.UndoAwareMolecularModelManager) InferenceProviderCreator(org.geneontology.minerva.server.inferences.InferenceProviderCreator) ModelContainer(org.geneontology.minerva.ModelContainer) UndoMetadata(org.geneontology.minerva.UndoAwareMolecularModelManager.UndoMetadata) Test(org.junit.Test)

Example 3 with ModelContainer

use of org.geneontology.minerva.ModelContainer in project minerva by geneontology.

the class ModelEditTest method testAddEdgeAsBatch.

@Test
public void testAddEdgeAsBatch() throws Exception {
    List<M3Request> batch = new ArrayList<>();
    M3Request r;
    final String individualId = "http://model.geneontology.org/5437882f00000024/5437882f0000032";
    final IRI individualIRI = IRI.create(individualId);
    final String individualIdCurie = curieHandler.getCuri(individualIRI);
    final String modelId = "http://model.geneontology.org/5437882f00000024";
    final ModelContainer model = models.getModel(IRI.create(modelId));
    assertNotNull(model);
    boolean found = false;
    boolean foundCurie = false;
    Set<OWLNamedIndividual> individuals = model.getAboxOntology().getIndividualsInSignature();
    for (OWLNamedIndividual individual : individuals) {
        if (individualIRI.equals(individual.getIRI())) {
            found = true;
            foundCurie = individualIdCurie.equals(curieHandler.getCuri(individual.getIRI()));
        }
    }
    assertTrue(found);
    assertTrue(foundCurie);
    // create new individual
    r = BatchTestTools.addIndividual(modelId, "GO:0003674");
    r.arguments.assignToVariable = "VAR1";
    batch.add(r);
    // add link to existing individual (converted from old model)
    r = BatchTestTools.addEdge(modelId, "VAR1", "BFO:0000050", individualId);
    batch.add(r);
    r = BatchTestTools.addEdge(modelId, "VAR1", "RO:0002333", individualId);
    batch.add(r);
    executeBatch(batch);
}
Also used : ModelContainer(org.geneontology.minerva.ModelContainer)

Example 4 with ModelContainer

use of org.geneontology.minerva.ModelContainer in project minerva by geneontology.

the class ValidationTest method validateGoCams.

public static void validateGoCams(String input, boolean should_fail, boolean check_shex) throws Exception {
    String blazegraph_journal = makeBlazegraphJournal(input);
    UndoAwareMolecularModelManager m3 = new UndoAwareMolecularModelManager(tbox_ontology, curieHandler, modelIdPrefix, blazegraph_journal, null, go_lego_journal_file, true);
    try {
        URL shex_schema_url = new URL(shexFileUrl);
        // for some reason the temporary_model file won't parse..
        File shex_schema_file = new File("src/test/resources/validate.shex");
        org.apache.commons.io.FileUtils.copyURLToFile(shex_schema_url, shex_schema_file);
        URL shex_map_url = new URL(goshapemapFileUrl);
        File shex_map_file = new File("src/test/resources/validate.shapemap");
        org.apache.commons.io.FileUtils.copyURLToFile(shex_map_url, shex_map_file);
        MinervaShexValidator shex = new MinervaShexValidator(shex_schema_file, shex_map_file, curieHandler, m3.getGolego_repo());
        if (check_shex) {
            if (check_shex) {
                shex.setActive(true);
            } else {
                shex.setActive(false);
            }
        }
        InferenceProviderCreator ipc = StartUpTool.createInferenceProviderCreator("arachne", m3, shex);
        LOGGER.info("Validating models:");
        m3.getAvailableModelIds().stream().forEach(modelIRI -> {
            boolean isConsistent = true;
            boolean isConformant = true;
            LOGGER.info("processing \t" + modelIRI);
            ModelContainer mc = m3.getModel(modelIRI);
            Set<OWLAnnotation> annos = mc.getAboxOntology().getAnnotations();
            // this is where everything actually happens
            InferenceProvider ip;
            try {
                // this ipc.create method results in the execution of the OWL reasoner and, if shex is set to active, the shex validation
                ip = ipc.create(mc);
                isConsistent = ip.isConsistent();
                if (!should_fail) {
                    assertTrue(modelIRI + " is assessed to be (OWL) inconsistent but should not be.", isConsistent);
                } else if (!check_shex) {
                    assertFalse(modelIRI + " is assessed to be (OWL) consistent but should not be.", isConsistent);
                }
                if (check_shex) {
                    ValidationResultSet validations = ip.getValidation_results();
                    isConformant = validations.allConformant();
                    if (!should_fail) {
                        assertTrue(modelIRI + " does not conform to the shex schema and it should: \n" + annos, isConformant);
                    } else {
                        assertFalse(modelIRI + " conforms to the shex schema and it should not: \n" + annos, isConformant);
                    }
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        });
        LOGGER.info("done with validation");
    } finally {
        m3.dispose();
    }
}
Also used : UndoAwareMolecularModelManager(org.geneontology.minerva.UndoAwareMolecularModelManager) InferenceProviderCreator(org.geneontology.minerva.server.inferences.InferenceProviderCreator) InferenceProvider(org.geneontology.minerva.json.InferenceProvider) ModelContainer(org.geneontology.minerva.ModelContainer) URL(java.net.URL) RepositoryException(org.openrdf.repository.RepositoryException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) IOException(java.io.IOException) RDFParseException(org.openrdf.rio.RDFParseException) File(java.io.File) ValidationResultSet(org.geneontology.minerva.validation.ValidationResultSet)

Example 5 with ModelContainer

use of org.geneontology.minerva.ModelContainer in project minerva by geneontology.

the class ModelReasonerTest method testReasoner.

// FIXME @Test
public void testReasoner() throws Exception {
    List<M3Request> batch = new ArrayList<>();
    M3Request r;
    final String individualId = "http://model.geneontology.org/5525a0fc00000001/5525a0fc0000023";
    final IRI individualIRI = IRI.create(individualId);
    final String individualIdCurie = curieHandler.getCuri(individualIRI);
    final String modelId = "http://model.geneontology.org/5525a0fc00000001";
    final ModelContainer model = models.getModel(IRI.create(modelId));
    assertNotNull(model);
    boolean found = false;
    boolean foundCurie = false;
    Set<OWLNamedIndividual> individuals = model.getAboxOntology().getIndividualsInSignature();
    for (OWLNamedIndividual individual : individuals) {
        if (individualIRI.equals(individual.getIRI())) {
            found = true;
            foundCurie = individualIdCurie.equals(curieHandler.getCuri(individual.getIRI()));
        }
    }
    assertTrue(found);
    assertTrue(foundCurie);
    // get model
    r = new M3Request();
    r.entity = Entity.model;
    r.operation = Operation.get;
    r.arguments = new M3Argument();
    r.arguments.modelId = modelId;
    batch.add(r);
    M3BatchResponse response = executeBatch(batch);
    JsonOwlIndividual[] responseIndividuals = BatchTestTools.responseIndividuals(response);
    JsonOwlIndividual targetIndividual = null;
    for (JsonOwlIndividual individual : responseIndividuals) {
        if (individualIdCurie.equals(individual.id)) {
            targetIndividual = individual;
            break;
        }
    }
    assertNotNull(targetIndividual);
    assertNotNull(targetIndividual.inferredType);
    assertEquals("Expected two inferences", 2, targetIndividual.inferredType.length);
}
Also used : ArrayList(java.util.ArrayList) ModelContainer(org.geneontology.minerva.ModelContainer) JsonOwlIndividual(org.geneontology.minerva.json.JsonOwlIndividual)

Aggregations

ModelContainer (org.geneontology.minerva.ModelContainer)9 UndoAwareMolecularModelManager (org.geneontology.minerva.UndoAwareMolecularModelManager)5 Test (org.junit.Test)4 File (java.io.File)3 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)3 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)3 UndoMetadata (org.geneontology.minerva.UndoAwareMolecularModelManager.UndoMetadata)2 CurieHandler (org.geneontology.minerva.curie.CurieHandler)2 MappedCurieHandler (org.geneontology.minerva.curie.MappedCurieHandler)2 InferenceProvider (org.geneontology.minerva.json.InferenceProvider)2 InferenceProviderCreator (org.geneontology.minerva.server.inferences.InferenceProviderCreator)2 IRI (org.semanticweb.owlapi.model.IRI)2 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 JsonModel (org.geneontology.minerva.json.JsonModel)1 JsonOwlIndividual (org.geneontology.minerva.json.JsonOwlIndividual)1 MolecularModelJsonRenderer (org.geneontology.minerva.json.MolecularModelJsonRenderer)1 ValidationResultSet (org.geneontology.minerva.validation.ValidationResultSet)1