X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FText%2FTradition%2FParser%2FSelf.pm;h=5499fc711138bc923c8fe7ff66a2bcb4668e1fc5;hb=bf6e338dd676742fbd0c6d88c98795adae40429f;hp=bdadce226c01c3eeb7b16cacaa813b559d1661c6;hpb=adc08836a8f9e1bff3b372c498ac1dcda1100894;p=scpubgit%2Fstemmatology.git diff --git a/lib/Text/Tradition/Parser/Self.pm b/lib/Text/Tradition/Parser/Self.pm index bdadce2..5499fc7 100644 --- a/lib/Text/Tradition/Parser/Self.pm +++ b/lib/Text/Tradition/Parser/Self.pm @@ -202,7 +202,8 @@ sub parse { # Nodes are added via the call to add_reading above. We only need # add the relationships themselves. # TODO check that scoping does trt - foreach my $e ( @{$rel_data->{'edges'}} ) { + $rel_data->{'edges'} ||= []; # so that the next line doesn't break on no rels + foreach my $e ( sort { _layersort_rel( $a, $b ) } @{$rel_data->{'edges'}} ) { my $from = $collation->reading( $e->{'source'}->{'id'} ); my $to = $collation->reading( $e->{'target'}->{'id'} ); delete $e->{'source'}; @@ -230,6 +231,21 @@ sub parse { $collation->text_from_paths(); } +## Return the relationship that comes first in priority. +my %LAYERS = ( + 'collated' => 1, + 'orthographic' => 2, + 'spelling' => 3, + ); + +sub _layersort_rel { + my( $a, $b ) = @_; + my $key = exists $a->{'type'} ? 'type' : 'relationship'; + my $at = $LAYERS{$a->{$key}} || 99; + my $bt = $LAYERS{$b->{$key}} || 99; + return $at <=> $bt; +} + 1; =head1 BUGS / TODO