KnowRob Language

The KnowRob query language supports logic programming syntax. However, language expressions are potentially compiled by KnowRob into other formats such as mongo DB queries in order to combine different backends for query answering. KnowRob orchestrates this process through a pipeline of query steps where different steps are linked with each other by feeding groundings of one step into the input queue of the next step.

The main interface predicates for using the KnowRob query language are kb_call/2 and kb_project/2. Their first argument is a language term (such as holds/3), and their second argument is a contextual parameter used to handle scoped statements and questions.

Language terms

The binary operators ?> (querying operator) and +> (projection operator) are used to declare language terms, and how they are hooked into the querying and projection predicates respectively. Syntactically, these declarations are similar to regular Prolog rules, which, instead, use the operator :-. When such a declaration appears in a module, the code is expanded into additional clauses of the querying and projection predicates. A regular Prolog rule is also generated, but the body of the rule is replaced with a call of the querying or projection predicate with the respective term as argument.

Each call within the body of such a rule is expanded to a call of the querying or projection predicate instead where the language term argument is instantiated to the term called in the original body of the rule. So if we write, for example, is_object(OBJ) on the right-hand side of an querying rule, it is internally expanded to kb_call(is_object(OBJ),Context). In the case of a projection rule, above expression would expand to kb_project(is_object(OBJ),Context), which is also meaningful. In such a case, where querying and projection rules can be declared identical within the querying and projection operators, one can also use the operator ?+> which expands into both cases to avoid code redundancy.

Scoped questions and statements

Another aspect of these operators is that they hide the contextual argument from the declaration (above: the Context argument of predicates). This is handy for declaring context-invariant rules. However, rules may be written that retrieve or update the context hidden in the operator. This is possible through a DSL that allows to interact with the hidden context argument.

Within projection rules, context is a tuple of fact scope (also called statement scope), and configuration. The scope of the statement restricts the context in which the statement is true, for example, that some statement is true after some event has happened. The scope must be instantiated before calling the projection predicate. Statements in projection rules expand into scoped assertions. Within querying rules, on the other hand, context has an additional query scope (also called question scope). Question scopes are used to restrict the scope of considered statements to statements with overlapping scopes to the one provided. The querying rule instantiates the statement scope to some scope within which the given statement is true, if any. In case of the term expands into a conjunctive query, the statament scope is instantiated to the intersection of individual statement scopes (if the intersection is not empty).

Special scoping language terms are used to restrict the scope within a nested term. Restrictions of the scope will allways be passed through to child terms, hence the scoping is done in the outer term such as in since(holds(S,P,O),Time). As these terms are usually defined as operators, one can also write, for example, holds(S,P,O) since Time. Generally, scoping terms are nested terms where another language term is called with an updated scope. In the case of querying-rules, scoping predicates will modify the question scope, while, in the case of projection-rules, the statement scope is modified.

The following time-scoping terms are pre-defined:

TermDescription
during/2The time frame in which a statement holds
since/2The begin time of a statement being true
until/2The end time of a statement being true

Sub directories

[dir] mongolog
[dir] terms

Prolog files

__init__.pl
computable.pl  -- Computable predicates.
add_computable_predicate/2Register a computable predicate.
add_computable_property/2Register a computable property.
computables/1Register a list of comutables.
drop_computable_predicate/1Unregister all computable predicates in a module.
drop_computable_predicate/2Unregister a computable predicate.
drop_computable_property/1Unregister all computable properties in a module.
drop_computable_property/2Unregister a computable predicate.
db.pl  -- Database predicates.
drop_graph/1Deletes all triples asserted into given named graph.
get_unique_name/2Generates a unique name with given prefix.
is_unique_name/1True if Name is not the subject of any known fact.
load_json_rdf/1Load JSON-encoded triple data into the knowledge base.
load_owl/1Same as load_owl/2 with empty Options list.
load_owl/2Same as load_owl/3 with universal scope, and graph name argument as given in the options list or "user" if none is given.
load_owl/3Load RDF data from URL, and assert it into the triple DB using the scope provided and into a graph named according to the ontology.
memorize/1Store knowledge into given directory.
remember/1Restore memory previously stored into given directory.
setup_collection/2Configure the indices of a named collection.
unwatch/1Stop a previously started watch operation.
watch/3Start watching possible instantiations of variables in Goal.
watch_event/2This predicate is called by the mongo client when changes are received in a watch operation.
designator.pl  -- Implementation of entity designators.
has_designator/2Find entities denoted by some designator.
is_designator/1True for instantiated designators.
messages.pl
query.pl  -- Query aggregation.
ask/1Same as kb_call/1.
ask/2Same as kb_call/4 with empty options list and FScope as wildcard.
call_with/3Calls a goal in given backend.
is_callable_with/2True if Backend is a querying backend that can handle Goal.
kb_add_rule/2Register a rule that translates into an aggregation pipeline.
kb_call/1Same as kb_call/3 with default scope to include only facts that hold now.
kb_call/3Same as kb_call/4 with empty options list.
kb_call/4True if Statement holds within QScope.
kb_drop_rule/1Drop a previously added mongolog rule.
kb_expand/2Translate a goal into a sequence of terminal commands.
kb_project/1Same as kb_project/2 with universal scope.
kb_project/2Same as kb_project/3 with empty options list.
kb_project/3Assert that some statement is true.
kb_unproject/1Same as kb_unproject/2 with universal scope.
kb_unproject/2Same as kb_unproject/3 with empty options list.
kb_unproject/3Unproject that some statement is true.
rdf_tests.pl  -- A test environment for running tests with RDF data.
begin_rdf_tests/2Same as begin_rdf_tests/3 with empty options list.
begin_rdf_tests/3Begin unit testing code section with RDF data.
end_rdf_tests/1End unit testing code section with RDF data.
scope.pl  -- Scoping predicates.
current_scope/1The scope of facts that are currently true.
scope_intersect/3Intersect two scopes.
subscope_of/2True if scope Sup contains all facts that are contained in scope Sub.
time_scope/3
time_scope_data/2Read since/until pair of temporal scope.
universal_scope/1The scope of facts that are universally true.
wildcard_scope/1A scope that matches any fact.
subgraph.pl  -- subgraph-of relationship between RDF graphs.
add_subgraph/2Adds the subgraph-of relation between two named graphs.
get_subgraphs/2Get all subgraphs of a named graph.
get_supgraphs/2Get all super-graphs of a named graph.
load_graph_structure/0Avoid that there are any orphan graphs.