Search in sources :

Example 1 with InferenceProvider

use of org.geneontology.minerva.json.InferenceProvider in project minerva by geneontology.

the class InferenceProviderCreatorImpl method create.

// public static InferenceProviderCreator createHermiT(MinervaShexValidator shex) {
// int maxConcurrent = Runtime.getRuntime().availableProcessors();
// return createHermiT(maxConcurrent, shex);
// }
// public static InferenceProviderCreator createHermiT(int maxConcurrent, MinervaShexValidator shex) {
// return new InferenceProviderCreatorImpl(new org.semanticweb.HermiT.ReasonerFactory(), maxConcurrent, true, "Hermit-SLME", shex);
// }
@Override
public InferenceProvider create(ModelContainer model) throws OWLOntologyCreationException, InterruptedException, IOException {
    OWLOntology ont = model.getAboxOntology();
    final OWLOntologyManager m = ont.getOWLOntologyManager();
    OWLOntology module = null;
    OWLReasoner reasoner = null;
    OWLOntology temp_ont = null;
    try {
        InferenceProvider provider;
        synchronized (ont) {
            concurrentLock.acquire();
            try {
                if (useSLME) {
                    LOG.info("Creating for module: " + model.getModelId());
                    ModuleType mtype = ModuleType.BOT;
                    SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, ont, mtype);
                    Set<OWLEntity> seeds = new HashSet<OWLEntity>(ont.getIndividualsInSignature());
                    module = ont = sme.extractAsOntology(seeds, IRI.generateDocumentIRI());
                    LOG.info("Done creating module: " + model.getModelId());
                }
                // add root types for gene products.
                // TODO investigate performance impact
                // tradefoff these queries versus loading all possible genes into tbox
                // temp_ont = addRootTypesToCopy(ont, shex.externalLookupService);
                temp_ont = addAllInferredTypesToCopyLocalOntoBlazegraph(ont);
                // do reasoning and validation on the enhanced model
                reasoner = rf.createReasoner(temp_ont);
                provider = MapInferenceProvider.create(reasoner, temp_ont, shex);
            } finally {
                concurrentLock.release();
            }
        }
        return provider;
    } finally {
        if (reasoner != null) {
            reasoner.dispose();
        }
        if (module != null) {
            m.removeOntology(module);
        }
        if (temp_ont != null) {
            temp_ont.getOWLOntologyManager().removeOntology(temp_ont);
        }
    }
}
Also used : ModuleType(uk.ac.manchester.cs.owlapi.modularity.ModuleType) InferenceProvider(org.geneontology.minerva.json.InferenceProvider) OWLReasoner(org.semanticweb.owlapi.reasoner.OWLReasoner) SyntacticLocalityModuleExtractor(uk.ac.manchester.cs.owlapi.modularity.SyntacticLocalityModuleExtractor)

Example 2 with InferenceProvider

use of org.geneontology.minerva.json.InferenceProvider 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 3 with InferenceProvider

use of org.geneontology.minerva.json.InferenceProvider in project minerva by geneontology.

the class CommandLineInterface method owl2LegoJson.

/**
 * Convert a GO-CAM owl file to a minerva json structure
 * --owl-lego-to-json
 *
 * @param input
 * @param output
 * @param usePretty
 * @throws Exception
 */
