Full text
Geometri data strutures for multihierarhial XML tagging of manusripts Jerzy W. Jaromzyk a ; 1 ,Neil Mo ore a ; 1 , a Deparment of Computer Siene, University of Kentuky, Lexington, KY, USA Abstrat This pap er shows an appliation of omputational geometry methods to the preparation of image-based digital library editions. We present a formalism for desribing non-hierarahial markup of manusripts in terms of oneand two-dimensional geometry. This formalism allows us to use geometri data strutures and algorithms to pro ess marked-up do uments. With this approah we an overome many well-known and inherently diÆult problems with non-hierarhial markup. We present algorithms based on segment trees and range-query strutures for p erforming a number of queries on markup struture. This appliation of omputational geometry data strutures to a new domain also provides insights into novel types of geometri op erations and queries. Some of these tehniques are urrently being used by researhers in the Researh Computing for Humanities pro jet, whih aims to pro due eletroni editions of seleted manusripts from the British Library. 1. Intro dution From a omputational geometry p oint of view, an old manusript, a folio (a sheet of writing material) and the sript (a text on the manusript page) have interesting features in one, two and three dimensions and all of them are imp ortant. Spatial deformations of the folio an be studied for restoration purp oses in three dimensions. Illuminations, damages, restorations, and paleographi features of individual letters an b e studied as two dimensional ob jets. The sript, a sequene of lines of text, an b e viewed as one dimensional as it follows visible or invisible rulings that guide the layout of the text [B94℄. In fat, onneting the image view of a manusript with its transript is typially the rst task. In this pap er we will disuss this linear asp et of folia and we will disuss geometri stru- tures that supp ort its tagging. Extensive tagging or markup is an often exruiating task in the preparation of eletroni editions of manusripts. The tagging pro ess results in a strutured desription of the doument's ontents, its features and attributes in a form that an b e Email addresses: jureks.uky.edu (Jerzy W. Jaromzyk), neils.uky.edu (Neil Mo ore). 1 This researh was supported in part by NSF ITR grant 0219924 used to view and eetively query the edition. The XML (eXtensible Markup Language) is a prevailing format used for desribing literary and artisti work for Digital Libraries. XML les desrib e wellhierarhial strutures (e.g., bo ok, volume, setion, page, line, word and harater) of the do ument and for that reason they an be viewed as rooted trees. Although it seems natural that most douments adhere to suh hierarhies, it is often not true in pratie. Even worse, this happ ens in the ontext of ultural heritage that urgently requires preservation: old and severely damaged manusripts. An image of a damaged folio from Alfred the Great's Old English translation of Bo ethius's Consolation of Philosophy is demonstrated in Figure 1. Words an span more than one line, damages or restorations an overlap words and parts of them. A rather simple ase is illustrated in Figure 2 where in the onvoluted tagging one word spans two lines; as suh, it is not well-formed XML. It has been long reognized that, in spite of its p opularity, XML suers from an inability to en- o de elements that are not in hierarhial relationships [RMD93℄. There are numerous approahes to address this problem alled the onurrent hierarhies problem; see, for example, [B95℄. Mostly these approahes are onerned with tagging tran20th EWCG Seville, Spain (2004)
20th Europ ean Workshop on Computational Geometry Fig. 1. An image of a damaged manusript page Fig. 2. Markup that is not hierarhial sripts (text-based do uments). In our task a manusript or an image of it is the primary soure for preparing an eletroni edition and we need to handle the onurrent hierarhies in geometri ontext of the image. This image-based approah is the most distinguishing aspet of our work. A geometri view of the problem allows us to engage many data strutures, in partiular multidimensional ones. In this paper, we will fo us on two of them: segment trees and a grid based data struture develop ed by Overmars for range queries (we will use it for line segments rather than p oints, though). We will analyze how these strutures supp ort a variety of queries that are essential in the ontext of editing and studying manusripts. There are several ontributions of this pap er. The rst is in applying omputational geometry to a new area. We will present a formalism for onurrent hierarhies that allows us to onnet geometri strutures with XML do uments. Sp eially, we will disuss a numb er of algorithms for querying the struture of a do ument, together with their asymptoti omplexities. 2. Denitions In this setion we desrib e a formalism for representing multihierarhial doument markup. This formalism allows us to onnet the struture of markup with a geometri representation; this allows us to use geometri data strutures and algorithms to pro ess tagged do uments. 2.1. Markup elements We represent a markup element as a tuple ( N ; A; ; ! ) where N is the element name, A (a map from strings to strings) the attributes, and and ! are integers with 1 ! . The interval of a markup element e , written I( e ), is the losed interval [ ( e ) ; ! ( e )℄ N . Definition 2.1 Let e 1 and e 2 be two markup elements. We dene the relations: { e 1 e 2 if ! ( e 1 ) < ( e 2 ) { e 1 e 2 if ( e 1 ) ( e 2 ) and ! ( e 1 ) ! ( e 2 ) and I( e 1 ) 6 = I( e 2 ) . In this ase we say that e 1 is a desendant of e 2 , or equivalently that e 2 is an anestor of e 1 . We state without pro of the following theorems: Theorem 2.1 The relations and eah form a strit partial order. Theorem 2.2 Let e 1 and e 2 be two markup elements. Exatly one of the fol lowing holds: e 1 e 2 ; e 2 e 1 ; e 1 e 2 ; e 2 e 1 ; e 1 overlaps e 2 ; or I( e 1 ) = I( e 2 ) . 3. Hierarhies Definition 3.1 Let E be a nite set of markup elements. E is hierarhial if: { There is an element r 2 E , al led the root, suh that, for eah element e 2 E , e r or e = r { No two elements of E overlap, and no distint elements of E share the same interval. Lemma 3.1 Let E be a hierarhial set of markup elements, and e 2 E . Then either e is the root and has no parents in E , or e is not the root and has exatly one parent in E .
Marh 25-26, 2004 Seville (Spain) Theorem 3.1 Let E be a hierarhial set of markup elements. Let G be a graph on E suh that the edge ( e 1 ; e 2 ) is in G if e 1 is the parent of e 2 . G is a tree. This justies our use of the term \hierarhy". Beause hildren of the same parent annot be desendants of one another, by Theorem 2.2 they an b e ordered by . The tree is therefore an ordered tree. 4. Data strutures and queries In this setion we desrib e two geometri data strutures and apply them to a number of ommon queries on do uments. A segment tree [BW80, PS85℄ is a dynami data struture to represent a set of segments. For insertions and deletions it is assumed that the endp oints b elong to the set of n p oints known in advane. The underlying struture is a balaned binary tree with leaves representing atomi segments. Eah node orresp onds to the union of the atomi segments ro oted in this no des. Intervals that b elong to the olletion represented in the segment tree are assoiated with no des of the tree and satisfy the following prop erty: a no de v stores s if the union of its atomi segments is ontained in s but the union of the atomi segments assoiated with the parent of v do not. Thanks to this prop erty eah segment is represented in at most O (log n ) no des. Insertions and deletions an b e p erformed in O (log n ) time. Also, in the same time one an ount the number of segments in the olletion that in- ludes a given query point. While segment trees are well-suited for some typ es of queries, there are other queries whih segment trees do not p erform as eÆiently. We use a rangequery struture to supp ort these queries. We treat a segment S = [ ; ! ℄ in U = [1 ; M ℄ as a point p ( S )=( ; ! ) in U 2 . We all this representation of (a olletion of ) segments a segment grid . Many prop erties of S then orresp ond to range prop erties of p ( S ) in the segment grid. For example, S T if and only if p ( S ) lies to the lower right of p ( T ). We shall make use of general range queries of the form: nd all points lying in the (losed) retangle b ounded by ( a; b ) and ( ; d ). There exist a number of data strutures supp orting suh queries in a twodimensional grid. A number of these strutures are desrib ed in [O88℄; two are of partiular interest for our purp oses. Theorem 4.1 (Overmars) We an represent n points in U 2 (and thus n segments in U ) using O ( n log n ) spae in suh a way that range queries take O ( k + log log j U j ) time, where k is the number of results returned by the query. This data struture makes use of p erfet hashing, and is therefore slow to build. There is an alternative data struture with slightly worse query time, but signiantly better reation time: Theorem 4.2 (Overmars) We an represent n points in U 2 using O ( n log n ) spae in suh a way that range queries take O k + p log j U j time, where k is the number of returned results. This data struture an be built in O ( n log n ) time. Neither of the range-query data strutures permits eÆient insertion or deletion. For more information on these strutures, see [O88℄. 4.1. Desendant queries A ommon query on do uments is to nd all elements of a ertain typ e that are desendants of a given element e . For example, given a <page> element, one may wish to nd all <damage> elements ontained within that element, either diretly (as hildren) or indiretly. We an p erform this op eration by nding all desendants of e and reporting only those of the requested typ e. Reall from Denition 2.1 that the desendants of e are those elements whih b egin no earlier than e , end no later than e , and do not b oth b egin and end at the same p oint as e . In terms of the segment grid, p (I( x )) is a desendant of e if I( x ) 6 = I( e ) and p (I( x )) lies in the retangle b ounded by the p oints ( ( e ) ; ( e )) and ( ! ( e ) ; ! ( e )). Using the data struture from Theorem 4.2, we an nd all suh p oints in O ( k + p log M ) time, where M is the do ument's maximum oset and k is the number of results. 4.2. Overlap queries Another useful query is: given an element e , nd all elements whih overlap e . If e 1 overlaps e 2 , e 1 ontains at least one of the endp oints of e 2 . Conversely, if e 1 ontains at least one endp oint of e 2 , either e 1 overlaps e 2 , e 1 = e 2 , e 1 e 2 , or e 2 e 1 . This suggests the following: Theorem 4.3 Let D be a doument ontaining the element e . Let k be the number of elements overlapping e , d the number of desendants of e , a the number of anestors of e , and M the maximum o-
20th Europ ean Workshop on Computational Geometry set of D . We an nd al l elements overlapping e in O ( k + d + a + log M ) time. We rst nd the sets B ( e ) and E ( e ) of all elements whose intervals ontain ( e ) and ! ( e ), resp etively, using stabbing queries in a segment tree. B ( e ) ontains at most k + d + a + 1 elements, and likewise for E ( e ). The stabbing queries an therefore b e p erformed in time O ( k + d + a + log M ). We then iterate through the results, rep orting those whih atually overlap e . Testing whether a given segments overlaps e requires onstant time, so this step do es not inrease the omplexity. We an improve on this b ound somewhat by making use of range queries. If e 1 overlaps e 2 , e 1 ontains exatly one endp oint of e 2 . In the segment grid, segments ontaining ( e ) but not ! ( e ) lie in the retangle R b ounded by the p oints (1 ; ( e )) and ( ( e ) ; ! ( e )). Likewise, segments ontaining ! ( e ) but not ( e ) lie in the retangle R ! b ounded by ( ( e ) ; ! ( e )) and ( ! ( e ) ; M ), where M is the maximum oset of the doument. While these retangles ontain all the elements whih overlap e , they do not ontain only suh elements. As with the stabbing queries desribed ab ove, the range queries also return e , and may return some anestors and desendants of e , so we must remove these from the result set. It is lear, however, that the retangles do not ontain any element x suh that x e or e x . Theorem 4.4 Let D be a doument ontaining the element e . Let k be the number of elements overlapping e , d the number of desendants of e , a the number of anestors of e , and M the maximum o- set of D . We an nd al l elements overlapping e in O ( k + d + a + p log M ) time. Eah range query returns at most k + d + a + 1 elements, and an therefore b e p erformed in time O ( k + d + a + p log M ). As with the stabbing query, we then iterate through the results of the range query, rep orting those elements whih overlap e ; again, this do es not aet the overall omplexity of the overlap query. The running time of overlap queries an be improved still further if we impose additional restri- tions on the endpoints of elements: Theorem 4.5 Let D be a doument suh that no two elements share an endpoint in ommon, and let e be an element in D . If k is the number of elements overlapping e and M is the maximum oset of D , we an nd al l elements overlapping e in O ( k + p log M ) time. 5. Conlusion We have presented a formalism that onnets the realm of omputational geometry to algorithmi problems that we have faed in the marking up of image-based eletroni editions. As examples of geometri strutures we have disussed segment trees and range query strutures and have applied them to the well-reognized and inherently diÆult problem of non-hierarhial markup. Twodimensional asp ets of manusript marking, suh as marginalia, paleographi features and damages will involve additional geometri strutures. Aknowledgement The authors aknowledge a partial supp ort from the NSF ARCHway: Arhiteture for Researh in Computing for Humanities through Researh, Teahing and Learning pro jet. We are thankful to Kevin Kiernan, the Bo ethius Pro jet and the British Library Board for allowing us to use the image. We also thank our olleagues from the Researh Computing for Humanities Lab at the University of Kentuky for many useful disussions. Bibliography [B95℄ Barnard, D., et al. Hierarhial Eno ding of Text: Tehnial problem and SGML Solutions, Computers and the Humanities 29/3 (1995) 211-231. [BW80℄ Bentley, J. L., and D. Wo o d. An optimal worst-ase algorithm for reporting intersetions of retangles, IEEE Trans. on Computers C-29 (1980) 571-577. [B94℄ Brown, M. P. Understanding Il luminated Manusripts: a Guide to Tehnial Terms . London: The British Library, 1994. [KJDP03℄ Kiernan, K., J. W. Jaromzyk, A. Dekhtyar, D. C. Porter, et al. The ARCHway Pro jet: Arhiteture for Researh in Computing for Humanities through Researh, Teahing, and Learning. To b e published in Literary and Linguisti Computing , 2003. [O87℄ Overmars, Mark H. EÆient data strutures for range searhing on a grid, J. Algorithms 9 (1988) 254-275. [PS85℄ Preparata, F. P. and M. I. Shamos. Computational Geometry: an Introdution . New York: Springer-Verlag, 1985. [RMD93℄ Renear, A., E. Mylonas, and D. Durand. Rening our Notion of What Text Really Is: The Problem of Overlapping Hierarhies. In Researh in Humanities Computing , eds. N. Ide and S. Ho key. Oxford: Oxford Univeristy Press, 1993. [S99℄ Samet, H.. Multidimensional Data Strutures. In Algorithms and Theory of Computation Handbook , ed. M. J. Atallah. Bo a Raton: CRC Press, 1999. [XML-W3C℄ Bray, T., J. Paoli, C. M. Sp erb erg-MQueen, and E. Maler, eds. Extensible Markup Language (XML) 1.0, W3C Reommendation. http://www.w3.org/TR/2000 / REC-xml-20001006 . W3 Consortium, 2000.