• Keine Ergebnisse gefunden

In this section, we discuss the implementation of the deduction systems for the various goal types. The Prolog code of the core of the deduction engine is given in appendix C.

GeLD includes the bottom-up Earley deduction described in chapter 3. In addition, it provides interpreters for a top-down Prolog proof strategy, top-down Earley deduction and for a head-driven strategy, as well the the option to pass calls directly to the underlying Prolog system for more efficient execution or for side effects.

Each goal can be annotated with one of the following goal types (in addition to the goal types i and m that are dealt with by the partial deduction system) which are described in section 5.3.1 on control information (cf. figure 5.8, page 174).

c chart-based proof (Bottom-Up Earley Deduction) d top-down search (Prolog search strategy

e top-down Earley Deduction

h head-driven search (head-driven strategy) p Prolog call

w waiting goal

The deduction system is completely modular so that other deduction algo-rithms (e.g. LR strategies) can be added as needed.

Unlike Prolog, the order of clauses in the source file does not determine the order in which clauses are executed.9 This is due to the fact that we are do not want to provide a procedural programming language, but a deduction system that enumerates all solutions to a given query. The instrument for controlling the order of execution are the preference values given to clauses.

In Prolog clauses, the order is of course respected — their execution should (apart from the effects of partial deduction) be no different than it would be if they had been consulted directly by Prolog.

9In reality, the order of clauses happens to be respected with the exception that facts are always looked up first before more complex deduction procedures are attempted for proving a goal.

5.4.1 Top-down processing

D-goals are executed in the same fashion as Prolog p-goals: top-down, left-to-right, backtracking. The following is the inference step that is used in the pro-cessing ofdgoals. σis the merged constraint (the unifying substitution) ofB and B0.

A←B∧Γ B0σ(A←Γ)

The reason why d-goals are used instead of p-goals is that a d-goal may be defined by a clause whose body contains goals of another goal type. If something is called as ap-goal, control is passed to Prolog entirely. An example for a predicate which should be called as ad-goal is the following top-level predicate parse/0, which reads a string to be parsed, and then uses the grammatical specification (the predicatesentence/2) to parse the sentence using head-driven methods.

parse

<-p read_string(String),

u sentence(String,Structure), p pretty_print(Structure).

Alternatively, this clause can be specified as follows.10 parse

:-read_string(String),

u sentence(String,Structure), pretty_print(Structure).

This will be compiled into the following Prolog clause (where prove/2 is a predicate which calls the deduction system with a goal type and a goal).

parse

:-read_string(String),

prove(u,sentence(String,Structure)), pretty_print(Structure).

10At the present stage of the implementation, there is no absolute necessity ford-goals since they could always be replaced byp-goals. However, we keep them in the implementation to keep the system extensible.

5.4.2 Head-Driven Processing

Head-driven processing is appropriate if only one base case is sufficient to start the bottom-up process. In head-driven processing, as soon as some predicate P has been proven or put into the bottom-up process as the base case of a recursion, the system looks for a clauseC which starts with aw-goal which unifies withP.

Then the remaining goals of the clauseC are proven, and the head of the clause again looks for aw-goal that waits for it. This is continued until a solution to the h-goal has been found.

The following is the inference rule that is used in head-driven processing. Dur-ing the processDur-ing, Ais either entered as a base case or has been derived by the inference rules, and A0 is a waiting goal. σ is the merged constraint (unifying substitution) ofAandA0.

A B←A0 Γ

σ(B Γ) (5.14)

As soon as ah-goalGis called, the system looks for an instance of thelookup/3 relation, which specifies the base case with which a head-driven proof of a goal can be started. The goalB returned as the second argument the relationlookup/3is proven according to the goal type returned as the third argument. The goal type can be ad-goal, which is defined by a clause containing ah-goal, in which case a head-driven proof is executed for finding the base case from which the head-driven process can be started (in the case of semantic-head driven processing, this can be a non-lexical non-chain rule).

The goalBthat has been looked up and proven serves as input to the bottom-up proof procedure. IfBunifies with the original goalG, then the proof is finished.

Otherwise, the system looks for a clauseCthat needsBas its first goal (a waiting goal). Then the remaining goals ofCare proven according to their goal types. The consequent of the clause then serves as the next input to the bottom-up process.

Note that there is no inference rule for base case lookup because there is no inference involved in base case lookup. Base case lookup only instantiates known (or provable) facts as a in the inference rule, but it does not produce any new conclusions.

5.4.3 Chart-Based Algorithms

Two chart-based algorithms (top-down Earley deduction and bottom-up Earley deduction) are implemented in the GeLD system. These two algorithms share all the basic procedures for managing the agenda, combination of active and passive items, and for the representation of items. They only differ in their rule invocation strategy (prediction in the top-down case and lookup of a set of initial items in the bottom-up case).

In general, there can be more than one chart active at the same time. This is the case if several independent goals are proved as c-goals or e-goals. The items of the different charts are stored in different databases, so that an active item of one chart cannot be combined with a passive item of another chart.

5.4.3.1 Earley Deduction

This component implements top-down Earley deduction for logic programs. Top-down Earley deduction makes use of prediction and a subsumption check. When goals other thane-goals occur, these are handled by the appropriate proof proce-dure.

Like the bottom-up Earley deduction procedure described in chapter 3, top-down Earley deduction makes use of indexing and allows other goal types than e-goals. Therefore, in figure 5.12, we extend the algorithm given in chapter 1 (figure 1.7) to handle indexing and other goal types.

5.4.3.2 Bottom-Up Earley Deduction

This component is a faithful implementation of the bottom-up Earley deduction algorithm (figure 3.7 described in chapter 3, with best-first search based on pref-erence values (cf. section 4.1).

For bottom-up Earley deduction, all non-unit clauses of the program which start with waiting goals are assumed to be present as active items. In order to increase efficiency, these are detected at compile time, and represented in such a way as to make optimal use of Prolog’s first-argument indexing for most efficient lookup.

Bottom-up Earley deduction involves a lookup step which relies on the user-defined relationlookup/4.

5.4.4 Prolog Call

P goals are executed directly by Prolog. This may be done either for efficiency reasons, or to call other system components implemented in Prolog (e.g., know-ledge processing), or for side effects (e.g., reading and pretty-printing as in the above example.)

5.5 Best-First Search

Best-first search based on preferences is implemented for bottom-up and top-down Earley deduction. The agenda is represented as a list of items which is ordered according to the priority of the items.

In the current stage of the implementation, the priority of each item is simply the upper bound of its preference value. If two items on the agenda have the same

procedureprove(Goal):

– predict(Goal) – consume-agenda – for any item hG,Ii

– return mgu(Goal,G) as solution if it exists procedureadd itemI to agenda

– compute the priority ofI

– if there is no itemI0 in the chart or the agenda such thatI0 subsumes I then agenda:=agenda∪ {I}

else agenda:=agenda procedureconsume-agenda – while agenda is not empty

– remove itemI with highest priority from agenda – add itemI to chart

procedurepredict G – for all rulesC=G0Γ

– ifσ=mgu(G, G0)exists then create indexI forσ(C) add itemhσ(G0 Γ),Ii

procedureadd itemhC, I1ito chart – chart := chart ∪ {hC, I1i}

– ifCis a unit clause

– for all itemshH ←G∧ΞΩ, I2i – ifI=I2? I1 exists

and σ=mgu(C, G)exists

and goalsΞare provable with solutionτ then add item hτ σ(H Ω), Iito agenda – ifC=H ←G∧ΞΩis a non-unit clause

– for all itemshG0←, I2i – ifI=I1? I2 exists

and σ=mgu(G, G0)exists

and goalsΞare provable with solutionτ then add item hτ σ(H Ω), Iito agenda – predictG

Figure 5.12: Algorithm for best-first Earley deduction with indexing and different goal types

priority, the newer one is preferred. As a consequence, depth-first search results if all items on the agenda have the same priority.