1 package Text::Tradition::Collation::Relationship;
4 use Moose::Util::TypeConstraints;
5 ## CAREFUL in our use of Moose::Util::TypeConstraints. That 'from'
6 ## clashes with Graph::Easy::Edge 'from', so we'll need to unimport
7 ## TypeConstraints after defining the types. Or else we would have to
8 ## finally split out our types into another module.
11 extends 'Graph::Easy::Edge';
13 enum 'RelationshipType' => qw( spelling orthographic grammatical repetition lexical );
15 subtype 'RelationshipVector',
18 && $_->[0]->isa( 'Graph::Easy::Node' )
19 && $_->[1]->isa( 'Graph::Easy::Node' )
21 message { 'Argument should be [ SourceReading, TargetReading ]' };
23 subtype 'RelationshipTokenVector',
25 => where { @$_ == 2 },
26 message { 'Argument should be [ \'source\', \'target\' ]' };
28 no Moose::Util::TypeConstraints; ## see comment above
32 isa => 'RelationshipType',
36 has 'this_relation' => (
38 isa => 'RelationshipVector',
42 has 'primary_relation' => (
44 isa => 'RelationshipTokenVector',
53 has 'non_correctable' => (
58 has 'non_independent' => (
63 sub FOREIGNBUILDARGS {
67 # Make the label match our 'type' attribute.
69 if( exists $args{'type'} ) {
70 push( @superclass_args, 'label', $args{'type'} );
72 return @superclass_args;
76 my( $self, $args ) = @_;
78 $self->set_attribute( 'class', 'relationship' );
80 my( $source, $target ) = @{$self->this_relation};
81 if( $source->has_position && $target->has_position ) {
82 # Harmonize the positions.
83 $source->match_position( $target );
85 unless( $self->primary_relation ) {
86 $self->primary_relation( [ $self->this_relation->[0]->label,
87 $self->this_relation->[1]->label ] );
92 __PACKAGE__->meta->make_immutable;