SetBrowserSlotPattern

From Protege Wiki
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.


Setting the browser pattern for classes and properties

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);


Setting the browser pattern for individuals

The code from below shows how to configure an application to use the rdfs:label for displaying the individuals of class "MyClass". You may choose to replace rdfs:label with another property.

  OWLNamedClass myClass = owlModel.getOWLNamedClass("MyClass");

  OWLBrowserSlotPattern rdfsLabelBrowserPattern = new OWLBrowserSlotPattern(owlModel.getRDFSLabelProperty());
  //set rdfs:label as the browser pattern for the individuals of MyClass
  myClass.setDirectBrowserSlotPattern(rdfsLabelBrowserPattern);

NOTE: The browser pattern is always set for a class and it applies to the individuals of that class.


Setting the default language

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");