-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.pl
230 lines (208 loc) · 8.26 KB
/
configuration.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
:-module(configuration, [explanation_connectives/1
,explanation_operators/2
,interactive_session/1
,interpretation_string/2
,interpretation_string/4
,invention_assumption/1
,interpretation_cleanup/1
,merge_interpretations/1
,named_metarule/2
,recursion_explanation/1
,variable_interpretation/1
]).
/** <module> Configuration options for metasplain library.
*/
%! explanation_connectives(?Connectives) is semidet.
%
% Connectives used to connect clauses of an invented predicate.
%
% Connectives is alist of explanation connectives, atoms of the
% form connective(C) where C is a word used to connect clauses of
% an invented predicate.
%
% Given that invented predicates are conjunctions of clauses, the
% principal connective that mostly makes sense is "or", but "and",
% and perhaps others may be desired, depending on the predicate.
%
explanation_connectives([connective(or)]).
%! explanation_operators(?Metarule,?Operators) is semidet.
%
% A list of explanation Operators for the named Metarule.
%
% Metarule is the name of a named metarule, as in
% named_metarule/2. Operators is a list of explanation operators,
% atoms of the form Precendence(Expresion) where Precedence is one
% of [prefix,infix,suffix] and Expression is a natural language
% expression used to explain the relation between predicates in a
% clause of the Metarule.
%
% Expression should be given as a Prolog atom (a constant). It may
% not include spaces. If spaces are required, the underscore '_'
% can be used in their stead.
%
explanation_operators(identity,[prefix('')]).
explanation_operators(inverse,[prefix(anti)]).
explanation_operators(chain,[infix(of)]).
explanation_operators(unchain,[infix(of),infix('')]).
explanation_operators(precon,[infix(if)]).
explanation_operators(postcon,[infix(if)]).
explanation_operators(curry_3,[prefix('')]).
explanation_operators(curry_4,[prefix('')]).
explanation_operators(curry_5,[prefix('')]).
explanation_operators(tailrec,[infix(of)]).
%! interactive_session(?Bool) is semidet.
%
% Whether to start an interactive user session or not.
%
% If Bool is true metasplain will pause and prompt the user for an
% interpretation of automatically derived explanations. If it is
% false, nothing will happen.
%
% Note well: the value of Bool is not validated in any way. If
% Bool is anything other than true or false, explanation will fail
% silently.
%
interactive_session(false).
%! interpretation_cleanup(?Operation) is semidet.
%
% Operations to perform to cleanup automatic interpretations.
%
% Currently the only known Operation is remove_underscores that
% replaces underscores in predicate symbols with spaces, to make
% them look more natural. Be advised though that this breaks
% program reconstruction.
%
% Additionally, Operation can be the atom _none_ that disables all
% cleanup operations.
%
interpretation_cleanup(none).
%interpretation_cleanup(remove_underscores).
%! interpretation_string(?Metarule,?String) is semidet.
%
% A String used to interpret a clause of a Metarule.
%
% The 2-arity version of interpretation_string is used when
% variable_interpretation(false) is set. When that is the case,
% variables in clauses' literals are excluded from the
% interpretation of a program resulting in a string resembling an
% expression in a natural language.
%
interpretation_string(identity,[the,_P,is,the,_Q]).
interpretation_string(chain,[the,_P,is,the,_Q,of,the,_R]).
interpretation_string(postcon,[a,_P,is,a,_Q,if,the,game,is,_R]).
interpretation_string(unchain,[a,_P,is,a,_Q,that,is,not,followed,by,a,_R]).
%! interpretation_string(?Metarule,?Second_Order,?First_Order,?String)
%! is semidet.
%
% A string used to interpret a clause of a metarule.
%
% The 4-arity version of interpretation_string is used when
% variable_interpretation(true) is set. When that is the case,
% variables in clauses' literals are included to the
% interpretation of a program.
%
interpretation_string(identity,[P,Q],[A,B],[A,is,the,P,of,B,if,A,is,the,Q,of,B]).
interpretation_string(chain
,[P,Q,R]
,[A,B,C]
,[A,is,the,P,of,B,if,A,is,the,Q,of,C,and,C,is,the,R,of,B]).
interpretation_string(postcon,[P,Q,R]
,[A,B]
,[A,is,the,B,of,P,if,A,is,the,Q,of,B,and,B,is,R]).
interpretation_string(unchain
,[P,Q,not,R]
,[A,B,C]
,[A,is,the,P,of,B,if,A,is,the,Q,of,C,and,C,is,not,the,R,of,B]).
%! invention_assumption(?Strength) is semidet.
%
% The Strength of assumptions about invented predicates.
%
% Strength can be one of [strong,weak]. Both refer to the
% strength of the assumptions about the naming of invented
% predicate symbols, in metasplain.
%
% Under the strong assumption metasplain will consider any legal
% Prolog atom that ends in an underscore followed by at least one
% number as an invented predicate symbol.
%
% Under the weak assumption metasplain will only consider a
% predicate symbol to be invented if its list of characters can be
% unified to the list of characters in the top-goal of the
% processed program, followed by any number of digits preceded by
% underscores.
%
% For example, the following tabulates examples of identifiers and
% their acceptance or not as invented under the strong or weak
% predicate invention assumption, given that the predicate symbol
% of the top-goal in the program is "p":
%
% | Predicate symbol | Strong assumption | Weak assumption |
% | p | not invented | not invented |
% | p_1 | invented | invented |
% | r_1 | invented | not invented |
% | p_1_2_1 | invented | invented |
% | p1 | not invented | not invented |
% | p_ | not invented | not invented |
% | p_aux | not invented | not invented |
%
% The motivation for this option is to allow processing of
% programs where the top-goal is itself an invented predicate. For
% instance, in the following example, the predicate symbol win_2
% is the symbol of the top-goal in the program:
% ==
% win_2(A,B):-win_2_1_1(A,B),not(win_2_1_1(B,C)).
% win_2_1_1(A,B):-move(A,B),not(win_1(B,C)).
% win_1(A,B):- move(A,B),won(B)).
% ==
%
% However, it is not possible to say whether win_2 is itself
% invented, and therefore, requires explanation, or not. Perhaps
% the user simply wanted to keep this program separate from a
% different one, learned (or written) earlier. Other predicate
% symbols in the program can offer some hint but nothing can be
% said with certainty.
%
% Therefore, an assumption must be made about the structure of
% invented predicate symbols, in order to proceed with
% explanation. Under the strong assumption win_2 will be
% considered to be an invented predicate and metasplain will try
% to explain it, as well as win_2_1_1 and win_1, even though
% win_1 does not match the start of the top-goal, win_2. Under the
% weak assumption, metasplain will consider win_2 as not invented
% and will only attempt to explain win_2_1_1, but not win_1,
% because its start doesn't match of win_2.
%
invention_assumption(weak).
%! merge_interpretations(?Bool) is semidet.
%
% Whether clause explanations should be merged.
%
merge_interpretations(true).
%! named_metarule(?Name,?Metarule) is semidet.
%
% A named metarule in Metagol syntax.
%
named_metarule(identity,metarule([P,Q],([P,A,B]:-[[Q,A,B]]))).
named_metarule(inverse,metarule([P,Q],([P,A,B]:-[[Q,B,A]]))).
named_metarule(chain,metarule([P,Q,R],([P,A,B]:-[[Q,A,C],[R,C,B]]))).
named_metarule(unchain,metarule([P,Q,not,R],([P,A,B]:-[[Q,A,B],[not,[R,B,_C]]]))).
named_metarule(precon,metarule([P,Q,R],([P,A,B]:-[[Q,A],[R,B]]))).
named_metarule(postcon,metarule([P,Q,R],([P,A,B]:-[[Q,A,B],[R,B]]))).
named_metarule(curry_3,metarule([P,Q,R],([P,A,B]:-[[Q,A,B,R]]))).
named_metarule(curry_4,metarule([P,Q,R,S],([P,A,B]:-[[Q,A,B,R,S]]))).
named_metarule(curry_5,metarule([P,Q,R,S,T],([P,A,B]:-[[Q,A,B,R,S,T]]))).
named_metarule(tailrec,metarule([P,Q,P],([P,A,B]:-[[Q,A,C],[P,C,B]]))).
%! recursion_explanation(?String) is semidet.
%
% Explanation String for recursive literals.
%
% The symbol of a recursive literal, i.e. one with the same symbol
% as the head literal in a clause, will be renamed to the given
% String during clause explanation.
%
recursion_explanation(this).
%! variable_interpretation(?Bool) is semidet.
%
% Whether to include variables to an automatic interpretation.
%
variable_interpretation(false).