Menu Constraints

Regular Expression Constraints

Each Regular Expression Constraint consists of 2 main parts and 3 additional(optional) parts:

Edit Regular Expression Constraints (REC)

This section is responsible for the regular expression constraint management. Here the REC can be created, modified, removed, saved to a file and loaded from a file. Here is a picture of the dialog window:

The left side of the window is a table with all REC in the system. The first column contains the names of the contstraints. The second one contains the regular expressions for each of the constraints. Having selected a row in this table, the user can apply a manipulation over a constraint by using the buttons on the right.

Description of the buttons on the right:

Regular Expression Constraint Editor

Here is the interface view of the editor window for the REC:

Image2.gif (4865 bytes)

The last three fields are optional. The tokenizer and filter lists contain all tokenizers and filters defined in the system. The regular expression may consist of: tags, token kategories, token values and token value templates.

Apply Regular Expression Constraints

The actual applying of the Regilar Expression Constraints can be performed in two ways:

Here we describe the latter case. The user chooses 'Apply Regular Expression Constraints' from the menu Constraints/Regular Expression Constraints. Then the following dialog window appears:

Image3.gif (4823 bytes)

The first input field Select nodes contains the XPath which is evaluated in order to select nodes for the constraints operation. If the default XPath expression is specified for the constraint, then it appears in this field as a default text.

The second field selects by name a constraint to be applied.

The last two fields are activated when the constraint tokenizer and filter are ignored and new ones have to be defined explicitly.

Having pressed the Apply button, the XPath is evaluated and a set of nodes is selected. Then for each of them the constraint is applied. If the node's content satisfies the constraint, then the node is marked as Valid. Otherwise it is marked as Non Valid. In this way two groups of nodes are formed and each of them can be observed separately. Here is a picture of the navigation panel window:

Image4.gif (4531 bytes)

Here the user can change the group under observation by using the two radio buttons. Pushing Next and Previous buttons the user changes the current selection in the editor. On the top of the window there is some information about the constraint and the nodes which satisfy or do not satisfy it.

Value Constraints

The constraint engine is a means for setting restrictions on the content of nodes in an XML Document, which can not be expressed by the DTD. Each value constraint in the system is attached to a DTD.
A value constraint in general consists of two parts. A target section and a source section.
    Target Section
        In this part one can find a description of the nodes to which the constraint will be applied. Initially, the nodes are selected by their tag name and then a further restriction is made by an XPath expression. In this way, using the expressive power of the XPath language, a context dependancy can be expressed. The evaluation of the target nodes is performed in the following way. First, from all the elements in the current document only the nodes with the specified tag name are retrieved. Then for each of them the XPath expression is evaluated with the current node as a context one. If the XPath expression is evaluated as a non-empty list, then the context node is included in the set of nodes to which the constraint is to be applied. Otherwise, it is excluded.

    Source Section
        Here the possible values for the target nodes (selected by the previous section) are defined. The possible values are tag names and tokens depending on the type of the constraint. The source list can be selected by an XPath expression or by typing the choices explicitly as an XML markup. If the selection is made by a relative XPath expression, then the current target node is taken as a context node for the constraint. If a text node is selected as a source, then its text value is tokenized and the tokens are added to the source list, excluding the node itself. It is possible that the source for the constraint is an external document. The only requirements in such cases are the following: the external document has to be in the internal database of the system and the XPath expression cannot be relative.

There are four types of value constraints, currently supported by the system. They are distinguished by their target and the way of their usage. Here is a description each value constraint separately:

    1. Parent Constraint
        This type of a value constraint sets limits on the possible parents of a node. There are two ways of applying this constraint type: by changing the parent of a node(local) or explicitly runing the constraint engine(global).

The first possibility is changing the parent of a node(or a set of nodes at one level). The list of all the relevant parent nodes can be restricted further by applying other constraints. The final list contains the intersection between the source of the constraints and its former content. If the operation - changing of the parent of a set of nodes - is performed, then all compatible (parent)constraints are applied.

The second possibility is running the Constraint Engine. It works in the following way. First, the targets are selected(by their tag names and the XPath restriction). Then the source is compiled. If there is more than one choice, the user is asked to select one option from a list. If the choice happens to be exactly one element, it automaticly is inserted as a parent of the target.

