Chart Parsing and Constraint Programming Frank Morawietz Seminar f¨ur Sprachwissenschaft Universit¨at T¨ubingen Wilhelmstr. 113 72074 T¨ubingen, Germany [email protected] Abstract yet another language. The approach allows for a rapid In this paper, parsing-as-deduction and constraint pro- and very flexible but at the same time uniform method gramming are brought together to outline a procedure for of implementation of all kinds of parsing algorithms (for the specification of constraint-based chart parsers. Fol- constraint-based theories). The goal is not necessarily to lowing the proposal in Shieber et al. (1995), we show build the fastest parser, but rather to build – for an ar- how to directly realize the inference rules for deductive bitrary algorithm – a parser fast and perspicuously. For parsers as Constraint Handling Rules (Fr¨uhwirth, 1998) example, the advantage of our approach compared to the by viewing the items of a chart parser as constraints and one proposed in Shieber et al. (1995) is that we do not the constraint base as a chart. This allows the direct use have to design a special deduction engine and we do not of constraint resolution to parse sentences. have to handle chart and agenda explicitly. Furthermore, the process can be used in any constraint-based formal- 1 Introduction ism which allows for constraint propagation and there- fore can be easily integrated into existing applications. The parsing-as-deduction approach proposed in Pereira The paper proceeds by reviewing the parsing-as- and Warren (1983) and extended in Shieber et al. (1995) deduction approach and a particular way of imple- and the parsing schemata defined in Sikkel (1997) are menting constraint systems, Constraint Handling Rules well established parsing paradigms in computational lin- (CHR) as presented in Fr¨uhwirth (1998). Then it shows guistics. Their main strengths are their flexibility and how to implement several parsing algorithms very natu- the level of abstraction concerning control information rally with constraint propagation rules before concluding inherent in parsing algorithms. Furthermore, they are with an outlook on how to extend the technique to more easily extensible to more complex formalisms, e.g., aug- advanced applications. mented phrase structure rules or the ID/LP format. Constraint Programming (CP) has been used in com- 1.1 Parsing as Deduction putational linguistics in several areas, for example in Although I assume some familiarity with parsing-as- (typed) feature-based systems (Smolka, 1995), or condi- deduction, I will recall some basic definitions for con- tional constraints (Matiasek, 1994), or advanced compi- venience. The notations and the three basic algorithms lation techniques (G¨otz and Meurers, 1997) or special- are directly taken from Shieber et al. (1995). ized constraint solvers (Manandhar, 1994). But none As usual, strings w result from concatenation of sym- Σ Σ£ of these approaches uses constraint programming tech- bols from some alphabet set , i.e., w ¾ . We refer niques to implement standard chart parsing algorithms to the decomposition of such a string into its alphabet directly in a constraint system. symbols with indices. We fix this notation using w = ; ¾ Æ In this paper, I will bring these two paradigms to- w1 ::: wn. Further notational conventions are: i j , n ; ;::: gether by showing how to implement algorithms from for the length of the string to be parsed, A ; B C for ; ;::: the parsing-as-deduction scheme by viewing the parsing arbitrary formulas or nonterminals, a ; b c for termi- β ; γ;::: process as constraint propagation. nals, ε for the empty string and α; for strings of The core idea is that the items of a conventional chart terminals and nonterminals. Formulas used in parsing parser are constraints on labeled links between the words will also be called items or edges. A grammatical deduc- and positions of an input string. Then the inference rules tion system or, in Sikkel’s terminology a parsing schema, allow for the deduction of new constraints, again labeled is defined as a set of deduction schemes and a set of ax- and spanning parts of the input string, via constraint ioms. These are given with the help of formula schemata propagation. The resulting constraint store represents the which contain (syntactic) meta-variables which are in- chart which can be accessed to determine whether the stantiated with concrete terms on application of the rules. parse was successful or to reconstruct a parse tree. A deduction scheme R has the general form While this may seem a trivial observation, it is not A1 ::: An ::: ; i h side conditions on A A C just another way of implementing deductive parsing in C 1 n Table 1: Parsing algorithms as Grammatical Deduction Systems Bottom-Up Top-Down Earley ; α ¯ ] [ ; ¯ β ] [ ; ; ; α ¯ β ] Items [ j j i j A ¼ ; ¯ ] [ ; ¯ ] [ ; ; ; ¯ ] Axiom [0 0 S 0 0 S S ¼ ; ¯ ] [ ; ¯ ] [ ; ; ; ¯ ] Goal [n S n 0 n S S [ ; ¯ β ] [ ; ; ; α ¯ β ] [ ; α ¯ ] · j j w · i j A w Scan j 1 j 1 [ · ; α ¯ ] [ · ; ¯ β ] [ ; · ; ; α ¯ β ] · j 1 w j ·1 j 1 i j 1 A w j 1 ; ¯ β ] [ ; ; ; α ¯ β ] [ j B i j A B ! γi h ! γi Predict hB B ; ¯ γβ ] [ ; ; ; ¯ γ] [ j j j B ; αγ ¯ ] [ ; ; ; α ¯ β ] [ ; ; ; γ ¯ ] [ j i k A B k j B ! γi Complete hB ; α ¯ ] [ ; ; ; α ¯ β ] [ j B i j A B ! ! where the Ai and C are formula schemata. The Ai are S NP VP V hit ! j ! called antecedents and C the consequence. Note that de- VP VNP VNPPP PN John duction schemes may refer to string positions, i.e., the ! ! j PP PNP N dog stick indices within the input string, in their side conditions. ! j ! NP PN Det N1 P with Application of these schemata and derivations of formu- ! j ! las are then defined as in the Shieber et al. article. In- N1 N N1 PP Det the tuitively, parsing uses the deductive rules – if their an- tecedents and the side conditions are met – to infer new Figure 1: Example Grammar: PP-attachment items from the axioms and already generated items until no new ones can be derived. The parse was successful if maintain a constraint base or store which is continually a goal item was derived. monitored for possible rule applications, i.e., whether Therefore, all the parsing systems used in this paper there is enough information present to successfully use a are defined by specifying a class of items, a set of ax- rule to simplify constraints or to derive new constraints. ioms, a set of inference rules and a subset of the items, Whereas usually one deals with a fixed constraint domain the goals. For better readability, I follow Shieber et al. in and a specialized solver, CHR is an extension of the Pro- using the familiar dotted items for the presentation. The log language which allows for the specification of user- three classical example algorithms we will use to illus- defined constraints and arbitrary solvers. The strength of trate our technique are given in Tab. 1. I assume famil- the CHR approach lies in the fact that it allows for mul- iarity with these algorithms. tiple (conjunctively interpreted) heads in rules, that it is Unless specified differently, we assume that we are flexible and that it is tightly and transparently integrated into the Prolog engine. h ; Σ; ; i given a context-free grammar G = N S P with non- terminals N,terminalsΣ, start symbol S and set of pro- In CHR constraints are just distinguished sets of ductions P. For Earley’s algorithm we also assume a new (atomic) formulas. CHR allow the definition of rule sets start symbol S ¼ which is not in N. Each production is of for constraint solving with three types of rules: Firstly <=> £ simplification rules ( ) which replace a number of ! α ¾ ; α ¾ ´ [ Σµ the form A with A N N . For examples I will use the simple PP-attachment grammar G given in constraints in the store with new constraints; secondly > Fig. 1 with the obvious sets of nonterminals and termi- propagation rules ( == ) which add new constraints nals, the start symbol S and productions P. Itisleftto to the store in case a number of constraints is already => the reader to calculate example derivations for the three present; and thirdly “simpagation” rules ( < in com- algorithms for a sentence such as John hit the dog with bination with a Ò in the head of the rule) which replace the stick. only those constraints with new ones which are to the right of the backslash. Rules can have guards. A guard 1.2 Constraint Handling Rules (separated from the rest of the body by a j ) is a condition There are several constraint programming environments which has to be met before the rule can be applied. available. The most recent and maybe the most flexible is We cannot go into the details of the formal seman- the Constraint Handling Rules (CHR) package included tics of CHR here. The interested reader is referred to in SICStus Prolog (Fr¨uhwirth, 1998). These systems Fr¨uhwirth (1998). Since I will refer back to it let us just note that logically, simplification rules are equivalences parse(InList):- and propagation rules are implications if their guard is axiom, satisfied. Simpagation rules are special cases of simpli- post_const(InList, 0, Length), fication rules. Soundness and completeness results for report(Length). CHR are available (Abdennadher et al., 1996 Abdennad- her, 1998). post_const([], Len, Len). post_const([Word|Str], InLen, Len):- 2 Parsing as Constraint Propagation findall(Cat, lex(Word,Cat), Cats), post_words(Cats, InLen, Word), The basic observation which turns parsing-as-deduction NewLen is InLen + 1, into constraint propagation is simple: items of a chart post_const(Str, NewLen, Len).
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages7 Page
-
File Size-