File Information

File: 05-lr/acl_arc_1_sum/cleansed_text/xml_by_section/metho/06/p06-2036_metho.xml

Size: 20,607 bytes

Last Modified: 2025-10-06 14:10:23

<?xml version="1.0" standalone="yes"?>
<Paper uid="P06-2036">
  <Title>Factoring Synchronous Grammars By Sorting</Title>
  <Section position="4" start_page="279" end_page="279" type="metho">
    <SectionTitle>
2 Synchronous CFGs and permutation
trees
</SectionTitle>
    <Paragraph position="0"> We begin by describing the synchronous CFG formalism, which is more rigorously de ned by Aho and Ullman (1972) and Satta and Peserico (2005).</Paragraph>
    <Paragraph position="1"> Let us consider strings de ned over some set of nonterminal and terminal symbols, as de ned for CFGs. We say that two such strings are synchronous if some bijective relation is given between the occurrences of the nonterminals in the two strings. A synchronous context-free grammar (SCFG) is de ned as a CFG, with the difference that it uses synchronous rules of the form [A1 -a1, A2 -a2], with A1, A2 nonterminals and a1, a2 synchronous strings. We can use production [A1 -a1, A2 -a2] to rewrite any synchronous strings [g11A1g12, g21A2g22] into the synchronous strings [g11a1g12, g21a2g22], under the condition that the indicated occurrences of A1 and A2 be related by the bijection associated with the source synchronous strings. Furthermore, the bijective relation associated with the target synchronous strings is obtained by composing the relation associated with the source synchronous strings and the relation associated with synchronous pair [a1, a2], in the most obvious way.</Paragraph>
    <Paragraph position="2"> As in standard constructions that reduce the rank of a CFG, in this paper we focus on each single synchronous rule and factorize it into synchronous rules of lower rank. If we view the bijective relation associated with a synchronous rule as a permutation, we can further reduce our factorization problem to the problem of factorizing a permutation of arity n into the composition of several permutations of arity k &lt; n. Such factorization can be represented as a tree of composed permutations, called in what follows a permutation tree. A permutation tree can be converted into a set of k-ary SCFG rules equivalent to the input rule. For example, the input rule:</Paragraph>
    <Paragraph position="4"> yields the permutation tree of Figure 1(left). Introducing a new grammar nonterminal Xi for each internal node of the tree yields an equivalent set of smaller rules:</Paragraph>
    <Paragraph position="6"> In the case of stochastic grammars, the rule corresponding to the root of the permutation tree is assigned the original rule's probability, while all other rules, associated with new grammar nonterminals, are assigned probability 1. We process each rule of an input SCFG independently, producing an equivalent grammar with the smallest possible arity.</Paragraph>
  </Section>
  <Section position="5" start_page="279" end_page="283" type="metho">
    <SectionTitle>
