Definite Clause Deduction

Home News Older Versions Downloads Supported Platforms People Report a bug!  

 

Back to tutorials.


Tutorial Two: Queries

Once you switch to 'Solve' mode, you will be looking at a blank canvas with several buttons near the top of the screen. At the bottom of the screen is th knowledge base from the 'Create' mode and the algorithm which is selected for the search. Below is an example of what the applet will look like:


If you have not already written a knowledge base or loaded a sample one, do so now. Then, click the button marked 'Create New Query'. A new window will open, providing you with a space to type in an atom to query, and a dropdown menu allowing you to select one of the knowledge base's predicates. Below is the atom selection frame, with the list operations knowledge base loaded.


The dropdown menu listing predicates is there to assist you in creating new queries. If you pick a predicate from the list, a small window will open to help you build the atom to query. This is the frame to help you build a query for the predicate append/3.


Type the terms into the correct boxes, and click 'Ok'. The new atom should appear in the textfield in the original window. If this is the only goal you would like to query, click 'Ok'. Otherwise, you can click the button marked 'Add atom'. Then, the atom you have just built will be parsed, and where you originally saw 'No query', you will see your atom. This allows you to repeat the above process to select a larger query. If, in subsequent atoms, you reuse variable names from previous atoms, they will be set to be the same variable. For example, if I were to choose member(X,[a,b,c]) and member(X,[c,d]) as my query, the only answer would be X = c, since X is the only constant that is a member of both lists.

Once you click 'Ok', you will see a node at the top of the canvas containing your query. It is also possible to add to queries. If you click the 'Create New Query' button again, you will see a button that was not previously there, marked 'Add current query'. If you click this, the present query will be added to your new list.

Below is a simplified version of the applet, set up to query 'member(X,[a,b,c]) & member(X,[c,d])'. In the full version, you will be able to use the buttons at top of the screen instead of right-clicking on nodes to perform the desired action.

To try applying a clause to an atom, click on the node containing it. You are in query mode by default. A window will open allowing you to choose an atom and select a corresponding clause to apply. If the head of the clause successfully unifies with the atom, then a new node will appear.

The atoms of this node will consist of the previous node's remaining atoms as well as the body of the clause that was applied.

If the unification is unsuccessful, you can try a different clause. Once there are no more clauses, that path on the search tree is considered to have failed. Certain atoms do not have associate clauses or facts. Atoms with built-in predicates, for example, or negation as failure atoms, are solved in different ways.

For examples of atoms of that kind and a listing of built-in predicates, see Tutorial Five.

Once the entire query has been solved, you will see a success node shaped like a diamond. If there are no more clauses that can be tried for a particular node, a failure node labelled 'false' will appear below it. Try solving the query below. Go ahead and experiment with the right-click menus. The menus that pop up are different depending on what you click on. To reset the search tree, right-click on the canvas and click 'Reset Search'.



- Click here to begin interactive tutorial.

When querying manually, it is also possible to prune the irrelevant clauses, so that only the clauses which can unify with the atom will appear in the clause selection box. In the deduction applet, that pruning option is found under the 'Deduction Options' menu.

Click here to prune the irrelevant clauses in the applet above, and here to stop pruning.

The next tutorial has more information about querying, and gives an overview of the algorithms that can be used to automatically search for the answer.