LoadOWLOntologyFromDB

From Protege Wiki
Revision as of 16:41, May 22, 2008 by JenniferVendetti (talk | contribs) (categorizing page)

Jump to: navigation, search

How do I load a Protege-OWL ontology from a Protege database using the API?

Method 1

The simplest way to load a Protege-OWL ontology from a Protege database is to programatically load the project file (.pprj), which already contains all of the necessary database connection information:

Project prj = Project.loadProjectFromFile("/home/pizza_db.pprj",errors);
OWLModel owlModel = (OWLModel) prj.getKnowledgeBase();
...


Method 2

The second method should be used if there is no project file (.pprj) associated with the Protege-OWL database ontology:

OWLDatabaseKnowledgeBaseFactory factory = new OWLDatabaseKnowledgeBaseFactory();
Project prj = Project.createNewProject(factory, errors);
OWLDatabaseKnowledgeBaseFactory.setSources(prj.getSources(), "com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/protege", "pizza", "user", "password");
prj.createDomainKnowledgeBase(factory, errors, true);

OWLModel owlModel = (OWLModel) prj.getKnowledgeBase();
...