Merge branch 'master' into relationships
Tara L Andrews [Sat, 14 Jan 2012 21:53:01 +0000 (22:53 +0100)]
1  2 
lib/Text/Tradition/Collation.pm

@@@ -538,6 -538,7 +538,7 @@@ sub as_graphml 
      my $edi = 0;
      my %edge_data_keys;
      my %edge_data = (
+       class => 'string',                              # Class, deprecated soon
        witness => 'string',                    # ID/label for a path
        relationship => 'string',               # ID/label for a relationship
        extra => 'boolean',                             # Path key
      $sgraph->setAttribute( 'parse.nodes', scalar($self->readings) );
      $sgraph->setAttribute( 'parse.order', 'nodesfirst' );
      
-     my $rgraph = $root->addNewChild( $graphml_ns, 'graph' );
-     $rgraph->setAttribute( 'edgedefault', 'undirected' );
-     $rgraph->setAttribute( 'id', 'relationships' );
-     $rgraph->setAttribute( 'parse.edgeids', 'canonical' );
-     $rgraph->setAttribute( 'parse.edges', scalar($self->relationships) );
-     $rgraph->setAttribute( 'parse.nodeids', 'canonical' );
-     $rgraph->setAttribute( 'parse.nodes', scalar($self->readings) );
-     $rgraph->setAttribute( 'parse.order', 'nodesfirst' );
-     
+     my $rgraph;
+     if( scalar $self->relationships ) {
+               my $rgraph = $root->addNewChild( $graphml_ns, 'graph' );
+               $rgraph->setAttribute( 'edgedefault', 'undirected' );
+               $rgraph->setAttribute( 'id', 'relationships' );
+               $rgraph->setAttribute( 'parse.edgeids', 'canonical' );
+               $rgraph->setAttribute( 'parse.edges', scalar($self->relationships) );
+               $rgraph->setAttribute( 'parse.nodeids', 'canonical' );
+               $rgraph->setAttribute( 'parse.nodes', scalar($self->readings) );
+               $rgraph->setAttribute( 'parse.order', 'nodesfirst' );
+       }
+           
      # Collation attribute data
      foreach my $datum ( @graph_attributes ) {
        my $value = $datum eq 'version' ? '3.0' : $self->$datum;
                        if defined $nval;
          }
          # Add to the relationships graph
-         my $rnode_el = $rgraph->addNewChild( $graphml_ns, 'node' );
-         $rnode_el->setAttribute( 'id', $node_xmlid );
+         if( $rgraph ) {
+                       my $rnode_el = $rgraph->addNewChild( $graphml_ns, 'node' );
+                       $rnode_el->setAttribute( 'id', $node_xmlid );
+         }
      }
  
      # Add the path edges to the sequence graph
                                _add_graphml_data( $edge_el, $edge_data_keys{'extra'}, $aclabel );
                        }
                        _add_graphml_data( $edge_el, $edge_data_keys{'witness'}, $base );
+                       _add_graphml_data( $edge_el, $edge_data_keys{'class'}, 'path' );
                }
        }
        
        # Add the relationship edges to the relationships graph
-       foreach my $e ( sort { $a->[0] cmp $b->[0] } $self->relationships ) {
-               my( $id, $from, $to ) = ( 'e'.$edge_ctr++,
-                                                                       $node_hash{ $e->[0] },
-                                                                       $node_hash{ $e->[1] } );
-               my $edge_el = $rgraph->addNewChild( $graphml_ns, 'edge' );
-               $edge_el->setAttribute( 'source', $from );
-               $edge_el->setAttribute( 'target', $to );
-               $edge_el->setAttribute( 'id', $id );
-               
-               my $data = $self->relations->get_edge_attributes( @$e );
-               # It's a relationship, so save the relationship data
-               _add_graphml_data( $edge_el, $edge_data_keys{'relationship'}, $data->{type} );
-               _add_graphml_data( $edge_el, $edge_data_keys{'colocated'}, $data->{colocated} );
-               if( exists $data->{non_correctable} ) {
-                       _add_graphml_data( $edge_el, $edge_data_keys{'non_correctable'}, 
-                               $data->{non_correctable} );
-               }
-               if( exists $data->{non_independent} ) {
-                       _add_graphml_data( $edge_el, $edge_data_keys{'non_independent'}, 
-                               $data->{non_independent} );
+       if( $rgraph ) {
+               foreach my $e ( sort { $a->[0] cmp $b->[0] } $self->relationships ) {
+                       my( $id, $from, $to ) = ( 'e'.$edge_ctr++,
+                                                                               $node_hash{ $e->[0] },
+                                                                               $node_hash{ $e->[1] } );
+                       my $edge_el = $rgraph->addNewChild( $graphml_ns, 'edge' );
+                       $edge_el->setAttribute( 'source', $from );
+                       $edge_el->setAttribute( 'target', $to );
+                       $edge_el->setAttribute( 'id', $id );
+                       
+                       my $data = $self->relations->get_edge_attributes( @$e );
+                       # It's a relationship, so save the relationship data
+                       _add_graphml_data( $edge_el, $edge_data_keys{'relationship'}, $data->{type} );
+                       _add_graphml_data( $edge_el, $edge_data_keys{'colocated'}, $data->{colocated} );
+                       if( exists $data->{non_correctable} ) {
+                               _add_graphml_data( $edge_el, $edge_data_keys{'non_correctable'}, 
+                                       $data->{non_correctable} );
+                       }
+                       if( exists $data->{non_independent} ) {
+                               _add_graphml_data( $edge_el, $edge_data_keys{'non_independent'}, 
+                                       $data->{non_independent} );
+                       }
+                       _add_graphml_data( $edge_el, $edge_data_keys{'class'}, 'relationship' );
                }
      }
  
@@@ -719,7 -729,7 +729,7 @@@ sub make_alignment_table 
      }
      my $table = { 'alignment' => [], 'length' => $self->end->rank - 1 };
      my @all_pos = ( 1 .. $self->end->rank - 1 );
 -    foreach my $wit ( $self->tradition->witnesses ) {
 +    foreach my $wit ( sort { $a->sigil cmp $b->sigil } $self->tradition->witnesses ) {
        if( $include ) {
                next unless $include->{$wit->sigil};
        }