2.1.2. Pattern Body

[Tip]Description

Pattern body is the basic part of the graph pattern definition. It determines a constraint set that identifies a part of the model space.

[Important]Syntax
PatternBodiesAST ::= PatternBodyAST
                   | PatternBodiesAST or PatternBodyAST
	
PatternBodyAST ::= { PatternBodyContentsAST }
	
PatternBodyContentsAST ::= $empty 
                         | PatternBodyContentsAST PatternBodyContentDefAST

PatternBodyContentDefAST ::= PatternBodyContentAST ;
                           | neg GraphPatternDefAST

PatternBodyContentAST ::= LocalPatternBodyElementAST
                        | PatternCompositionAST
                        | NegativePatternAST
                        | PatternVariableAssignmentAST
                        | CheckConditionAST

LocalPatternBodyElementAST ::= ModelElementAST  | RelationshipAST
ModelElementAST ::= EntityAST| RelationAST
	

A pattern body mainly consists of local pattern body elements . These defines the typed structure of the pattern. A local pattern body element can be either a model element or a relationship definition between model elements. A model element is either an entity or a relation. Model element are identified by pattern variables: these are either the parameters of the pattern or internal variables.

From a pattern body , another graph pattern can be invoked by pattern composition or as a negative pattern.

Within a pattern body the unification of variables can be defined: it is called pattern variable assignment.

Extra conditions can be states in addition to those that defines the typed structure. These are called check condition s and are formulated by ASM terms.

[Note]Semantics

A pattern body defines a conjunction of constraints which has to be fulfilled by a part of the model space during pattern matching.

The following list of core constraints are interpreted by the pattern matcher:

  • entity(E): pattern variable E should be bound to an entity in the model space;

  • relation(R): pattern variable R should be bound to a relation in the model space;

  • from(R,X): relation R should lead from model element X;

  • to(R, X): relation R should lead into model element X;

  • super(X, Y): X is a supertype of Y or Y is a subtype of X;

  • type(X, Y): X is type of Y, or Y is instance of X;

  • in(X, Y): X is a direct child of Y (Y is the parent of X) in the containment hierarchy of the model space.

  • below(X, Y): X is a descendant of Y (Y is an ancestor of X) in the containment hierarchy of the model space.

Here the super and the belowconstraints are transitive.

In case of pattern composition, a predicate representing the invoked pattern is derived as a conjunction of the core constraints of its body. A negative pattern defines negative constraints: the pattern body can match only if none of the negative patterns can be satisfied. In case of recursion, the fixpoint of the recursive predicate is calculated.

In case of multiple pattern bodies (OR-patterns), a different set of constraints is derived, and one of them needs to be matched for a successful match of the pattern.

The pattern matching engine implements injective pattern matching, i.e. each pattern variable has to be bound to different model elements in the model space unless (i) two pattern variables are explicitly assigned to the same model element by pattern variable assignment or (ii) both variables appear in as actual parameters of called subpatterns.

[Caution]Constraints

All variables in the head of the pattern must appear in the pattern body

  • locally in a model element, or

  • in a (positive or negative) pattern composition or

  • in a variable assignment or

  • in the check condition,

otherwise a compile-time error is generated. In case of OR-patterns, this rule applies to all pattern bodies.

This is a significant change wrt. the previous versions of VIATRA where all pattern variables had to appear locally or in the check condition.

The actual parameters of a pattern composition inside a pattern body are restricted to pattern variables .

Example 2.3. Overview of pattern body contents

pattern myPattern(A,B,C,D) = 
{
  myType(A); // local pattern body element 
  B = A; // variable assignment 
  neg find myNestedPattern(C); // negative pattern composition 
  check (name(B) = D); // check condition
} 


Defined In:  graph pattern definition