An expression allows describing the constraints of avatar properties more precisely. It can embed functions processing arithmetic, logic, string and array or accessing property of a specified avatar.
An expression can be view as a function with arguments. and it is qualified by the response type that could be NUMBER, STRING, ARRAY, ANY
.
{
"$expr" : function_code,
"arg_name1" : value,
"arg_name2" : value,
...
}
{
"query": {
"$domain": {"$eq":
{
"$expr":"$concat",
"left": "http://domain-example",
"right":".org/"
}
}
},
"view": {}
}
Here the expression $concat
concats 2 object values placed at left and right. To build more complex expression, some arguments could be also any expression. An expression can be see as an expression tree (recursion).
Then for instance, you can write:
{
"query": {
"$domain": {"$eq":
{
"$expr":"$concat",
"left": {"$expr":"$concat", "left": "http://", "right" : "domain-example"},
"right":{"$expr":"$concat", "left": ".", "right" : "org"}
}
}
},
"view": {}
}
{
"query": [
{
"$alias": "a",
"$uuid": "xxxx"
},
{
"$alias": "b",
"$uuid": "yyy"
},
{
"$alias": "c",
"$domain": { // => compare domain of avatar c with the domain of avatar a
"$eq": {
"$expr": "$domain",
"alias": "a"
}
},
"http://www.w3.org/2006/vcard/ns#prodid": {
// => compare data-property http://www.w3.org/2006/vcard/ns#prodid of avatar c
// with the data-property http://www.w3.org/2006/vcard/ns#prodid of avatar b
"$eq": {
"$expr": "$dp",
"alias": "b",
"property": "http://www.w3.org/2006/vcard/ns#prodid"
}
}
}
],
"return": "c",
"view": {}
}
To use an avatar alias, it should be defined before
Compare the equality of 2 any values (left and right) and return the result as a boolean. true
if left value == right value false
otherwise.
{
"$expr":"$eq",
"left": ANY,
"right": ANY
}
Test if a value left is greater than a value right and return the result as a boolean. true
if left value > right value false
otherwise.
{
"$expr":"$gt",
"left": ANY,
"right": ANY
}
Test if a value left is greater than or equal a value right and return the result as a boolean. true
if left value >= right value false
otherwise.
{
"$expr":"$gte",
"left": ANY,
"right": ANY
}
Test if a value left is less than a value right and return the result as a boolean. true
if left value < right value false
otherwise.
{
"$expr":"$lt",
"left": ANY,
"right": ANY
}
Test if a value left is less or equal than a value right and return the result as a boolean. true
if left value <= right value false
otherwise.
{
"$expr":"$lte",
"left": ANY,
"right": ANY
}
Test if a value left is not equal to a value right and return the result as a boolean. true
if left value != right value false
otherwise.
{
"$expr":"$ne",
"left": ANY,
"right": ANY
}
Test if a boolean value is not true
.
{
"$expr":"$not",
"expression": BOOLEAN
}
Apply the logical operator and
between a left and a right expression. left value && right value.
{
"$expr":"$and",
"left": BOOLEAN,
"right": BOOLEAN
}
Apply the logical operator or
between a left and a right expression. left value || right value.
{
"$expr":"$or",
"left": BOOLEAN,
"right": BOOLEAN
}
Test if a value left is contained equal to a array value right and return the result as a boolean. true
if left value is in right array value false
otherwise.
{
"$expr":"$in",
"left": ANY,
"right": ARRAY
}
Test if any element of the array value left is contained in a array value right and return the result as a boolean. true
if any element of left array value is in right array value false
otherwise.
{
"$expr":"$any_in",
"left": ARRAY,
"right": ARRAY
}
Test if all the elements of the array value left are contained in a array value right and return the result as a boolean. true
if all the elements of left array value are in right array value false
otherwise.
{
"$expr":"$all_in",
"left": ARRAY,
"right": ARRAY
}
Test if none element of the array value left is contained in a array value right and return the result as a boolean. true
if none element of left array value is in right array value false
otherwise.
{
"$expr":"$none_in",
"left": ARRAY,
"right": ARRAY
}
Apply the arithmetical operator add
(addition) between a left and a right expression. left value + right value.
{
"$expr":"$add",
"left": NUMBER,
"right": NUMBER
}
Apply the arithmetical operator minus
(substraction) between a left and a right expression. left value - right value.
{
"$expr":"$minus",
"left": NUMBER,
"right": NUMBER
}
Apply the arithmetical operator mul
(multiplication) between a left and a right expression. left value * right value.
{
"$expr":"$mul",
"left": NUMBER,
"right": NUMBER
}
Apply the arithmetical operator div
(division) between a left and a right expression. left value / right value.
{
"$expr":"$div",
"left": NUMBER,
"right": NUMBER
}
Apply the arithmetical operator mod
(modulus) between a left and a right expression. left value % right value.
{
"$expr":"$mod",
"left": NUMBER,
"right": NUMBER
}
Apply the arithmetical operator exp
(euler exponentiation) to the expression. eexpression.
{
"$expr":"$exp",
"expression": NUMBER
}
Apply the arithmetical operator log
(logarithm) to the expression. log(expression).
{
"$expr":"$log",
"expression": NUMBER,
}
Apply the arithmetical operator pow
(power) between a left and a right expression. left_valueright_value.
{
"$expr":"$pow",
"left": NUMBER,
"right": NUMBER
}
Apply the arithmetical operator sqrt
(square root) to the expression. sqrt(expression).
{
"$expr":"$sqrt",
"expression": NUMBER
}
Apply the arithmetical operator abs
(absolute) to the expression. abs(expression).
{
"$expr":"$abs",
"expression": NUMBER,
}
Apply the arithmetical operator ceil
(the smallest integer greater or equal than x) to the expression. ceil(expression).
{
"$expr":"$ceil",
"expression": NUMBER
}
Apply the arithmetical operator floor
(the largest integer less or equal than x) to the expression. floor(expression).
{
"$expr":"$floor",
"expression": NUMBER
}
Apply the arithmetical operator round
(the integer closest to x) to the expression. round(expression).
{
"$expr":"$round",
"expression": NUMBER
}
Apply the arithmetical operator round
(Return a pseudo-random number between 0 and 1). rand().
{
"$expr":"$rand"
}
Return the value of Pi.
{
"$expr":"$pi"
}
Return the sine of value. sin(expression).
{
"$expr":"$sin",
"n": NUMBER
}
Return the cosine of value. cos(expression).
{
"$expr":"$cos",
"n": NUMBER
}
Return the tangent of value. tan(expression).
{
"$expr":"$tan",
"n": NUMBER
}
Return the arccosine of value. asin(expression).
{
"$expr":"$acos",
"n": NUMBER
}
Return the arcsine of value. asin(expression).
{
"$expr":"$asin",
"n": NUMBER
}
Return the arctangent of value. atan(expression).
{
"$expr":"$atan",
"n": NUMBER
}
Return the angle converted from degrees to radians.
{
"$expr":"$radians",
"deg": NUMBER
}
Return the angle converted from radians to degrees.
{
"$expr":"$degrees",
"rad": NUMBER
}
Return the nth element of the array.
{
"$expr":"$nth",
"array": ARRAY,
"n" : NUMBER
}
Return the length of the array.
{
"$expr":"$length",
"array": ARRAY
}
Append 2 arrays as a new array
{
"$expr":"$append",
"left": ARRAY,
"right": ARRAY
}
Return an array containing each element of input array only once.
{
"$expr":"$unique",
"array": ARRAY
}
example:
UNIQUE([1, 1, 1, 1, 2, 2, 3]) => [1, 2, 3]
Return the union of 2 arrays.
{
"$expr":"$unique",
"left": ARRAY,
"right": ARRAY
}
example:
UNION([1, 1, 2, 2, 3], [2, 3, 4]) => [1, 1, 2, 2, 3, 2, 3, 4]
Return the intersection of 2 arrays.
{
"$expr":"$intersection",
"left": ARRAY,
"right": ARRAY
}
INTERSECTION( [1,2,3,4,5], [2,3,4,5,6]) => [2, 3, 4, 5]
Return the outersection of 2 arrays.
{
"$expr":"$outersection",
"left": ARRAY,
"right": ARRAY
}
OUTERSECTION( [ 1, 2, 3 ], [ 2, 3, 4 ]) => [1, 4]
Return the concatenation of 2 strings.
{
"$expr":"$concat",
"left": STRING,
"right": STRING
}
example:
CONCAT("hello ", "wolrd!") => "hello world!"
Return true if the left string contains the right string.
{
"$expr":"$contains",
"left": STRING,
"right": STRING
}
examples:
CONTAINS("hello", "el") => true
CONTAINS("hello", "bye") => false
Return true if the left string begins with the right string.
{
"$expr":"$startswith",
"left": STRING,
"right": STRING
}
examples:
STARTSWITH("hello", "hell") => true
STARTSWITH("hello", "heaven") => false
Return true if the left string matches with the regex (in right string).
The regex format should respect the java regex format
{
"$expr":"$match",
"left": STRING,
"right": STRING
}
examples:
MATCH("hello", "h.*o") => true
MATCH("hello ", ".*lo$") => true
MATCH("hello ", "^he.*") => true
Return the given string in a converted lower case string.
{
"$expr":"$lower",
"s": STRING,
}
examples:
LOWER("HELLO") => "hello"
LOWER("HeLlO WoRlD !") => "hello world !"
Return the given string in a converted upper case string.
{
"$expr":"$upper",
"s": STRING,
}
examples:
UPPER("hello") => "HELLO"
UPPER("HeLlO WoRlD !") => "HELLO WORLD !"
In the following, each operator allows to acces a specific property of an avatar.
To use an avatar alias, it should be defined before
Return an array containing the classes of an avatar designed by an alias.
{
"$expr":"$classes",
"alias": ALIAS STRING
}
Return an array containing the inherited classes of an avatar designed by an alias.
{
"$expr":"$inherited_classes",
"alias": ALIAS STRING
}
Return the iri of an avatar designed by an alias.
{
"$expr":"$iri",
"alias": ALIAS STRING
}
Return the uuid of an avatar designed by an alias.
{
"$expr":"$uuid",
"alias": ALIAS STRING
}
Return the lastUpdated of an avatar designed by an alias.
{
"$expr":"$lastUpdated",
"alias": ALIAS STRING
}
Return the domain of an avatar designed by an alias.
{
"$expr":"$domain",
"alias": ALIAS STRING
}
Return an array containing the labels of an avatar designed by an alias.
{
"$expr":"$label",
"alias": ALIAS STRING
}
Return the owner id of an avatar designed by an alias.
{
"$expr":"$owner",
"alias": ALIAS STRING
}
Return the visibility value of an avatar designed by an alias.
{
"$expr":"$visibility",
"alias": ALIAS STRING
}
Return if an avatar designed by an alias is static.
{
"$expr":"$static",
"alias": ALIAS STRING
}
Return the value of a given dataproperty of an avatar designed by an alias.
{
"$expr":"$dp",
"alias": ALIAS STRING,
"property" : PROPERTY NAME STRING
}