1 package Text::Tradition::Collation::Relationship;
4 use Moose::Util::TypeConstraints;
6 enum 'RelationshipScope' => [ qw( local document global ) ];
8 no Moose::Util::TypeConstraints;
12 Text::Tradition::Collation::Relationship - represents a syntactic or semantic
13 relationship between two readings
17 Text::Tradition is a library for representation and analysis of collated
18 texts, particularly medieval ones. A relationship connects two readings
19 within a collation, usually when they appear in the same place in different
26 Creates a new relationship. Usually called via $collation->add_relationship.
31 =item * type - Can be one of spelling, orthographic, grammatical, lexical,
32 collated, repetition, transposition. All but the last two are only valid
33 relationships between readings that occur at the same point in the text.
34 The 'collated' relationship should only be used by parsers to align readings
35 in the graph when the input information would otherwise be lost, e.g. from
38 =item * displayform - (Optional) The reading that should be displayed if the
39 related nodes are treated as one.
41 =item * scope - (Optional) A meta-attribute. Can be one of 'local',
42 'document', or 'global'. Denotes whether the relationship between the two
43 readings holds always, independent of context, either within this tradition
44 or across all traditions.
46 =item * annotation - (Optional) A freeform note to attach to the relationship.
48 =item * alters_meaning - Indicate whether, in context, the related words cause
49 the text to have different meanings. Possible values are 0 (no), 1 (slightly),
52 =item * non_correctable - (Optional) True if the reading would not have been
53 corrected independently.
55 =item * non_independent - (Optional) True if the variant is unlikely to have
56 occurred independently in unrelated witnesses.
70 =head2 non_correctable
72 =head2 non_independent
74 See the option descriptions above.
96 has 'displayform' => (
99 predicate => 'has_displayform',
104 isa => 'RelationshipScope',
108 has 'annotation' => (
111 predicate => 'has_annotation',
114 has 'alters_meaning' => (
120 has 'non_correctable' => (
125 has 'non_independent' => (
130 around 'alters_meaning' => sub {
134 if( $_[0] eq 'no' ) {
135 return $self->$orig( 0 );
136 } elsif( $_[0] eq 'slightly' ) {
137 return $self->$orig( 1 );
138 } elsif( $_[0] eq 'yes' ) {
139 return $self->$orig( 2 );
142 return $self->$orig( @_ );
145 # A read-only meta-Boolean attribute.
149 Returns true if the relationship type is one that requires that its readings
150 occupy the same place in the collation.
156 return $self->type !~ /^(repetition|transposition)$/;
161 Returns true if the relationship scope is anything other than 'local'.
167 return $self->scope ne 'local';
170 =head2 is_equivalent( $otherrel )
172 Returns true if the type and scope of $otherrel match ours.
177 my( $self, $other, $check_ann ) = @_;
178 my $oksofar = $self->type eq $other->type && $self->scope eq $other->scope;
180 return $oksofar && $self->annotation eq $other->annotation;
187 __PACKAGE__->meta->make_immutable;