Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
doc:defining_computables [2013/04/22 08:39] – created admin | doc:defining_computables [2014/11/26 20:57] – [Prolog computables] admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Define computables ====== | ====== Define computables ====== | ||
~~NOTOC~~ | ~~NOTOC~~ | ||
- | Computables serve for // | + | \\ |
+ | ^ This page describes the ' | ||
+ | \\ | ||
+ | |||
+ | Computables serve for // | ||
* computable classes, which create instances of their target class, and | * computable classes, which create instances of their target class, and | ||
* computable properties, which compute relations between instances. | * computable properties, which compute relations between instances. | ||
- | For each of them, two techniques are supported: | ||
- | * SQL computables, | ||
- | * Prolog computables, | ||
- | |||
- | Some general remarks: | ||
- | * Computables should be defined in their own module; the computables for temporal relations (before, after, during etc), for example, are defined in the module comp_temporal. This helps to resolve conflicts if there are different computables for a relation (e.g. one observes and another one predicts a relation). | ||
- | * The &bla; identifiers are XML entities that are replaced with the string specified at the beginning of the file when the file is being loaded. They are useful for making the code a bit shorter and more readable, and also for ensuring consistency. | ||
- | We will explain the two techniques (SQL and Prolog) for computable properties, while computable classes work in a rather similar way and will only briefly be described. | ||
===== General concept ===== | ===== General concept ===== | ||
Line 18: | Line 14: | ||
For computable properties to work, the following things need to be defined: | For computable properties to work, the following things need to be defined: | ||
- | * the property to be computed, including its domain and range (datatype, object | + | * The property to be computed, including its domain and range (datatype |
- | * an instance of ComputableProperty that has this property as its target | + | * A Prolog predicate |
- | * either a set of SQL queries or a Prolog predicate that is accessible | + | * An instance of ComputableProperty that has the property to be computed as its //target//. |
- | For including computable relations into the reasoning process, use rdf_triple(P, | + | For including |
- | < | + | < |
| | ||
| | ||
| | ||
- | | + | |
- | ; rdfs_computable_compute_property_concatenation(SubProperty, | + | |
; catch( rdfs_computable_triple(SubProperty, | ; catch( rdfs_computable_triple(SubProperty, | ||
; user: | ; user: | ||
). | ). | ||
</ | </ | ||
- | rdf_triple first searches for sub-properties of the current property, and for each of them, calls first rdf_has for reading information asserted in the knowledge base directly, then tries to find property concatenations (currently unused), | + | The //rdf_triple// predicate combines the results of different inference methods: It first searches for sub-properties of the current property, and for each of them, first calls //rdf_has// for reading information asserted in the knowledge base directly, then calls all computable triples |
- | rdfs_computable_triple handles caching issues and calls rdfs_computable_triple_1, which simply looks for and executes computables for SQL and Prolog. | + | |
- | < | + | |
- | rdfs_computable_triple_1(Property, | + | ===== Prolog computables ===== |
- | catch(rdfs_computable_sql_triple(Property, | + | Prolog computables computes an OWL relation by evaluating a binary Prolog predicate. |
- | ; catch(rdfs_computable_prolog_triple(Property, | + | |
+ | |||
+ | |||
+ | ==== Prolog properties ==== | ||
+ | |||
+ | For Prolog properties, we will have a look at the knowrob: | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
</ | </ | ||
- | The whole code for managing the computables is contained in rdfs_computable.pl in the module semweb. | ||
- | ===== Caveats ===== | + | Then, the property is linked to the Prolog predicate // |
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | [...] | ||
+ | </ | ||
+ | </ | ||
- | When something does not work, check the following. Most likely, there is a minor inconsistency in the OWL names that makes the whole process break. | + | Note that the target |
- | * is the right property being computed? knowrob: | + | < |
- | * is there a typo anywhere in the namespaces or base URLs? | + | % after(TimePoint, TimePoint) |
- | * check if there is a hash sign # between the URL and the property name (if using XML entities, check if the hash is either part of the entity | + | comp_after(Pre, After) :- |
- | * debug with the following calls and step through | + | rdf_has(Pre, |
- | < | + | rdf_has(After, rdf:type, knowrob:' |
- | guitracer, spy(yourpredicate), rdf_triple(knowrob:pred, Subj, Obj). for Prolog computables | + | |
- | guitracer, spy(rdfs_computable_sql_triple), rdf_triple(knowrob: | + | term_to_atom(A, After), |
+ | P<A. | ||
</ | </ | ||
- | ===== SQL properties ===== | + | This predicate first checks if the subject and property have the correct types, then transforms the time points into numerical values using // |
+ | * Prolog computables can do more than comparing values: Using the Java interface JPL, we included the ehow.com plan import as a Prolog computable datatype property which links Strings like "set a table" to plan specifications in OWL. The same technique was used to interface Prolog to ROS and read object poses. Rule knowledge (for unary or binary predicates) can be encoded in Prolog computables if the body of the rule is checked inside the computable. | ||
+ | * When trying to use rdf_assert inside a Prolog computable, you are likely to get an error " | ||
+ | |||
+ | ==== Prolog classes | ||
+ | |||
+ | The definition of computable prolog classes is similar to Prolog | ||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== SQL computables ===== | ||
+ | SQL computables, | ||
+ | |||
+ | |||
+ | ==== SQL properties | ||
As mentioned before, the first step is to define the target to be computed. In this example, which can be found in ias_gram_human.owl, | As mentioned before, the first step is to define the target to be computed. In this example, which can be found in ias_gram_human.owl, | ||
Line 97: | Line 131: | ||
</ | </ | ||
- | ===== Prolog properties ===== | + | ==== SQL classes ==== |
- | + | ||
- | For Prolog properties, we will have a look at the knowrob: | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | Then, the computable that is attached to this property needs to be specified: | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | Note that the target is described as in SQL properties, but instead of covering the different cases of bound/free variables with different SQL queries, we only specify one Prolog predicate (comp_after) that is supposed to handle them correctly. comp_after needs to be specified somewhere where it is available once knowrob.owl is loaded, which, in our case, is the gram_base.pl. | + | |
- | < | + | |
- | % after(TimePoint, | + | |
- | comp_after(Pre, | + | |
- | rdf_has(Pre, | + | |
- | rdf_has(After, | + | |
- | term_to_atom(P, | + | |
- | term_to_atom(A, | + | |
- | P<A. | + | |
- | </ | + | |
- | + | ||
- | This predicate first checks if the subject and property have the correct types, then transforms the time points into numerical values using term_to_atom, | + | |
- | * Prolog computables can do much more than just compare values: Using the Java interface JPL, we included the ehow.com plan import as a Prolog computable datatype property which links Strings like "set a table" to plan specifications in OWL. The same technique was used to interface Prolog to ROS and read object poses from the jlo service. Rule knowledge (for unary or binary predicates) can be encoded in Prolog computables, | + | |
- | * When trying to use rdf_assert inside a Prolog computable, you are likely to get an error " | + | |
- | + | ||
- | ===== SQL classes | + | |
The definition of computable SQL classes is rather similar to properties and will only be shortly explained. Obviously, the target class has to exist for the method to work. computeReaching reads human motion frames labeled as ' | The definition of computable SQL classes is rather similar to properties and will only be shortly explained. Obviously, the target class has to exist for the method to work. computeReaching reads human motion frames labeled as ' | ||
Line 154: | Line 152: | ||
Here, we do not have the frame/value scheme, but rather one command for creating instances (command) and one for checking if an instance belongs to the respective class (testCommand). | Here, we do not have the frame/value scheme, but rather one command for creating instances (command) and one for checking if an instance belongs to the respective class (testCommand). | ||
- | ===== Prolog classes ===== | ||
- | The definition of computable prolog classes is similar to the preceding ones, you simply need to describe | + | ===== Debugging ===== |
+ | |||
+ | When something does not work, check the following. Most likely, there is a minor inconsistency in the OWL names that makes the whole process break. | ||
+ | * is the right property being computed? knowrob:objectActedOn is something else than ias: | ||
+ | * is there a typo anywhere in the namespaces or base URLs? | ||
+ | * check if there is a hash sign # between the URL and the property name (if using XML entities, check if the hash is either | ||
+ | * debug with the following calls and step through to check that the right computable is being found, that the right query is sent, or that your predicate performs the right computations. | ||
< | < | ||
- | < | + | |
- | < | + | guitracer, spy(rdfs_computable_sql_triple), |
- | < | + | |
- | < | + | |
- | < | + | |
- | </ | + | |
</ | </ | ||
+ | |||
+ | |||
+ | Some general remarks: | ||
+ | * Computables should be defined in their own module; the computables for temporal relations (before, after, during etc), for example, are defined in the module // | ||
+ | * The &bla; identifiers are XML entities that are replaced with the string specified at the beginning of the file when the file is being loaded. They are useful for making the code a bit shorter and more readable, and also for ensuring consistency. | ||
+ | |||
+ |