The Assertion Package
Overview
Assertions are expressed in archetypes in typed first-order predicate logic (FOL). They are used in two places: to express archetype slot constraints, and to express rules in complex object constraints. In both of these places, their role is to constrain something inside the archetype. Constraints on external resources such as terminologies are expressed in the constraint binding part of the archetype ontology, described in [_terminology_package]. The assertion package is illustrated below.
Semantics
Archetype assertions are statements which contain the following elements:
-
variables, which are inbuilt, archetype path-based, or external query results;
-
manifest constants of any primitive type, including the date/time types
-
arithmetic operators:
+,*,-,/,^(exponent),%(modulo division) -
relational operators:
>,<,>=,<=,=,!=,matches -
boolean operators:
not,and,or,xor -
quantifiers applied to container variables:
for_all,exists
The written syntax of assertions is defined in the openEHR ADL document. The package described here is currently designed to allow the representation of a general-purpose binary expression tree, as would be generated by a parser. This may be replaced in the future by a more specific model, if needed.
This relatively simple model of expressions is sufficiently powerful for representing FOL expressions on archetype structures, although it could clearly be more heavily subtyped.
Class Descriptions
ASSERTION Class
-
Definition
-
Effective
-
BMM
-
UML
Class |
ASSERTION |
|
|---|---|---|
Description |
Structural model of a typed first order predicate logic assertion, in the form of an expression tree, including optional variable definitions. |
|
Attributes |
Signature |
Meaning |
0..1 |
tag: |
Expression tag, used for differentiating multiple assertions. |
0..1 |
string_expression: |
String form of expression, in case an expression evaluator taking String expressions is used for evaluation. |
1..1 |
expression: |
Root of expression tree. |
0..1 |
variables: |
Definitions of variables used in the assertion expression. |
Invariants |
Tag_valid: |
|
Expression_valid: |
||
| ASSERTION | |
|---|---|
Structural model of a typed first order predicate logic assertion, in the form of an expression tree, including optional variable definitions. |
|
Attributes |
|
tag: |
Expression tag, used for differentiating multiple assertions. |
string_expression: |
String form of expression, in case an expression evaluator taking String expressions is used for evaluation. |
expression: |
Root of expression tree. |
variables: |
Definitions of variables used in the assertion expression. |
Invariants |
|
Tag_valid: |
|
Expression_valid: |
|
{
"name": "ASSERTION",
"documentation": "Structural model of a typed first order predicate logic assertion, in the form of an expression tree, including optional variable definitions. ",
"properties": {
"tag": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "tag",
"documentation": "Expression tag, used for differentiating multiple assertions.",
"type": "String"
},
"string_expression": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "string_expression",
"documentation": "String form of expression, in case an expression evaluator taking String expressions is used for evaluation. ",
"type": "String"
},
"expression": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "expression",
"documentation": "Root of expression tree.",
"is_mandatory": true,
"type": "EXPR_ITEM"
},
"variables": {
"_type": "P_BMM_CONTAINER_PROPERTY",
"name": "variables",
"documentation": "Definitions of variables used in the assertion expression.",
"type_def": {
"container_type": "List",
"type": "ASSERTION_VARIABLE"
},
"cardinality": {
"lower": 0,
"upper_unbounded": true
}
}
},
"invariants": {
"Tag_valid": "tag /= Void implies not tag.is_empty",
"Expression_valid": "expression /= Void and then expression.type.is_equal(“BOOLEAN”)"
}
}
EXPR_ITEM Class
-
Definition
-
Effective
-
BMM
-
UML
Class |
EXPR_ITEM (abstract) |
|
|---|---|---|
Description |
Abstract parent of all expression tree items. |
|
Attributes |
Signature |
Meaning |
1..1 |
type: |
Type name of this item in the mathematical sense. For leaf nodes, must be the name of a primitive type, or else a reference model type. The type for any relational or boolean operator will be “Boolean”, while the type for any arithmetic operator, will be “Real” or “Integer”. |
| EXPR_ITEM (abstract) | |
|---|---|
Abstract parent of all expression tree items. |
|
Attributes |
|
type: |
Type name of this item in the mathematical sense. For leaf nodes, must be the name of a primitive type, or else a reference model type. The type for any relational or boolean operator will be “Boolean”, while the type for any arithmetic operator, will be “Real” or “Integer”. |
{
"name": "EXPR_ITEM",
"documentation": "Abstract parent of all expression tree items.",
"is_abstract": true,
"properties": {
"type": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "type",
"documentation": "Type name of this item in the mathematical sense. For leaf nodes, must be the name of a primitive type, or else a reference model type. The type for any relational or boolean operator will be “Boolean”, while the type for any arithmetic operator, will be “Real” or “Integer”.",
"is_mandatory": true,
"type": "String"
}
}
}
EXPR_LEAF Class
-
Definition
-
Effective
-
BMM
-
UML
Class |
EXPR_LEAF |
|
|---|---|---|
Description |
Expression tree leaf item representing one of:
|
|
Inherit |
||
Attributes |
Signature |
Meaning |
1..1 |
reference_type: |
Type of reference: “constant”, “attribute”, “function”, “constraint”. The first three are used to indicate the referencing mechanism for an operand. The last is used to indicate a constraint operand, as happens in the case of the right-hand operand of the ‘matches’ operator. |
1..1 |
item: |
The value referred to; a manifest constant, an attribute path (in the form of a String), or for the right-hand side of a ‘matches’ node, a constraint, often a C_PRIMITIVE_OBJECT. |
| EXPR_LEAF | |
|---|---|
Expression tree leaf item representing one of:
|
|
Inherits: EXPR_ITEM |
|
Attributes |
|
type: |
Type name of this item in the mathematical sense. For leaf nodes, must be the name of a primitive type, or else a reference model type. The type for any relational or boolean operator will be “Boolean”, while the type for any arithmetic operator, will be “Real” or “Integer”. |
reference_type: |
Type of reference: “constant”, “attribute”, “function”, “constraint”. The first three are used to indicate the referencing mechanism for an operand. The last is used to indicate a constraint operand, as happens in the case of the right-hand operand of the ‘matches’ operator. |
item: |
The value referred to; a manifest constant, an attribute path (in the form of a String), or for the right-hand side of a ‘matches’ node, a constraint, often a C_PRIMITIVE_OBJECT. |
{
"name": "EXPR_LEAF",
"documentation": "Expression tree leaf item representing one of:\n\n* a manifest constant of any primitive type;\n* a path referring to a value in the archetype;\n* a constraint;\n* a variable reference.\n",
"ancestors": [
"EXPR_ITEM"
],
"properties": {
"reference_type": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "reference_type",
"documentation": "Type of reference: “constant”, “attribute”, “function”, “constraint”. The first three are used to indicate the referencing mechanism for an operand. The last is used to indicate a constraint operand, as happens in the case of the right-hand operand of the ‘matches’ operator.",
"is_mandatory": true,
"type": "String"
},
"item": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "item",
"documentation": "The value referred to; a manifest constant, an attribute path (in the form of a String), or for the right-hand side of a ‘matches’ node, a constraint, often a C_PRIMITIVE_OBJECT.",
"is_mandatory": true,
"type": "Any"
}
}
}
EXPR_OPERATOR Class
-
Definition
-
Effective
-
BMM
-
UML
Class |
EXPR_OPERATOR (abstract) |
|
|---|---|---|
Description |
Abstract parent of operator types. |
|
Inherit |
||
Attributes |
Signature |
Meaning |
0..1 |
precedence_overridden: |
True if the natural precedence of operators is overridden in the expression represented by this node of the expression tree. If True, parentheses should be introduced around the totality of the syntax expression corresponding to this operator node and its operands. |
1..1 |
operator: |
Code of operator. |
| EXPR_OPERATOR (abstract) | |
|---|---|
Abstract parent of operator types. |
|
Inherits: EXPR_ITEM |
|
Attributes |
|
type: |
Type name of this item in the mathematical sense. For leaf nodes, must be the name of a primitive type, or else a reference model type. The type for any relational or boolean operator will be “Boolean”, while the type for any arithmetic operator, will be “Real” or “Integer”. |
precedence_overridden: |
True if the natural precedence of operators is overridden in the expression represented by this node of the expression tree. If True, parentheses should be introduced around the totality of the syntax expression corresponding to this operator node and its operands. |
operator: |
Code of operator. |
{
"name": "EXPR_OPERATOR",
"documentation": "Abstract parent of operator types.",
"is_abstract": true,
"ancestors": [
"EXPR_ITEM"
],
"properties": {
"precedence_overridden": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "precedence_overridden",
"documentation": "True if the natural precedence of operators is overridden in the expression represented by this node of the expression tree. If True, parentheses should be introduced around the totality of the syntax expression corresponding to this operator node and its operands.",
"type": "Boolean"
},
"operator": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "operator",
"documentation": "Code of operator.",
"is_mandatory": true,
"type": "OPERATOR_KIND"
}
}
}
EXPR_UNARY_OPERATOR Class
-
Definition
-
Effective
-
BMM
-
UML
Class |
EXPR_UNARY_OPERATOR |
|
|---|---|---|
Description |
Unary operator expression node. |
|
Inherit |
||
Attributes |
Signature |
Meaning |
1..1 |
operand: |
Operand node. |
| EXPR_UNARY_OPERATOR | |
|---|---|
Unary operator expression node. |
|
Inherits: EXPR_ITEM, EXPR_OPERATOR |
|
Attributes |
|
type: |
Type name of this item in the mathematical sense. For leaf nodes, must be the name of a primitive type, or else a reference model type. The type for any relational or boolean operator will be “Boolean”, while the type for any arithmetic operator, will be “Real” or “Integer”. |
precedence_overridden: |
True if the natural precedence of operators is overridden in the expression represented by this node of the expression tree. If True, parentheses should be introduced around the totality of the syntax expression corresponding to this operator node and its operands. |
operator: |
Code of operator. |
operand: |
Operand node. |
{
"name": "EXPR_UNARY_OPERATOR",
"documentation": "Unary operator expression node.",
"ancestors": [
"EXPR_OPERATOR"
],
"properties": {
"operand": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "operand",
"documentation": "Operand node.",
"is_mandatory": true,
"type": "EXPR_ITEM"
}
}
}
EXPR_BINARY_OPERATOR Class
-
Definition
-
Effective
-
BMM
-
UML
Class |
EXPR_BINARY_OPERATOR |
|
|---|---|---|
Description |
Binary operator expression node. |
|
Inherit |
||
Attributes |
Signature |
Meaning |
1..1 |
left_operand: |
Left operand node. |
1..1 |
right_operand: |
Right operand node. |
| EXPR_BINARY_OPERATOR | |
|---|---|
Binary operator expression node. |
|
Inherits: EXPR_ITEM, EXPR_OPERATOR |
|
Attributes |
|
type: |
Type name of this item in the mathematical sense. For leaf nodes, must be the name of a primitive type, or else a reference model type. The type for any relational or boolean operator will be “Boolean”, while the type for any arithmetic operator, will be “Real” or “Integer”. |
precedence_overridden: |
True if the natural precedence of operators is overridden in the expression represented by this node of the expression tree. If True, parentheses should be introduced around the totality of the syntax expression corresponding to this operator node and its operands. |
operator: |
Code of operator. |
left_operand: |
Left operand node. |
right_operand: |
Right operand node. |
{
"name": "EXPR_BINARY_OPERATOR",
"documentation": "Binary operator expression node.",
"ancestors": [
"EXPR_OPERATOR"
],
"properties": {
"left_operand": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "left_operand",
"documentation": "Left operand node.",
"is_mandatory": true,
"type": "EXPR_ITEM"
},
"right_operand": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "right_operand",
"documentation": "Right operand node.",
"is_mandatory": true,
"type": "EXPR_ITEM"
}
}
}
ASSERTION_VARIABLE Class
-
Definition
-
Effective
-
BMM
-
UML
Class |
ASSERTION_VARIABLE |
|
|---|---|---|
Description |
Definition of a named variable used in an assertion expression. |
|
Attributes |
Signature |
Meaning |
1..1 |
name: |
Name of variable. |
1..1 |
definition: |
Formal definition of the variable. |
| ASSERTION_VARIABLE | |
|---|---|
Definition of a named variable used in an assertion expression. |
|
Attributes |
|
name: |
Name of variable. |
definition: |
Formal definition of the variable. |
{
"name": "ASSERTION_VARIABLE",
"documentation": "Definition of a named variable used in an assertion expression.",
"properties": {
"name": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "name",
"documentation": "Name of variable.",
"is_mandatory": true,
"type": "String"
},
"definition": {
"_type": "P_BMM_SINGLE_PROPERTY",
"name": "definition",
"documentation": "Formal definition of the variable.",
"is_mandatory": true,
"type": "String"
}
}
}
OPERATOR_KIND Enumeration
-
Definition
-
Effective
-
BMM
-
UML
Enumeration |
OPERATOR_KIND |
|
|---|---|---|
Description |
Enumeration type for operator types in assertion expressions. |
|
Constants |
Signature |
Meaning |
op_eq |
Equals operator (= or ==) |
|
op_ne |
Not equals operator (!= or /=) |
|
op_le |
Less-than or equals operator (<=) |
|
op_lt |
Less-than operator (<=) |
|
op_ge |
Greater-than or equals operator (>=) |
|
op_gt |
Greater-than operator (>) |
|
op_matches |
Matches operator (matches or is_in) |
|
op_not |
Not logical operator |
|
op_and |
And logical operator |
|
op_or |
Or logical operator. |
|
op_xor |
Xor logical operator |
|
op_implies |
Implies logical operator |
|
op_for_all |
For-all (universal) quantifier |
|
op_exists |
Exists quantifier |
|
op_plus |
Arithmetic plus operator (+) |
|
op_minus |
Arithmetic minus operator (-) |
|
op_multiply |
Arithmetic multiplication operator (*) |
|
op_divide |
Arithmetic division operator (/) |
|
op_exponent |
Arithmetic exponentiation operator (^) |
|
| OPERATOR_KIND | |
|---|---|
Enumeration type for operator types in assertion expressions. |
|
Constants |
|
op_eq |
Equals operator (= or ==) |
op_ne |
Not equals operator (!= or /=) |
op_le |
Less-than or equals operator (<=) |
op_lt |
Less-than operator (<=) |
op_ge |
Greater-than or equals operator (>=) |
op_gt |
Greater-than operator (>) |
op_matches |
Matches operator (matches or is_in) |
op_not |
Not logical operator |
op_and |
And logical operator |
op_or |
Or logical operator. |
op_xor |
Xor logical operator |
op_implies |
Implies logical operator |
op_for_all |
For-all (universal) quantifier |
op_exists |
Exists quantifier |
op_plus |
Arithmetic plus operator (+) |
op_minus |
Arithmetic minus operator (-) |
op_multiply |
Arithmetic multiplication operator (*) |
op_divide |
Arithmetic division operator (/) |
op_exponent |
Arithmetic exponentiation operator (^) |
Functions |
|
Value equality. |
|
Reference equality. |
|
Create new instance of a type. |
|
Type name of an object as a string. May include generic parameters, as in "Interval<Time>". |
|
Arithmetic comparison. In conjunction with ‘=’, enables the definition of the operators ‘>’, ‘>=’, ‘<=’, ‘<>’. In real type systems, this operator might be defined on another class for comparability. |
|
Concatenation operator - causes ‘other’ to be appended to this string. |
|
is_empty (): |
True if string is empty, i.e. equal to "". |
is_integer (): |
True if string can be parsed as an integer. |
as_integer (): |
Return the integer corresponding to the integer value represented in this string. |
{
"_type": "P_BMM_ENUMERATION_STRING",
"name": "OPERATOR_KIND",
"documentation": "Enumeration type for operator types in assertion expressions.",
"ancestors": [
"String"
],
"item_names": [
"op_eq",
"op_ne",
"op_le",
"op_lt",
"op_ge",
"op_gt",
"op_matches",
"op_not",
"op_and",
"op_or",
"op_xor",
"op_implies",
"op_for_all",
"op_exists",
"op_plus",
"op_minus",
"op_multiply",
"op_divide",
"op_exponent"
],
"item_documentations": [
"Equals operator (= or ==)",
"Not equals operator (!= or /=)",
"Less-than or equals operator (<=)",
"Less-than operator (<=)",
"Greater-than or equals operator (>=)",
"Greater-than operator (>)",
"Matches operator (matches or is_in)",
"Not logical operator",
"And logical operator",
"Or logical operator.",
"Xor logical operator",
"Implies logical operator",
"For-all (universal) quantifier",
"Exists quantifier",
"Arithmetic plus operator (+)",
"Arithmetic minus operator (-)",
"Arithmetic multiplication operator (*)",
"Arithmetic division operator (/)",
"Arithmetic exponentiation operator (^)"
]
}