Using the Knowledge Expert Language (KWE)   

For more information about the Knowledge Language in general, see Knowledge Advisor User's Guide: Engineering Knowledge Language.

This page contains information concerning the languages to be used when working with the Knowledge Expert application.

When defining rules in Knowledge Expert, you may use 2 languages:

When defining checks in Knowledge Expert, you may use 3 languages:

  • KWE language.
  • KWE Advanced Language: Extension of the Knowledge Expert (KWE) language. It enables you to use local variables, and if then else, for, while control structures.
    You can also fill in a list of succeeded and failed objects that will be used when generating the report.
     Note that this language can only be used when creating checks.
  • Visual Basic Language

Declaring variables

    in the For All field  

Rules and checks variables are declared in the For All field.
For more information about the types to use in this field, see Defining Types.

Note that:

When using KWE language, you may now declare autoreferencing variables in the Check or the Rule body by using Thisrule or Thischeck. For more information, see Accessing the Expert Check in the Check Body.

In the Check Body

Temporary variables can be declared  by using the let keyword. A temporary variable does not persist as a parameter after the check/rule execution is finished.

let Mylist(List)
let childrenCheck(KWECheck)
let i = 1
let condition = 0
Mylist = H.DirectChildren
for i while condition == 0 AND i <= Mylist.Size()
   {
    childrenCheck = Mylist.GetItem(i)
    if (childrenCheck.Name == "TargetCheck")
     {
       ThisCheck.AddTupleFailed(childrenCheck)
       condition = 1
     }
else
      {
       ThisCheck.AddTupleSucceeded(ChildrenCheck)
      }
   }

Using Types  

The types described below are those you can use in the Rule Editor or in the Check Editor by using the Object Browser.

In the (For all) field, use the following syntax:   type_identifier:type_name

  • where type_identifier corresponds to the variable you want to declare and type_name stands for the type to be declared, available in the Browser.
  • Note that you can insert feature names (types) by keying them in the For all field, by selecting them in the Check/Rule Editor browser or by clicking the features in the geometry window or in the specification tree.

Examples:

H:Hole ; S:Shell
Hl:Hole ; Sel:Shell

 

Type declarations must be separated with semi-colons.

Using Types Attributes  

The types attributes described below are those you can select in the Object Browser available from the Rule Editor or the Check Editor.

Types are allocated attributes that you can key in in the check or rule body or that you can select in the Object Browser.

type_identifier.object_name

  Example: 

if H.Diameter > 10.0 then H.Activity = False

Using Functions  

Functions supported by Knowledge Expert may be entered manually in the check or rule body or can be selected from the Object Browser (See description above to know how to access the browser.)

  • Select the Show Inherited Attributes box for the methods to be visible.
  • The > operator is required when using functions.

Example

(for all) Prod1:Product ; Prod2:Product

if Prod1 > Prod2 and ClashOrContact("Clash", Prod1,Prod2)
Message ("Products clashing are # and #", Prod1 > Name(),Prod2 > Name())

Using Statements  

The control structures described below are the one you can use in the Rule Editor or in the Check Editor.

Any KWE script is built out of a series of statements. A statement can be an assignment, a function call, or a conditional statement. Statements usually end with a semicolon. In addition, statements can be grouped into a statement-group by encapsulating a group of statements within curly braces.

If Construct

This construct allows for conditional execution of code fragments. Note that "if" constructs cannot be nested.

if(Hole.HoleType == "Simple")
{
Hole.Diameter = 24mm;
}

 

  • and and or are supported in the KWE statements.
  • To execute a statement if a certain condition is met, and a different statement if the condition is not met, create two different rules or checks. This is how to provide "else" functionality in other languages.

 if  ... else ... else...if Construct

Rules

if  ... else  ... else if

Conditionally executes a group of statements, depending on the value of an expression. You can use either block form syntaxes:

if condition statements [else elsestatements ]

or

if condition 
    { statements }
[else if condition-n  
    [  { elseifstatements  }  ]  ] . . .
[else
    [  {  elsestatements   }  ]  ]

Checks

statement1  => statement2  (if statement1  then statement2)
Displays a message (if type is Warning or Information) and turns to red in the specification tree each time statement2 is invalid as statement1 is fulfilled.

 if  ... then  ... else Construct

Note that the if...then...else construct is only available for:
  • checks created using the KWE Advanced Language.
  • rules. In this case, use the KWE Language.

if then else statements are used for conditional computation. The else statement is optional.  Statements can be nested that is, contained within one another.

H:Hole

if H.Diameter > 20mm
ThisCheck > AddTupleFailed(H)
else
ThisCheck > AddTupleSucceeded(H)

while Construct 

Note that the while construct is only available for:
  • checks created using the KWE Advanced Language.
  • rules. In this case, use the KWE Language.

while loops are used to execute a statement if an expression evaluates to true.

let Mylist(List)
let childrenCheck(KWECheck)
let i = 1
let condition = 0
Mylist = H.DirectChildren
for i while condition == 0 AND i <= Mylist.Size()
{
childrenCheck = Mylist.GetItem(i)
if (childrenCheck.Name == "TargetCheck")
{
ThisCheck.AddTupleFailed(childrenCheck)
condition = 1
}
}

for Construct 

Note that the for construct is only available for:
  • checks created using the KWE Advanced Language.
  • rules.  In this case, use the KWE Language.

 

for executes a loop based on the element of a list. See syntax opposite. It executes a statement Nth times where N is the number of elements of the list.

In the example opposite:

  • x is a variable name (of a given type). It may represent an object or a value.
  • List is a variable name of type List or an expression returning a list.
  • x (like any other variable of the language) can be used in the body. It contains the Nth element of the list.

 

For x inside List
{
Body
}
Example

let Mylist(List)
let children(KWERuleSet)
Mylist = H.DirectChildren
for children inside Mylist
{
    Message("Finding RuleSet #",children.Name)
}

for executes a loop until an expression becomes false. See syntax opposite.

In the example opposite:

  • x is a variable name of integer type. It is incremented at the end of each execution of the body.
  • Predicate is a Boolean expression. The body is executed if this expression is true. This expression is evaluated before the body.

Note that the second for operator can lead to infinite loops.

 

For x while predicate
{
Body
}

Using Operators 

Arithmetic operators

+  Addition operator (also concatenates strings)

-  Subtraction operator

*  Multiplication operator

/  Division operator

Comparison Operators

<>   Not equal to

==   Equal to

>=   Greater or equal to

<=   Less than or equal to

<    Less than

>    Greater than

Others

=  Assignment  operator 

**   Exponentiation operator

Filter Operator

The Filter Operator (=>) is designed for implication: It enables you to restrict the check operation on a subset of the features that were specified in the For all field:

Example 1

Given the check below:

H:Hole
H.HasAttribute("Cost")=>H.Diameter>10mm
The check report will only provide you with the results of the H.Diameter > 10 mm tests on the holes with a Cost attribute. Tests on other holes won't be performed.
 

Example 2

H.Diameter > 3mm =>H.Depth>10mm If the diameter of a hole is greater than 3mm, its depth must be greater than 10mm.