Query options control the execution and output of a query.
Syntactically they are provided as annotations to the query. Annotations are written in front of the query with the syntax @{<queryName>,options[<option1>,<option2>]}.
Example: query without id and options
?- ?X::?Y.
Example: query with id "subconcepts"
@{subconcepts} ?- ?X::?Y.
Example: query with options "inferOff" and "profile"
@{options[inferOff,profile]} ?- ?X::?Y.
Sorting
This query option allows sorting of the result of a query. Example:
@{q1, options[sort(asc(?X),desc(?Y)]} ?- ?X::?Y.
This example will sort the query results in the ascending order of bindings for ?X and in descending order of bindings for ?Y. It is also possible to write:
@{q1, options[sort(?X,desc(?Y)]} ?- ?X::?Y.
The ?X will be be interpreted as asc(?X), so you can just leave out the asc(..).
Sequence and restriction of the result variables (output ordering)
If you want to specify the sequence of the output variables, you can use the "outorder" query option. E.g. with the facts
Man::Person.
Woman::Person.
the output of the query
@{q1, options[outorder(?X,?Y)]} ?- ?X::?Y.
will be
Man,Person
Woman,Person
With
@{q1, options[outorder(?Y,?X)]} ?- ?X::?Y.
the output will be
Person,Man
Person,Woman
The "outorder" option can also be used for skipping some variable bindings in the result: with
@{q1, options[outorder(?X)]} ?- ?X::?Y.
the output will be
Man
Woman
Limiting the number of answers
If you want to limit the number of answers, you can use the "limit" option:
@{q1, options[limit(1),outorder(?Y,?X)]} ?- ?X::?Y.
In this example, only one answer will be given. Note that limiting the number of answers does not necessarily mean that the performance will improve.
Answer offset
If you want to skip some answers, then you can use the "offset" option:
@{q1, options[offset(10),limit(5),sort(?Y,?Y),outorder(?Y,?X)]} ?- ?X::?Y.
In this example five answers will be given, starting with answers then. Using offset only makes sense if the answer order is specified. Otherwise it is not assured that the answers are returned in the same order.
Skip sendings answers
Using the option "skipSendingAnswers", you can execute a query without receiving the results. This can be useful for benchmarking, if the time for sending the answers to the client complicates time measurements.
@{q1, options[skipSendingAnswers]} ?- ?X::?Y.
Tracing
OntoBroker will log trace information about the query execution if you use the query option "trace".
@{q1, options[trace]} ?- ?X::?Y.
Profiling
The logging of the performance characteristics can be enabled with the query options "profile" and "profileAll". The profileAll executes the query with full profiling (including execution plans etc.)
@{q1, options[profile]} ?- ?X::?Y.
@{q1, options[profileAll]} ?- ?X::?Y.
Turning off inferencing
You may tell OntoBroker not to do inferencing for query answering. This will prohibit the evaluation of all rules and you will only get the given facts matching your query.
@{q1, options[inferOff]} ?- ?X::?Y.
Turning off user rules
You may tell the OntoBroker to disable all user rules, i.e. all rules explicitly defined in any module. Internal axiom rules (like e.g. subclass and property hierarchy) are not influenced by this option,
@{q1, options[userRulesOff]} ?- ?X::?Y.
Turning off imports
If module A imports module B, all facts of B are included on querying facts from module A. Using the "ignoreImports" query option you can query for facts only stored explictly in module A.
Module A
:- module A.
:- importmodule B.
John:person.
Module B
:- module B.
Ann:person.
@{q1} ?- ?X:person@A. // returns John and Ann
@{q1,options[ignoreImports]} ?- ?X:person@A. // returns only John
Working with null values
If a property is not set in ObjectLogic, it is just not there, i.e. querying for the property value returns no result.
Under some circumstances, it is useful to get null values in these cases instead. In this case you can use the query option "fillNull".
Assume you have following facts
John[name->"John"].
Then
@{q1} ?- John[age->?X]. // no results
@{q1,options[fillNull]} ?- John[age->?X]. // returns ?X = null
Explain
This option is used to generate explanations for the query. See chapter Explanations in OntoBroker manual for details.
@{q1,options[explain]} ?- ?X::?Y.
EvaluationMethod
This is an advanced option. To change the evaluation method for a single query, you can use the "EvaluationMethod" option. It takes one argument. The values for the argument are the same as in the OntoConfig.prp.
@{q1,options[EvaluationMethod(BottomUp)]} ?- ?X::?Y.
BottomUpEvaluator
This is an advanced option. To change the bottom up evaluation method for a single query, you can use the "BottomUpEvaluator" option. It takes one argument. The values for the argument are the same as in the OntoConfig.
@{q1,options[BottmUpEvaluator(BottomUp)]} ?- ?X::?Y.