{
"query": {
"$iri": "<I>"
}
}
the property
IRI
is indexed in the underlying database, then this query is fast.
{
"query": {
"$domain": "<D>"
}
}
the property
domain
is indexed in the underlying database, then this query is fast.
{
"query": {
"$owner": "<U>"
}
}
the property
owner
is not indexed in the underlying database, then this query could scan all the database and then it is slow. To improve it, add for instance a domain constraint.
{
"query": {
"$label": "<L>"
}
}
in fact, an avatar can have multiple labels. This query describes the constraint : the avatar label list should contain L.
the property
label
is implemented as a graph node with id = its name. Then giving a label, accessing the avatars that use this label is easy (one step graph query). This query is fast.
{
"query": {
"$domain": "<D>",
"$classes": "<C>"
}
}
in fact, an avatar can have multiple classes. This query describes the constraint : the avatar class list should contain C.
As the
domain
property, the propertyclasses
is also indexed in the underlying database. The database engine chooses the best index to have better performance, then this query is fast.
{
"query": {
"$classes": { "$contains_all" : ["<C1>", "<C2>"]}
}
}
{
"query": {
"$classes": {
"$any_in" : ["<C1>", "<C2>"],
"$inheritance" : true
}
}
}
{
"query": {
"$domain": "<D>",
"$lastUpdated": {"$gt" : <T>}
}
}
{
"query": {
"$domain": "<D>",
"<size>": {"$lt" : <S>}
}
}
{
"query": [
{
"$alias" : "a",
"$iri": "<I>"
},
{
"$alias" : "b",
"$domain": {
"$eq" : {"$expr" : "$domain", "alias" : "a"}
}
}
],
"return" : "b"
}
{
"query": [
{
"$alias" : "a",
"$iri": "<I>"
},
{
"$alias" : "b",
"<size>": {
"$gt" : {
"$expr" : "$mul",
"left" : 2,
"right" : {"$expr" : "$dp", "alias" : "a", "property" : "<size>"}
}
}
}
],
"return" : "b"
}
{
"query": [
{
"$alias" : "a1",
"$iri": "<I1>"
},
{
"$alias" : "a2",
"$iri": "<I2>"
},
{
"$alias" : "b",
"<size>": {
"$lt" : {
"$expr" : "$div",
"left" : {
"$expr" : "$add",
"left" : {"$expr" : "$dp", "alias" : "a1", "property" : "<size>"},
"right" : {"$expr" : "$dp", "alias" : "a2", "property" : "<size>"}
},
"right" : 2
}
}
}
],
"return" : "b"
}
{
"query": [
{
"$alias" : "a",
"$iri": "<I>"
},
{
"$alias" : "b",
"$domain": "<D>",
"-><R>": "a"
}
],
"return" : "b"
}
{
"query": [
{
"$alias" : "a",
"$iri": "<I>"
},
{
"$alias" : "b",
"$domain": "<D>",
"-><R>": "a",
"<size>": {
"$gt" : {
"$expr" : "$dp", "alias" : "a", "property" : "<size>"
}
}
}
],
"return" : "b"
}
The type of query below allows to include in your query filters dedicated to the ontologies themselves, and to combine filters on both ontology classes, object / datatype properties, along with regular filters on avatars that are linked to these classes/properties.
For semantic web practitioners, this is the norm. For instance, if you are familiar with SPARQL, it is common practice to make queries about the "model" part of your data, or TBox, at the same time as its instances, or ABox.
In ThingIn, the query structure for this type of query is the same as any query. The $classes clause is the single entrypoint to perform these queries.
Essentially, the $classes clause can embed a seb-query about ontology classes and properties.
{
"query": [
{
"$alias": "specializedToiletAvatars",
"$classes": {
"$all_in": [
{
"->http://www.w3.org/2000/01/rdf-schema#subClassOf":"parentClass"
},
{
"$alias":"parentClass",
"$iri":"http://orange-labs.fr/fog/ont/building.owl#Toilet"
}
]
},
"->http://elite.polito.it/ontologies/dogont.owl#isIn": "myBuilding"
},
{
"$alias": "myBuilding",
"$iri": "http://thingin.orange.com/example/building"
}
],
"view": {}
}
This query finds all avatars inside the bulding http://thingin.orange.com/example/building, and ensures that the class of the avatar must be a subClass of the http://orange-labs.fr/fog/ont/building.owl#Toilet class.
Below is an example result where no avatars match the description. You can notice that on top of the list of avatars returned, the ontology classes are themselves added to the result payload. For the query above, this includes the "http://orange-labs.fr/fog/ont/building.owl#Toilet" class, along with its sub class "http://orange-labs.fr/fog/ont/building.owl#ToiletForDisabled". Any avatar instance of the latter would be retrieved, if any.
{
"size": 0,
"items": [],
"page_size": 100,
"index": 0,
"hidden": 0,
"classes": [
{
"_uuid": null,
"_iri": "http://orange-labs.fr/fog/ont/building.owl#ToiletForDisabled",
"_classes": [
"http://www.w3.org/2002/07/owl#Class"
],
"_visibility": -1,
"http://www.w3.org/2000/01/rdf-schema#comment": [
"A room used for relieving oneself that can be use by disabled persons."
],
"http://www.w3.org/2000/01/rdf-schema#label": [
"ToiletForDisabled"
]
},
{
"_uuid": null,
"_iri": "http://orange-labs.fr/fog/ont/building.owl#Toilet",
"_classes": [
"http://www.w3.org/2002/07/owl#Class"
],
"_visibility": -1,
"http://www.w3.org/2000/01/rdf-schema#comment": [
"A room used for relieving oneself."
],
"http://www.w3.org/2000/01/rdf-schema#label": [
"Toilet"
]
}
],
"next": "http://localhost:8080/avatars/find?index=100&page_size=100"
}
Below is the equivalent response in turtle format. The ontology classes are also included :
@prefix org-iot: <http://orange-labs.fr/fog/ont/iot.owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://orange-labs.fr/fog/ont/building.owl#Toilet> a <http://www.w3.org/2002/07/owl#Class> ;
rdfs:label "[Toilet]"^^xsd:string ;
org-iot:visibility "-1"^^xsd:int ;
rdfs:comment "[A room used for relieving oneself.]"^^xsd:string .
<http://orange-labs.fr/fog/ont/building.owl#ToiletForDisabled> a <http://www.w3.org/2002/07/owl#Class> ;
rdfs:label "[ToiletForDisabled]"^^xsd:string ;
org-iot:visibility "-1"^^xsd:int ;
rdfs:comment "[A room used for relieving oneself that can be use by disabled persons.]"^^xsd:string .
{
"query": [
{
"$alias": "textFilterOnClassAvatars",
"$classes": {
"$all_in": [
{
"$alias":"classFromTextFilter",
"rdfs:label": {
"$startswith":"Desk"
}
}
]
},
"->http://elite.polito.it/ontologies/dogont.owl#isIn": "myBuilding"
},
{
"$alias": "myBuilding",
"$iri": "http://thingin.orange.com/example/building"
}
],
"view": {}
}
This query finds all avatars inside the bulding http://thingin.orange.com/example/building, and adds an additional filter on property "rdfs:label" of the class of the avatar, with a text prefix filter ($startswith).