Difference between revisions of "LoadOWLOntologyFromDB"
From Protege Wiki
Line 18: | Line 18: | ||
JenaKnowledgeBaseFactory.useStandalone = false; | JenaKnowledgeBaseFactory.useStandalone = false; | ||
Collection errors = new ArrayList(); | Collection errors = new ArrayList(); | ||
− | + | OwlDatabaseCreator creator = new OwlDatabaseCreator(false); | |
creator.setDriver("com.mysql.jdbc.Driver"); | creator.setDriver("com.mysql.jdbc.Driver"); | ||
creator.setURL("jdbc:mysql://localhost/protege"); | creator.setURL("jdbc:mysql://localhost/protege"); | ||
Line 26: | Line 26: | ||
OWLModel owlModel = creator.getOWLModel(); | OWLModel owlModel = creator.getOWLModel(); | ||
</code> | </code> | ||
+ | |||
+ | The "false" argument to the <pre>OwlDatabaseCreator</pre> class tells it to use an existing database rather than overwrite it. | ||
[[Category:Protege developer documentation]] | [[Category:Protege developer documentation]] |
Revision as of 15:23, July 8, 2008
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:
JenaKnowledgeBaseFactory.useStandalone = false; Collection errors = new ArrayList(); OwlDatabaseCreator creator = new OwlDatabaseCreator(false); creator.setDriver("com.mysql.jdbc.Driver"); creator.setURL("jdbc:mysql://localhost/protege"); creator.setUsername("protege"); creator.setPassword("mypass"); creator.create(errors); OWLModel owlModel = creator.getOWLModel();
The "false" argument to the
OwlDatabaseCreatorclass tells it to use an existing database rather than overwrite it.