This implementation needs XSB Prolog to be installed in your machine. For convenience, you might want to put the path to directory where the XSB command is found in your $PATH
environment variable. Otherwise, you have to include the path to directory where you have this implementation into XSB default search paths using predicate library_directory/1
.
This implementation consists of two stages:
- Program transformation. In this stage, your input program will be transformed into its corresponding output program that supports contextual abduction. The output program will be used in the next stage. Before you transform your input program, you can choose what mode of transformation you want to use using predicate
switch_mode/1
. There are three available modes: transformation without tabling, with tabling, and with (tabling) answer subsumption. - Abduction. In this stage, you may perform the abduction itself output program that is produced in the previous stage. Practically, you have to load the output program first, only then you can perform abduction by asking queries to the loaded program.
You can define an input program, i.e. a logic program, as your own knowledge base inside in
folder in a file called {filename}.ab
. Your input program has to satisfy following properties:
- Abducibles is specified by predicate
abds/1
whose argument is a list of abducibles along with its arity. For exampleabds([a/1, b/2, c/3])
. - To define a rule (including an integrity constraint), please use
<-
instead of:-
to denote if operator. For example, please useH <- X, Y.
instead of usingH :- X, Y.
. - Predicates comprising just fact are written separately between the
beginProlog.
andendProlog.
identifiers. Seein/4.ab
for an example. - Regular Prolog programs (those that will not be transformed) are also written separately between the
beginProlog.
andendProlog.
identifiers. Please useH :- X, Y.
instead of usingH <- X, Y.
when defining regular Prolog programs because these programs will not be transformed but will be rewritten as it is.
With regard to properties mentioned above, your input program must be written in following parts, ordered from top to bottom:
beginProlog.
andendProlog.
identifiers, and also facts and programs that need to be placed between them. This part is unnecessary when no such program in it.- Abducibles.
- Rules.
Please take a look at in
folder for examples.
-
Open a terminal in the directory where you have this implementation.
-
Invoke XSB by the command:
$ xsb
Notice that this command may vary depends on how XSB is configured in your machine. Make sure you have entered XSB prompt level (indentified by | ?-
prompt) before you proceed to the next step.
-
Type
[tabdual].
and then hit Enter to load the main program. -
Type
switch_mode(Mode).
to switch between modes. There are three available options ofMode
:n
(no tabling),t
(with tabling), ands
(with answer subsumption). -
Type
transform({filename}).
and then hit Enter to transform your input program{filename}.ab
. The output program{filename}.P
will be created inout
folder. For example, if you want to transform an input program1.ab
, you have to typetransform(1)
, and consequently a file1.P
will be created inout
folder. Remember that your input program1.ab
must be placed insidein
folder. To avoid errors in the next steps, please always perform this step even though the corresponding output program has been created. -
Type
load({filename}).
and then hit Enter to load your output program. For example, you have to typeload(1)
to load the output program created in step number4
. Make sure you have transformed the corresponding input program that you want to load, otherwise errors may occur. -
Now you may ask a query using predicate
ask/1
whose argument is the query you want to ask. If you want to retrieve the solution gradually, please useask/2
whose first argument is the query you want to ask, while the second is the solution to the query, retrieved one by one. If you want to supply abductive contexts, use predicateask/3
instead, whose second argument is a list of abductive contexts you want to supply, the first and the last arguments remain the same asask/2
. Please do not forget to use parentheses if you are asking multiple goals in the query.
Below are some examples of how you can interact with the program in XSB command prompt. These examples will use in/1.ab
as its input program.
?- [tabdual]. % compile and load the main program
?- transform(1). % transform the input program in/1.ab
?- load(1). % load the resulting output program out/1.P
?- ask(q(1)). % using ask/1
(1) [not a(1)]
yes
?- ask((q(1), q(2), q(3))). % using ask/1 with multiple goals
no
?- ask(q(1), O). % using ask/2
O = [not a(1)]; % type ';' to retrieve next goals
no
?- ask(q(1), [not a(1)], O). % using ask/3 (with non-conflicting abductive context)
O = [not a(1)];
no
?- ask(q(1), [a(1)]). % using ask/2 (with conflicting abductive context)
no