3 Factorization Algorithm
</SectionTitle>
    <Paragraph position="0"> In this section we specify and discuss our factorization algorithm. The algorithm takes as input a permutation de ned on the set{1,***, n}, representing a rule of some SCFG, and provides a permutation tree of arity k [?]n for that permutation, with k as small as possible.</Paragraph>
    <Paragraph position="1"> Permutation trees covering a given input permutation are unambiguous with the exception of sequences of binary rules of the same type (either inverted or straight) (Albert et al., 2003). Thus, when factorizing a permutation into a permutation  tree, it is safe to greedily reduce a subsequence into a new subtree as soon as a subsequence is found which represents a continuous span in both dimensions of the permutation matrix1 associated with the input permutation. For space reasons, we omit the proof, but emphasize that any greedy reduction turns out to be either necessary, or equivalent to the other alternatives.</Paragraph>
    <Paragraph position="2"> Any sequences of binary rules can be rearranged into a normalized form (e.g. always leftbranching) as a postprocessing step, if desired. The top-level structure of the algorithm exploits a divide-and-conquer approach, and is the same as that of the well-known mergesort algorithm (Cormen et al., 1990). We work on subsequences of the original permutation, and 'merge' neighboring subsequences into successively longer subsequences, combining two subsequences of length 2i into a subsequence of length 2i+1 until we have built one subsequence spanning the entire permutation. If each combination of subsequences can be performed in linear time, then the entire permutation can be processed in time O(n log n). As in the case of mergesort, this is an application of the so-called master theorem (Cormen et al., 1990).</Paragraph>
    <Paragraph position="3"> As the algorithm operates, we will maintain the invariant that we must have built all subtrees of the target permutation tree that are entirely within a given subsequence that has been processed. This is analogous to the invariant in mergesort that all processed subsequences are in sorted order. When we combine two subsequences, we need only build nodes in the tree that cover parts of both subsequences, but are entirely within the combined subsequence. Thus, we are looking for subtrees that span the midpoint of the combined subsequence, but have left and right boundaries within the boundaries of the combined subsequence. In what follows, this midpoint is called the split point.</Paragraph>
    <Paragraph position="4"> From this invariant, we will be guaranteed to have a complete, correct permutation tree at the end of last subsequence combination. An example of the operation of the general algorithm is shown in Figure 2. The top-level structure of the algorithm is presented in function KARIZE of Figure 3. There may be more than one reduction necessary spanning a given split point when combining two subsequences. Function MERGE in Fig1A permutation matrix is a way of representing a permutation, and is obtained by rearranging the row (or the columns) of an identity matrix, according to the permutation itself. 2 1 3 4 7 5 8 6  trees. Top row, the input permutation. Second row, after combination into sequences of length two, binary nodes have been built where possible. Third row, after combination into sequences of length four; bottom row, the entire output tree.</Paragraph>
    <Paragraph position="5"> ure 3 initializes certain data structures described below, and then checks for reductions repeatedly until no further reduction is possible. It looks rst for the smallest reduction crossing the split point of the subsequences being combined. If SCAN, described below, nds a valid reduction, it is committed by calling REDUCE. If a reduction is found, we look for further reductions crossing either the left or right boundary of the new reduction, repeating until no further reductions are possible. Because we only need to nd reductions spanning the original split point at a given combination step, this process is guaranteed to nd all reductions needed.</Paragraph>
    <Paragraph position="6"> We now turn to the problem of identifying a speci c reduction to be made across a split point, which involves identifying the reduction's left and right boundaries. Given a subsequence and candidate left and right boundaries for that subsequence, the validity of making a reduction over this span can be tested by verifying whether the span constitutes a permuted sequence, that is, a permutation of a contiguous sequence of integers. Since the starting permutation is de ned on a set {1, 2,***, n}, we have no repeated integers in our subsequences, and the above condi- null function KARIZE(pi) triangleright initialize with identity mapping</Paragraph>
    <Paragraph position="8"> MERGE(min, div, max); function MERGE(min, div, max) triangleright initialize h sort h[min..max] according to pi[i]; sort hmin[min..max] according to pi[i]; sort hmax[min..max] according to pi[i]; triangleright merging sorted list takes linear time triangleright initialize v for i-min; i[?]max; i-i + 1 do v [ h[i] ]-i; triangleright check if start of new reduced block if i = min or hmin[i]negationslash= hmin[i-1] then vmin-i; vmin[ h[i] ]-vmin; for i-max; i[?]min; i-i - 1 do triangleright check if start of new reduced block if i = max or hmax[i]negationslash= hmax[i+1] then vmax-i ; vmax[ h[i] ]-vmax; triangleright look for reductions if SCAN(div) then</Paragraph>
    <Paragraph position="10"> tical to that of mergesort. MERGE: combines two subsequences of size 2i into new subsequence of size 2i+1. REDUCE: commits reduction by updating min and max arrays.</Paragraph>
    <Paragraph position="11"> tion can be tested by scanning the span in question, nding the minimum and maximum integers in the span, and checking whether their difference is equal to the length of the span minus one. Below we call this condition the reduction test. As an example of the reduction test, consider the sub-sequence (7, 5, 8, 6), and take the last three elements, (5, 8, 6), as a candidate span. We see that 5 and 8 are the minimum and maximum integers in the corresponding span, respectively. We then compute 8[?]5 = 3, while the length of the span minus one is 2, implying that no reduction is possible. However, examining the entire subsequence, the minimum is 5 and the maximum is 8, and 8[?]5 = 3, which is the length of the span minus one. We therefore conclude that we can reduce that span by means of some permutation, that is, parse the span by means of a node in the permutation tree. This reduction constitutes the 4-ary node in the permutation tree of Figure 2.</Paragraph>
    <Paragraph position="12"> A trivial implementation of the reduction test would be to tests all combinations of left and right boundaries for the new reduction. Unfortunately, this would take time Ohm(n2) for a single subsequence combination step, whereas to achieve the overall O(n log n) complexity we need linear time for each combination step.</Paragraph>
    <Paragraph position="13"> It turns out that the boundaries of the next reduction, covering a given split point, can be computed in linear time with the technique shown in function SCAN of Figure 5. We start with left and right candidate boundaries at the two points immediately to the left and right of the split point, and then repeatedly check whether the current left and right boundaries identify a permuted sequence by applying the reduction test, and move the left and right boundaries outward as necessary, as soon as 'missing' integers are identi ed outside the current boundaries, as explained below. We will show that, as we move outward, the number of possible con gurations achieved for the positions of the left and the right boundaries is linearly bounded in the length of the combined subsequence (as opposed to quadratically bounded).</Paragraph>
    <Paragraph position="14"> In order to ef ciently implement the above idea, we will in fact maintain four boundaries for the candidate reduction, which can be visualized as the left, right, top and bottom boundaries in the permutation matrix. No explicit representation of the permutation matrix itself is constructed, as that would require quadratic time. Rather, we  7 1 4 6 3 5 8 2pi 4  tion pi (left) and within-subsequence permutation v (right) for subsequences of size four.</Paragraph>
    <Paragraph position="15"> maintain two arrays: h, which maps from vertical to horizontal positions within the current subsequence, and v which maps from horizontal to vertical positions. These arrays represent the within-subsequence permutation obtained by sorting the elements of each subsequence according to the input permutation, while keeping each element within its block, as shown in Figure 4.</Paragraph>
    <Paragraph position="16"> Within each subsequence, we alternate between scanning horizontally from left to right, possibly extending the top and bottom boundaries (Figure 5 lines 9 to 14), and scanning vertically from bottom to top, possibly extending the left and right boundaries (lines 20 to 26). Each extension is forced when, looking at the within-subsequence permutation, we nd that some element is within the current boundaries in one dimension but outside the boundaries in the other. If the distance between vertical boundaries is larger in the input permutation than in the subsequence permutation, necessary elements are missing from the current sub-sequence and no reduction is possible at this step (line 18). When all necessary elements are present in the current subsequence and no further extensions are necessary to the boundaries (line 30), we have satis ed the reduction test on the input permutation, and make a reduction.</Paragraph>
    <Paragraph position="17"> The trick used to keep the iterative scanning linear is that we skip the subsequence scanned on the previous iteration on each scan, in both the horizontal and vertical directions. Lines 13 and 25 of Figure 5 perform this skip by advancing the x and y counters past previously scanned regions. Considering the horizontal scan of lines 9 to 14, in a given iteration of the while loop, we scan only the items  between newleft and left and between right and newright. On the next iteration of the while loop, the newleft boundary has moved further to the left, 1: function SCAN (div) 2: left-[?][?]; 3: right-[?][?]; 4: newleft-div; 5: newright-div + 1 ; 6: newtop-[?][?]; 7: newbot-[?]; 8: while 1 do triangleright horizontal scan 9: for x-newleft; x[?]newright ; do 10: newtop-max(newtop, vmax[x]); 11: newbot-min(newbot, vmin[x]); triangleright skip to end of reduced block 12: x-hmax[vmin[x]] + 1; triangleright skip section scanned on last iter 13: if x = left then 14: x-right + 1; 15: right-newright; 16: left-newleft; triangleright the reduction test 17: if newtop - newbot &lt; 18: pi[h[newtop]] - pi[h[newbot]] then 19: return (0); triangleright vertical scan 20: for y-newbot; y[?]newtop ; do 21: newright22: max(newright, hmax[y]); 23: newleft-min(newleft, hmin[y]); triangleright skip to end of reduced block 24: y-vmax[hmin[y]] + 1; triangleright skip section scanned on last iter 25: if y = bot then 26: y-top + 1; 27: top-newtop; 28: bot-newbot; triangleright if no change to boundaries, reduce 29: if newright = right 30: and newleft = left then 31: return (1, left, right, bot, top);  gle reduction at split point div.</Paragraph>
    <Paragraph position="18">  while the variable left takes the previous value of newleft, ensuring that the items scanned on this iteration are distinct from those already processed. Similarly, on the right edge we scan new items, between right and newright. The same analysis applies to the vertical scan. Because each item in the permutation is scanned only once in the vertical direction and once in the horizontal direction, the entire call to SCAN takes linear time, regardless of the number of iterations of the while loop that are required.</Paragraph>
    <Paragraph position="19"> We must further show that each call to MERGE takes only linear time, despite that fact that it may involve many calls to SCAN. We accomplish this by introducing a second type of skipping in the scans, which advances past any previously reduced block in a single step. In order to skip past previous reductions, we maintain (in function REDUCE) auxiliary arrays with the minimum and maximum positions of the largest block each point has been reduced to, in both the horizontal and vertical dimensions. We use these data structures (hmin, hmax, vmin, vmax) when advancing to the next position of the scan in lines 12 and 24 of Figure 5. Because each call to SCAN skips items scanned by previous calls, each item is scanned at most twice across an entire call to MERGE, once when scanning across a new reduction's left boundary and once when scanning across the right boundary, guaranteeing that MERGE completes in linear time.</Paragraph>
  </Section>
  <Section position="6" start_page="283" end_page="444" type="metho">
    <SectionTitle>
