SetBrowserSlotPattern

From Protege Wiki
Revision as of 12:54, April 22, 2008 by TaniaTudorache (talk | contribs)

Jump to: navigation, search

How to set the browser slot pattern to rdfs:label (or other property) using the API

Sometimes you may want to display the classes, properties and/or individuals in your ontology using the value of rdfs:label or some other property, rather than using the name, which might be a meaningless identifier. You can configure the Protege UI to use a different browser slot pattern (also referred to as browser slot) for the display of the entities. A users guide to do this for the UI mode is here.

The same functionality can be achieved in an external application that uses the Protege API and its UI components.


The code from below shows how to configure an application to use the rdfs:label for displaying the classes and properties. You may choose to replace rdfs:label with another property.

  OWLBrowserSlotPattern rdfsLabelBrowserPattern = new OWLBrowserSlotPattern(owlModel.getRDFSLabelProperty());
  //set rdfs:label as the browser pattern for owl:Class
  owlModel.getOWLNamedClassClass().setDirectBrowserSlotPattern(rdfsLabelBrowserPattern);

  //set rdfs:label as the browser pattern for rdf:Property
  owlModel.getRDFPropertyClass().setDirectBrowserSlotPattern(rdfsLabelBrowserPattern);


If you want to use also a default language for rdfs:label, then you have to set the default language of the top ontology. This is done by setting the value of the property protege:defaultLanguage to a default language, like fr (for French), for example.


So, you need a definition of the property protege:defaultLanguage in your ontology. This can be done either by:

  1. Importing the protege ontology (This is the right way of doing it), or
  2. Creating the property protege:defaultLanguage in your code (The less orthodox way of doing it)


You can implement solution (1) by importing the protege ontology as described in this page.

You can implement solution (2) by calling owlModel.createRDFProperty(ProtegeNames.getDefaultLanguageSlotName()). (Less recommended, as I already mentioned)


After that, you are ready for setting the default language of the top ontology, by using this code:

  RDFProperty defaultLanguage = owlModel.getRDFProperty(ProtegeNames.getDefultLanguageSlotName());		
  owlModel.getDefaultOWLOntology().setPropertyValue(defaultLanguage, "fr");