Download pdf - arXiv
Transcript
58 CHAPTER 4. THE TOOL ResultProb is Number * Branch . Later, in a second visit to the generated tree of probabilities, we will normalize the values (because the probability of each predicate must be 1). 4.4.1 Executing the rules when solving an example There are some predefined predicates in Prolog that could affect the behavior of the calculations. For instance, the debug/0 predicate will be executed and it interacts with the same MML coding. So, since those predicates involved with debugging conflict with our purposes (their presence would increase the information and then the cost for the MML coding), we will ignore them during the execution when we are executing the evidence to find its probability. During that process of executing the rules of the program to analyze an example, we need to analyze whether each term to execute is or is not a predefined predicate (using predefined_predicate/2 from Yap Prolog). If it is, they will be discarded. Once we have discarded those predicates, the next step is to execute the others using with_output_to_chars/2, used to send the output of the execution of the goal to a string instead to current_output: executeTransparently ( debug ) : -!. executeTransparently (( spy _ ) ) : -!. [...] executeTransparently ( Term ) : copy_term ( Term , NewCopy ) , with_output_to_chars ( NewCopy , _ ) . With this technique, all these predicates are ignored and not executed during the evaluation of examples: • debug/0, nodebug/0, which switches the debugger on/off. • spy/1, nospyall, nospy/1, which set/unset spy-points on predicates. • trace/0, notrace/0, which switch on/off the debugger and also implies the same with the tracing. • leash/1, which sets leashing mode to certain value. • source/0, no_source/0: these two predicates are not for debugging, but when we analyze the program we need to ensure that we are obtaining its source. If in the middle of the code a no_source appears, the tool will have no more access to the source. To avoid this, we block that predicates also. • halt/1 and halt/0, to abort the execution of program. The schema of execution of items of clauses is shown in Figure 4.6.