Number
Literals
You can use real numbers (integers or with a decimal
part). var x = 0; // integer
x = 3.14; // double
x = 8.5e-7; // scientific notation
Operators
Number variables can be used in expressions using the following operators:
- Arithmetic operators:
+ - * / %
- Assignments:
= += -= *= /* %=
- Comparison:
== != < > <= >=
- Iterators (for integers):
++ --
Math Functions
The following built-in functions can be used with numbers:
| Function |
Description |
Example |
Result |
| Math.sqrt() |
Square root |
x = Math.sqrt(16);
|
4 |
| Math.abs() |
Absolute value |
x = Math.abs(-5);
|
5 |
| Math.cbrt() |
Cubical root |
x = Math.cbrt(8);
|
2 |
| Math.ceil() |
Rounding up to the nearest integer |
x =
Math.ceil(-42.6);
|
-42 |
| Math.exp() |
Exponential |
x = Math.exp(1.0);
|
2.71828182845905 |
| Math.floor() |
Rounding down to the nearest integer |
x = Math.floor(-42.6);
|
-43 |
| Math.log10() |
Base 10 logarithms |
x = Math.log10(100);
|
2 |
| Math.round() |
Rounding to the nearest integer |
x = Math.round(-42.6);
|
-43 |
| Math.trunc() |
Integer part |
x = Math.trunc(42.6);
|
42 |
| Math.log() |
Natural logarithm (base E) |
x = Math.log(2.0);
|
0.693147180559945 |
| Math.random() |
Pseudo-random number that is greater than or equal to 0 and
less than 1 |
x = Math.random();
|
0.6588300753867891 |
| Math.PI |
Pi |
x = Math.PI;
|
3.141592654 |
Boolean
Literals
You can use boolean literals with the keywords true and
false. var b = true;
b = false;
Operators
You can use boolean variables in expressions with the following operators:
- Assignment:
=
- Logical conditions:
== !=
- Logical operators:
&& ||
String
Literals
Note:
Simple quotes (’) are not supported for string literals.
var s = ""; // empty string
s = "text"; // standard text
s = "text with a \" inside"; // text with a " inside
Operators
You can use string variables in expressions with the following operators:
- Assignment:
=
- Comparison:
== !=
- Concatenation:
+
Note:
<, > or other comparison operators are not
supported with strings.
Functions
The following built-in functions can be used with strings:
| Function |
Description |
Example |
Result |
length |
Length of the string |
var text = "text";
var result = text.length;
|
4 |
concat(stringToConcat) |
Join two strings |
var text1 = "sea";
var text2 = "food";
var result = text1.concat(text2);
|
seafood |
substring(startPosition,
endPosition)) |
Extract a substring from text |
var text = "Hello world!";
var result = text.substring(0, 5);
|
Hello |
search(stringToSearch) |
Search a string for a value, and return the position of the
match |
var text = "Hello world!";
var result = text.substring(0, 5);
|
2 |
replace(stringToReplace,
replacementString) |
Search a string for a pattern, and return a string where the
first match is replaced |
var text = "Turn left";
var result = text.replace("left", "right");
|
Turn right |
toLowerCase() |
Return a string converted to lowercase letters |
var text = "Hello World!";
var result = text.toLowerCase();
|
hello world! |
toUpperCase() |
Return a string converted to uppercase letters |
var text = "Hello World!";
var result = text.toUpperCase();
|
HELLO WORLD! |
Specificities:
- Search: If the
stringToSearch is not found, -1 is
returned.
- Substring:
- If
endPosition is omitted, substring()
extracts characters to the end of the string.
- If
startPosition is equal to endPosition,
substring() returns an empty string.
- If
startPosition is greater than endPosition,
then the effect of substring() is as if the two arguments were
swapped. Any argument value that is less than 0 or greater than
length is treated as if it were 0 and
length, respectively.
Note:
- All string methods return a new value. They do not change the original variable.
- Positions in string start at
0 and end at length –
1.
Array
Literals
var tab = []; // empty array
tab = [1, 2, 3]; // simple array
tab = ["text1", "text2", "text3"]; // array of strings
Note:
Arrays of arrays are not supported.
Operators
You can use array variables in expressions with the following operators:
- Assignment:
=
- Element access (read or write):
[]
Functions
The following built-in functions can be used with arrays:
| Function |
Description |
Example |
Result |
length |
Length of the array |
var tab = [1, 2, 3];
var result = tab.length;
|
result=3 |
at() |
Return the element at the given position |
var tab = [1, 2, 3];
var result = tab.at(2);
|
result=3 |
push() |
Add a new element to an array (at the end) |
var tab = [1, 2, 3];
tab.push(10);
|
tab=[1, 2, 3, 10] |
pop() |
Remove the last element from an array and return it |
var tab = [1, 2, 3];
var result = tab.pop();
|
tab=[1, 2, 3, 10] result=3 |
clear() |
Remove all the elements of an array |
var tab = [1, 2, 3]; tab.clear();
|
tab=[] |
splice() |
Change the contents of an array by removing or replacing
existing elements and/or adding new elements in their place. For more
information, see Splice()
Method. |
|
|
Note:
- Positions in arrays start at
0 and end at length –
1.
at() cannot be used to modify an element of an array. Use
tab[index] instead.
- Splice() Method
- This method is called as follows:
splice(startIndex, deleteCount, item1,
item2, …,itemN).
| Parameters |
Rules |
Example |
startIndex is a zero-based index from which to start
changing the array (mandatory).
deleteCount is an integer indicating the number of
elements in the array to be removed from the start (mandatory).
item1...itemN are the elements to add to the array
starting from the beginning (optional).
|
- startIndex > = 0
- startIndex < tab.length
- startIndex + deleteCount < = tab.length
|
var tab1 = [1, 2, 3, 4, 5];
tab1.splice(1, 2); // tab1 = [1, 4, 5]
var tab2 = [1, 2, 3, 4, 5];
tab2.splice(1, 0, 9); // tab2 = [1, 9, 2, 3, 4, 5]
var tab3 = [1, 2, 3, 4, 5, 6];
tab3.splice(3, 2, 8, 9, 10, 11); // tab3 = [1, 2, 3, 8, 9, 10, 11, 6]
|
Object
Structured objects (objects with properties) can be used in SemEL. Their definition
(the object type, the type, and name of its properties) is not part of the script, but must be
deported in an ontology.
Create
The new operator allows you to create an object as an instance of a
concept defined in the registered ontology. All properties will be created for this new
object and set as undefined. Note:
Properties that are objects will not be created recursively.
var myAsset = new Asset();
myAsset.name = "John";
To check whether a variable holds a defined object or not, you can use the
if statement. For more information, see Conditional Statements.
Access Object Properties
Properties are the values associated with the SemEL object. All properties can be
created, read, and updated.
- Read
- The syntax for accessing the property of an object is:
objectName.property.You must specify the annotation type when
a variable declaration is initialized with a read property statement that returns
an object (otherwise, it is optional). The TypeScript syntax is used with
colon annotation: var WC1 : WorkCenter = iWorker.isWorkingAt;
var capacity = WC1.capacity;
- Update/Create
- You can update or define the properties of an existing object by assigning it a
value:
iWorker.name = "John"; Note:
Properties must be defined
in the ontology.
Multivalued Property
A multivalued property can be handled like an array but the property must be stored in a
local variable before any manipulation. Note:
Chained invocation, such as
object.property.subproperty, is not supported.
You can access an item of a multivalued property using the at() method.
It takes an integer value and returns a copy of the item at this
index. var assetList = myWorkCenter.hasAssets;
var firstAsset : Asset = assetList.at(0);
You can update an item of a multivalued property using the []
operator. var assetList = myWorkCenter.hasAssets;
assetList[0] = otherAsset;
Note:
You can use the push(), pop(),
clear() and length methods on multivalued
properties.
You can iterate over a multivalued property using the for statement. For
more information, see Loop Statements.
var assetList = myWorkCenter.hasAssets;
for (var asset : Asset of assetList)
statement
|