Starting in Thing'In 3.4.0, the new endpoint POST /avatars/findAvatarAndValues/
allows to return arbitrary data elements, i.e. not restrained to avtars and relationships.
The new endpoint can for example be used to return :
Because of the JSON-oriented user-defined payload construction, the resultsets returned by this endpoint are restricted to the applicaiton/JSON syntax (unlike the regular find/avatars).
The new endpoint accepts the same queries as find/avatars. Only Thing'In base query language (TiQL
) is supported as of v3.4.0 (cypher isn't supported as of 3.4.0).
The difference with the base TiQL
is an extension to the result
field. In find/avatars
, it is restricted to a declared variable name (i.e. an alias
), or an array of variables. In /avatars/findAvatarAndValues/
, the return field can hold the user-defined JSON payload as mentionned above.
this functionality do not work on very old avatars
Basic example equivalent to what is possible in find/avatar:
{
"query": [
{
"$alias": "a",
"$domain": "http://www.example.com/values/",
"->http://elite.polito.it/ontologies/dogont.owl#isIn": "b"
},
{
"$alias": "b"
}
],
"view": {},
"return": "b"
}
JSON Array payload combining an avatar's property value and an avatar:
{
"query": [
{
"$alias": "a",
"$domain": "http://www.example.com/values/",
"->http://elite.polito.it/ontologies/dogont.owl#isIn": "b"
},
{
"$alias": "b"
}
],
"view": {},
"return": ["a.http://knoesis.wright.edu/ssw/ont/sensor-observation.owl#distance", "b"]
}
JSON Object payload combining several avatars properties. The JSON object can be used to easily rename the variables:
{
"query": [
{
"$alias": "a",
"$domain": "http://www.example.com/values/",
"->http://elite.polito.it/ontologies/dogont.owl#isIn": "b"
},
{
"$alias": "b"
}
],
"view": {},
"return": {
"creationTS" : "a.creationDate",
"distance": "b.http://knoesis.wright.edu/ssw/ont/sensor-observation.owl#distance"
}
}
Example with nested JSON array and object:
{
"query": [
{
"$alias": "a",
"$domain": "http://www.example.com/values/",
"->http://elite.polito.it/ontologies/dogont.owl#isIn": "b"
},
{
"$alias": "b"
}
],
"view": {},
"return": [
{
"creationTS": "a.creationDate",
"target": "b"
},
"b"
]
}
Nested example to return an avatar property value along with a relationship (b_e
) and its target (b
):
{
"query": [
{
"$alias": "a",
"$domain": "http://www.example.com/values/",
"->http://elite.polito.it/ontologies/dogont.owl#isIn": "b"
},
{
"$alias": "b"
}
],
"view": {},
"return": {
"sourceTS" : "a.creationDate",
"target": ["b","b_e"]
}
}
Alternative example with a more nested arrangement:
{
"query": [
{
"$alias": "a",
"$domain": "http://www.example.com/values/",
"->http://elite.polito.it/ontologies/dogont.owl#isIn": "b"
},
{
"$alias": "b"
}
],
"view": {},
"return": {
"sourceTS" : "a.creationDate",
"target": [
{
"node":"b",
"edge":"b_e"
}
]
}
}
Adding to the above, this endpoint allows to declare expressions as base variables and return them. This allows to make (advanced) computations in-query, and directly return the result of the computation.
The new exprVar
keyword allows to declare expressions directly in query blocs, and use them later in the return payload along with avatars/relationships.
Extract the creation date of a node and add it with itself:
{
"query": [
{
"$alias": "a",
"$domain": "http://www.example.com/values/",
"$exprVar":{
"$alias": "mySum",
"$expr":"$add",
"left": {
"$expr": "$dp",
"alias": "a",
"property": "creationDate"
},
"right": {
"$expr": "$dp",
"alias": "a",
"property": "creationDate"
}
}
}
],
"view": {},
"return": "mySum"
}
Extract the creation dates of two neighbor nodes and return a JSON object containing simple computations on these dates :
{
"query": [
{
"$alias": "a",
"$domain": "http://www.example.com/values/",
"->http://elite.polito.it/ontologies/dogont.owl#isIn": "b",
"$exprVar":{
"$alias": "myLog",
"$expr":"$log",
"n": {
"$expr": "$dp",
"alias": "a",
"property": "creationDate"
}
}
},
{
"$alias": "b",
"$exprVar":{
"$alias": "myMul",
"$expr":"$mul",
"left": {
"$expr": "$dp",
"alias": "a",
"property": "creationDate"
},
"right": {
"$expr": "$dp",
"alias": "b",
"property": "creationDate"
}
}
}
],
"view": {},
"return": {
"sourceCreationDate":"a.creationDate",
"targetCreationDate":"b.creationDate",
"multipliedSourceAndTarget":"myMul",
"logOfA":"myLog"
}
}