In an avatar, labels are stored in a list (considered as a set). Then list operator ($any_in and $contains) can be applyied to the label operator $label.
At the backend graph database, the labels of type
instance
are stored as vertices with a relationship between the avatar. As the labels are indexed (via their name as key), finding avatars thanks to theirs labels is efficient.
Filter the avatars that have the label "tag1"
"$label" : {"$contains" : "tag1"}
Filter the avatars that have the labels "tag1" or "tag2"
"$label" : {"$any_in" : ["tag1", "tag2"]}
To filter the avatars that have the labels "tag1" and "tag2", you can make a conjonction
"$label" : {"$contains" : "tag1"},
"$label" : {"$contains" : "tag2"}
For simple property, direct filter on the label can be used.
// create avatar with label property
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <http://orange-labs.fr/fog/ont/iot.owl#> .
@prefix ngsi: <https://uri.etsi.org/ngsi-ld/> .
<http://www.example.com/obj0>
:label "tag:red"^^xsd:string ;
:hasProperty [
:type "Integer"^^xsd:string ;
:label "tag:prop1"^^xsd:string ;
ngsi:hasValue "10"^^xsd:string
].
You can request a Find by using label as property:
{
"query": {"$label":"tag:red", "tag:prop1": 10 },
"view": {}
}
Considering the following example :
// create with complex property
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <http://orange-labs.fr/fog/ont/iot.owl#> .
@prefix ngsi: <https://uri.etsi.org/ngsi-ld/> .
<http://www.example.com/obj1>
:label "tag:red"^^xsd:string ;
:hasProperty [
:type "TimeInterval"^^xsd:string ;
:label "tag:prop1"^^xsd:string ;
ngsi:startAt "2021-05-10T21:36:00Z"^^xsd:string ;
ngsi:endAt "2021-06-10T21:36:00Z"^^xsd:string
].
You can request a Find by using label as property:
{
"query": {"$label":"tag:red", "tag:prop1[http://orange-labs.fr/fog/ont/iot.owl#type]":"TimeInterval"},
"view": {}
}
As "http://orange-labs.fr/fog/ont/iot.owl#type" is defined in core context as "type", this request can be rewritten :
{
"query": {"$label":"tag:red", "tag:prop1[type]":"TimeInterval"},
"view": {}
}
An in the same way, the other fields can be filtered :
{
"query": {"$label":"tag:red", "tag:prop1[https://uri.etsi.org/ngsi-ld/startAt]": "2021-05-10T21:36:00Z"},
"view": {}
}
As "https://uri.etsi.org/ngsi-ld/startAt" is defined in core context as "startAt", this request can be rewritten :
{
"query": {"$label":"tag:red", "tag:prop1[startAt]": "2021-05-10T21:36:00Z"},
"view": {}
}
The relationships can embed properties, then they should be considered as entities and not only as a "name".
We introduce a new keyword "$relationships"
that aims to improve filtering over relationships.
Here an example that try to define the use.
"$relationships" : [{ "$avatar" : "aliasx", "$direction" : "OUT", "$label" : "tag:rel1", "tag:prop1[startAt]" : "2021-05-10T21:36:00Z"}]
It is expected a list of relationships between the current avatar to or from others.
In each relationship filter, "$avatar"
specifies an alias at the other side of the relationship, "$direction"
gives the direction of the relationship "out" means the relation goes from the avatar to the avatar specified by the alias. "IN"
from the avatar specified by the alias to this avatar. "ANY"
there is no specific direction. by default (if not defined) direction is "OUT"
. The "$label"
specifies the type of the relationship (could be an objectproperty name or a label).
According to this definition and the existing syntax:
"$relationships" : [{ "$avatar" : "aliasx", "$direction" : "OUT", "$label" : "http://elite.polito.it/ontologies/dogont.owl#isIn"}]
is equivalent to
"->http://elite.polito.it/ontologies/dogont.owl#isIn" : "aliasx"
This functionality is applyable to graph pattern matching syntax.
Here an example that find the pattern avatar av1 with a property tag:prop set to 10 linked to another avatar av2:
{
"query":[
{
"$alias" : "av1",
"tag:prop": 10,
"$relationships" : [{ "$avatar" : "av2", "$direction" : "ANY"}]
},
{
"$alias" : "av2"
}
],
"view": {}
}
Filters can be put on avatars and on the relationship :
{
"query":[
{
"$alias" : "av1",
"$iri" : "http://www.example.com/toto0",
"$relationships" : [{ "$avatar" : "av2", "$direction" : "IN", "tag:prop2": "deuxieme"}]
},
{
"$alias" : "av2",
"$iri" : "http://www.example.com/toto"
}
],
"view": {}
}
Specific operators can be added to the relationship
to specify that the relationship could exist or not
$optional
: true or false. by default false.
to build a path:
$maxDepth
and $minDepth
: specify the number of time the relationship could be repeated.
examples
{
"query": [
{
"$alias": "n",
"$relationships": [
{
"$avatar": "r",
"$label": "http://orange-labs.fr/fog/ont/oasis.owl#hasOwner",
"$direction": "OUT",
"$optional" : true
}
],
"$domain": {
"$eq": "http://www.dechorgnat.com/auto/206/"
}
}
]
}
{
"query": [
{
"$alias": "n",
"$relationships": [
{
"$avatar": "r",
"$label": "http://orange-labs.fr/fog/ont/oasis.owl#hasOwner",
"$direction": "OUT",
"$minDepth" : 2,
"$maxDepth" : 5
}
],
"$domain": {
"$eq": "http://www.dechorgnat.com/auto/206/"
}
}
]
}