Difference between revisions of "SetBrowserSlotPattern"

From Protege Wiki
Jump to: navigation, search
(New page: = 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...)
 
Line 2: Line 2:
  
 
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.
 
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 [http://protege.cim3.net/cgi-bin/wiki.pl?HidingIdentifiersWithLabelsInOWLPlugin here].
+
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 [http://protege.cim3.net/cgi-bin/wiki.pl?HidingIdentifiersWithLabelsInOWLPlugin here].
  
 
The same functionality can be achieved in an external application that uses the Protege API and its UI components.  
 
The same functionality can be achieved in an external application that uses the Protege API and its UI components.  
Line 16: Line 16:
 
   //set rdfs:label as the browser pattern for rdf:Property
 
   //set rdfs:label as the browser pattern for rdf:Property
 
   owlModel.getRDFPropertyClass().setDirectBrowserSlotPattern(rdfsLabelBrowserPattern);
 
   owlModel.getRDFPropertyClass().setDirectBrowserSlotPattern(rdfsLabelBrowserPattern);
 +
</pre>
 +
</code>
 +
 +
 +
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 <code>protege:defaultLanguage</code> to a default language, like <code>fr</code> (for French), for example.
 +
 +
For this, you, either:
 +
# Import the [http://protege.stanford.edu/plugins/owl/protege protege ontology] (This is the right way of doing it), or
 +
# Create the property <code>protege:defaultLanguage</code> in your code (The less orthodox way of doing it)
 +
 +
 +
You can implement solution (1) by importing the [http://protege.stanford.edu/plugins/owl/protege protege ontology] as described in [http://protege.cim3.net/cgi-bin/wiki.pl?HowToImport this page].
 +
 +
You can implement solution (2) by calling <code>owlModel.createRDFProperty(ProtegeNames.getDefaultLanguageSlotName())</code>. (Less recommended, as I already mentioned)
 +
 +
 +
After that, you are ready for setting the default language of the top ontology, by using this code:
 +
 +
<code>
 +
<pre>
 +
  RDFProperty defaultLanguage = owlModel.getRDFProperty(ProtegeNames.getDefultLanguageSlotName());
 +
  owlModel.getDefaultOWLOntology().setPropertyValue(defaultLanguage, "fr");
 
</pre>
 
</pre>
 
</code>
 
</code>

Revision as of 11:52, April 22, 2008

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.

For this, you, either:

  1. Import the protege ontology (This is the right way of doing it), or
  2. Create 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");