ChAO API
Contents
Accessing the collaboration features programatically (The Changes and Annotations API)
Protege provides support for collaboration through the Collaborative Protege extension: e.g., tracking changes, annotating ontology components (classes, properties, etc.) or changes (creation of a class). This wiki page describes how to access the change tracking and the annotation information programatically.
Other relevant documentation: the Changes Tab, the Collaborative Protege paper, the paper describing the Changes and Annotation ontology.
The change tracking information and annotation of ontology entities and changes is stored as instances of the Changes and Annotation Ontology (ChAO), called the ChAO KB. This wiki page shows how to access this information programmatically.
The ChAO KB Manager
One of the most important classes is the edu.stanford.bmir.protegex.chao.ChAOKbManager
found in the change-model.jar
from the edu.stanford.smi.protegex.changes plugin folder. It contains methods for creating and retrieving the ChAO KB for different modes: stand-alone, multi-user client and multi-user server. All code should use the method:
public static KnowledgeBase getChAOKb(KnowledgeBase kb)
to get access to the ChAO KB associated to kb.
You may also create the ChAO KB. To create a ChAO KB stored in RDF(S) files (default option), call:
public static KnowledgeBase createRDFFileChAOKb(KnowledgeBase kb, URI chaoURI)
Code example:
private KnowledgeBase void createCHAOFileProject() { //load the project Project prj = Project.loadProjectFromFile("/tmp/pizza.pprj", new ArrayList()); OWLModel owlModel = (OWLModel) prj.getKnowledgeBase();
//create the ChAO KB KnowledgeBase changesKb = ChAOKbManager.createRDFFileChAOKb(owlModel, ChAOKbManager.getChAOProjectURI(owlModel));
//save the ChAO ArrayList errors = new ArrayList(); changesKb.getProject().save(errors); //optional to save also the main project. It helps if the ChAO project does not have the default name prj.save(errors); return changesKb; }
To create the ChAO KB stored in a database, call:
public static KnowledgeBase createDbChAOKb(KnowledgeBase kb, URI chaoURI, String dbDriver, String dbUrl, String dbTable, String dbUser, String dbPassword)
Code example:
private KnowledgeBase void createCHAOFileProject() { //load the project Project prj = Project.loadProjectFromFile("/tmp/pizza.pprj", new ArrayList()); OWLModel owlModel = (OWLModel) prj.getKnowledgeBase();
//create the ChAO KB KnowledgeBase changesKb = ChAOKbManager.createDbChAOKb(owlModel, ChAOKbManager.getChAOProjectURI(owlModel), "com.mysql.jdbc.Driver", "jdbc:mysql://localhost/protege", "myTableName", "myUser", "myPassword");
//save the ChAO ArrayList errors = new ArrayList(); changesKb.getProject().save(errors); //optional to save also the main project. It helps if the ChAO project does not have the default name prj.save(errors); return changesKb; }