public static void owl2LegoJson(String input, String output, boolean usePretty) throws Exception {
    // minimal inputs
    if (input == null) {
        System.err.println("No input model was configured.");
        System.exit(-1);
        return;
    }
    if (output == null) {
        System.err.println("No output file was configured.");
        System.exit(-1);
        return;
    }
    // configuration
    CurieHandler curieHandler = DefaultCurieHandler.getDefaultHandler();
    GsonBuilder gsonBuilder = new GsonBuilder();
    if (usePretty) {
        gsonBuilder.setPrettyPrinting();
    }
    Gson gson = gsonBuilder.create();
    // process each model
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Loading model from file: " + input);
    }
    OWLOntology model = null;
    final JsonModel jsonModel;
    ParserWrapper pw = new ParserWrapper();
    try {
        // load model
        model = pw.parseOWL(IRI.create(new File(input).getCanonicalFile()));
        // TODO decide if we need reasoning
        InferenceProvider inferenceProvider = null;
        String modelId = null;
        Optional<IRI> ontologyIRI = model.getOntologyID().getOntologyIRI();
        if (ontologyIRI.isPresent()) {
            modelId = curieHandler.getCuri(ontologyIRI.get());
        }
        // render json
        final MolecularModelJsonRenderer renderer = new MolecularModelJsonRenderer(modelId, model, inferenceProvider, curieHandler);
        jsonModel = renderer.renderModel();
    } finally {
        if (model != null) {
            pw.getManager().removeOntology(model);
            model = null;
        }
    }
    // save as json string
    final String json = gson.toJson(jsonModel);
    final File outputFile = new File(output).getCanonicalFile();
    try (OutputStream outputStream = new FileOutputStream(outputFile)) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Saving json to file: " + outputFile);
        }
        IOUtils.write(json, outputStream);
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) JsonModel(org.geneontology.minerva.json.JsonModel) Gson(com.google.gson.Gson) InferenceProvider(org.geneontology.minerva.json.InferenceProvider) DefaultCurieHandler(org.geneontology.minerva.curie.DefaultCurieHandler) MappedCurieHandler(org.geneontology.minerva.curie.MappedCurieHandler) CurieHandler(org.geneontology.minerva.curie.CurieHandler) ParserWrapper(owltools.io.ParserWrapper) MolecularModelJsonRenderer(org.geneontology.minerva.json.MolecularModelJsonRenderer)

Example 4 with InferenceProvider

use of org.geneontology.minerva.json.InferenceProvider in project minerva by geneontology.

the class CommandLineInterface method validateGoCams.

/**
 * --validate-go-cams
 * -i /GitHub/GO_Shapes/test_ttl/go_cams/should_pass/
 * -c ./catalog-no-import.xml
 *
 * @param input
 * @param basicOutputFile
 * @param explanationOutputFile
 * @param ontologyIRI
 * @param catalog
 * @param modelIdPrefix
 * @param modelIdcurie
 * @param shexpath
 * @param shapemappath
 * @param travisMode
 * @param shouldPass
 * @throws IOException
 * @throws OWLOntologyCreationException
 */