The source list of each constraint must contain only tag names. All tokens in the list are ignored.

    2. All Children Constraint
        This type of a value constraint sets limits on the names of a node's children and the content of its text children. All children, that are tags, must have names coinciding with the name of some node from the source list. Then all the data in text children is tokenized and a list A of tokens is formed. After that all the data in text nodes in the source list is tokenized and a list B of tokens is formed. For every token in A there must exist a token in B such that the values (not categories) of A and B are equal. This type of a value constraint is applied automatically during the validation of a document.

    3. Some Children Constraint
        This is a special type of a value constraint, because its main task is not to set limits on the node's content. Instead, it is used for a value restriction when the operation inserting a child in a node is performed. This constraint type is not applied each time a new node is inserted. These constraints are used separately. Here the target node is the node where the insertion takes place. The constraint is blocked when:
            - there is a child of the target node that is a tag and there is a node in source list, such that both nodes have the same names.
            - there is a text node in the target node that has a token, whose value equals the value of a token in the source list.
        To sum up, when there is a non-empty intersection between the sourse list and the target node's content, the constraint is satisfied and there is nothing more to be done. In cases when the source list is empty and there is content for the target node, an error message is shown. If the target content is also empty, then the constraint is satisfied.
        When the source list is not empty and there is no intersection with the target's content, the user is offered a list with the possible values from the source list for the target node. The user can choose one item to add. If the item is a token and the target node has already some text content, the new value is appended to it with a comma as a separator.
    4. Some Attributes Constraint
        This constraint is very similar to the previous one. The only difference is that the target here is an attribute of a node. Also the target selection includes a selection of an attribute defined in the DTD for the selected tag name.

The following screen shot is the dialog window of the value constraints editor:

VConst.gif (19423 bytes)

The dialog is separated into 5 sections:

In this section a short description of the Constraint Editor was presented. It is envoked whenever a change on a Value Constraint is needed or a new constraint is to be defined. The Value Constraint management is handled by the following Constraint Manager dialog window:

VConst_m.gif (22410 bytes)

Within the CLaRK System this module can be envoked from the menu: Constraints/Value constraints. The user is asked to choose the DTD according to which the Value Constraints are to be applied. Then the dialog window from the picture above appears.

The Constraint Manager represents a table of all constraints defined for the current DTD(if any). Each constraint is represented as one row in the table. The ordering in the table is important only if the constraints depend on each other. The constraint in the first row is applied first, then the second constraint is applied and so on. But the ordering can be changed by the two buttons on the right side: "Move Up" and "Move Down". They swap the position of the selected row with one of its neighbours above or below.

Sometimes it is useful to deactivate some of the constraints temporarily. It can be done just by non-selecting the check box on the constraint row. For example, in the picture above the second constraint remains deactivated.

The other buttons:

Value Constraints Group

The constraints described so far work in the following way: the first constraint is applied to all targets, then the second one is applied, and so on. The constraint groups, however, work in a slightly different way. First, a context node is selected and then all constraints from the group are applied within this context. Each group contains three parts:

The Value Constraint Group Manager:

VGroup.gif (8389 bytes)

The Group management includes: the creation of a new group, the modification and removal of an existing group, the application of a group of constraints. Each operation (except New Group) is preceded by selecting a group from the list.

Number Constraints

This constraint type restricts the occurences of some specific elements within the content of a document. The node specification is given by an XPath expression. This XPath evaluates the root of the document as a context node . The evaluation of the expression produces a list of nodes. The number of the entries in this list must range between MIN and MAX values in order to satisfy the constraint. The MIN or MAX value must not be a negative number. Instead of specifying MAX value, the user can write the character '*' which means positive infinity, i.e. without any upper limit.

The Number Constraint Manager dialog:

NumConst.gif (6065 bytes)

In the example above, the first constraint has no upper limit. The fourth column is responsible for the activation/deactivation of the constraints. It becomes necessary when the user would like to apply only a certain subset from all the constraints. Checking the (active)constraints can be done by pressing the Apply button. This button is disabled when there in no document in the editor. After applying the constraints, the user receives information about the number of the satisfied constraints and the number and type of the unsatisfied ones.