1 package Text::Tradition::Parser::CTE;
6 use Encode qw/ decode /;
7 use Text::Tradition::Error;
8 use Text::Tradition::Parser::Util qw/ collate_variants /;
10 use XML::LibXML::XPathContext;
13 binmode( STDERR, ':utf8' );
17 Text::Tradition::Parser::CTE
21 Parser module for Text::Tradition, given a TEI file exported from
22 Classical Text Editor.
28 my @apparatus = read( $xml_file );
30 Takes a Tradition object and a TEI file exported from Classical Text
31 Editor using double-endpoint-attachment critical apparatus encoding;
32 initializes the Tradition from the file.
36 my %sigil_for; # Save the XML IDs for witnesses.
37 my %apps; # Save the apparatus XML for a given ID.
38 my %has_ac; # Keep track of witnesses that have corrections.
41 my( $tradition, $opts ) = @_;
42 my $c = $tradition->collation; # Some shorthand
45 $opts->{interpret_transposition} = 1;
47 # First, parse the XML.
48 my( $tei, $xpc ) = _remove_formatting( $opts );
49 return unless $tei; # we have already warned.
51 # CTE uses a DTD rather than any xmlns-based parsing. Thus we
52 # need no namespace handling.
53 # Get the witnesses and create the witness objects.
57 foreach my $wit_el ( $xpc->findnodes( '//sourceDesc/listWit/witness' ) ) {
58 # The witness xml:id is used internally, and is *not* the sigil name.
59 my $id= $wit_el->getAttribute( 'xml:id' );
60 # If the witness element has an abbr element, that is the sigil. Otherwise
61 # the whole thing is the sigil.
62 my $sig = $xpc->findvalue( 'abbr', $wit_el );
63 my $identifier = 'CTE witness';
65 # The sigil is what is in the <abbr/> tag; the identifier is anything
67 $identifier = _tidy_identifier(
68 $xpc->findvalue( 'child::text()', $wit_el ) );
70 my @sig_parts = $xpc->findnodes( 'descendant::text()', $wit_el );
71 $sig = _stringify_sigil( @sig_parts );
73 do_warn( $opts, "Adding witness $sig ($identifier)" );
74 $tradition->add_witness( sigil => $sig, identifier => $identifier,
75 sourcetype => 'collation' );
76 $sigil_for{'#'.$id} = $sig; # Make life easy by keying on the ID ref syntax
79 # Now go through the text and find the base tokens, apparatus tags, and
80 # anchors. Make a giant array of all of these things in sequence.
81 # TODO consider combining this with creation of graph below
83 foreach my $pg_el ( $xpc->findnodes( '/TEI/text/body/p' ) ) {
84 foreach my $xn ( $pg_el->childNodes ) {
85 push( @base_text, _get_base( $xn ) );
88 # We now have to work through this array applying the alternate
89 # apparatus readings to the base text. Essentially we will put
90 # everything on the graph, from which we will delete the apps and
91 # anchors when we are done.
93 # First, put the base tokens, apps, and anchors in the graph. Save the
94 # app siglorum separately as it has to be processed in order.
99 foreach my $item ( @base_text ) {
101 if( $item->{'type'} eq 'token' ) {
102 $r = $c->add_reading( { id => 'n'.$counter++,
103 text => $item->{'content'} } );
104 } elsif ( $item->{'type'} eq 'anchor' ) {
105 $r = $c->add_reading( { id => '__ANCHOR_' . $item->{'content'} . '__',
107 } elsif ( $item->{'type'} eq 'app' ) {
108 my $tag = '__APP_' . $counter++ . '__';
109 $r = $c->add_reading( { id => $tag, is_ph => 1 } );
110 my $app = $item->{'content'};
112 # Apparatus should be differentiable by type attribute; apparently
113 # it is not. Peek at the content to categorize it.
114 # Apparatus criticus is type a1; app siglorum is type a2
115 my @sigtags = $xpc->findnodes( 'descendant::*[name(witStart) or name(witEnd)]', $app );
117 push( @app_sig, $tag );
119 push( @app_crit, $tag );
122 $c->add_path( $last, $r, $c->baselabel );
125 $c->add_path( $last, $c->end, $c->baselabel );
127 # Now we can parse the apparatus entries, and add the variant readings
129 foreach my $app_id ( @app_crit ) {
130 _add_readings( $c, $app_id, $opts );
132 _add_lacunae( $c, @app_sig );
134 # Finally, add explicit witness paths, remove the base paths, and remove
135 # the app/anchor tags.
137 _expand_all_paths( $c, $opts );
138 } catch( Text::Tradition::Error $e ) {
139 throw( $e->message );
144 # Save the text for each witness so that we can ensure consistency
146 unless( $opts->{'nocalc'} ) {
148 $tradition->collation->text_from_paths();
149 $tradition->collation->calculate_ranks();
150 $tradition->collation->flatten_ranks();
151 } catch( Text::Tradition::Error $e ) {
152 throw( $e->message );
159 sub _stringify_sigil {
161 my @parts = grep { /\w/ } map { $_->data } @nodes;
162 my $whole = join( '', @parts );
167 sub _tidy_identifier {
173 # Get rid of all the formatting elements that get in the way of tokenization.
174 sub _remove_formatting {
177 # First, parse the original XML
178 my $parser = XML::LibXML->new();
180 if( exists $opts->{'string'} ) {
181 $doc = $parser->parse_string( $opts->{'string'} );
182 } elsif ( exists $opts->{'file'} ) {
183 $doc = $parser->parse_file( $opts->{'file'} );
184 } elsif ( exists $opts->{'xmlobj'} ) {
185 $doc = $opts->{'xmlobj'};
187 warn "Could not find string or file option to parse";
191 # Second, remove the formatting
192 my $xpc = XML::LibXML::XPathContext->new( $doc->documentElement );
193 my @useless = $xpc->findnodes( '//hi' );
194 foreach my $n ( @useless ) {
195 my $parent = $n->parentNode();
196 my @children = $n->childNodes();
197 my $first = shift @children;
199 $parent->replaceChild( $first, $n );
200 foreach my $c ( @children ) {
201 $parent->insertAfter( $c, $first );
205 $parent->removeChild( $n );
209 # Third, write out and reparse to merge the text nodes.
210 my $enc = $doc->encoding || 'UTF-8';
211 my $result = decode( $enc, $doc->toString() );
212 my $tei = $parser->parse_string( $result )->documentElement;
213 unless( $tei->nodeName =~ /^tei(corpus)?$/i ) {
214 throw( "Parsed document has non-TEI root element " . $tei->nodeName );
216 $xpc = XML::LibXML::XPathContext->new( $tei );
217 return( $tei, $xpc );
220 ## Helper function to help us navigate through nested XML, picking out
221 ## the words, the apparatus, and the anchors.
226 if( $xn->nodeType == XML_TEXT_NODE ) {
227 # Base text, just split the words on whitespace and add them
231 my @tokens = split( /\s+/, $str );
232 push( @readings, map { { type => 'token', content => $_ } } @tokens );
233 } elsif( $xn->nodeName eq 'app' ) {
234 # Apparatus, just save the entire XML node.
235 push( @readings, { type => 'app', content => $xn } );
236 } elsif( $xn->nodeName eq 'anchor' ) {
237 # Anchor to mark the end of some apparatus; save its ID.
238 if( $xn->hasAttribute('xml:id') ) {
239 push( @readings, { type => 'anchor',
240 content => $xn->getAttribute( 'xml:id' ) } );
241 } # if the anchor has no XML ID, it is not relevant to us.
242 } elsif( $xn->nodeName !~ /^(note|seg|milestone|emph)$/ ) { # Any tag we don't know to disregard
243 say STDERR "Unrecognized tag " . $xn->nodeName;
249 my( $list, @tokens ) = @_;
250 if( @$list && $list->[-1]->{'content'} =~ /\#JOIN\#$/ ) {
251 # The list evidently ended mid-word; join the next token onto it.
252 my $t = shift @tokens;
253 if( ref $t && $t->{'type'} eq 'token' ) {
255 $t = $t->{'content'};
257 # An app or anchor intervened; end the word.
258 unshift( @tokens, $t );
261 $list->[-1]->{'content'} =~ s/\#JOIN\#$/$t/;
263 foreach my $t ( @tokens ) {
264 unless( ref( $t ) ) {
265 $t = { 'type' => 'token', 'content' => $t };
272 my( $c, $app_id, $opts ) = @_;
273 my $xn = $apps{$app_id};
274 my $anchor = _anchor_name( $xn->getAttribute( 'to' ) );
276 # Get the lemma, which is all the readings between app and anchor,
277 # excluding other apps or anchors.
278 my @lemma = _return_lemma( $c, $app_id, $anchor );
279 my $lemma_str = join( ' ', map { $_->text } grep { !$_->is_ph } @lemma );
281 # For each reading, send its text to 'interpret' along with the lemma,
282 # and then save the list of witnesses that these tokens belong to.
283 my %wit_rdgs; # Maps from witnesses to the variant text
286 $tag =~ s/^\__APP_(.*)\__$/$1/;
288 foreach my $rdg ( $xn->getChildrenByTagName( 'rdg' ) ) {
289 my @witlist = split( /\s+/, $rdg->getAttribute( 'wit' ) );
291 foreach ( $rdg->childNodes ) {
292 push( @text, _get_base( $_ ) );
294 my( $interpreted, $flag ) = ( '', undef );
296 ( $interpreted, $flag ) = interpret(
297 join( ' ', map { $_->{'content'} } @text ), $lemma_str, $anchor, $opts );
299 next if( $interpreted eq $lemma_str ) && !keys %$flag; # Reading is lemma.
302 if( $interpreted eq '#LACUNA#' ) {
303 push( @rdg_nodes, $c->add_reading( { id => 'r'.$tag.".".$ctr++,
304 is_lacuna => 1 } ) );
305 } elsif( $flag->{'TR'} ) {
306 # Our reading is transposed to after the given string. Look
307 # down the collation base text and try to find it.
308 # The @rdg_nodes should remain blank here, so that the correct
309 # omission goes into the graph.
311 foreach my $w ( split( /\s+/, $interpreted ) ) {
312 my $r = $c->add_reading( { id => 'r'.$tag.".".$ctr++,
314 push( @transp_nodes, $r );
316 if( $anchor && @lemma ) {
317 my $success = _attach_transposition( $c, \@lemma, $anchor,
318 \@transp_nodes, \@witlist, $flag->{'TR'}, $opts );
320 # If we didn't manage to insert the displaced reading,
321 # then restore it here rather than silently deleting it.
322 push( @rdg_nodes, @transp_nodes );
326 foreach my $w ( split( /\s+/, $interpreted ) ) {
327 my $r = $c->add_reading( { id => 'r'.$tag.".".$ctr++,
329 push( @rdg_nodes, $r );
333 # For each listed wit, save the reading.
334 # If an A.C. or P.C. reading is implied rather than explicitly noted,
335 # this is where it will be dealt with.
336 foreach my $wit ( @witlist ) {
337 $wit .= '_ac' if $flag->{'AC'};
338 $wit_rdgs{$wit} = \@rdg_nodes;
339 # If the PC flag is set, there is a corresponding AC that
340 # follows the lemma and has to be explicitly declared.
341 if( $flag->{'PC'} ) {
342 $wit_rdgs{$wit.'_ac'} = \@lemma;
346 # Does the reading have an ID? If so it probably has a witDetail
347 # attached, and we need to read it. If an A.C. or P.C. reading is
348 # declared explicity, this is where it will be dealt with.
349 if( $rdg->hasAttribute( 'xml:id' ) ) {
350 warn "Witdetail on meta reading" if $flag; # this could get complicated.
351 my $rid = $rdg->getAttribute( 'xml:id' );
352 my $xpc = XML::LibXML::XPathContext->new( $xn );
353 my @details = $xpc->findnodes( './witDetail[@target="'.$rid.'"]' );
354 foreach my $d ( @details ) {
355 _parse_wit_detail( $d, \%wit_rdgs, \@lemma );
360 # Now collate the variant readings, since it is not done for us.
361 collate_variants( $c, \@lemma, values %wit_rdgs );
363 # Now add the witness paths for each reading. If we don't have an anchor
364 # (e.g. with an initial witStart) there was no witness path to speak of.
365 foreach my $wit_id ( keys %wit_rdgs ) {
366 my $witstr = _get_sigil( $wit_id, $c->ac_label );
367 my $rdg_list = $wit_rdgs{$wit_id};
368 _add_wit_path( $c, $rdg_list, $app_id, $anchor, $witstr );
375 return sprintf( "__ANCHOR_%s__", $xmlid );
379 my( $c, $app, $anchor ) = @_;
380 my @nodes = grep { $_->id !~ /^__A(PP|NCHOR)/ }
381 $c->reading_sequence( $c->reading( $app ), $c->reading( $anchor ),
386 # Make a best-effort attempt to attach a transposition farther down the line.
387 # $lemmaseq contains the Reading objects of the lemma
388 # $anchor contains the point at which we should start scanning for a match
389 # $rdgseq contains the Reading objects of the transposed reading
390 # (should be identical to the lemma)
391 # $witlist contains the list of applicable witnesses
392 # $reftxt contains the text to match, after which the $rdgseq should go.
393 sub _attach_transposition {
394 my( $c, $lemmaseq, $anchor, $rdgseq, $witlist, $reftxt, $opts ) = @_;
395 my @refwords = split( /\s+/, $reftxt );
396 my $checked = $c->reading( $anchor );
399 while( $checked ne $c->end && !$found ) {
400 my $next = $c->next_reading( $checked, $c->baselabel );
401 if( $next->text eq $refwords[0] ) {
402 # See if the entire sequence of words matches.
404 foreach my $w ( 1..$#refwords ) {
405 $found = $c->next_reading( $next, $c->baselabel );
406 unless( $found->text eq $refwords[$w] ) {
415 # The $found variable should now contain the reading after which we
416 # should stick the transposition.
417 my $fnext = $c->next_reading( $found, $c->baselabel );
418 my $aclabel = $c->ac_label;
419 foreach my $wit_id ( @$witlist ) {
420 my $witstr = _get_sigil( $wit_id, $aclabel );
421 _add_wit_path( $c, $rdgseq, $found->id, $fnext->id, $witstr );
423 # ...and add the transposition relationship between lemma and rdgseq.
424 if( @$lemmaseq == @$rdgseq ) {
425 foreach my $i ( 0..$#{$lemmaseq} ) {
426 $c->add_relationship( $lemmaseq->[$i], $rdgseq->[$i],
427 { type => 'transposition', annotation => 'Detected by CTE' } );
431 throw( "Lemma at $found and transposed sequence different lengths?!" );
434 do_warn( $opts, "WARNING: Unable to find $reftxt in base text for transposition" );
439 =head2 interpret( $reading, $lemma )
441 Given a string in $reading and a corresponding lemma in $lemma, interpret what
442 the actual reading should be. Used to deal with apparatus-ese shorthands for
443 marking transpositions, prefixed or suffixed words, and the like.
448 # A utility function to change apparatus-ese into a full variant.
449 my( $reading, $lemma, $anchor, $opts ) = @_;
450 return $reading if $reading eq $lemma;
451 my $oldreading = $reading;
452 # $lemma =~ s/\s+[[:punct:]]+$//;
453 my $flag = {}; # To pass back extra info about the interpretation
454 my @words = split( /\s+/, $lemma );
455 # Discard any 'sic' notation - that rather goes without saying.
456 $reading =~ s/([[:punct:]]+)?sic([[:punct:]]+)?//g;
458 # Now look for common jargon.
459 if( $reading =~ /^(.*) praem.$/ || $reading =~ /^praem\. (.*)$/ ) {
460 $reading = "$1 $lemma";
461 } elsif( $reading =~ /^(.*) add.$/ || $reading =~ /^add\. (.*)$/ ) {
462 $reading = "$lemma $1";
463 } elsif( $reading =~ /locus [uv]acuus/
464 || $reading eq 'def.'
465 || $reading eq 'illeg.'
466 || $reading eq 'desunt'
468 $reading = '#LACUNA#';
469 } elsif( $reading eq 'om.' ) {
471 } elsif( $reading =~ /^in[uv]\.$/
472 || $reading =~ /^tr(ans(p)?)?\.$/ ) {
473 # Hope it is two words.
474 do_warn( $opts, "WARNING: want to invert a lemma that is not two words" )
475 unless scalar( @words ) == 2;
476 $reading = join( ' ', reverse( @words ) );
477 } elsif( $reading =~ /^iter(\.|at)$/ ) {
479 $reading = "$lemma $lemma";
480 } elsif( $reading =~ /^(.*?)\s*\(?in marg\.\)?$/ ) {
483 # The given text is a correction.
486 # The lemma itself was the correction; the witness carried
487 # no reading pre-correction.
490 } elsif( $reading =~ /^(.*) \.\.\. (.*)$/ ) {
491 # The first and last N words captured should replace the first and
492 # last N words of the lemma.
493 my @begin = split( /\s+/, $1 );
494 my @end = split( /\s+/, $2 );
495 if( scalar( @begin ) + scalar ( @end ) > scalar( @words ) ) {
496 # Something is wrong and we can't do the splice.
497 throw( "$lemma is too short to accommodate $oldreading" );
499 splice( @words, 0, scalar @begin, @begin );
500 splice( @words, -(scalar @end), scalar @end, @end );
501 $reading = join( ' ', @words );
503 } elsif( $opts->{interpret_transposition} &&
504 ( $reading =~ /^post\s*(?<lem>.*?)\s+tr(ans(p)?)?\.$/ ||
505 $reading =~ /^tr(ans(p)?)?\. post\s*(?<lem>.*)$/) ) {
506 # Try to deal with transposed readings
508 say STDERR "Will attempt transposition: $reading at $anchor";
510 $flag->{'TR'} = $+{lem};
512 return( $reading, $flag );
515 sub _parse_wit_detail {
516 my( $detail, $readings, $lemma ) = @_;
517 my $wit = $detail->getAttribute( 'wit' );
518 my $content = $detail->textContent;
519 if( $content =~ /^a\.?\s*c(orr)?\.$/ ) {
520 # Replace the key in the $readings hash
521 my $rdg = delete $readings->{$wit};
522 $readings->{$wit.'_ac'} = $rdg;
523 $has_ac{$sigil_for{$wit}} = 1;
524 } elsif( $content =~ /^p\.?\s*c(orr)?\.$/ || $content =~ /^s\.?\s*l\.$/ ) {
525 # If no key for the wit a.c. exists, add one pointing to the lemma
526 unless( exists $readings->{$wit.'_ac'} ) {
527 $readings->{$wit.'_ac'} = $lemma;
529 $has_ac{$sigil_for{$wit}} = 1;
530 } else { #...not sure what it is?
531 say STDERR "WARNING: Unrecognized sigil annotation $content";
536 my( $c, @app_id ) = @_;
537 # Go through the apparatus entries in order, noting where to start and stop our
541 foreach my $tag ( @app_id ) {
542 my $app = $apps{$tag};
543 # Find the anchor, if any. This marks the point where the text starts
545 my $anchor = $app->getAttribute( 'to' );
549 $aname = _anchor_name( $anchor );
552 foreach my $rdg ( $app->getChildrenByTagName( 'rdg' ) ) {
553 my @witlist = map { _get_sigil( $_, $c->ac_label ) }
554 split( /\s+/, $rdg->getAttribute( 'wit' ) );
555 my @start = $rdg->getChildrenByTagName( 'witStart' );
556 my @end = $rdg->getChildrenByTagName( 'witEnd' );
557 if( @start && @end ) {
558 throw( "App sig entry at $anchor has both witStart and witEnd!" );
560 if( @start && $anchor &&
561 $c->prior_reading( $aname, $c->baselabel ) ne $c->start ) {
562 # We are picking back up after a hiatus. Find the last end and
563 # add a lacuna link between there and here.
564 foreach my $wit ( @witlist ) {
565 my $stoppoint = delete $lacunose{$wit};
566 my $stopname = $stoppoint ? _anchor_name( $stoppoint ) : $c->start->id;
567 say STDERR "Adding lacuna for $wit between $stopname and $anchor";
568 my $lacuna = $c->add_reading( { id => "as_$anchor.".$ctr++,
570 _add_wit_path( $c, [ $lacuna ], $stopname, $aname, $wit );
572 } elsif( @end && $anchor &&
573 $c->next_reading( $aname, $c->baselabel ) ne $c->end ) {
574 # We are stopping. If we've already stopped for the given witness,
575 # flag an error; otherwise record the stopping point.
576 foreach my $wit ( @witlist ) {
577 if( $lacunose{$wit} ) {
578 throw( "Trying to end $wit at $anchor when already ended at "
581 $lacunose{$wit} = $anchor;
587 # For whatever remains in the %lacunose hash, add a lacuna between that spot and
588 # $c->end for each of the witnesses.
589 foreach my $wit ( keys %lacunose ) {
590 next unless $lacunose{$wit};
591 my $aname = _anchor_name( $lacunose{$wit} );
592 say STDERR "Adding lacuna for $wit from $aname to end";
593 my $lacuna = $c->add_reading( { id => 'as_'.$lacunose{$wit}.'.'.$ctr++,
595 _add_wit_path( $c, [ $lacuna ], $aname, $c->end, $wit );
600 my( $xml_id, $layerlabel ) = @_;
601 if( $xml_id =~ /^(.*)_ac$/ ) {
603 return $sigil_for{$real_id} . $layerlabel;
605 return $sigil_for{$xml_id};
609 sub _expand_all_paths {
610 my( $c, $opts ) = @_;
612 # Walk the collation and fish out the paths for each witness
613 foreach my $wit ( $c->tradition->witnesses ) {
614 my $sig = $wit->sigil;
615 my @path = grep { !$_->is_ph }
616 $c->reading_sequence( $c->start, $c->end, $sig );
617 $wit->path( \@path );
618 if( $has_ac{$sig} ) {
619 my @ac_path = grep { !$_->is_ph }
620 $c->reading_sequence( $c->start, $c->end, $sig.$c->ac_label );
621 $wit->uncorrected_path( \@ac_path );
626 foreach my $anchor ( grep { $_->is_ph } $c->readings ) {
627 $c->del_reading( $anchor );
629 # Delete the base edges
630 map { $c->del_path( $_, $c->baselabel ) } $c->paths;
632 # Make the path edges
633 $c->make_witness_paths();
635 # Now remove any orphan nodes, and warn that we are doing so.
637 while( $c->sequence->predecessorless_vertices > 1 ) {
638 foreach my $v ( $c->sequence->predecessorless_vertices ) {
639 my $r = $c->reading( $v );
640 next if $r->is_start;
642 $tag =~ s/^r(\d+)\.\d+/$1/;
643 do_warn( $opts, "Deleting orphan reading $r / " . $r->text );
644 push( @{$suspect_apps{$tag}}, $r->id ) if $tag =~ /^\d+$/;
645 $c->del_reading( $r );
648 if( $c->sequence->successorless_vertices > 1 ) {
649 my @bad = grep { $_ ne $c->end->id } $c->sequence->successorless_vertices;
652 next unless $tag =~ /^r/;
653 $tag =~ s/^r(\d+)\.\d+/$1/;
654 push( @{$suspect_apps{$tag}}, $_ );
656 _dump_suspects( $opts, %suspect_apps );
657 throw( "Remaining hanging readings: @bad" );
659 _dump_suspects( $opts, %suspect_apps ) if keys %suspect_apps;
663 my( $c, $rdg, $app, $anchor, $wit ) = @_;
665 push( @nodes, $c->reading( $anchor ) );
667 my $cur = $c->reading( $app );
668 foreach my $n ( @nodes ) {
669 $c->add_path( $cur, $n, $wit );
677 my @warning = "Suspect apparatus entries:";
678 foreach my $suspect ( sort { $a <=> $b } keys %list ) {
679 my @badrdgs = @{$list{$suspect}};
680 push( @warning, _print_apparatus( $suspect ) );
681 push( @warning, "\t(Linked to readings @badrdgs)" );
683 do_warn( $opts, join( "\n", @warning ) );
686 sub _print_apparatus {
688 my $tag = '__APP_' . $appid . '__';
689 my $app = $apps{$tag};
691 # Interpret the XML - get the lemma and readings and print them out.
692 my $xpc = XML::LibXML::XPathContext->new( $app );
693 my $anchor = $app->getAttribute('to');
695 # We have a lemma, so we construct it.
697 $appstring .= "(Anchor $anchor) ";
700 last if $curr->nodeType eq XML_ELEMENT_NODE
701 && $curr->hasAttribute( 'xml:id' )
702 && $curr->getAttribute( 'xml:id' ) eq $anchor;
703 $appstring .= $curr->data if $curr->nodeType eq XML_TEXT_NODE;
704 $curr = $curr->nextSibling;
709 foreach my $rdg_el ( $xpc->findnodes( 'child::rdg' ) ) {
713 foreach my $child_el ( $rdg_el->childNodes ) {
714 if( $child_el->nodeType eq XML_TEXT_NODE ) {
715 $rdgtext .= $child_el->data;
716 } elsif( $child_el->nodeName =~ /^wit(Start|End)$/ ) {
717 my $startend = lc( $1 );
718 } elsif( $child_el->nodeName eq 'witDetail' ) {
719 foreach my $wit ( map { _get_sigil( $_ ) }
720 split( /\s+/, $child_el->getAttribute('wit') ) ) {
721 $detail{$wit} = $child_el->textContent;
727 foreach my $witrep ( map { _get_sigil( $_ ) }
728 split( /\s+/, $rdg_el->getAttribute('wit') ) ) {
729 if( exists $detail{$witrep} ) {
730 $witrep .= '(' . $detail{$witrep} . ')'
732 if( $startend eq 'start' ) {
733 $witrep = '*' . $witrep;
734 } elsif( $startend eq 'end' ) {
737 push( @witlist, $witrep );
739 $rdgtext .= " @witlist";
740 push( @readings, $rdgtext );
742 $appstring .= join( ' ', @readings );
747 my( $opts, $message ) = @_;
748 if( $opts->{'warnings_to'} ) {
749 push( @{$opts->{'warnings_to'}}, $message );
756 Text::Tradition::Error->throw(
757 'ident' => 'Parser::CTE error',
764 This package is free software and is provided "as is" without express
765 or implied warranty. You can redistribute it and/or modify it under
766 the same terms as Perl itself.
770 Tara L Andrews, aurum@cpan.org