Add user_traditionlist
[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
c84275ff 7 collated repetition transposition );
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
0fa07e25 51=item * non_correctable - (Optional) True if the reading would not have been
52corrected independently.
22222af9 53
0fa07e25 54=item * non_independent - (Optional) True if the variant is unlikely to have
55occurred independently in unrelated witnesses.
22222af9 56
22222af9 57=back
58
027d819c 59=head1 ACCESSORS
60
61=head2 type
62
63=head2 displayform
64
65=head2 scope
66
4633f9e4 67=head2 annotation
68
027d819c 69=head2 non_correctable
70
71=head2 non_independent
72
73See the option descriptions above.
74
22222af9 75=cut
76
77has 'type' => (
78 is => 'ro',
79 isa => 'RelationshipType',
80 required => 1,
81 );
82
83has 'reading_a' => (
84 is => 'ro',
85 isa => 'Str',
86 required => 1,
87 );
88
89has 'reading_b' => (
90 is => 'ro',
91 isa => 'Str',
92 required => 1,
93 );
94
732e9c4e 95has 'displayform' => (
96 is => 'ro',
97 isa => 'Str',
98 predicate => 'has_displayform',
99 );
100
22222af9 101has 'scope' => (
102 is => 'ro',
103 isa => 'RelationshipScope',
104 default => 'local',
105 );
4633f9e4 106
107has 'annotation' => (
108 is => 'ro',
109 isa => 'Str',
31aaf446 110 predicate => 'has_annotation',
4633f9e4 111 );
22222af9 112
113has 'non_correctable' => (
114 is => 'ro',
115 isa => 'Bool',
116 );
117
118has 'non_independent' => (
119 is => 'ro',
120 isa => 'Bool',
121 );
732e9c4e 122
22222af9 123# A read-only meta-Boolean attribute.
027d819c 124
125=head2 colocated
126
127Returns true if the relationship type is one that requires that its readings
128occupy the same place in the collation.
129
130=cut
131
22222af9 132sub colocated {
133 my $self = shift;
134 return $self->type !~ /^(repetition|transposition)$/;
135}
136
027d819c 137=head2 nonlocal
138
139Returns true if the relationship scope is anything other than 'local'.
140
141=cut
142
22222af9 143sub nonlocal {
144 my $self = shift;
145 return $self->scope ne 'local';
146}
147
148no Moose;
149__PACKAGE__->meta->make_immutable;
150
1511;