LoadFramesOntologyFromDB

From Protege Wiki
Jump to: navigation, search

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

Method 1

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

Project prj = Project.loadProjectFromFile("/tmp/newspaper.pprj",errors);
KnowledgeBase kb = prj.getKnowledgeBase();
...


Method 2

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

DatabaseKnowledgeBaseFactory factory = new DatabaseKnowledgeBaseFactory();
Collection errors = new ArrayList();

Project project = Project.createNewProject(factory, errors);
//replace the arguments with your own specific values
DatabaseKnowledgeBaseFactory.setSources(project.getSources(), "com.mysql.jdbc.Driver", "jdbc:mysql://localhost/protege", "table", "user", "password");

project.createDomainKnowledgeBase(factory, errors, true);

//the following lines are optional. Use them only if you want to save the project
project.setProjectURI(new URI("file:/tmp/newspaper_saved.pprj"));
project.save(errors);
...