stemmaweb bugfixes and style fixes; add 'punctuation' relationship type
[scpubgit/stemmatology.git] / lib / Text / Tradition / Collation / Relationship.pm
CommitLineData
22222af9 1package Text::Tradition::Collation::Relationship;
2
3use Moose;
4use Moose::Util::TypeConstraints;
5
0fa07e25 6enum 'RelationshipType' => qw( spelling orthographic grammatical lexical
7b7abf10 7 collated repetition transposition punctuation );
22222af9 8
4633f9e4 9enum 'RelationshipScope' => qw( local document global );
22222af9 10
11no Moose::Util::TypeConstraints;
12
027d819c 13=head1 NAME
14
15Text::Tradition::Collation::Relationship - represents a syntactic or semantic
16relationship between two readings
17
18=head1 DESCRIPTION
19
20Text::Tradition is a library for representation and analysis of collated
21texts, particularly medieval ones. A relationship connects two readings
22within a collation, usually when they appear in the same place in different
23texts.
24
25=head1 CONSTRUCTOR
26
27=head2 new
28
29Creates a new relationship. Usually called via $collation->add_relationship.
30Options include:
31
22222af9 32=over 4
33
0fa07e25 34=item * type - Can be one of spelling, orthographic, grammatical, lexical,
35collated, repetition, transposition. All but the last two are only valid
36relationships between readings that occur at the same point in the text.
37The 'collated' relationship should only be used by parsers to align readings
38in the graph when the input information would otherwise be lost, e.g. from
39an alignment table.
22222af9 40
0fa07e25 41=item * displayform - (Optional) The reading that should be displayed if the
42related nodes are treated as one.
732e9c4e 43
0fa07e25 44=item * scope - (Optional) A meta-attribute. Can be one of 'local',
45'document', or 'global'. Denotes whether the relationship between the two
46readings holds always, independent of context, either within this tradition
47or across all traditions.
4633f9e4 48
0fa07e25 49=item * annotation - (Optional) A freeform note to attach to the relationship.
4633f9e4 50
94654e27 51=item * alters_meaning - Indicate whether, in context, the related words cause
52the text to have different meanings. Possible values are 0 (no), 1 (slightly),
53and >1 (yes).
54
0fa07e25 55=item * non_correctable - (Optional) True if the reading would not have been
56corrected independently.
22222af9 57
0fa07e25 58=item * non_independent - (Optional) True if the variant is unlikely to have
59occurred independently in unrelated witnesses.
22222af9 60
22222af9 61=back
62
027d819c 63=head1 ACCESSORS
64
65=head2 type
66
67=head2 displayform
68
69=head2 scope
70
4633f9e4 71=head2 annotation
72
027d819c 73=head2 non_correctable
74
75=head2 non_independent
76
77See the option descriptions above.
78
22222af9 79=cut
80
81has 'type' => (
82 is => 'ro',
83 isa => 'RelationshipType',
84 required => 1,
85 );
86
87has 'reading_a' => (
88 is => 'ro',
89 isa => 'Str',
90 required => 1,
91 );
92
93has 'reading_b' => (
94 is => 'ro',
95 isa => 'Str',
96 required => 1,
97 );
98
732e9c4e 99has 'displayform' => (
100 is => 'ro',
101 isa => 'Str',
102 predicate => 'has_displayform',
103 );
104
22222af9 105has 'scope' => (
106 is => 'ro',
107 isa => 'RelationshipScope',
108 default => 'local',
109 );
4633f9e4 110
111has 'annotation' => (
112 is => 'ro',
113 isa => 'Str',
31aaf446 114 predicate => 'has_annotation',
4633f9e4 115 );
94654e27 116
117has 'alters_meaning' => (
118 is => 'rw',
119 isa => 'Int',
120 default => 0,
121 );
22222af9 122
123has 'non_correctable' => (
124 is => 'ro',
125 isa => 'Bool',
126 );
127
128has 'non_independent' => (
129 is => 'ro',
130 isa => 'Bool',
131 );
732e9c4e 132
94654e27 133around 'alters_meaning' => sub {
134 my $orig = shift;
135 my $self = shift;
136 if( @_ ) {
137 if( $_[0] eq 'no' ) {
138 return $self->$orig( 0 );
139 } elsif( $_[0] eq 'slightly' ) {
140 return $self->$orig( 1 );
141 } elsif( $_[0] eq 'yes' ) {
142 return $self->$orig( 2 );
143 }
144 }
145 return $self->$orig( @_ );
146};
147
22222af9 148# A read-only meta-Boolean attribute.
027d819c 149
150=head2 colocated
151
152Returns true if the relationship type is one that requires that its readings
153occupy the same place in the collation.
154
155=cut
156
22222af9 157sub colocated {
158 my $self = shift;
159 return $self->type !~ /^(repetition|transposition)$/;
160}
161
027d819c 162=head2 nonlocal
163
164Returns true if the relationship scope is anything other than 'local'.
165
166=cut
167
22222af9 168sub nonlocal {
169 my $self = shift;
170 return $self->scope ne 'local';
171}
172
173no Moose;
174__PACKAGE__->meta->make_immutable;
175
1761;