Search in sources :

Example 1 with InferenceProviderCreator

use of org.geneontology.minerva.server.inferences.InferenceProviderCreator in project minerva by geneontology.

the class ARTHandlerTest method setUpBeforeClass.

/**
 * @throws java.lang.Exception
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    LOGGER.info("Setup shex.");
    File shex_schema_file = new File("src/test/resources/validate.shex");
    File shex_map_file = new File("src/test/resources/validate.shapemap");
    LOGGER.info("Set up molecular model manager - loading files into a journal");
    // set curie handler
    final CurieMappings localMappings = new CurieMappings.SimpleCurieMappings(Collections.singletonMap(modelIdcurie, modelIdPrefix));
    curieHandler = new MappedCurieHandler(DefaultCurieHandler.loadDefaultMappings(), localMappings);
    String inputDB = makeBlazegraphJournal(valid_model_folder);
    OWLOntologyManager ontman = OWLManager.createOWLOntologyManager();
    // empty tbox
    tbox_ontology = ontman.createOntology(IRI.create("http://example.org/dummy"));
    models = new UndoAwareMolecularModelManager(tbox_ontology, curieHandler, modelIdPrefix, inputDB, model_save, go_lego_journal_file, true);
    models.addTaxonMetadata();
    LOGGER.info("Setup Jetty config.");
    ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.register(GsonMessageBodyHandler.class);
    resourceConfig.register(RequireJsonpFilter.class);
    MinervaShexValidator shex = new MinervaShexValidator(shex_schema_file, shex_map_file, curieHandler, models.getGolego_repo());
    shex.setActive(true);
    // setup the config for the startup tool.
    MinervaStartUpConfig conf = new MinervaStartUpConfig();
    conf.reasonerOpt = "arachne";
    conf.shex = shex;
    conf.port = 6800;
    conf.contextString = "/";
    InferenceProviderCreator ipc = StartUpTool.createInferenceProviderCreator(conf.reasonerOpt, models, conf.shex);
    ModelARTHandler artHandler = new ModelARTHandler(models, ipc);
    // set up a handler for testing with M3BatchRequest service
    handler = new JsonOrJsonpBatchHandler(models, "development", ipc, Collections.<OWLObjectProperty>emptySet(), (ExternalLookupService) null);
    resourceConfig = resourceConfig.registerInstances(artHandler);
    // setup jetty server port, buffers and context path
    server = new Server();
    // create connector with port and custom buffer sizes
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setRequestHeaderSize(conf.requestHeaderSize);
    ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(http_config));
    connector.setPort(conf.port);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath(conf.contextString);
    server.setHandler(context);
    ServletHolder h = new ServletHolder(new ServletContainer(resourceConfig));
    context.addServlet(h, "/*");
    // start jetty server
    LOGGER.info("Start server on port: " + conf.port + " context: " + conf.contextString);
    server.start();
}
Also used : MappedCurieHandler(org.geneontology.minerva.curie.MappedCurieHandler) CurieMappings(org.geneontology.minerva.curie.CurieMappings) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) UndoAwareMolecularModelManager(org.geneontology.minerva.UndoAwareMolecularModelManager) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) InferenceProviderCreator(org.geneontology.minerva.server.inferences.InferenceProviderCreator) MinervaStartUpConfig(org.geneontology.minerva.server.StartUpTool.MinervaStartUpConfig) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServerConnector(org.eclipse.jetty.server.ServerConnector) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) File(java.io.File) MinervaShexValidator(org.geneontology.minerva.server.validation.MinervaShexValidator) ExternalLookupService(org.geneontology.minerva.lookup.ExternalLookupService)

Example 2 with InferenceProviderCreator

use of org.geneontology.minerva.server.inferences.InferenceProviderCreator 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 InferenceProviderCreator

use of org.geneontology.minerva.server.inferences.InferenceProviderCreator in project minerva by geneontology.

the class ModelEditTest method init.

static void init(ParserWrapper pw) throws OWLOntologyCreationException, IOException {
    // This includes only the needed terms for the test to pass
    final OWLOntology tbox = OWLManager.createOWLOntologyManager().loadOntology(IRI.create(new File("src/test/resources/edit-test/go-lego-empty.owl")));
    // curie handler
    final String modelIdcurie = "gomodel";
    final String modelIdPrefix = "http://model.geneontology.org/";
    final CurieMappings localMappings = new CurieMappings.SimpleCurieMappings(Collections.singletonMap(modelIdcurie, modelIdPrefix));
    curieHandler = new MappedCurieHandler(DefaultCurieHandler.loadDefaultMappings(), localMappings);
    models = new UndoAwareMolecularModelManager(tbox, curieHandler, modelIdPrefix, folder.newFile().getAbsolutePath(), null, go_lego_journal_file, true);
    InferenceProviderCreator ipc = null;
    handler = new JsonOrJsonpBatchHandler(models, "development", ipc, Collections.<OWLObjectProperty>emptySet(), (ExternalLookupService) null);
}
Also used : MappedCurieHandler(org.geneontology.minerva.curie.MappedCurieHandler) CurieMappings(org.geneontology.minerva.curie.CurieMappings) UndoAwareMolecularModelManager(org.geneontology.minerva.UndoAwareMolecularModelManager) InferenceProviderCreator(org.geneontology.minerva.server.inferences.InferenceProviderCreator) File(java.io.File) ExternalLookupService(org.geneontology.minerva.lookup.ExternalLookupService)

Example 4 with InferenceProviderCreator

use of org.geneontology.minerva.server.inferences.InferenceProviderCreator 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 InferenceProviderCreator

use of org.geneontology.minerva.server.inferences.InferenceProviderCreator in project minerva by geneontology.

the class StartUpTool method startUp.

public static Server startUp(UndoAwareMolecularModelManager models, MinervaStartUpConfig conf, Map<IRI, Set<OWLAnnotation>> ont_annos) throws Exception {
    LOGGER.info("Setup Jetty config.");
    // Configuration: Use an already existing handler instance
    // Configuration: Use custom JSON renderer (GSON)
    ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.register(GsonMessageBodyHandler.class);
    resourceConfig.register(RequireJsonpFilter.class);
    resourceConfig.register(SPARQLResultsMessageBodyWriter.class);
    resourceConfig.register(SPARQLGraphMessageBodyWriter.class);
    if (conf.useRequestLogging) {
        resourceConfig.register(LoggingApplicationEventListener.class);
    }
    // resourceConfig.register(AuthorizationRequestFilter.class);
    LOGGER.info("BatchHandler config inference provider: " + conf.reasonerOpt);
    LOGGER.info("BatchHandler config importantRelations: " + conf.importantRelations);
    LOGGER.info("BatchHandler config lookupService: " + conf.lookupService);
    LOGGER.info("BatchHandler config checkLiteralIds: " + conf.checkLiteralIds);
    LOGGER.info("BatchHandler config useRequestLogging: " + conf.useRequestLogging);
    if (conf.golrSeedUrl == null) {
        // default fall back to normal golr URL
        conf.golrSeedUrl = conf.golrUrl;
    }
    LOGGER.info("SeedHandler config golrUrl: " + conf.golrSeedUrl);
    InferenceProviderCreator ipc = createInferenceProviderCreator(conf.reasonerOpt, models, conf.shex);
    JsonOrJsonpBatchHandler batchHandler = new JsonOrJsonpBatchHandler(models, conf.defaultModelState, ipc, conf.importantRelations, conf.lookupService);
    // conf.checkLiteralIds;
    batchHandler.CHECK_LITERAL_IDENTIFIERS = false;
    SimpleEcoMapper ecoMapper = EcoMapperFactory.createSimple();
    // JsonOrJsonpSeedHandler seedHandler = new JsonOrJsonpSeedHandler(models, conf.defaultModelState, conf.golrSeedUrl, ecoMapper );
    // SPARQLHandler sparqlHandler = new SPARQLHandler(models, conf.sparqlEndpointTimeout);
    ModelSearchHandler searchHandler = new ModelSearchHandler(models);
    ModelARTHandler artHandler = new ModelARTHandler(models, ipc);
    LocalDate d = LocalDate.now();
    LocalTime t = LocalTime.now();
    String startup = d.toString() + " " + t.toString();
    StatusHandler statusHandler = new StatusHandler(conf, ont_annos, startup);
    TaxonHandler taxonHandler = new TaxonHandler(models);
    resourceConfig = resourceConfig.registerInstances(batchHandler, searchHandler, artHandler, statusHandler, taxonHandler);
    // setup jetty server port, buffers and context path
    Server server = new Server();
    // create connector with port and custom buffer sizes
    // old jetty
    // SelectChannelConnector connector = new SelectChannelConnector();
    // old jetty - they must be configured somewhere else in new jetty
    // connector.setRequestHeaderSize(conf.requestHeaderSize);
    // connector.setRequestBufferSize(conf.requestBufferSize);
    // new jetty - does not have setRequestBufferSize at all
    // seems to push defaults harder here.
    // to change request header size need to create a new connector and manipulate httpconfiguration
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setRequestHeaderSize(conf.requestHeaderSize);
    ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(http_config));
    connector.setPort(conf.port);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath(conf.contextString);
    server.setHandler(context);
    ServletHolder h = new ServletHolder(new ServletContainer(resourceConfig));
    context.addServlet(h, "/*");
    // start jetty server
    LOGGER.info("Start server on port: " + conf.port + " context: " + conf.contextString);
    server.start();
    return server;
}
Also used : LocalTime(java.time.LocalTime) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) InferenceProviderCreator(org.geneontology.minerva.server.inferences.InferenceProviderCreator) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) LocalDate(java.time.LocalDate) ServerConnector(org.eclipse.jetty.server.ServerConnector) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) SimpleEcoMapper(owltools.gaf.eco.SimpleEcoMapper) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

InferenceProviderCreator (org.geneontology.minerva.server.inferences.InferenceProviderCreator)8 UndoAwareMolecularModelManager (org.geneontology.minerva.UndoAwareMolecularModelManager)6 CurieMappings (org.geneontology.minerva.curie.CurieMappings)5 MappedCurieHandler (org.geneontology.minerva.curie.MappedCurieHandler)5 File (java.io.File)4 ExternalLookupService (org.geneontology.minerva.lookup.ExternalLookupService)3 URL (java.net.URL)2 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)2 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)2 Server (org.eclipse.jetty.server.Server)2 ServerConnector (org.eclipse.jetty.server.ServerConnector)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 ModelContainer (org.geneontology.minerva.ModelContainer)2 InferenceProvider (org.geneontology.minerva.json.InferenceProvider)2 MinervaShexValidator (org.geneontology.minerva.server.validation.MinervaShexValidator)2 ValidationResultSet (org.geneontology.minerva.validation.ValidationResultSet)2 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)2 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)2 RepositoryException (org.openrdf.repository.RepositoryException)2