use of org.geneontology.minerva.curie.CurieMappings 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");
}
use of org.geneontology.minerva.curie.CurieMappings in project minerva by geneontology.
the class CommandLineInterface method legoToAnnotationsSPARQL.
/**
* Output GPAD files via inference+SPARQL
* cli --lego-to-gpad-sparql
*
* @param modelIdPrefix
* @param modelIdcurie
* @param inputDB
* @param gpadOutputFolder
* @param ontologyIRI
* @throws Exception
*/
public static void legoToAnnotationsSPARQL(String modelIdPrefix, String modelIdcurie, String inputDB, String gpadOutputFolder, String ontologyIRI, String catalog, String go_lego_journal_file) throws Exception {
if (modelIdPrefix == null) {
modelIdPrefix = "http://model.geneontology.org/";
}
if (modelIdcurie == null) {
modelIdcurie = "gomodel";
}
if (inputDB == null) {
inputDB = "blazegraph.jnl";
}
if (gpadOutputFolder == null) {
gpadOutputFolder = null;
}
if (ontologyIRI == null) {
ontologyIRI = "http://purl.obolibrary.org/obo/go/extensions/go-lego.owl";
}
OWLOntologyManager ontman = OWLManager.createOWLOntologyManager();
if (catalog != null) {
LOGGER.info("using catalog: " + catalog);
ontman.setIRIMappers(Sets.newHashSet(new owltools.io.CatalogXmlIRIMapper(catalog)));
} else {
LOGGER.info("no catalog, resolving all ontology uris directly");
}
OWLOntology ontology = ontman.loadOntology(IRI.create(ontologyIRI));
CurieMappings localMappings = new CurieMappings.SimpleCurieMappings(Collections.singletonMap(modelIdcurie, modelIdPrefix));
CurieHandler curieHandler = new MappedCurieHandler(DefaultCurieHandler.loadDefaultMappings(), localMappings);
boolean loadTboxIntoOntJournal = (!(new File(go_lego_journal_file)).exists());
BlazegraphMolecularModelManager<Void> m3 = new BlazegraphMolecularModelManager<>(ontology, curieHandler, modelIdPrefix, inputDB, null, go_lego_journal_file, false);
if (loadTboxIntoOntJournal) {
m3.getGolego_repo().loadRepositoryFromOntology(ontology, "http://example.org/", true);
}
final String immutableModelIdPrefix = modelIdPrefix;
final String immutableGpadOutputFolder = gpadOutputFolder;
m3.getAvailableModelIds().stream().parallel().forEach(modelIRI -> {
try {
// TODO investigate whether changing to a neo-lite model has an impact on this - may need to make use of ontology journal
String gpad = new GPADSPARQLExport(curieHandler, m3.getLegacyRelationShorthandIndex(), m3.getTboxShorthandIndex(), m3.getGolego_repo().regulatorsToRegulated).exportGPAD(m3.createInferredModel(modelIRI), modelIRI);
String fileName = StringUtils.replaceOnce(modelIRI.toString(), immutableModelIdPrefix, "") + ".gpad";
Writer writer = new OutputStreamWriter(new FileOutputStream(Paths.get(immutableGpadOutputFolder, fileName).toFile()), StandardCharsets.UTF_8);
writer.write(gpad);
writer.close();
} catch (InconsistentOntologyException e) {
LOGGER.error("Inconsistent ontology: " + modelIRI);
} catch (IOException e) {
LOGGER.error("Couldn't export GPAD for: " + modelIRI, e);
}
});
m3.dispose();
}
use of org.geneontology.minerva.curie.CurieMappings in project minerva by geneontology.
the class ModelReasonerTest method init.
static void init() throws OWLOntologyCreationException, IOException {
// FIXME need more from go-lego
final OWLOntology tbox = OWLManager.createOWLOntologyManager().loadOntology(IRI.create(new File("src/test/resources/go-lego-minimal.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 = CachingInferenceProviderCreatorImpl.createElk(false, null);
handler = new JsonOrJsonpBatchHandler(models, "development", ipc, Collections.<OWLObjectProperty>emptySet(), (ExternalLookupService) null);
// models.setPathToOWLFiles("src/test/resources/reasoner-test");
}
use of org.geneontology.minerva.curie.CurieMappings in project minerva by geneontology.
the class ModelSearchHandlerTest method setUpBeforeClass.
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
LOGGER.info("Set up molecular model manager - loading files into a journal");
// set curie handler
String modelIdPrefix = "http://model.geneontology.org/";
String modelIdcurie = "gomodel";
final CurieMappings localMappings = new CurieMappings.SimpleCurieMappings(Collections.singletonMap(modelIdcurie, modelIdPrefix));
curieHandler = new MappedCurieHandler(DefaultCurieHandler.loadDefaultMappings(), localMappings);
String valid_model_folder = "src/test/resources/models/should_pass/";
String model_save = "src/test/resources/models/tmp/";
String inputDB = makeBlazegraphJournal(valid_model_folder);
// leave tbox empty for now
OWLOntologyManager ontman = OWLManager.createOWLOntologyManager();
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.");
// 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);
ModelSearchHandler searchHandler = new ModelSearchHandler(models);
resourceConfig = resourceConfig.registerInstances(searchHandler);
// setup jetty server port, buffers and context path
server = new Server();
// create connector with port and custom buffer sizes
HttpConfiguration http_config = new HttpConfiguration();
int requestHeaderSize = 64 * 1024;
int requestBufferSize = 128 * 1024;
int port = 6800;
String contextString = "/";
http_config.setRequestHeaderSize(requestHeaderSize);
ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(http_config));
connector.setPort(port);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath(contextString);
server.setHandler(context);
ServletHolder h = new ServletHolder(new ServletContainer(resourceConfig));
context.addServlet(h, "/*");
// start jetty server
LOGGER.info("Start server on port: " + port + " context: " + contextString);
server.start();
// set up a handler for testing with M3BatchRequest service
handler = new JsonOrJsonpBatchHandler(models, "development", null, Collections.<OWLObjectProperty>emptySet(), (ExternalLookupService) null);
}
use of org.geneontology.minerva.curie.CurieMappings in project minerva by geneontology.
the class StartUpTool method main.
public static void main(String[] args) throws Exception {
Opts opts = new Opts(args);
MinervaStartUpConfig conf = new MinervaStartUpConfig();
while (opts.hasArgs()) {
if (opts.nextEq("-g|--graph")) {
conf.ontology = opts.nextOpt();
} else if (opts.nextEq("-c|--catalog")) {
conf.catalog = opts.nextOpt();
} else if (opts.nextEq("-f|--journal-file")) {
conf.journalFile = opts.nextOpt();
} else if (opts.nextEq("--export-folder")) {
conf.exportFolder = opts.nextOpt();
} else if (opts.nextEq("--model-id-prefix")) {
conf.modelIdPrefix = opts.nextOpt();
} else if (opts.nextEq("--model-id-curie")) {
conf.modelIdcurie = opts.nextOpt();
} else if (opts.nextEq("-p|--protein-folder")) {
System.err.println("specific protein ontologies are no longer supported");
System.exit(-1);
} else if (opts.nextEq("--gaf-folder")) {
System.err.println("--gaf-folder is not longer supported");
System.exit(-1);
} else if (opts.nextEq("--context-prefix")) {
conf.contextPrefix = opts.nextOpt();
} else if (opts.nextEq("--port")) {
conf.port = Integer.parseInt(opts.nextOpt());
} else if (opts.nextEq("-i|--import|--additional-import")) {
System.err.println("-i|--import|--additional-import is no longer supported, all imports are expected to be in the source ontology '-g|--graph'");
System.exit(-1);
} else if (opts.nextEq("--obsolete-import")) {
System.err.println("--obsolete-import is no longer supported");
System.exit(-1);
} else if (opts.nextEq("--set-relevant-relations")) {
System.err.println("--set-relevant-relations is no longer supported, use '--set-important-relation-parent' instead");
System.exit(-1);
} else if (opts.nextEq("--add-relevant-relations")) {
System.err.println("--add-relevant-relations is no longer supported, use '--set-important-relation-parent' instead");
System.exit(-1);
} else if (opts.nextEq("--add-relevant-relation")) {
System.err.println("--add-relevant-relation is no longer supported, use '--set-important-relation-parent' instead");
System.exit(-1);
} else if (opts.nextEq("--set-important-relation-parent")) {
conf.importantRelationParent = opts.nextOpt();
} else if (opts.nextEq("--skip-class-id-validation")) {
conf.checkLiteralIds = false;
} else if (opts.nextEq("--golr-cache-size")) {
String sizeString = opts.nextOpt();
conf.golrCacheSize = Integer.parseInt(sizeString);
} else // --golr-labels http://noctua-golr.berkeleybop.org/
if (opts.nextEq("--golr-labels")) {
conf.golrUrl = opts.nextOpt();
} else if (opts.nextEq("--monarch-labels")) {
conf.monarchUrl = opts.nextOpt();
} else if (opts.nextEq("--golr-seed")) {
conf.golrSeedUrl = opts.nextOpt();
} else if (opts.nextEq("--no-reasoning|--no-reasoner")) {
conf.reasonerOpt = null;
} else if (opts.nextEq("--slme-hermit")) {
conf.reasonerOpt = "slme-hermit";
} else if (opts.nextEq("--slme-elk")) {
conf.reasonerOpt = "slme-elk";
} else if (opts.nextEq("--elk")) {
conf.reasonerOpt = "elk";
} else if (opts.nextEq("--arachne")) {
conf.reasonerOpt = "arachne";
} else if (opts.nextEq("--use-request-logging|--request-logging")) {
conf.useRequestLogging = true;
} else if (opts.nextEq("--use-golr-url-logging|--golr-url-logging")) {
conf.useGolrUrlLogging = true;
} else if (opts.nextEq("--prefix-mappings")) {
conf.prefixesFile = opts.nextOpt();
} else if (opts.nextEq("--sparql-endpoint-timeout")) {
conf.sparqlEndpointTimeout = Integer.parseInt(opts.nextOpt());
} else if (opts.nextEq("--ontojournal")) {
conf.pathToOntologyJournal = opts.nextOpt();
} else {
break;
}
}
if (conf.pathToOntologyJournal == null) {
System.err.println("No blazegraph journal containing tbox ontology provided. exit.");
System.exit(-1);
}
if (conf.ontology == null) {
System.err.println("No ontology graph available");
System.exit(-1);
}
if (conf.journalFile == null) {
System.err.println("No journal file available");
System.exit(-1);
}
// if (conf.golrUrl == null) {
// conf.golrUrl = "http://noctua-golr.berkeleybop.org/";
// System.err.println("No GOLR service configured. This is required, please add e.g. --golr-labels http://noctua-golr.berkeleybop.org/ to start up parameters ");
// //System.exit(-1);
// }
conf.contextString = "/";
if (conf.contextPrefix != null) {
conf.contextString = "/" + conf.contextPrefix;
}
// set curie handler
final CurieMappings mappings;
if (conf.prefixesFile != null) {
mappings = DefaultCurieHandler.loadMappingsFromFile(new File(conf.prefixesFile));
} else {
mappings = DefaultCurieHandler.loadDefaultMappings();
}
CurieMappings localMappings = new CurieMappings.SimpleCurieMappings(Collections.singletonMap(conf.modelIdcurie, conf.modelIdPrefix));
conf.curieHandler = new MappedCurieHandler(mappings, localMappings);
// wrap the Golr service with a cache
// get rid of external look ups altogether.
// if (conf.golrUrl != null) {
// conf.lookupService = new GolrExternalLookupService(conf.golrUrl, conf.curieHandler, conf.useGolrUrlLogging);
// LOGGER.info("Setting up Golr cache with size: "+conf.golrCacheSize+" duration: "+
// conf.golrCacheDuration+" "+conf.golrCacheDurationUnit+
// " use url logging: "+conf.useGolrUrlLogging);
// conf.lookupService = new CachingExternalLookupService(conf.lookupService, conf.golrCacheSize, conf.golrCacheDuration, conf.golrCacheDurationUnit);
// }
// if (conf.monarchUrl != null) {
// conf.lookupService = new MonarchExternalLookupService(conf.monarchUrl, conf.curieHandler, conf.useGolrUrlLogging);
// LOGGER.info("Setting up Monarch Golr cache with size: "+conf.golrCacheSize+" duration: "+
// conf.golrCacheDuration+" "+conf.golrCacheDurationUnit+
// " use url logging: "+conf.useGolrUrlLogging);
// conf.lookupService = new CachingExternalLookupService(conf.lookupService, conf.golrCacheSize, conf.golrCacheDuration, conf.golrCacheDurationUnit);
// }
// TODO maybe make these command line parameters
URL shex_schema_url = new URL(conf.shexFileUrl);
File shex_schema_file = new File("./target/shex-schema.shex");
org.apache.commons.io.FileUtils.copyURLToFile(shex_schema_url, shex_schema_file);
URL shex_map_url = new URL(conf.goshapemapFileUrl);
File shex_map_file = new File("./target/go-cam-shapes.shapeMap");
org.apache.commons.io.FileUtils.copyURLToFile(shex_map_url, shex_map_file);
// reasoner set in next phase after ontologies loaded
conf.shex = new MinervaShexValidator(shex_schema_file, shex_map_file, conf.curieHandler, null);
Server server = startUp(conf);
try {
server.join();
} finally {
server.stop();
server.destroy();
}
}
Aggregations