PrF UG meta all
Contents
- 1 Metaclasses
- 1.1 Understanding Metaclasses
- 1.2 Example: Creating and Using a Metaclass
- 1.3 Looking at :STANDARD-CLASS
- 1.4 Creating a Slot Metaclass
- 1.5 Creating a Class Using a Metaclass
- 1.6 Changing the Metaclass of a Class
- 1.7 Changing the Metaclass of Subclasses
- 1.8 Setting the Default Metaclass
- 1.9 Customizing the Class or Slot Editor
- 1.10 Understanding Slot Metaclasses
- 1.11 Creating a Metaclass
- 1.12 Changing the Slot Metaclass of a Slot
- 1.13 Creating a Subslot Using a Slot Metaclass
- 1.14 Changing the Slot Metaclass of Subslots
- 1.15 Setting the Default Slot Metaclass
Metaclasses
This section of the User's Guide covers the concepts of understanding, creating, and using Protege-Frames metaclasses.
Note: Before you create and use classes, you should be confident with the basic Protege-Frames interface. You should also be comfortable with Protege-Frames projects, project types, windows, classes, slots, forms, instances, and queries.
To return to the main table of contents, click the Protege-Frames User's Guide link (located at the top of the table of contents on the right-hand side of this page).
Understanding Metaclasses
Overview
Metaclasses are part of the way Protege-Frames internally handles and constructs classes. A metaclass is a template, that is, a class whose instances are themselves classes. For example, the default metaclass used by Protege-Frames to create new classes is :STANDARD-CLASS; by default, all classes you create are instances of it.
Metaclasses allow you to attach additional information to your class at the class level. This is especially useful if you have several classes, each of which has a similar structure. This also allows you to give your classes more complex properties and to greatly extend the power of your Protege-Frames projects.
Because of the power of metaclasses, you may want to be particularly cautious how much you experiment with a current project. It is a good idea to work on a copy or to archive your project beforehand.
Metaclasses in the Class Hierarchy
Metaclasses are created as part of the :SYSTEM-CLASS hierarchy, which is included in every project. Metaclasses appear under the :CLASS class. Every class that is created subordinate to :CLASS is a metaclass. Just like regular classes, metaclasses can be concrete or abstract and can have more than one superclass.
Metaclasses and the Class Editor
When you attach a template slot to a metaclass, it appears as an entry field on the Class Editor for all classes that you create with that metaclass. For example, :STANDARD-CLASS has the slot :NAME; this slot appears as the Name field in that standard Class Editor. In the Wines project, which is used as an example throughout this section, the Wine Template has a slot best_wineries; this translates to a field Best Wineries on the Class Editor for classes created with that template:
Facet in Metaclass | Facet in Class Editor for classes created with that metaclass |
---|---|
best_wineries slot |
Best Wineries field |
By creating your own metaclasses and defining their slots - for example, by creating a subclass of :STANDARD-CLASS and then creating new slots or overriding existing ones - you can create additional templates for your classes. You can then create all or some of the classes in your project using the new metaclass as a template instead of :STANDARD-CLASS.
Example: Creating and Using a Metaclass
This example gives an overview of how to create and use a metaclass.
Suppose you are creating a knowledge base of wines and wineries. In this knowledge base, a type of wine, such as Chardonnay, is a class, while a specific label is an instance of that class. Suppose that, for each class of wine, you wanted to be able to enter the wineries that are, in your opinion, the best producers of that type of wine. You could do this using metaclasses, as described below.
Creating a Metaclass
First, set up your metaclass:
Create a metaclass, Wine Template, to use for wines. You create this subordinate to :STANDARD-CLASS, so that it inherits all the structure of a typical class.
Create an additional template slot, best wineries, that allows you to enter a list of wineries.
Configure best wineries as follows:
Set the Value Type to Instance, so that the values of this slot can be instances in the knowledge base.
Set the Allowed Classes to Winery, so that, specifically, these instances are wineries.
Set the Cardinality to Multiple to allow more than one winery on the list for each class.
Attach Best Wineries to Wine template as a template slot, if you have not already done so.
Using the Metaclass
Once you have created the metaclass, you can use it as follows:
Create a class, such as Chardonnay, using Wine template as the metaclass. Or, if you have already created the classes for your wines, change the metaclass to Wine template. When you do this, the best wineries slot that you attached to the template shows up as a new field (located at the lower left) in the Class Editor for your class.
You can now use the Best Wineries field to select one or more wineries from your instances.
Looking at :STANDARD-CLASS
By default, when a class is created as part of a project, Protege-Frames; treats that class as an instance of the metaclass :STANDARD-CLASS. The slots of :STANDARD-CLASS define generic properties of the class. For example, :NAME is a slot of type String which you use to name your class; :ROLE is a slot of type Symbol which can take the values Abstract or Concrete.
Some template slots for :STANDARD-CLASS are translated to entry fields in the Class Editor. The :NAME slot becomes the Name entry field, while the :ROLE slot becomes the Role menu. When you create or attach a template slot to a metaclass, it also becomes an entry field in the Class Editor.
The other slots are more complex. For example, consider the :DIRECT-SUPERCLASSES slot. This slot keeps track of the direct superclasses of a class by storing them as a list of instances. Internal programmatic operations add (delete) instances to (from) the appropriate slot value whenever you make changes to a Protege-Frames project. In this way, Protege-Frames represents the structure of your project using its tools for storing and representing structure, in much the same way you create the project structure.
Since any new class is by default created using :STANDARD-CLASS, the Class Editor itself reflects the structure and layout specified for :STANDARD-CLASS at the Forms tab. If you create a new project, then modify the Class Editor at the Forms tab, your modifications will show up for every class, whether existing or new.
Creating a Slot Metaclass
Note: Before you create and use metaclasses, you should be confident with the basic Protege-Frames interface and be comfortable designing a project, and creating and modifying classes, slots, forms and instances.
Creating a slot metaclass is almost identical to creating a metaclass. You simply have to make sure the class is created subordinate to :SLOT. Usually, it is desirable to create a slot metaclass subordinate to :STANDARD-SLOT, so that the slot created using the slot metaclass will have the various properties defined by :STANDARD-SLOT.
To create a new slot metaclass:
Click on the desired superclass in the Class Browser. The selected superclass must itself be a slot metaclass. As mentioned above, this will be true only if the selected superclass is subordinate to :SLOT.
Click the Create Class () button at the right of the Class Browser, or click the right mouse button and select Create subclass from the Class menu. The new class will be added under the highlighted class. It will inherit the properties of the selected metaclass.
Use the Class Editor to name the slot metaclass, create constraints, and create and edit template slots. For example, click the Create Slot () button at the right of the Template Slots pane to create a new slot. This slot will show up as an entry field in the Slot Editor for any slot that uses the slot metaclass.
Creating a Class Using a Metaclass
If you have non-standard metaclasses in your project, you can select the metaclass you want to use when you create a class. You can add metaclasses either by creating them directly, or by including a project that already has metaclasses.
By default, when you create a class using the Create Class () button, you use the metaclass of the direct superclass as the metaclass for the new class. (Unless you have made changes, this is the default :STANDARD-CLASS.) If you have used a non-standard metaclass for a class, every new subclass you create for the class will also use the selected metaclass. When you create a class using a non-standard metaclass, the class is given the attributes specified by the selected metaclass.
To create a class using a specified metaclass:
In the Class Browser, select the class that you want as the superclass of the new class.
Click the right mouse button and select "Create subclass using metaclass..."
A dialog box will display the Concrete metaclasses, which are the classes you can use when creating a class. You cannot create a class as an instance of an Abstract metaclass.
[[Image:PrF_UG_meta_select_metaclass.png|frame|none| Select Metaclass dialog, "Wine template" selected]Select the metaclass that has the properties that you want and click OK. The new class will be added under the highlighted class. It will have the Class Editor from the selected metaclass, with entry fields determined by the template slots of the metaclass. In the Wineries example, there is an extra entry field called Best Wineries, displayed below the Template Slots pane in the Class Editor. The name of the metaclass you used will be displayed at the top of the Class Editor, immediately after the name of the class.
Use the Class Editor to name the class, choose its role, create constraints, and create and edit slots.
Changing the Metaclass of a Class
For any existing class in your project, you can change the metaclass used for that class. This gives the class and the Class Editor the attributes defined by the newly-assigned metaclass. New classes that you create as subclasses of the class will also use the new metaclass. However, each existing subclass will continue to use its previously assigned metaclass unless you specifically change it.
This example uses the wines project, which includes a Wine template that supplies metaclass structure.
To change the metaclass of an existing class:
In the Class Browser, click on the class that you want to change.
Click the right mouse button and select "Change metaclass...".
A dialog box will display the Concrete metaclasses, which are the classes you can use. You cannot use Abstract metaclasses in this way. Note that if the class currently uses a non-standard class, you can revert to :STANDARD-CLASS.
Select the metaclass that has the properties you want and click OK. The highlighted class will now have the Class Editor from the selected metaclass, with entry fields determined by the template slots of the metaclass. The name of the metaclass you used will be displayed at the top of the Class Editor, immediately after the name of the class.
Changing the Metaclass of Subclasses
When you change the metaclass of a class, all of its subclasses will retain their previous metaclass. This ensures that you do not propagate changes when you do not want to. However, often you will want existing subclasses to have the same metaclass as their superclass. Protege-Frames provides an option to quickly change the metaclasses of all the classes subordinate to a given class. Note that you only have to do this once; by default, new classes use the metaclass of their direct superclass.
To change the metaclass of all existing subclasses of a given class:
In the Class Browser, find the class whose subclasses you want to change.
Click the right mouse button and select "Change metaclass of subclasses". This will change all of the classes below this one to have the same metaclass as the selected class.
A dialog box will ask you for verification. Click OK to continue.
The change will be made: all subordinate classes will now have the metaclass of the selected class.
Setting the Default Metaclass
If you have multiple metaclasses in your project, Protege-Frames allows you to choose which metaclass you want to use as the default for every new class you create.
To set a metaclass as the default:
In the Class Browser, click on the metaclass you want to use. This must be a class that is subordinate to :CLASS.
Click the right mouse button and select Set as default metaclass from the Class menu. This option is available only when a metaclass is selected.
The selected metaclass will become the default. Now, unless you choose otherwise, every new class you create will use the new default metaclass as its template and inherit the properties defined by the default.
Customizing the Class or Slot Editor
Using metaclasses, you can customize the layout of the Class Editor or the Slot Editor at the Forms tab. You can hide entry fields and resize and reposition fields. Normally you do not want to change widgets, as the Class Editor and Slot Editor use special widgets for the standard fields.
To customize the standard Class Editor, select :STANDARD-CLASS at the Forms tab and then make your desired edits. Since any new class is (by default) created using :STANDARD-CLASS, the Class Editor itself reflects the structure and layout specified for :STANDARD-CLASS at the Forms tab. Your modifications will show up for every class, whether existing or new. Similarly, to customize the standard Slot Editor, select :STANDARD-SLOT at the Forms tab and make your desired edits.
If you have non-standard metaclasses or slot metaclasses in your project, you can create custom editors for classes or slots that use these. For example, when you add a field, you may want to reposition it or resize it in the editor.
Example
For example, you could customize the Class Editor for classes that used the Wine template to an InstanceTableWidget that shows the location and the name of the best wineries:
At the Forms tab, select the Wine template.
Select the Best Wineries widget.
Select InstanceTableWidget from the Select Widget Type menu at the top right of the Form Editor.
This will change the widget display, adding field headings.
You can further configure the widget by double-clicking on it to open the Configure widget dialog. To delete the produces column, select the Define columns of instance table tab, click on the slot name produces, click the Remove the currently selected column () button and click OK.
You can also resize the widget by dragging.
See the Forms Table of Contents for more information about customizing forms.
Understanding Slot Metaclasses
Slot metaclasses are similar to metaclasses, except that they determine the properties of slots instead of classes. Therefore, a slot metaclass is a metaclass that can be used as a template to determine the way Protege-Frames constructs a slot. By creating a new slot metaclass, you can create a different template for selected slots and attach additional information to your slot at the class level.
Note that slot metaclasses appear at the Classes tab as the :SLOT hierarchy. This is because every slot is an instance of a slot meta class. Slots are not values or subslots of a global slot. As with metaclasses, every subclass of a slot metaclass is also a slot metaclass.
Similar to metaclasses, slots are normally created using :STANDARD-SLOT, which provides the structure for slot attributes such as name, value type, etc. When you create a new slot metaclass, you will most often want to create it subordinate to :STANDARD-SLOT, so that any slots created using the slot metaclass will have the various properties defined by :STANDARD-SLOT.
Creating a Metaclass
Despite the power of metaclasses, their basic interface is very simple. Creating a metaclass is almost identical to creating a class. You simply have to make sure that the class is created subordinate to :CLASS. Every metaclass is subordinate to :CLASS. By default, every class subordinate to :CLASS is a metaclass, unless you change it.
Most often, it is desirable to create a metaclass subordinate to :STANDARD-CLASS, so that the classes created using the metaclass will have the various properties defined by the :STANDARD-CLASS slots. Without these properties, you cannot name the class or add template slots.
To create a new class as a metaclass:
Click on the desired superclass in the Class Browser. The selected superclass must itself be a metaclass. As mentioned above, this will be true only if the selected superclass is subordinate to :CLASS.
Click the Create Class () button, at the right of the Class Browser. The new class will be added under the highlighted class. It will inherit the properties of the selected metaclass, including any template slots.
Use the Class Editor to name the class, create constraints, and attach and edit template slots. Remember that the template slots you attach to the metaclass appear as entry fields on the Class Editor for the classes you create using this metaclass. For example, the :NAME slot for :STANDARD-CLASS becomes the Name entry field when you create a class. In the Wineries example, there is an additional slot named best_wineries.
Changing the Slot Metaclass of a Slot
If you have multiple slot metaclasses in your project, then for any existing slot, you can change the slot metaclass you use for that slot. This gives the slot and the Slot Editor the attributes defined by the new slot metaclass. Subslots that you create subordinate to the slot will also use the new slot metaclass. However, any existing subslots will continue to use their previously assigned slot metaclass unless you specifically change it.
Unlike metaclasses, you cannot create a slot using the slot metaclass. If you want to have a slot that uses a specfic slot metaclass, you must first create the slot, then change the slot metaclass.
To change the slot metaclass of an existing slot:
In the Slots tab, click on the slot that you want to change.
Click the right mouse button and select Change slot metaclass....
A dialog box displays the slot metaclasses. Note that if the slot currently uses a non-standard slot metaclass, you can revert to :STANDARD-SLOT.
Select the slot metaclass that has the properties that you want and click OK. The highlighted slot will now have the Slot Editor and properties determined by the selected slot metaclass.
Creating a Subslot Using a Slot Metaclass
Once you have added one or more slot metaclasses to your project, you can select the slot metaclass you want to use to create a subslot. When you create a subslot using a non-standard slot metaclass, the slot is given the attributes specified by the selected slot metaclass.
If you create a top-level slot, you must first create the slot, and then change its slot metaclass.
To create a subslot using a non-standard slot metaclass:
In the Slots tab, find the slot that you want as the superslot of the new slot.
Click the right mouse button and select "Create subslot using slot metaclass...".
A dialog box displays the slot metaclasses.
Select the slot metaclass that you want and click OK. The new slot will be added under the highlighted slot. It will have the Slot Editor determined by the selected slot metaclass. The name of the slot metaclass you used is displayed at the top of the Slot Editor, immediately after the name of the slot. The Slot Editor may include additional widgets that are not part of :STANDARD-SLOT.
Use the Slot Editor to name the slot, choose its value type, and set its other properties.
Changing the Slot Metaclass of Subslots
When you change the slot metaclass of a slot, all of its subslots will retain their previous slot metaclass. This ensures that you do not propagate changes when you do not want to. However, often you will want existing subslots to have the same slot metaclass as their superslot. Protege-Frames provides an option to quickly change the slot metaclass of all the slots subordinate to a given slot. Note that you only have to do this once; by default, new slots use the slot metaclass of their direct superslot.
To change the slot metaclass of all existing subslots of a given slot:
In the Slot Browser, find the slot whose subslots you want to change.
Click the right mouse button and select "Change slot metaclass of subslots". This will change all the slots below this one to have the same slot metaclass as the selected slot.
A dialog box will appear, asking you for verification. Click OK to continue.
The change will be made; all subordinate slots will now have the slot metaclass of the selected slot.
Setting the Default Slot Metaclass
If you have multiple slot metaclasses in your project, Protege-Frames allows you to choose which slot metaclass you want to use as the default for every new slot you create.
Setting the Default Slot Metaclass
To set a slot metaclass as the default:
Click on the slot metaclass you want to use in the Class Browser. This must be a class that is subordinate to :SLOT.
Click the right mouse button and select Set as default metaslot from the Class menu. This option is available only when a slot metaclass is selected.
The selected slot metaclass will become the default. Now, unless you choose otherwise, every new slot you create will use the new default slot metaclass as its template and inherit the properties defined by the default.
Unsetting the Default Slot Metaclass
It is also possible to remove the default property from a slot metaclass. If you do this, the new slot will be created with no fields in the Slot Editor. To unset the default metaslot:
Select the default slot metaclass in the Class Browser.
Click the right mouse button and select Unset as default slot metaclass.