{ "paper_id": "P96-1015", "header": { "generated_with": "S2ORC 1.0.0", "date_generated": "2023-01-19T09:02:51.269404Z" }, "title": "Directed Replacement", "authors": [ { "first": "Lauri", "middle": [], "last": "Karttunen", "suffix": "", "affiliation": { "laboratory": "Rank Xerox Research Centre Grenoble 6", "institution": "chemin de Maupertuis", "location": { "postCode": "F-38240", "settlement": "MEYLAN~", "country": "FRANCE" } }, "email": "karttunen@xerox@fr" } ], "year": "", "venue": null, "identifiers": {}, "abstract": "This paper introduces to the finite-state calculus a family of directed replace operators. In contrast to the simple replace expression, UPPER-> LOWER, defined in Karttunen (1995), the new directed version, UPPER \u00a9-> LOWER, yields an unambiguous transducer if the lower language consists of a single string. It transduces the input string from left to right, making only the longest possible replacement at each point. A new type of replacement expression, UPPER @-> PREFIX ... SUFFIX, yields a transducer that inserts text around strings that are instances of UPPER. The symbol ... denotes the matching part of the input which itself remains unchanged. PREFIX and SUFFIX are regular expressions describing the insertions. Expressions of the type UPPER @-> PI~EFIX \u2022.. SUFFIX may be used to compose a deterministic parser for a \"local grammar\" in the sense of Gross (1989). Other useful applications of directed replacement include tokenization and filtering of text streams.", "pdf_parse": { "paper_id": "P96-1015", "_pdf_hash": "", "abstract": [ { "text": "This paper introduces to the finite-state calculus a family of directed replace operators. In contrast to the simple replace expression, UPPER-> LOWER, defined in Karttunen (1995), the new directed version, UPPER \u00a9-> LOWER, yields an unambiguous transducer if the lower language consists of a single string. It transduces the input string from left to right, making only the longest possible replacement at each point. A new type of replacement expression, UPPER @-> PREFIX ... SUFFIX, yields a transducer that inserts text around strings that are instances of UPPER. The symbol ... denotes the matching part of the input which itself remains unchanged. PREFIX and SUFFIX are regular expressions describing the insertions. Expressions of the type UPPER @-> PI~EFIX \u2022.. SUFFIX may be used to compose a deterministic parser for a \"local grammar\" in the sense of Gross (1989). Other useful applications of directed replacement include tokenization and filtering of text streams.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Abstract", "sec_num": null } ], "body_text": [ { "text": "Transducers compiled from simple replace expressions UPPER -> LOWER (Karttunen 1995, Kempe and Karttunen 1996) are generally nondeterministic in the sense that they may yield multiple results even if the lower language consists of a single string. For example, let us consider the transducer in The application of this transducer to the input \"aba\" produces four alternate results, \"axa\", \"ax\", \"xa\", and \"x\", as shown in Figure 1 , since there are four paths in the network that contain \"aba\" on the upper side with different strings on the lower side.", "cite_spans": [ { "start": 68, "end": 94, "text": "(Karttunen 1995, Kempe and", "ref_id": null }, { "start": 95, "end": 110, "text": "Karttunen 1996)", "ref_id": "BIBREF8" } ], "ref_spans": [ { "start": 422, "end": 430, "text": "Figure 1", "ref_id": "FIGREF1" } ], "eq_spans": [], "section": "Introduction", "sec_num": "1" }, { "text": "This nondeterminism arises in two ways. First of all, a replacement can start at any point. Thus we get different results for the \"aba\" depending on whether we start at the beginning of the string or in the middle at the \"b\". Secondly, there may be alternative replacements with the same starting point. In the beginning of \"aba\", we can replace either \"ab\" or \"aba\". Starting in the middle, we can replace either \"b\" or \"ba\". The underlining in Figure 2 shows aba aba aba aba a X a a X X a X Figure 2 : Four factorizations of \"aba\".", "cite_spans": [], "ref_spans": [ { "start": 446, "end": 454, "text": "Figure 2", "ref_id": null }, { "start": 493, "end": 501, "text": "Figure 2", "ref_id": null } ], "eq_spans": [], "section": "Introduction", "sec_num": "1" }, { "text": "the four alternate factorizations of the input string, that is, the four alternate ways to partition the string \"aba\" with respect to the upper language of the replacement expression. The corresponding paths in the transducer are listed in Figure 1 . For many applications, it is useful to define an-other version of replacement that produces a unique outcome whenever the lower language of the relation consists of a single string. To limit the number of alternative results to one in such cases, we must impose a unique factorization on every input. The desired effect can be obtained by constraining the directionality and the length of the replacement. Directionality means that the replacement sites in the input string are selected starting from the left or from the right, not allowing any overlaps. The length constraint forces us always to choose the longest or the shortest replacement whenever there are multiple candidate strings starting at a given location. We use the term directed replacement to describe a replacement relation that is constrained by directionality and length of match. (See the end of Section 2 for a discussion about the choice of the term.)", "cite_spans": [], "ref_spans": [ { "start": 240, "end": 248, "text": "Figure 1", "ref_id": "FIGREF1" } ], "eq_spans": [], "section": "Introduction", "sec_num": "1" }, { "text": "With these two kinds of constraints we can define four types of directed replacement, listed in Figure 3 . For reasons of space, we discuss here only the leftto-right, longest-match version. The other cases are similar.", "cite_spans": [], "ref_spans": [ { "start": 96, "end": 105, "text": "Figure 3", "ref_id": "FIGREF2" } ], "eq_spans": [], "section": "Introduction", "sec_num": "1" }, { "text": "The effect of the directionality and length constraints is that some possible replacements are ignored. For example, a b I b I b a [ a b a @-> x maps \"aba\" uniquely into \"x\", Because we must start from the left and have to choose the longest match, \"aba\" must be replaced, ignoring the possible replacements for \"b\", \"ba\", and \"ab\". The \u00a9-> operator allows only the last factorization of \"aba\" in Figure 2 .", "cite_spans": [], "ref_spans": [ { "start": 397, "end": 405, "text": "Figure 2", "ref_id": null } ], "eq_spans": [], "section": "Introduction", "sec_num": "1" }, { "text": "Left-to-right, longest-match replacement can be thought of as a pr.ocedure that rewrites an input string sequentially from left to right. It copies the input until it finds an instance of UPPER. At that point it selects the longest matching substring, which is rewritten as LOWER, and proceeds from the end of that substring without considering any other alternatives. Figure 5 illustrates the idea.", "cite_spans": [], "ref_spans": [ { "start": 369, "end": 377, "text": "Figure 5", "ref_id": null } ], "eq_spans": [], "section": "Introduction", "sec_num": "1" }, { "text": "Scan Scan", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Scan", "sec_num": null }, { "text": ".... ~ r . . . . I r - ----~\" i Copy ' Replace I Copy ' Replace' ~[ ~I Copy ~ .~ ' f Longest Longest Match Match Figure 5: Left-to-right, longest-match replacement", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Scan", "sec_num": null }, { "text": "It is not obvious at the outset that the operation can in fact be encoded as a finite-state transducer for arbitrary regular patterns. Although a unique substring is selected for replacement at each point, in general the transduction is not unambiguous because LOWER is not required to be a single string; it can be any regular language.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Scan", "sec_num": null }, { "text": "The idea of treating phonological rewrite rules in this way was the starting point of Kaplan and Kay (1994) . Their notion of obligatory rewrite rule incorporates a directionality constraint. They observe (p. 358), however, that this constraint does not by itself guarantee a single output. Kaplan and Kay suggest that additional restrictions, such as longestmatch, could be imposed to further constrain rule application. 2 We consider this issue in more detail.", "cite_spans": [ { "start": 86, "end": 107, "text": "Kaplan and Kay (1994)", "ref_id": "BIBREF4" } ], "ref_spans": [], "eq_spans": [], "section": "Scan", "sec_num": null }, { "text": "The crucial observation is that the two constraints, left-to-right and longest-match, force a unique factorization on the input string thus making the transduction unambiguous if the L01gER language consists of a single string. In effect, the input string is unambiguously parsed with respect to the UPPER language. This property turns out to be important for a number of applications. Thus it is useful to provide a replacement operator that implements these constraints directly.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Scan", "sec_num": null }, { "text": "The definition of the UPPER @-> LOWER relation is presented in the next section. Section 3 introduces a novel type of replace expression for constructing transducers that unambiguously recognize and mark 2The tentative formulation of the longest-match constraint in (Kaplan and Kay, 1994, p. 358 ) is too weak. It does not cover all the cases. instances of a regular language without actually replacing them. Section 4 identifies some useful applications of the new replacement expressions.", "cite_spans": [ { "start": 266, "end": 295, "text": "(Kaplan and Kay, 1994, p. 358", "ref_id": null } ], "ref_spans": [], "eq_spans": [], "section": "Scan", "sec_num": null }, { "text": "We define directed replacement by means of a composition of regular relations. As in Kaplan and Kay (1994) , Karttunen (1995) , and other previous works on related topics, the intermediate levels of the composition introduce auxiliary symbols to express and enforce constraints on the replacement relation. Replacement by a caret that are instances of the upper language. The initial caret is replaced by a <, and a closing > is inserted to mark the end of the match. We permit carets to appear freely while matching. No carets are permitted outside the matched substrings and the ignored internal carets are eliminated. In this case, there are four possible outcomes, shown in Figure 8 , but only two of them are allowed under the constraint that there can be no carets outside the brackets. Figure 6 are composed in advance, as our compiler does, the application of the replacement to an input string takes place in one step without any intervening levels and with no auxiliary symbols. But it helps to understand the logic to see where the auxiliary marks would be in the hypothetical intermediate results.", "cite_spans": [ { "start": 85, "end": 106, "text": "Kaplan and Kay (1994)", "ref_id": "BIBREF4" }, { "start": 109, "end": 125, "text": "Karttunen (1995)", "ref_id": "BIBREF7" } ], "ref_spans": [ { "start": 678, "end": 686, "text": "Figure 8", "ref_id": "FIGREF6" }, { "start": 793, "end": 801, "text": "Figure 6", "ref_id": "FIGREF7" } ], "eq_spans": [], "section": "Directed Replacement", "sec_num": "2" }, { "text": "Let us consider the caseofa b [ b I b a [ a b a ~-> x applying to the string \"aba\" and see in detail how the mapping implemented by the transducer in Figure 4 is composed from the four component relations. We use three auxiliary symbols, caret ('), left bracket (<) and right bracket (>), assuming here that they do not occur in any input. The first step, shown in Figure 7 , composes the input string with a transducer that inserts a caret, in the beginning of every substring that belongs to the upper language. Each caret marks the beginning of a substring that matches \"ab\", \"b\", \"ba\", or ~aba\".", "cite_spans": [], "ref_spans": [ { "start": 150, "end": 158, "text": "Figure 4", "ref_id": "FIGREF3" }, { "start": 365, "end": 373, "text": "Figure 7", "ref_id": "FIGREF8" } ], "eq_spans": [], "section": "Directed Replacement", "sec_num": "2" }, { "text": "Note that only one \" is inserted even if there are several candidate strings starting at the same location.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Directed Replacement", "sec_num": "2" }, { "text": "In the left-to-right step, we enclose in angle brackets all the substrings starting at a location marked In effect, no starting location for a replacement can be skipped over except in the context of another replacement starting further left in the input string. (Roche and Schabes (1995) introduce a similar technique for imposing the left-to-right order on the transduction.) Note that the four alternatives in Figure 8 represent the four factorizations in Figure 2 .", "cite_spans": [ { "start": 263, "end": 288, "text": "(Roche and Schabes (1995)", "ref_id": "BIBREF13" } ], "ref_spans": [ { "start": 413, "end": 421, "text": "Figure 8", "ref_id": "FIGREF6" }, { "start": 459, "end": 468, "text": "Figure 2", "ref_id": null } ], "eq_spans": [], "section": "Directed Replacement", "sec_num": "2" }, { "text": "The longest-match constraint is the identity relation on a certain set of strings. It forbids any replacement that starts at the same location as another, longer replacement. In the case at hand, it means that the internal > is disallowed in the context < a b > a. Because \"aba\" is in the upper language, there is a longer, and therefore preferred, < a b a > alternative at the same starting location, Figure 9 . In the final replacement step, the bracketed regions of the input string, in the case at hand, just < a b a > , are replaced by the strings of the lower language, yielding \"x\" as the result for our example.", "cite_spans": [], "ref_spans": [ { "start": 402, "end": 410, "text": "Figure 9", "ref_id": "FIGREF9" } ], "eq_spans": [], "section": "Directed Replacement", "sec_num": "2" }, { "text": "Note that longest match constraint ignores any internal brackets. For example, the bracketing < a > < a > is not allowed if the upper language contains \"aa\" as well as \"a\". Similarly, the left-to-right constraint ignores any internal carets.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Directed Replacement", "sec_num": "2" }, { "text": "As the first step towards a formal definition of UPPER \u00a9-> LOWER it is useful to make the notion of \"ignoring internal brackets\" more precise. Figure 10 contains the auxiliary definitions. For the details of the formalism (briefly explained in the Appendix), please consult Karttunen (1995) , Kempe and Karttunen (1996) . 3", "cite_spans": [ { "start": 274, "end": 290, "text": "Karttunen (1995)", "ref_id": "BIBREF7" }, { "start": 293, "end": 319, "text": "Kempe and Karttunen (1996)", "ref_id": "BIBREF8" } ], "ref_spans": [ { "start": 143, "end": 152, "text": "Figure 10", "ref_id": "FIGREF1" } ], "eq_spans": [], "section": "Directed Replacement", "sec_num": "2" }, { "text": "UPPER' = UPPER/[Y, ^] -[?* 7''] UPPER'' = UPPER/[7,] -[?* [7,<[7,>]']", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Directed Replacement", "sec_num": "2" }, { "text": "Figure 10: Versions of UPPER that freely allow nonfinal diacritics.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Directed Replacement", "sec_num": "2" }, { "text": "The precise definition of the UPPER ~-> LOWER relation is given in Figure 11 . It is a composition of many auxiliary relations. We label the major components in accordance with the outline in Figure 6 . The formulation of the longest-match constraint is based on a suggestion by Ronald M. Kaplan (p.c.).", "cite_spans": [], "ref_spans": [ { "start": 67, "end": 76, "text": "Figure 11", "ref_id": "FIGREF1" }, { "start": 192, "end": 200, "text": "Figure 6", "ref_id": "FIGREF7" } ], "eq_spans": [], "section": "Directed Replacement", "sec_num": "2" }, { "text": "\"$[ Y,\" 1 7'< 17'> \"I .0. [..] -> 7\" II _ UPPER \u00b00\u00b0 Left to right ['$[7,\"] [7,':7,< UPPER' 0:7,>]'1, \"$[7,':] ,O, 7,--> [] .Oo Longest match \"$[7,< [UPPER'' ~ $[7,>']']] ,O. Replacement Z< \"$[Z>] Y,> -> LOWER ;", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Initial match", "sec_num": null }, { "text": "Figure 11: Definition of UPPER @-> LOWER The logic of ~-> replacement could be encoded in many other ways, for example, by using the three pairs of auxiliary brackets, i, c, and a, introduced in Kaplan and Kay (1994) . We take here a more minimalist approach. One reason is that we prefer to think of the simple unconditional (uncontexted) replacement as the basic case, as in Karttunen (1995) . Without the additional complexities introduced by contexts, the directionality and 3UPPER' is the same language as UPPER except that carets may appear freely in all nonfinal positions. Similarly, UPPER'' accepts any nonfinal brackets. 111 length-of-match constraints can be encoded with fewer diacritics. (We believe that the conditional case can also be handled in a simpler way than in Kaplan and Kay (1994) .) The number of auxiliary markers is an important consideration for some of the applications discussed below.", "cite_spans": [ { "start": 221, "end": 231, "text": "Kay (1994)", "ref_id": "BIBREF4" }, { "start": 392, "end": 408, "text": "Karttunen (1995)", "ref_id": "BIBREF7" }, { "start": 799, "end": 820, "text": "Kaplan and Kay (1994)", "ref_id": "BIBREF4" } ], "ref_spans": [], "eq_spans": [], "section": "Initial match", "sec_num": null }, { "text": "In a phonological or morphological rewrite rule, the center part of the rule is typically very small: a modification, deletion or insertion of a single segment. On the other hand, in our text processing applications, the upper language may involve a large network representing, for example, a lexicon of multiword tokens. Practical experience shows that the presence of many auxiliary diacritics makes it difficult or impossible to compute the left-to-right and longest-match constraints in such cases. The size of intermediate states of the computation becomes a critical issue, while it is irrelevant for simple phonological rules. We will return to this issue in the discussion of tokenizing transducers in Section 4.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Initial match", "sec_num": null }, { "text": "The transducers derived from the definition in Figure 11 have the property that they unambiguously parse the input string into a sequence of substrings that are either copied to the output unchanged or replaced by some other strings. However they do not fall neatly into any standard class of transducers discussed in the literature (Eilenberg 1974 , Schiitzenberger 1977 , Berstel 1979 ). If the LOWER language consists of a single string, then the relation encoded by the transducer is in Berstel's terms a rational function, and the network is an unambigous transducer, even though it may contain states with outgoing transitions to two or more destinations for the same input symbol. An unambiguous transducer may also be sequentiable, in \u2022 which case it can be turned into an equivalent sequential transducer (Mohri, 1994) , which can in turn be minimized. A transducer is sequential just in case there are no states with more than one transition for the same input symbol. Roche and Sehabes (1995) call such transducers deterministic.", "cite_spans": [ { "start": 333, "end": 348, "text": "(Eilenberg 1974", "ref_id": "BIBREF2" }, { "start": 349, "end": 371, "text": ", Schiitzenberger 1977", "ref_id": "BIBREF14" }, { "start": 372, "end": 386, "text": ", Berstel 1979", "ref_id": "BIBREF0" }, { "start": 814, "end": 827, "text": "(Mohri, 1994)", "ref_id": "BIBREF11" }, { "start": 979, "end": 1003, "text": "Roche and Sehabes (1995)", "ref_id": null } ], "ref_spans": [ { "start": 47, "end": 56, "text": "Figure 11", "ref_id": "FIGREF1" } ], "eq_spans": [], "section": "Initial match", "sec_num": null }, { "text": "Our replacement transducers in general are not unambiguous because we allow LOWER to be any regular language. It may well turn out that, in all cases that are of practical interest, the lower language is in fact a singleton, or at least some finite set, but it is not so by definition. Even if the replacement transducer is unambiguous, it may well be unsequentiable if UPPER is an infinite language. For example, the simple transducer for a+ b ~-> x in Figure 12 cannot be sequentialized. It has to replace any string of \"a\"s by \"x\" or copy it to the output unchanged depending on whether the string eventually terminates at \"b'. It is obviously impossible for any finite-state b:O Figure 13 , a simple parallel replacement of the two auxiliary brackets that mark the selected regions. Because the placement of < and > is strictly controlled, they do not occur anywhere else. Insertion 7,< -> PREFIX, 7.> -> SUFFIX ; Figure 12 : a+ b ~-> x. This transducer is unambiguous but cannot be sequentialized.", "cite_spans": [], "ref_spans": [ { "start": 454, "end": 463, "text": "Figure 12", "ref_id": "FIGREF1" }, { "start": 683, "end": 692, "text": "Figure 13", "ref_id": "FIGREF1" }, { "start": 918, "end": 927, "text": "Figure 12", "ref_id": "FIGREF1" } ], "eq_spans": [], "section": "Initial match", "sec_num": null }, { "text": "device to accumulate an unbounded amount of delayed output. On the other hand, the transducer in Figure 4 is sequentiable because there the choice between a and a:x just depends on the next input symbol.", "cite_spans": [], "ref_spans": [ { "start": 97, "end": 105, "text": "Figure 4", "ref_id": "FIGREF3" } ], "eq_spans": [], "section": "Initial match", "sec_num": null }, { "text": "Because none of the classical terms fits exactly, we have chosen a novel term, directed transduction, to describe a relation induced by the definition in Figure 11 . It is meant to suggest that the mapping from the input into the output strings is guided by the directionality and length-of-match constraints. Depending on the characteristics of the UPPER and LOWER languages, the resulting transducers may be unambiguous and even sequential, but that is not guaranteed in the general case.", "cite_spans": [], "ref_spans": [ { "start": 154, "end": 163, "text": "Figure 11", "ref_id": "FIGREF1" } ], "eq_spans": [], "section": "Initial match", "sec_num": null }, { "text": "The effect of the left-to-right and longest-match constraint is to factor any input string uniquely with respect to the upper language of the replace expression, to parse it into a sequence of substrings that either belong or do not belong to the language. Instead of replacing the instances of the upper language in the input by other strings, we can also take advantage of the unique factorization in other ways. For example, we may insert a string before and after each substring that is an instance of the language in question simply to mark it as such.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Insertion", "sec_num": "3" }, { "text": "To implement this idea, we introduce the special symbol ... on the right-hand side of the replacement expression to mark the place around which the insertions are to be made. Thus we allow replacement expressions of the form UPPER ~-> PREFIX \u2022.. SUFFIX. The corresponding transducer locates the instances of UPPER in the input string under the left-to-right, longest-match regimen just described. But instead of replacing the matched strings, the transducer just copies them, inserting the specified prefix and suffix. For the sake of generality, we allow PREFIX and SUFFIX to denote any regular language.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Insertion", "sec_num": "3" }, { "text": "The definition of UPPER ~-> PREFIX ... SUFFIX is just as in Figure 11 except that the Replacement expression is replaced by the Insertion formula in Although the input string \"dannvaan\" contains many other instances of the noun phrase pattern, \"n\", \"an\", \"nn\", etc., the left-to-right and longestmatch constraints pick out just the two maximal ones. The transducer is displayed in Figure 15 . Note that ? here matches symbols, such as v, that are not included in the alphabet of the network. ", "cite_spans": [], "ref_spans": [ { "start": 60, "end": 69, "text": "Figure 11", "ref_id": "FIGREF1" }, { "start": 381, "end": 390, "text": "Figure 15", "ref_id": "FIGREF1" } ], "eq_spans": [], "section": "Insertion", "sec_num": "3" }, { "text": "The directed replacement operators have many useful applications. We describe some of them. Although the same results could often be achieved by using lex and yacc, sed, awk, perl, and other Unix utilities, there is an advantage in using finitestate transducers for these tasks because they can then be smoothly integrated with other finite-state processes, such as morphological analysis by lexical transducers (Karttunen et al 1992 , Karttunen 1994 ) and rule-based part-of-speech disambiguation (Chanod and Tapanainen 1995, Roche and Schabes 1995) .", "cite_spans": [ { "start": 412, "end": 433, "text": "(Karttunen et al 1992", "ref_id": null }, { "start": 434, "end": 450, "text": ", Karttunen 1994", "ref_id": "BIBREF6" }, { "start": 498, "end": 509, "text": "(Chanod and", "ref_id": "BIBREF1" }, { "start": 510, "end": 536, "text": "Tapanainen 1995, Roche and", "ref_id": null }, { "start": 537, "end": 550, "text": "Schabes 1995)", "ref_id": "BIBREF13" } ], "ref_spans": [], "eq_spans": [], "section": "Applications", "sec_num": "4" }, { "text": "A tokenizer is a device that segments an input string into a sequence of tokens. The insertion of end-oftoken marks can be accomplished by a finite-state transducer that is compiled from tokenization rules. The tokenization rules may be of several types. For example, [WHITE_SPACE+ ~-> SPACE] is a normalizing transducer that reduces any sequence of tabs, spaces, and newlines to a single space. [LETTER+ ~-> ... END_0F_TOKEN] inserts a special mark, e.g. a newtine, at the end of a letter sequence.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Tokenization", "sec_num": "4.1" }, { "text": "Although a space generally counts as a token boundary, it can also be part of a multiword token, as in expressions like \"at least\", \"head over heels\", \"in spite of\", etc. Thus the rule that introduces the END_0F_TOKEN symbol needs to combine the LETTER+ pattern with a list of multiword tokens which may include spaces, periods and other delimiters. Figure 16 outlines the construction of a simple tokenizing transducer for English. The tokenizer in Figure 16 is composed of three transducers. The first reduces strings of whitespace characters to a single space. The second transducer inserts an END_0F_TOKEN mark after simple words and the, listed multiword expressions. The third removes the spaces that are not part of some multi-word token. The percent sign here means that the following blank is to be taken literally, that is, parsed as a symbol.", "cite_spans": [], "ref_spans": [ { "start": 350, "end": 359, "text": "Figure 16", "ref_id": "FIGREF1" }, { "start": 450, "end": 459, "text": "Figure 16", "ref_id": "FIGREF1" } ], "eq_spans": [], "section": "Tokenization", "sec_num": "4.1" }, { "text": "Without the left-to-right, longest-match constraints, the tokenizing transducer would not produce deterministic output. Note that it must introduce an END_0F_TOKEN mark after a sequence of letters just in case the word is not part of some longer multiword token. This problem is complicated by the fact that the list of multiword tokens may contain overlapping expressions. A tokenizer for French, for example, needs to recognize \"de plus\" (moreover), \"en plus\" (more), \"en plus de\" (in addition to), and \"de plus en plus\" (more and more) as single tokens. Thus there is a token boundary after \"de plus\" in de plus on ne le fai~ plus (moreover one doesn't do it anymore) but not in on le ]:air de plus en plus (one does it more and more) where \"de plus en plus\" is a single token.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Tokenization", "sec_num": "4.1" }, { "text": "If the list of multiword tokens contains hundreds of expressions, it may require a lot of time and space to compile the tokenizer even if the final result is not too large. The number of auxiliary symbols used to encode the constraints has a critical effect on the efficiency of that computation. We first observed this phenomenon in the course of building a tokenizer for the British National Corpus according to the specifications of the BNC Users Guide (Leech, 1995) , which lists around 300 multiword tokens and 260 foreign phrases. With the current definition of the directed replacement we have now been able to compute similar tokenizers for several other languages (French, Spanish, Italian, Portuguese, Dutch, German).", "cite_spans": [ { "start": 456, "end": 469, "text": "(Leech, 1995)", "ref_id": "BIBREF10" } ], "ref_spans": [], "eq_spans": [], "section": "Tokenization", "sec_num": "4.1" }, { "text": "Some text processing applications involve a preliminary stage in which the input stream is divided into regions that are passed on to the calling process and regions that are ignored. For example, in processing an SGML-coded document, we may wish to delete all the material that appears or does not appear in a region bounded by certain SGML tags, say and .", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Filtering", "sec_num": "4.2" }, { "text": "Both types of filters can easily be constructed using the directed replace operator. A negative filter that deletes all the material between the two SGML codes, including the codes themselves, is expressed as in Figure 17 .", "cite_spans": [], "ref_spans": [ { "start": 212, "end": 221, "text": "Figure 17", "ref_id": "FIGREF1" } ], "eq_spans": [], "section": "Filtering", "sec_num": "4.2" }, { "text": "\"\" -$[\"\"I\"\"] \"\" ~-> [] ;", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Filtering", "sec_num": "4.2" }, { "text": "Figure 17: A negative filter A positive filter that excludes everything else can be expressed as in Figure 18 . The positive filter is composed of two transducers. The first reduces to any string that ends with it and does not contain the tag. The second transducer does a similar transduction on strings that begin with . Figure 12 illustrates the effect of the positive filter.", "cite_spans": [], "ref_spans": [ { "start": 100, "end": 109, "text": "Figure 18", "ref_id": "FIGREF1" }, { "start": 336, "end": 345, "text": "Figure 12", "ref_id": "FIGREF1" } ], "eq_spans": [], "section": "Filtering", "sec_num": "4.2" }, { "text": "onetwothreef our two four By means of this simple \"bottom-up\" technique, it is possible to compile finite-state transducers that approximate a context-free parser up to a chosen depth of embedding. Of course, the left-to-right, longest-match regimen implies that some possible analyses are ignored. To produce all possible parses, we may introduce the ... notation to the simple replace expressions in Karttunen (1995) . The idea of filtering by finite-state transduction of course does not depend on SGML codes. It can be applied to texts where the interesting and uninteresting regions are defined by any kind of regular pattern.", "cite_spans": [ { "start": 446, "end": 462, "text": "Karttunen (1995)", "ref_id": "BIBREF7" } ], "ref_spans": [], "eq_spans": [], "section": "Filtering", "sec_num": "4.2" }, { "text": "As we observed in section 3, by using the ... symbol on the lower side of the replacement expression, we can construct transducers that mark instances of a regular language without changing the text in any other way. Such transducers have a wide range of applications. They can be used to locate all kinds of expressions that can be described by a regular pattern, such as proper names, dates, addresses, social security and phone numbers, and the like. Such a marking transducer can be viewed as a deterministic parser for a \"local grammar\" in the sense of Gross (1989) , Roche (1993) , Silberztein (1993) and others.", "cite_spans": [ { "start": 558, "end": 570, "text": "Gross (1989)", "ref_id": "BIBREF3" }, { "start": 573, "end": 585, "text": "Roche (1993)", "ref_id": "BIBREF12" }, { "start": 588, "end": 606, "text": "Silberztein (1993)", "ref_id": "BIBREF15" } ], "ref_spans": [], "eq_spans": [], "section": "Marking", "sec_num": "4.3" }, { "text": "By composing two or more marking transducers, we can also construct a single transducer that builds nested syntactic structures, up to any desired depth. To make the construction simpler, we can start by defining auxiliary symbols for the basic regular patterns. For example, we may define NP as [(d) a* n+J. With that abbreviatory convention, a composition of a simple NP and VP spotter can be defined as in Figure 20 . Figure 21 shows the effect of applying this composite transducer to the string \"dannvaan\".", "cite_spans": [], "ref_spans": [ { "start": 409, "end": 418, "text": "Figure 20", "ref_id": "FIGREF17" }, { "start": 421, "end": 430, "text": "Figure 21", "ref_id": "FIGREF1" } ], "eq_spans": [], "section": "Marking", "sec_num": "4.3" }, { "text": "The definition of the left-to-right, longest-match replacement can easily be modified for the three other directed replace operators mentioned in Figure 3 . Another extension, already implemented, is a directed version of parallel replacement (Kempe and Karttunen 1996) , which allows any number of replacements to be done simultaneously without interfering with each other. Figure 22 is an example of a directed parallel replacement. It yields a transducer that maps a string of \"\u00a3's into a single \"b\" and a string of \"b\"s into a single '%'. a+ @-> b, b+ ~-> a ; Figure 22 : Directed, parallel replacement The definition of directed parallel replacement requires no additions to the techniques already presented. In the near future we also plan to allow directional and length-of-match constraints in the more complicated case of conditional context-constrained replacement.", "cite_spans": [ { "start": 243, "end": 269, "text": "(Kempe and Karttunen 1996)", "ref_id": "BIBREF8" } ], "ref_spans": [ { "start": 146, "end": 154, "text": "Figure 3", "ref_id": "FIGREF2" }, { "start": 375, "end": 384, "text": "Figure 22", "ref_id": null }, { "start": 564, "end": 573, "text": "Figure 22", "ref_id": null } ], "eq_spans": [], "section": "Marking", "sec_num": "4.3" }, { "text": "Appendix:", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "7", "sec_num": "6" }, { "text": "Notational conventions", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "7", "sec_num": "6" }, { "text": "The regular expression formalism used in this paper is essentially the same as in Kaplan and Kay (1994) , in Karttunen (1995) , and in Kempe and Karttunen (1996) . Upper-case strings, such as UPPER, represent regular languages, and lower-case letters, such as x, represent symbols. We recognize two types of symbols: unary symbols (a, b, c, etc) and symbol pairs (a:x, b:0, etc. ). A symbol pair a:x may be thought of as the crossproduct of a and x, the minimal relation consisting of a (the upper symbol) and x (the lower symbol). To make the notation less cumbersome, we systematically ignore the distinction between the language A and the identity relation that maps every string of A into itself. Consequently, we also write a:a as just a.", "cite_spans": [ { "start": 82, "end": 103, "text": "Kaplan and Kay (1994)", "ref_id": "BIBREF4" }, { "start": 109, "end": 125, "text": "Karttunen (1995)", "ref_id": "BIBREF7" }, { "start": 135, "end": 161, "text": "Kempe and Karttunen (1996)", "ref_id": "BIBREF8" }, { "start": 331, "end": 345, "text": "(a, b, c, etc)", "ref_id": null } ], "ref_spans": [], "eq_spans": [], "section": "7", "sec_num": "6" }, { "text": "Three special symbols are used in regular expressions: 0 (zero) represents the empty string (often denoted by c); ? stands for any symbol in the known alphabet and its extensions; in replacement expressions, .#. marks the start (left context) or the end (right context) of a string. The percent sign, Y,, is used as an escape character. It allows letters that have a special meaning in the calculus to be used as ordinary symbols. Thus Z[ denotes the literal square bracket as opposed to [, which has a special meaning as a grouping symbol; %0 is the ordinary zero symbol.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "7", "sec_num": "6" }, { "text": "The following simple expressions appear freqently in the formulas: [] the empty string language, ?* the universal (\"sigma star\") language.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "7", "sec_num": "6" }, { "text": "The regular expression operators used in the paper are: * zero or more (Kleene star), + one or more (Kleene plus), -not (complement), $ contains, / ignore, I or (union), t~ and (intersection), -minus (relative complement), .x. crossproduct, .o. composition, -> simple replace.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "7", "sec_num": "6" }, { "text": "In the transducer diagrams (Figures 1, 4, etc. ), the nonfinal states are represented by single circles, final states by double circles. State 0 is the initial state. The symbol ? represents any symbols that are not explicitly present in the network. Transitions that differ only with respect to the label are collapsed into a single multiply labelled arc.", "cite_spans": [], "ref_spans": [ { "start": 27, "end": 46, "text": "(Figures 1, 4, etc.", "ref_id": "FIGREF1" } ], "eq_spans": [], "section": "7", "sec_num": "6" } ], "back_matter": [ { "text": "I would like to thank Ronald M. Kaplan, Martin Kay, Andr4 Kempe, John Maxwell, and Annie Zaenen for helpful discussions at the beginning of the project, as well as Paula Newman and Kenneth 1%. Beesley for editorial advice on the first draft of the paper. The work on tokenizers and phrasal analyzers by Anne Schiller and Gregory Grefenstette revealed the need for a more efficient implementation of the idea. The final version of the paper has benefited from detailed comments by l%onald M. Kaplan and two anonymous reviewers, who convinced me to discard the ill-chosen original title (\"Deterministic Replacement\") in favor of the present one.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Acknowledgements", "sec_num": null } ], "bib_entries": { "BIBREF0": { "ref_id": "b0", "title": "Transductions and Context-Free Languages", "authors": [ { "first": "Jean", "middle": [], "last": "Berstel", "suffix": "" } ], "year": 1979, "venue": "B.G. Teubner", "volume": "", "issue": "", "pages": "", "other_ids": {}, "num": null, "urls": [], "raw_text": "Jean Berstel. 1979. Transductions and Context-Free Languages. B.G. Teubner, Stuttgart, Germany.", "links": null }, "BIBREF1": { "ref_id": "b1", "title": "Tagging French--comparing a statistical and a constraint-based mode", "authors": [ { "first": "Jean-", "middle": [], "last": "", "suffix": "" }, { "first": "Pierre", "middle": [], "last": "Chanod", "suffix": "" }, { "first": "Pasi", "middle": [], "last": "Tapanainen", "suffix": "" } ], "year": 1995, "venue": "The Proceedings of the Seventh Conference of the European Chapter of the Association for Computational Linguistics", "volume": "", "issue": "", "pages": "", "other_ids": {}, "num": null, "urls": [], "raw_text": "Jean-Pierre Chanod and Pasi Tapanainen. 1995. Tagging French--comparing a statistical and a constraint-based mode]. In The Proceedings of the Seventh Conference of the European Chapter of the Association for Computational Linguistics, Dublin, Ireland.", "links": null }, "BIBREF2": { "ref_id": "b2", "title": "Automata, Languages, and Machines", "authors": [ { "first": "Samuel", "middle": [], "last": "Eilenberg", "suffix": "" } ], "year": 1974, "venue": "", "volume": "", "issue": "", "pages": "", "other_ids": {}, "num": null, "urls": [], "raw_text": "Samuel Eilenberg. 1974. Automata, Languages, and Machines. Academic Press.", "links": null }, "BIBREF3": { "ref_id": "b3", "title": "The Use of Finite Automata in the Lexical Representation of Natural Language", "authors": [ { "first": "Maurice", "middle": [], "last": "Gross", "suffix": "" } ], "year": 1989, "venue": "Lecture Notes in Computer Science", "volume": "", "issue": "", "pages": "34--50", "other_ids": {}, "num": null, "urls": [], "raw_text": "Maurice Gross. 1989. The Use of Finite Automata in the Lexical Representation of Natural Lan- guage. In Lecture Notes in Computer Science, pages 34-50, Springer-Verlag, Berlin, Germany.", "links": null }, "BIBREF4": { "ref_id": "b4", "title": "Regular Models of Phonological Rule Systems", "authors": [ { "first": "M", "middle": [], "last": "Ronald", "suffix": "" }, { "first": "Martin", "middle": [], "last": "Kaplan", "suffix": "" }, { "first": "", "middle": [], "last": "Kay", "suffix": "" } ], "year": 1994, "venue": "Computational Linguistics", "volume": "20", "issue": "3", "pages": "331--378", "other_ids": {}, "num": null, "urls": [], "raw_text": "Ronald M. Kaplan and Martin Kay. 1994. Regular Models of Phonological Rule Systems. Computa- tional Linguistics, 20:3, pages 331-378.", "links": null }, "BIBREF5": { "ref_id": "b5", "title": "A Compiler for Two-level Phonological Rules", "authors": [ { "first": "Lauri", "middle": [], "last": "Karttunen", "suffix": "" }, { "first": "Kimmo", "middle": [], "last": "Koskenniemi", "suffix": "" }, { "first": "Ronald", "middle": [ "M" ], "last": "Kaplan", "suffix": "" } ], "year": 1987, "venue": "Report No. CSLL87-108. Center for the Study of Language and Information", "volume": "", "issue": "", "pages": "", "other_ids": {}, "num": null, "urls": [], "raw_text": "Lauri Karttunen, Kimmo Koskenniemi, and Ronald M. Kaplan. 1987. A Compiler for Two-level Phonological Rules. In Report No. CSLL87-108. Center for the Study of Language and Informa- tion, Stanford University. Palo Alto, California.", "links": null }, "BIBREF6": { "ref_id": "b6", "title": "Constructing Lexical Transducers", "authors": [ { "first": "Lauri", "middle": [], "last": "Karttunen", "suffix": "" } ], "year": 1994, "venue": "The Proceedings of the Fifteenth International Conference on Computational Linguistics. Coling 94, I", "volume": "", "issue": "", "pages": "406--411", "other_ids": {}, "num": null, "urls": [], "raw_text": "Lauri Karttunen. 1994. Constructing Lexical Trans- ducers. In The Proceedings of the Fifteenth Inter- national Conference on Computational Linguis- tics. Coling 94, I, pages 406-411, Kyoto, Japan.", "links": null }, "BIBREF7": { "ref_id": "b7", "title": "The Replace Operator", "authors": [ { "first": "Lauri", "middle": [], "last": "Karttunen", "suffix": "" } ], "year": 1995, "venue": "The Proceedings of the 33rd Annual Meeting of the Association for Computational Linguistics. ACL-94", "volume": "", "issue": "", "pages": "16--23", "other_ids": {}, "num": null, "urls": [], "raw_text": "Lauri Karttunen. 1995. The Replace Operator. In The Proceedings of the 33rd Annual Meeting of the Association for Computational Linguistics. ACL- 94, pages 16-23, Boston, Massachusetts.", "links": null }, "BIBREF8": { "ref_id": "b8", "title": "Parallel Replacement in the Finite-State Calculus", "authors": [ { "first": "Andr~", "middle": [], "last": "Kempe", "suffix": "" }, { "first": "Lauri", "middle": [], "last": "Karttunen", "suffix": "" } ], "year": 1996, "venue": "The Proceedings of the Sixteenth International Conference on Computational Linguistics. Coling 96", "volume": "", "issue": "", "pages": "", "other_ids": {}, "num": null, "urls": [], "raw_text": "Andr~ Kempe and Lauri Karttunen. 1996. Parallel Replacement in the Finite-State Calculus. In The Proceedings of the Sixteenth International Con- ference on Computational Linguistics. Coling 96.", "links": null }, "BIBREF10": { "ref_id": "b10", "title": "User's Guide to the British National Corpus", "authors": [ { "first": "Geoffrey", "middle": [], "last": "Leech", "suffix": "" } ], "year": 1995, "venue": "", "volume": "", "issue": "", "pages": "", "other_ids": {}, "num": null, "urls": [], "raw_text": "Geoffrey Leech. 1995. User's Guide to the British National Corpus. Lancaster University.", "links": null }, "BIBREF11": { "ref_id": "b11", "title": "On Some Applications of Finite-State Automata Theory to Natural Language Processing", "authors": [ { "first": "Mehryar", "middle": [], "last": "Mohri", "suffix": "" } ], "year": 1994, "venue": "", "volume": "", "issue": "", "pages": "", "other_ids": {}, "num": null, "urls": [], "raw_text": "Mehryar Mohri. 1994. On Some Applications of Finite-State Automata Theory to Natural Lan- guage Processing. Technical Report 94-22. L'In- stitute Gaspard Monge. Universit~ de Marne-la- ValiSe. Noisy Le Grand.", "links": null }, "BIBREF12": { "ref_id": "b12", "title": "Analyse syntaxique transformationelle du franfais par transducteurs el lexique-grammaire. Doctoral dissertation", "authors": [ { "first": "Emmanuel", "middle": [], "last": "Roche", "suffix": "" } ], "year": 1993, "venue": "", "volume": "", "issue": "", "pages": "", "other_ids": {}, "num": null, "urls": [], "raw_text": "Emmanuel Roche. 1993. Analyse syntaxique trans- formationelle du franfais par transducteurs el lexique-grammaire. Doctoral dissertation, Univer- sit~ Paris 7.", "links": null }, "BIBREF13": { "ref_id": "b13", "title": "Deterministic Part-of-Speech Tagging", "authors": [ { "first": "Emmanuel", "middle": [], "last": "Roche", "suffix": "" }, { "first": "Yves", "middle": [], "last": "Schabes", "suffix": "" } ], "year": 1995, "venue": "Computational Linguistics", "volume": "21", "issue": "2", "pages": "227--53", "other_ids": {}, "num": null, "urls": [], "raw_text": "Emmanuel Roche and Yves Schabes. 1995. Deter- ministic Part-of-Speech Tagging. Computational Linguistics, 21:2, pages 227-53.", "links": null }, "BIBREF14": { "ref_id": "b14", "title": "Sur une variante des fonctions sequentielles", "authors": [ { "first": "Marcel", "middle": [ "Paul" ], "last": "Schiitzenberger", "suffix": "" } ], "year": 1977, "venue": "Theoretical Computer Science", "volume": "4", "issue": "", "pages": "47--57", "other_ids": {}, "num": null, "urls": [], "raw_text": "Marcel Paul Schiitzenberger. 1977. Sur une variante des fonctions sequentielles. Theoretical Computer Science, 4, pages 47-57.", "links": null }, "BIBREF15": { "ref_id": "b15", "title": "Dictionnaires Electroniques et Analyse Lexicale du Franfais--Le Syst~me IN-TEX", "authors": [ { "first": "Max", "middle": [], "last": "Silberztein", "suffix": "" } ], "year": 1993, "venue": "", "volume": "", "issue": "", "pages": "", "other_ids": {}, "num": null, "urls": [], "raw_text": "Max Silberztein. 1993. Dictionnaires Electroniques et Analyse Lexicale du Franfais--Le Syst~me IN- TEX, Masson, Paris, France.", "links": null } }, "ref_entries": { "FIGREF0": { "num": null, "text": "Figure 1, representing a b I b I b a I a b a-> x. 1 1The regular expression formalism and other notational cdnventions used in the paper are explained in the Appendix at the end.", "type_str": "figure", "uris": null }, "FIGREF1": { "num": null, "text": "a b I b I b a I a b a-> x . The four paths with \"aba\" on the upper side are: <0 a 0 b:x 2 a 0>, <0 a 0 b:x 2 a:0 0>, <0 a:x 1 b:0 2 a 0>, and <0 a:x 1 b:0 2 a:0 0>.", "type_str": "figure", "uris": null }, "FIGREF2": { "num": null, "text": "Directed replacement operators", "type_str": "figure", "uris": null }, "FIGREF3": { "num": null, "text": ": a b [ b [ b a [ a b a @-> x. The single path with \"aba\" on the upper side is: <0 a:x I b:O 2 a:O 0>.", "type_str": "figure", "uris": null }, "FIGREF5": { "num": null, "text": "", "type_str": "figure", "uris": null }, "FIGREF6": { "num": null, "text": "Left-to-right constraint. No caret outside a bracketed region.", "type_str": "figure", "uris": null }, "FIGREF7": { "num": null, "text": "Composition of directed replacement If the four relations on the bottom of", "type_str": "figure", "uris": null }, "FIGREF8": { "num": null, "text": "Initial match.", "type_str": "figure", "uris": null }, "FIGREF9": { "num": null, "text": "Longest match constraint. No upper language string with an initial < and a nonfinal > in the middle.", "type_str": "figure", "uris": null }, "FIGREF10": { "num": null, "text": "Insertion expression in the definition of UPPER ~-> PREFIX ... SUFFIX.With the ... expressions we can construct transducers that mark maximal instances of a regular language. For example, let us assume that noun phrases consist of an optional determiner, (d), any number of adjectives, a*, and one or more nouns, n+. The expression (d) a* a+ ~-> 7,[ ... %3 compiles into a transducer that inserts brackets around maximal instances of the noun phrase pattern. For example, it maps \"damlvaan\" into \"[dann] v [aan] \", as shown inFigure 14. Application of (d) a* n+ \u00a9-> ~,[...Y,] to \"d a.tlI'tv aa.L-rl\"", "type_str": "figure", "uris": null }, "FIGREF11": { "num": null, "text": "(d) a* n+ e-> ~,[...~,]. The one path with \"dannvaan\" on the upper side is: <00: [ 7 d 3 a3n4n40:] 5v00:[7a3a3a40:] 5>.", "type_str": "figure", "uris": null }, "FIGREF13": { "num": null, "text": "A simple tokenizer", "type_str": "figure", "uris": null }, "FIGREF14": { "num": null, "text": "A positive filter Figure 21: Application of an NP-VP parser", "type_str": "figure", "uris": null }, "FIGREF15": { "num": null, "text": "Application of a positive filter", "type_str": "figure", "uris": null }, "FIGREF16": { "num": null, "text": "[NP NP Y,] @-> ~,[VP ... Y,] ;", "type_str": "figure", "uris": null }, "FIGREF17": { "num": null, "text": "Composition of an NP and a VP spotter", "type_str": "figure", "uris": null } } } }