Creating
a Sample Constraint
The PAL Expression Editor allows you to
create constraints in a semi-structured way. This example shows how to
create a constraint using the expression editor.
Like any programmatic editor, you need to have an idea of the syntax and
structure of the constraint you wish to create. The editor will then help
you to maintain correct syntax.
We will create a copy of the constraint that states that articles should be
indexed with more than two keywords. The syntax is:
(defrange ?article
:FRAME Article) |
((forall ?article
(> (number-of-slot-values keywords ?article) 2)) |
Getting Started
Start by opening the PAL Expression Editor. To do this:
- Go to the PAL Constraints tab.
- Click the Create
button at the top right of the Choose Constraints pane.
The PAL Expression Editor appears.
OR
- Go to the Instances tab.
- Display the classes under :SYSTEM-CLASS, display the classes under
:CONSTRAINT, and click on :PAL-CONSTRAINT to highlight it.
- Go to the Direct Instances pane and click the Create
button.
A new constraint is created and the PAL Expression
Editor appears in the
Forms pane of the Instances tab.
You can also create a constraint at the PAL Constraints Tab
or at the Classes Tab. See Creating a Blank Constraint
for more information.
Giving the Constraint a Name and Description
- Name the constraint by typing articles-more-than-2-keywords-copy in the Name entry bar.
- Type in the following description in the Description Entry Box
All articles should be indexed with more than two keywords (equivalent to minimum cardinality facet on slot attachment).
Defining Variable Ranges
It's a good idea to always start a constraint by defining the range of each
variable you intend to use. This also declares the variable names for use by the
Statement part of the editor.
To define ranges, use the Range editor area in the PAL Expression
Editor.
The variable we wish to declare is ?article, and we want to
allow it to take on the values of
instances in the Article class. The desired syntax is:
(defrange
?article :FRAME Article).
- Right click in the Range editor in the PAL Expression
Editor. (Macintosh users, hold down the Comand key while clicking
the mouse.)
- To set a range, first select defrange
from the pop-up menu. A second menu gives the options for defrange.
- To specify that you will be ranging over instances of a class, select
FRAME from the second pop-up menu. A third menu gives you the choices
for a frame.
- Select Without Slot to have the variable range over all
instances of the selected class.
- You now have the following syntax:
(defrange varName :FRAME
frameName)
The expression editor has created a skeleton variable declaration and range
definition.
- To name your variable, double-click on varName. An entry box
appears. Note that the entry box tells you that the variable you are
declaring is a symbol. Symbols in the editor include all defined variables
and their slots.
- You will name the variable ?article. Type ?article in the entry bar and click OK. Note that preceding a
variable with a ? states that it is a local variable.
- To select a range class for your variable, double-click frameName. The
editor displays a list of all possible class names. Using this method of
choosing a class ensures that you enter a legal class. Note: If you choose a class whose name contains a space, you must
manually enclose the name in single quotes after selecting it. For example, my
class must be written as 'my class'.
- Select Article and click OK.
Note: If this constraint were attached
to the Article class, the range definition for ?article could be omitted.
In this case (as for any unranged variable), the variable automatically ranges over the instances of Article.
Creating the Statement
To create a statement, use the Statement editor
area.
The statement we wish to create is:
((forall ?article
(> (number-of-slot-values keywords ?article) 2))
- To select the overall predicate, forall ,
double-click the word (Predicate) in the editor.
The Predicate window opens, showing a list of all possible predicates.
- To narrow down the number of options, you can type the first few letters, for,
of the predicate you want.
- Select forall in the
Predicate window and click OK.
The editor automatically fills in the skeleton syntax for the predicate you have
chosen.
- To select the variable on which the forall
predicate should apply, double-click the word Symbol.
The Symbol dialog box shows all defined variables and those related slots
and functions that can return a symbol. In this
case, we have only defined ?article.
- Select ?article and click OK.
The editor fills in the symbol you have selected.
- Now we need to fill out the new (inner) predicate. Double-click (Predicate) in the editor and select >(Number,Number)
from the Predicate window.
The skeleton syntax for that new predicate is filled in by the editor.
- Now we need to fill in the number arguments. To do this, double-click on the first Number.
The Number dialog box displays the possible replacement arguments (i.e.,
functions, or slots used as functions, that return numbers).
- Choose number-of-slot-values(Slot,Frame) and click OK.
The editor fills in the value you have chosen.
- In our case, we have only one declared variable, so the possible slots
that can replace Slot will all be related to that variable. In general, however, we may have more
than one variable, so it is better to pick the frame first, in order to
narrow the scope of possible slot replacements. To do this,
double-click on Frame.
The Frame dialog shows the possible frame replacements for that function.
- Choose ?article and click OK. Once again, the syntax is generated.
- Now we can choose a slot related to ?article. Double-click on Slot.
The Slot window opens. Because the ?article variable is defined to
range over the Article class, the slots that are attached to the Article
class are listed.
- Choose keywords and click OK.
- To put in a number, double-click Number and use the number text
field. Alternatively, simply highlight Number and type
2.
To check the syntax, click on the check
button. To check violations of the constraints, use the Evaluate indicated
constraints in the Choose Constraints Pane at
the PAL Constraints Tab.
The PAL Expression Editor/Creating a Sample Constraint
Next: Known Problems
PAL Table of Contents