Java Code Examples for org.semanticweb.owlapi.model.OWLOntologyManager#loadOntology()

The following examples show how to use org.semanticweb.owlapi.model.OWLOntologyManager#loadOntology() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OwlSimUtil.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param file
 * @return
 * @throws OWLOntologyCreationException
 * @throws IOException 
 * @throws OBOFormatParserException 
 */
public static OwlSim createOwlSimFromOntologyFile(File file) throws OWLOntologyCreationException, OBOFormatParserException, IOException {
	OWLOntologyManager m = OWLManager.createOWLOntologyManager();
	OWLOntology ont;
	if (file.getPath().endsWith(".obo")) {
		OBOFormatParser p = new OBOFormatParser();
		OBODoc obodoc = p.parse(file);
		Obo2Owl bridge = new Obo2Owl(m);
		ont = bridge.convert(obodoc);
	}
	else {
		ont = m.loadOntology(IRI.create(file));
	}
	
	return new FastOwlSimFactory().createOwlSim(ont);
}
 
Example 2
Source File: OwlApiUtils.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
/***
 * @param manager The ontology manager to use
 * @param ontology A string representing the ontology to load. This can be an URI or a file path
 * @return The loaded ontology
 * @throws OWLOntologyCreationException
 */
public static OWLOntology loadOntology(OWLOntologyManager manager, String ontology) throws OWLOntologyCreationException {
  logger.info(String.format("Loading ontology with owlapi: %s", ontology));
  String origThreadName = Thread.currentThread().getName();
  Thread.currentThread().setName("read - " + ontology);
  OWLOntology ont;

  if (validator.isValid(ontology)) {
    ont = manager.loadOntology(IRI.create(ontology));
  } else if (new File(ontology).exists()){
    ont = manager.loadOntologyFromOntologyDocument(new File(ontology));
  } else {
    try {
      ont = manager.loadOntologyFromOntologyDocument(Resources.getResource(ontology).openStream());
    } catch (Exception e) {
      throw new OWLOntologyCreationException("Failed to find ontology: " + ontology);
    }
  }
  logger.info(String.format("Finished loading ontology with owlapi: %s", ontology));
  Thread.currentThread().setName(origThreadName);
  return ont;
}
 
Example 3
Source File: SatisfiabilityChecker.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
  OWLOntology ont = manager.loadOntology(IRI.create(args[0]));
  ReasonerConfiguration config = new ReasonerConfiguration();
  config.setFactory(ElkReasonerFactory.class.getCanonicalName());
  ReasonerUtil util = new ReasonerUtil(config, manager, ont);
  Collection<OWLOntologyChange> removals = util.removeUnsatisfiableClasses();
  if (!removals.isEmpty()) {
    logger.info("Removed " + removals.size() + " to help prevent unsatisfiable classes.");
    for (OWLOntologyChange removal: removals) {
      logger.info(removal.toString());
    }
  }
  OWLReasoner reasoner = util.getReasoner();
  if (!reasoner.isConsistent()) {
    logger.severe("Ontology is inconsistent");
    System.exit(1);
  }
  Collection<OWLClass> unsatisfiableClasses = util.getUnsatisfiableClasses();
  if (!unsatisfiableClasses.isEmpty()) {
    logger.severe("Ontology is unsatisfiable");
     for (OWLClass unsatisfiableClass: unsatisfiableClasses) {
       logger.severe(unsatisfiableClass.toString());
     }
     System.exit(2);
  }
  logger.info("Ontology is consistent and satisfiable");
  System.exit(0);
}