From: Tara L Andrews Date: Wed, 26 Sep 2012 21:08:37 +0000 (+0200) Subject: some parser bugfixes / workarounds X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7c2ed85e0a33c3da0137d390fe68626e83b130f3;p=scpubgit%2Fstemmatology.git some parser bugfixes / workarounds --- diff --git a/base/lib/Text/Tradition/Parser/CTE.pm b/base/lib/Text/Tradition/Parser/CTE.pm index d7dc584..f161068 100644 --- a/base/lib/Text/Tradition/Parser/CTE.pm +++ b/base/lib/Text/Tradition/Parser/CTE.pm @@ -138,10 +138,14 @@ sub _remove_formatting { my $parent = $n->parentNode(); my @children = $n->childNodes(); my $first = shift @children; - $parent->replaceChild( $first, $n ); - foreach my $c ( @children ) { - $parent->insertAfter( $c, $first ); - $first = $c; + if( $first ) { + $parent->replaceChild( $first, $n ); + foreach my $c ( @children ) { + $parent->insertAfter( $c, $first ); + $first = $c; + } + } else { + $parent->removeChild( $n ); } } @@ -176,7 +180,7 @@ sub _get_base { # Anchor to mark the end of some apparatus; save its ID. push( @readings, { 'type' => 'anchor', 'content' => $xn->getAttribute( 'xml:id' ) } ); - } elsif ( $xn->nodeName ne 'note' ) { # Any tag we don't know to disregard + } elsif ( $xn->nodeName !~ /^(note|seg)$/ ) { # Any tag we don't know to disregard print STDERR "Unrecognized tag " . $xn->nodeName . "\n"; } return @readings; @@ -414,6 +418,13 @@ sub _expand_all_paths { # Make the path edges $c->make_witness_paths(); + + # Now remove any orphan nodes, and warn that we are doing so. + foreach my $v ( $c->sequence->isolated_vertices ) { + my $r = $c->reading( $v ); + print STDERR "Deleting orphan reading $r / " . $r->text; + $c->del_reading( $r ); + } } sub _add_wit_path { diff --git a/base/lib/Text/Tradition/Parser/JSON.pm b/base/lib/Text/Tradition/Parser/JSON.pm index b32c904..b8e09c7 100644 --- a/base/lib/Text/Tradition/Parser/JSON.pm +++ b/base/lib/Text/Tradition/Parser/JSON.pm @@ -109,7 +109,7 @@ sub parse { my %ac_wits; # Track these for later removal foreach my $sigil ( map { $_->{'witness'} } @{$table->{'alignment'}} ) { my $wit; - if( $tradition->has_witness( $sigil ) { + if( $tradition->has_witness( $sigil ) ) { $wit = $tradition->witness( $sigil ); $wit->is_collated( 1 ); } else {