4 An Example
</SectionTitle>
    <Paragraph position="0"> In this section we examine the operation of the algorithm on a permutation of length eight, resulting in the permutation tree of Figure 1(right).</Paragraph>
    <Paragraph position="1"> We will build up our analysis of the permutation by starting with individual items of the input permutation and building up subsequences of length 2, 4, and nally 8. In our example permutation, (7, 1, 4, 6, 3, 5, 8, 2), no reductions can be made until the nal combination step, in which one permutation of size 4 is used, and one of size 5.</Paragraph>
    <Paragraph position="2"> We begin with the input permutation along the bottom of Figure 6a. We represent the intermediate data structures h, hmin, and hmax along the vertical axis of the gure; these three arrays are all initialized to be the sequence (1, 2,***, 8).</Paragraph>
    <Paragraph position="3"> Figure 6b shows the combination of individual items into subsequences of length two. Each new subsequence of the h array is sorted according to  with input permutation pi on left and within-subsequence permutation described by v array on right. Panel (a) shows initial blocks of unit size, (b) shows combination of unit blocks into blocks of size two, and (c) size two into size four. No reductions are possible in these stages; example continued in next gure.</Paragraph>
    <Paragraph position="4">  Left and right boundaries are initialized to be adjacent to horizontal split point.</Paragraph>
    <Paragraph position="5"> Vertical scan shows left and right boundaries must be extended. Permutation of size four is reduced.</Paragraph>
    <Paragraph position="6">  Search for next reduction: left and right boundaries initialized to be adjacent to left edge of previous reduction.</Paragraph>
    <Paragraph position="7"> Vertical scan shows right boundary must be extended.</Paragraph>
    <Paragraph position="8">  Horizontal scan shows top boundary must be extended.</Paragraph>
    <Paragraph position="9"> Vertical scan shows left boundary must be extended. Permutation of size ve is reduced.</Paragraph>
    <Paragraph position="10">  left, right, top and bottom boundaries is shaded; darker shading indicates a reduction. In each scan, the span scanned in the previous panel is skipped over.  the vertical position of the dots in the corresponding columns. Thus, because pi[7] = 8 &gt; pi[8] = 2, we swap 7 and 8 in the h array. The algorithm checks whether any reductions can be made at this step by computing the difference between the integers on each side of each split point. Because none of the pairs of integers in are consecutive, no reductions are made at this step.</Paragraph>
    <Paragraph position="11"> Figure 6c shows the combination the pairs into subsequences of length four. The two split points to be examined are between the second and third position, and the sixth and seventh position. Again, no reductions are possible.</Paragraph>
    <Paragraph position="12"> Finally we combine the two subsequences of length four to complete the analysis of the entire permutation. The split point is between the fourth and fth positions of the input permutation, and in the rst horizontal scan of these two positions, we see that pi[4] = 6 and pi[5] = 3, meaning our top boundary will be 6 and our bottom boundary 3, shown in Figure 7a. Scanning vertically from position 3 to 6, we see horizontal positions 5, 3, 6, and 4, giving the minimum, 3, as the new left boundary and the maximum, 6, as the new right boundary, shown in Figure 7b. We now perform another horizontal scan starting at position 3, but then jumping directly to position 6, as horizontal positions 4 and 5 were scanned previously. After this scan, the minimum vertical position seen remains 3, and the maximum vertical position is still 6. At this point, because we have the same boundaries as on the previous scan, we can stop and verify whether the region determined by our current boundaries has the same length in the vertical and horizontal dimensions. Both dimensions have length four, meaning that we have found a subsequence that is continuous in both dimensions and can safely be reduced, as shown in Figure 6d. After making this reduction, we update the hmin array to have all 3's for the newly reduced span, and update hmax to have all sixes. We then check whether further reductions are possible covering this split point. We repeat the process of scanning horizontally and vertically in Figure 7c-f, this time skipping the span just reduced. One further reduction is possible, covering the entire input permutation, as shown in Figure 7f.</Paragraph>
  </Section>
class="xml-element"></Paper>
Download Original XML