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:

  1. Go to the PAL Constraints tab.
  2. Click the Create button at the top right of the Choose Constraints pane.
    The PAL Expression Editor appears.

OR

  1. Go to the Instances tab.
  2. Display the classes under :SYSTEM-CLASS, display the classes under :CONSTRAINT, and click on :PAL-CONSTRAINT to highlight it. 


  3. 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

  1. Name the constraint by typing articles-more-than-2-keywords-copy in the Name entry bar.


  2. 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)

  1. Right click in the Range editor in the PAL Expression Editor. (Macintosh users, hold down the Comand key while clicking the mouse.)
  2. To set a range, first select defrange from the pop-up menu. A second menu gives the options for defrange.
  3. 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.
  4. Select Without Slot to have the variable range over all instances of the selected class. 


  5. You now have the following syntax:
    (defrange varName :FRAME frameName)
    The expression editor has created a skeleton variable declaration and range definition. 
  6. 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.


  7. 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.
  8. 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'.


  9. 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))

  1. 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.
  2. To narrow down the number of options, you can type the first few letters, for, of the predicate you want. 
  3. Select forall  in the Predicate window and click OK.



    The editor automatically fills in the skeleton syntax for the predicate you have chosen.


  4. 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.
  5. Select ?article and click OK.



    The editor fills in the symbol you have selected.


  6. 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.


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


  8. Choose number-of-slot-values(Slot,Frame) and click OK.



    The editor fills in the value you have chosen.
  9. 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.


  10. Choose ?article and click OK. Once again, the syntax is generated.


  11. 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. 


  12. Choose keywords and click OK.


  13. 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