Indirect Queries

Last revised 6/24/2021. Contact us.

Normally a query in the SADL grammar consists of the Ask keyword, followed by a colon, followed by either a valid query string or an expression that can be translated to a valid query. For example, the following query finds any subject that  likes something and the object of likes. The query is expressed as a SPARQL query string.

Ask: "select ?p ?s where {?p <likes> ?s}".

The same query could have been expressed in the SADL grammar syntax, which would translate to an identical SPARQL query.

Ask: select p, s where p likes s.

Both of these query formats assume that the requisite query is known at the time the knowledge base is created. This is not always the case. Sometimes the query itself may only be determined by reasoning with situation-specific instance data. For this reason SADL supports what are referred to as indirect queries, queries that return a valid query string which is then executed as a query to obtain the returned query results. To make a query indirect, the query is preceded by the keywords "value of". To illustrate, consider a toy example with the following simple ontology.

QueryHost is a class described by queryStr with values of type string.

We will explicitly create an instance of QueryHost and assign a value of queryStr, but the creation of the instance and/or the assigning of a value of queryStr could be done by any process including reasoning over the scenario data.

MyQueryHost is a QueryHost with queryStr "select ?qh ?qs where {?qh <rdf:type> <QueryHost> . ?qh <queryStr> ?qs}".

An indirect query that uses the value of queryStr looks like this.

Ask: value of queryStr of MyQueryHost.

One could use SPARQL instead of SADL syntax for the query that returns the query.

Ask: value of "select ?qs where {?qh <rdf:type> <QueryHost> . ?qh <queryStr> ?qs}".