One of the interesting questions is a relationships between TMCL-Schema and TMCL-Rule. I think that for validation purposes we can translate TMCL-Schema patterns and constraints to TMCL rules. I provide an example of this kind of transformation in this note.
TMCL-Schema fragment
//This is a partial description of type 'person'.
//It can be merged with other descriptions of type 'person'.
//It also can be inherited by subtypes such as 'composer', for example.
define type person
{
//first we define a pattern and then add constraints to this pattern
a::born-in(who,where)
{
cardMin=1;
cardMax=1;
otherRole where
{
cardMin=1;
cardMax=1;
allPlayersFrom=city | village
}
}
}
TMCL-Rule validation equivalent
rule "person-1"
{
forEvery{$X}
where
{
$X : person
}
let
{
$PersonName:=oneOfNames($X)
}
//We use expect{..} construct to define 'expected' pattern and to mark all constructs in TM which match this pattern.
//After applying all validation rules we can find constructs which were not 'expected' by set of rules.
expect
{
born-in($X : who, _ : where)
}
assert
{
test{atLeast 1 $A suchAs born-in($X : who, _ : where) as $A}
message{"Person {$PersonName} has to have at least one association born-in where this Person plays role who"}
}
assert
{
test{atMost 1 suchAs born-in($X : who, _ : where) as $A}
message{"Person {$PersonName} has to have at most one association born-in where this Person plays role who"}
}
assert
{
test
{
every $A in born-in($X : who, _ : where) as $A satisfies
atLeast 1 $Y suchAs born-in($X : who, $Y: where) as $A
}
message{"Person {$PersonName} has to have at least one player of role where in associaion born-in"}
}
assert
{
test
{
every $A in born-in($X : who, _ : where) as $A satisfies
atMost 1 $Y suchAs born-in($X : who, $Y : where) as $A
}
message{"Person {$PersonName} has to have at most one player of role where in associaion born-in"}
}
assert
{
test
{
every $A in born-in($X : who, _ : where) as $A satisfies
every $Y in born-in($X : who, $Y : where) as $A satisfies $Y : (city | village)
}
message{"Person {$PersonName} has to have all players of role where in association born-in of type city or village"}
}
}