public static void validateGoCams(String input, String outputFolder, String ontologyIRI, String catalog, String modelIdPrefix, String modelIdcurie, String shexpath, String shapemappath, boolean travisMode, boolean shouldFail, boolean checkShex, String go_lego_journal_file, boolean run_reasoner_report) throws OWLOntologyCreationException, IOException {
    LOGGER.setLevel(Level.INFO);
    String inputDB = "blazegraph.jnl";
    String shexFileUrl = "https://raw.githubusercontent.com/geneontology/go-shapes/master/shapes/go-cam-shapes.shex";
    String goshapemapFileUrl = "https://raw.githubusercontent.com/geneontology/go-shapes/master/shapes/go-cam-shapes.shapeMap";
    CurieMappings localMappings = new CurieMappings.SimpleCurieMappings(Collections.singletonMap(modelIdcurie, modelIdPrefix));
    CurieHandler curieHandler = new MappedCurieHandler(DefaultCurieHandler.loadDefaultMappings(), localMappings);
    Map<String, String> modelid_filename = new HashMap<String, String>();
    if (outputFolder == null) {
        LOGGER.error("please specify an output folder with -r ");
        System.exit(-1);
    } else if (!outputFolder.endsWith("/")) {
        outputFolder += "/";
    }
    if (input == null) {
        LOGGER.error("please provide an input file - either a directory of ttl files or a blazegraph journal");
        System.exit(-1);
    }
    LOGGER.info("loading tbox ontology: " + ontologyIRI);
    OWLOntologyManager ontman = OWLManager.createOWLOntologyManager();
    if (catalog != null) {
        LOGGER.info("using catalog: " + catalog);
        try {
            ontman.setIRIMappers(Sets.newHashSet(new CatalogXmlIRIMapper(catalog)));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        LOGGER.info("no catalog, resolving all ontology uris directly");
    }
    OWLOntology tbox_ontology = null;
    try {
        tbox_ontology = ontman.loadOntology(IRI.create(ontologyIRI));
        LOGGER.info("tbox ontology axioms loaded: " + tbox_ontology.getAxiomCount());
    } catch (OWLOntologyCreationException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // either load directly from existing journal
    if (input.endsWith(".jnl")) {
        inputDB = input;
    } else {
        // or make sure that the journal file provided is cleared out and ready
        File i = new File(input);
        if (i.exists()) {
            // remove anything that existed earlier
            File bgdb = new File(inputDB);
            if (bgdb.exists()) {
                bgdb.delete();
            }
        }
    }
    // make the manager
    LOGGER.info("Setting up model manager and initializing rules for Arachne reasoner");
    UndoAwareMolecularModelManager m3 = new UndoAwareMolecularModelManager(tbox_ontology, curieHandler, modelIdPrefix, inputDB, null, go_lego_journal_file, true);
    // if provided a directory as input, load them ttl files into the manager
    File i = new File(input);
    if (i.exists() && !input.endsWith(".jnl")) {
        if (i.isDirectory()) {
            LOGGER.info("Loading models from " + i.getAbsolutePath());
            Set<String> model_iris = new HashSet<String>();
            FileUtils.listFiles(i, null, true).parallelStream().parallel().forEach(file -> {
                if (file.getName().endsWith(".ttl") || file.getName().endsWith("owl")) {
                    try {
                        String modeluri = m3.importModelToDatabase(file, true);
                        if (modeluri == null) {
                            LOGGER.error("Null model IRI: " + modeluri + " file: " + file);
                        } else if (!model_iris.add(modeluri)) {
                            LOGGER.error("Multiple models with same IRI: " + modeluri + " file: " + file + " file: " + modelid_filename.get(modeluri));
                        } else {
                            modelid_filename.put(modeluri, file.getName());
                        }
                    } catch (OWLOntologyCreationException | RepositoryException | RDFParseException | RDFHandlerException | IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            });
        } else {
            // just load the one provided
            LOGGER.info("Loading " + i);
            try {
                m3.importModelToDatabase(i, true);
            } catch (OWLOntologyCreationException | RepositoryException | RDFParseException | RDFHandlerException | IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        LOGGER.info("loaded files into blazegraph journal: " + input);
    }
    // now set up shex validator
    if (shexpath == null) {
        // fall back on downloading from shapes repo
        URL shex_schema_url;
        try {
            shex_schema_url = new URL(shexFileUrl);
            shexpath = "./go-cam-schema.shex";
            File shex_schema_file = new File(shexpath);
            org.apache.commons.io.FileUtils.copyURLToFile(shex_schema_url, shex_schema_file);
            System.err.println("-s .No shex schema provided, using: " + shexFileUrl);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    if (shapemappath == null) {
        URL shex_map_url;
        try {
            shex_map_url = new URL(goshapemapFileUrl);
            shapemappath = "./go-cam-shapes.shapeMap";
            File shex_map_file = new File(shapemappath);
            org.apache.commons.io.FileUtils.copyURLToFile(shex_map_url, shex_map_file);
            System.err.println("-m .No shape map file provided, using: " + goshapemapFileUrl);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    LOGGER.info("making shex validator: " + shexpath + " " + shapemappath + " " + curieHandler + " ");
    MinervaShexValidator shex = null;
    try {
        shex = new MinervaShexValidator(shexpath, shapemappath, curieHandler, m3.getGolego_repo());
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    if (checkShex) {
        shex.setActive(true);
    } else {
        shex.setActive(false);
    }
    // shex validator is ready, now build the inference provider (which provides access to the shex validator and provides inferences useful for shex)
    String reasonerOpt = "arachne";
    LOGGER.info("Building OWL inference provider: " + reasonerOpt);
    InferenceProviderCreator ipc = StartUpTool.createInferenceProviderCreator(reasonerOpt, m3, shex);
    LOGGER.info("Validating models: " + reasonerOpt);
    // Set up all the report files.
    String basic_output_file = outputFolder + "main_report.txt";
    String explanations_file = outputFolder + "explanations.txt";
    String activity_output_file = outputFolder + "activity_report.txt";
    if (outputFolder != null) {
        try {
            // valid or not
            FileWriter basic_shex_output = new FileWriter(basic_output_file, false);
            basic_shex_output.write("filename\tmodel_title\tmodel_url\tmodelstate\tcontributor\tprovider\tdate\tOWL_consistent\tshex_valid\tshex_meta_problem\tshex_data_problem\tvalidation_time_milliseconds\taxioms\tn_rows_gpad\t");
            basic_shex_output.write(GoCamModelStats.statsHeader() + "\n");
            basic_shex_output.close();
            // tab delimited explanations for failures
            FileWriter explanations = new FileWriter(explanations_file, false);
            explanations.write("filename\tmodel_title\tmodel_iri\tnode\tNode_types\tproperty\tIntended_range_shapes\tobject\tObject_types\tObject_shapes\n");
            explanations.close();
            // tab delimited summary of properties of activity units
            FileWriter activity_output = new FileWriter(activity_output_file, false);
            activity_output.write("filename\tmodel_title\tmodel_url\tmodelstate\tcontributor\tprovider\tdate\tactivity_iri\tactivity_xref\tactivity_label\tcomplete\tinputs\toutputs\tenablers\tlocations\tcausal upstream\tcausal downstream\tpart of n BP\tMF\tBP\n");
            activity_output.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    // this will generate the json file used for the go rules report for the pipeline
    BatchPipelineValidationReport pipe_report = null;
    Set<ErrorMessage> owl_errors = new HashSet<ErrorMessage>();
    Set<ErrorMessage> shex_errors = new HashSet<ErrorMessage>();
    pipe_report = new BatchPipelineValidationReport();
    try {
        pipe_report.setNumber_of_models(m3.getAvailableModelIds().size());
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    int bad_models = 0;
    int good_models = 0;
    final boolean shex_output = checkShex;
    // only used if OWL reasoning report is requested
    ReasonerReport reasoner_report = null;
    if (run_reasoner_report) {
        reasoner_report = initReasonerReport(outputFolder);
    }
    // now process each gocam
    try {
        for (IRI modelIRI : m3.getAvailableModelIds()) {
            long start = System.currentTimeMillis();
            String filename = modelid_filename.get(modelIRI.toString());
            // OWL
            boolean isConsistent = true;
            // shex
            boolean isConformant = true;
            if (filename != null) {
                LOGGER.info("processing " + filename + "\t" + modelIRI);
            } else {
                LOGGER.info("processing \t" + modelIRI);
            }
            // this is where everything actually happens
            ModelContainer mc = m3.getModel(modelIRI);
            OWLOntology gocam = mc.getAboxOntology();
            try {
                // if a model does not have an import statement that links in an ontology that defines all of its classes and object properties
                // or if the model does not define the classes and object properties itself, parsing problems will prevail
                // this step makes sure that does not happen
                gocam = CoreMolecularModelManager.fixBrokenObjectPropertiesAndAxioms(gocam);
            } catch (OWLOntologyCreationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            LOGGER.info("preparing model stats...");
            // The GoCamModel code is used to capture model-level statistics such as 'how many causal relations are there?'
            // This might be an area for a speed improvement if needed
            GoCamModel gcm = new GoCamModel(gocam, m3);
            String title = "title";
            if (gcm.getTitle() != null) {
                title = makeColSafe(gcm.getTitle());
            } else {
                LOGGER.error("no title for " + filename);
            }
            // this is to make clickable links in reports
            String link = modelIRI.toString().replace("http://model.geneontology.org/", "http://noctua.geneontology.org/editor/graph/gomodel:");
            if (modelIRI.toString().contains("R-HSA")) {
                link = link.replace("noctua.geneontology", "noctua-dev.berkeleybop");
            }
            String modelstate = makeColSafe(gcm.getModelstate());
            String contributor = makeColSafe(gcm.getContributors().toString());
            String date = makeColSafe(gcm.getDate());
            String provider = makeColSafe(gcm.getProvided_by().toString());
            pipe_report.setTaxa(gcm.getIn_taxon());
            LOGGER.info("model stats done for title: " + title);
            int axioms = gocam.getAxiomCount();
            // add activity level statistics as a default
            FileWriter activity_output = new FileWriter(activity_output_file, true);
            for (ActivityUnit unit : gcm.getActivities()) {
                activity_output.write(filename + "\t" + title + "\t" + link + "\t" + modelstate + "\t" + contributor + "\t" + provider + "\t" + date + "\t" + unit.getIndividual().getIRI().toString() + "\t" + unit.getXref() + "\t" + unit.getLabel() + "\t");
                activity_output.write(unit.isComplete() + "\t" + unit.getInputs().size() + "\t" + unit.getOutputs().size() + "\t" + unit.getEnablers().size() + "\t" + unit.getLocations().size() + "\t" + unit.getCausal_in().size() + "\t" + unit.getCausal_out().size() + "\t" + unit.getContaining_processes().size() + "\t" + unit.stringForClasses(unit.getDirect_types()) + "\t" + unit.getURIsForConnectedBPs() + "\n");
            }
            activity_output.close();
            InferenceProvider ip = ipc.create(mc);
            isConsistent = ip.isConsistent();
            // TODO re-use reasoner object from ip
            // TODO this is another area that could be touched/removed for speed improvement
            int n_rows_gpad = 0;
            if (isConsistent) {
                try {
                    Set<GPADData> gpad = new GPADSPARQLExport(curieHandler, m3.getLegacyRelationShorthandIndex(), m3.getTboxShorthandIndex(), m3.getGolego_repo().regulatorsToRegulated).getGPAD(m3.createInferredModel(modelIRI), modelIRI);
                    if (gpad != null) {
                        n_rows_gpad = gpad.size();
                    }
                } catch (InconsistentOntologyException e) {
                    LOGGER.error("inconsistent ontology, can't make gpad");
                }
            }
            long done = System.currentTimeMillis();
            long milliseconds = (done - start);
            // for rules report in pipeline
            if (!ip.isConsistent()) {
                String level = "ERROR";
                String model_id = curieHandler.getCuri(modelIRI);
                String message = BatchPipelineValidationReport.getOwlMessage();
                int rule = BatchPipelineValidationReport.getOwlRule();
                ErrorMessage owl = new ErrorMessage(level, model_id, gcm.getIn_taxon(), message, rule);
                owl_errors.add(owl);
            }
            if (!isConsistent) {
                FileWriter explanations = new FileWriter(explanations_file, true);
                explanations.write(filename + "\t" + title + "\t" + modelIRI + "\tOWL fail explanation: " + ip.getValidation_results().getOwlvalidation().getAsText() + "\n");
                explanations.close();
            }
            // travis mode causes the system to exit when an invalid model is detected (unless shouldFail is on)
            if (travisMode && !isConsistent) {
                if (!shouldFail) {
                    LOGGER.error(filename + "\t" + title + "\t" + modelIRI + "\tOWL:is inconsistent, quitting");
                    System.exit(-1);
                }
            }
            // basic is just one row per model - did it validate or not
            FileWriter basic = new FileWriter(basic_output_file, true);
            if (!shex_output) {
                if (ip.isConsistent()) {
                    good_models++;
                } else {
                    bad_models++;
                }
            } else {
                ValidationResultSet validations = ip.getValidation_results();
                isConformant = validations.allConformant();
                if (isConformant) {
                    good_models++;
                } else {
                    bad_models++;
                }
                if (!validations.getShexvalidation().isConformant()) {
                    String level = "WARNING";
                    String model_id = curieHandler.getCuri(modelIRI);
                    String message = BatchPipelineValidationReport.getShexMessage();
                    int rule = BatchPipelineValidationReport.getShexRule();
                    ErrorMessage shex_message = new ErrorMessage(level, model_id, gcm.getIn_taxon(), message, rule);
                    // TODO set as a parameter
                    boolean include_explanations_in_json = true;
                    if (include_explanations_in_json) {
                        shex_message.setExplanations(validations);
                    }
                    shex_errors.add(shex_message);
                    FileWriter explanations = new FileWriter(explanations_file, true);
                    explanations.write(ip.getValidation_results().getShexvalidation().getAsTab(filename + "\t" + title + "\t" + modelIRI));
                    explanations.close();
                }
                if (travisMode) {
                    if (!isConformant && !shouldFail) {
                        LOGGER.error(filename + "\t" + title + "\t" + modelIRI + "\tshex is nonconformant, quitting, explanation:\n" + ip.getValidation_results().getShexvalidation().getAsText());
                        System.exit(-1);
                    } else if (isConformant && shouldFail) {
                        LOGGER.error(filename + "\t" + title + "\t" + modelIRI + "\tshex validates, but it should not be, quitting");
                        System.exit(-1);
                    }
                }
                // is it a metadata violation or data ?
                boolean shex_meta_problem = false;
                boolean shex_data_problem = false;
                if (!validations.getShexvalidation().isConformant()) {
                    String model_curie = curieHandler.getCuri(modelIRI);
                    ValidationResultSet validationset = ip.getValidation_results();
                    ShexValidationReport shex_report = validationset.getShexvalidation();
                    Set<Violation> violations = shex_report.getViolations();
                    if (violations != null) {
                        for (Violation v : violations) {
                            if (v.getNode().equals(model_curie)) {
                                shex_meta_problem = true;
                            } else {
                                shex_data_problem = true;
                            }
                        }
                    } else {
                        LOGGER.error("Invalid model but no violations reported");
                    }
                }
                LOGGER.info(filename + "\t" + title + "\t" + modelIRI + "\tOWL:" + isConsistent + "\tshex:" + isConformant);
                basic.write(filename + "\t" + title + "\t" + link + "\t" + modelstate + "\t" + contributor + "\t" + provider + "\t" + date + "\t" + isConsistent + "\t" + isConformant + "\t" + shex_meta_problem + "\t" + shex_data_problem + "\t" + milliseconds + "\t" + axioms + "\t" + n_rows_gpad + "\t" + gcm.getGoCamModelStats().stats2cols() + "\n");
            }
            basic.close();
            if (run_reasoner_report) {
                addReasonerReport(outputFolder, gocam, ip, title, reasoner_report);
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (run_reasoner_report) {
        summarizeReasonerReport(outputFolder, reasoner_report);
    }
    pipe_report.setNumber_of_correct_models(good_models);
    pipe_report.setNumber_of_models_in_error(bad_models);
    pipe_report.getMessages().put(BatchPipelineValidationReport.getShexRuleString(), shex_errors);
    pipe_report.getMessages().put(BatchPipelineValidationReport.getOwlRuleString(), owl_errors);
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.setPrettyPrinting().create();
    String json = gson.toJson(pipe_report);
    try {
        FileWriter pipe_json = new FileWriter(outputFolder + "gorules_report.json", false);
        pipe_json.write(json);
        pipe_json.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    m3.dispose();
    LOGGER.info("done with validation");
}
Also used : Violation(org.geneontology.minerva.validation.Violation) MalformedURLException(java.net.MalformedURLException) Gson(com.google.gson.Gson) DefaultCurieHandler(org.geneontology.minerva.curie.DefaultCurieHandler) MappedCurieHandler(org.geneontology.minerva.curie.MappedCurieHandler) CurieHandler(org.geneontology.minerva.curie.CurieHandler) URL(java.net.URL) RDFHandlerException(org.openrdf.rio.RDFHandlerException) InconsistentOntologyException(org.semanticweb.owlapi.reasoner.InconsistentOntologyException) ValidationResultSet(org.geneontology.minerva.validation.ValidationResultSet) BatchPipelineValidationReport(org.geneontology.minerva.validation.pipeline.BatchPipelineValidationReport) MappedCurieHandler(org.geneontology.minerva.curie.MappedCurieHandler) CurieMappings(org.geneontology.minerva.curie.CurieMappings) ShexValidationReport(org.geneontology.minerva.validation.ShexValidationReport) GoCamModel(org.geneontology.minerva.model.GoCamModel) GPADSPARQLExport(org.geneontology.minerva.legacy.sparql.GPADSPARQLExport) GsonBuilder(com.google.gson.GsonBuilder) InferenceProviderCreator(org.geneontology.minerva.server.inferences.InferenceProviderCreator) InferenceProvider(org.geneontology.minerva.json.InferenceProvider) RepositoryException(org.openrdf.repository.RepositoryException) RepositoryException(org.openrdf.repository.RepositoryException) InconsistentOntologyException(org.semanticweb.owlapi.reasoner.InconsistentOntologyException) RDFParseException(org.openrdf.rio.RDFParseException) UpdateExecutionException(org.openrdf.query.UpdateExecutionException) MalformedQueryException(org.openrdf.query.MalformedQueryException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) MalformedURLException(java.net.MalformedURLException) ActivityUnit(org.geneontology.minerva.model.ActivityUnit) CatalogXmlIRIMapper(org.obolibrary.robot.CatalogXmlIRIMapper) GPADData(org.geneontology.minerva.legacy.sparql.GPADData) ErrorMessage(org.geneontology.minerva.validation.pipeline.ErrorMessage) MinervaShexValidator(org.geneontology.minerva.server.validation.MinervaShexValidator) RDFParseException(org.openrdf.rio.RDFParseException)

Example 5 with InferenceProvider

use of org.geneontology.minerva.json.InferenceProvider in project minerva by geneontology.

the class ModelARTHandler method addToModel.

private void addToModel(String modelId, ModelARTResult result) throws Exception {
    IRI modelIri = curieHandler.getIRI(modelId);
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology currentOntology = m3.getModelAbox(modelIri);
    OWLOntology storedOntology = m3.loadModelABox(modelIri, manager);
    // OWLOntology stored_ontology = man1.copyOntology(storedOntology, OntologyCopy.DEEP);
    ModelContainer storedMC = new ModelContainer(modelIri, null, storedOntology);
    final MolecularModelJsonRenderer storedRenderer = createModelRenderer(storedMC, go_lego, null, curieHandler);
    JsonModel jsonStoredModel = storedRenderer.renderModel();
    ModelContainer activeMC = new ModelContainer(modelIri, null, currentOntology);
    InferenceProvider inferenceProvider = ipc.create(activeMC);
    final MolecularModelJsonRenderer renderer = createModelRenderer(activeMC, go_lego, inferenceProvider, curieHandler);
    JsonModel jsonActiveModel = renderer.renderModel();
    result.storedModel = jsonStoredModel;
    result.activeModel = jsonActiveModel;
    result.diffModel = getDiff(jsonStoredModel, jsonActiveModel);
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) JsonModel(org.geneontology.minerva.json.JsonModel) InferenceProvider(org.geneontology.minerva.json.InferenceProvider) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) ModelContainer(org.geneontology.minerva.ModelContainer) MolecularModelJsonRenderer(org.geneontology.minerva.json.MolecularModelJsonRenderer)

Aggregations

InferenceProvider (org.geneontology.minerva.json.InferenceProvider)6 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 URL (java.net.URL)2 ModelContainer (org.geneontology.minerva.ModelContainer)2 CurieHandler (org.geneontology.minerva.curie.CurieHandler)2 DefaultCurieHandler (org.geneontology.minerva.curie.DefaultCurieHandler)2 MappedCurieHandler (org.geneontology.minerva.curie.MappedCurieHandler)2 JsonModel (org.geneontology.minerva.json.JsonModel)2 MolecularModelJsonRenderer (org.geneontology.minerva.json.MolecularModelJsonRenderer)2 InferenceProviderCreator (org.geneontology.minerva.server.inferences.InferenceProviderCreator)2 ValidationResultSet (org.geneontology.minerva.validation.ValidationResultSet)2 RepositoryException (org.openrdf.repository.RepositoryException)2 RDFHandlerException (org.openrdf.rio.RDFHandlerException)2 RDFParseException (org.openrdf.rio.RDFParseException)2 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 UndoAwareMolecularModelManager (org.geneontology.minerva.UndoAwareMolecularModelManager)1 CurieMappings (org.geneontology.minerva.curie.CurieMappings)1