save and display relationship annotations
[scpubgit/stemmatology.git] / lib / Text / Tradition / Collation / Relationship.pm
CommitLineData
22222af9 1package Text::Tradition::Collation::Relationship;
2
3use Moose;
4use Moose::Util::TypeConstraints;
5
6enum 'RelationshipType' => qw( spelling orthographic grammatical meaning 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
34=item * type - Can be one of spelling, orthographic, grammatical, meaning, lexical, collated, repetition, transposition. All but the last two are only valid relationships between readings that occur at the same point in the text.
35
732e9c4e 36=item * displayform - (Optional) The reading that should be displayed if the related nodes are treated as one.
37
4633f9e4 38=item * scope - (Optional) A meta-attribute. Can be one of 'local', 'document', or 'global'. Denotes whether the relationship between the two readings holds always, independent of context, either within this tradition or across all traditions.
39
40=item * anotation - (Optional) A freeform note to attach to the relationship.
41
22222af9 42=item * non_correctable - (Optional) True if the reading would not have been corrected independently.
43
44=item * non_independent - (Optional) True if the variant is unlikely to have occurred independently in unrelated witnesses.
45
22222af9 46=back
47
027d819c 48=head1 ACCESSORS
49
50=head2 type
51
52=head2 displayform
53
54=head2 scope
55
4633f9e4 56=head2 annotation
57
027d819c 58=head2 non_correctable
59
60=head2 non_independent
61
62See the option descriptions above.
63
22222af9 64=cut
65
66has 'type' => (
67 is => 'ro',
68 isa => 'RelationshipType',
69 required => 1,
70 );
71
72has 'reading_a' => (
73 is => 'ro',
74 isa => 'Str',
75 required => 1,
76 );
77
78has 'reading_b' => (
79 is => 'ro',
80 isa => 'Str',
81 required => 1,
82 );
83
732e9c4e 84has 'displayform' => (
85 is => 'ro',
86 isa => 'Str',
87 predicate => 'has_displayform',
88 );
89
22222af9 90has 'scope' => (
91 is => 'ro',
92 isa => 'RelationshipScope',
93 default => 'local',
94 );
4633f9e4 95
96has 'annotation' => (
97 is => 'ro',
98 isa => 'Str',
31aaf446 99 predicate => 'has_annotation',
4633f9e4 100 );
22222af9 101
102has 'non_correctable' => (
103 is => 'ro',
104 isa => 'Bool',
c84275ff 105 predicate => 'noncorr_set',
22222af9 106 );
107
108has 'non_independent' => (
109 is => 'ro',
110 isa => 'Bool',
c84275ff 111 predicate => 'nonind_set',
22222af9 112 );
732e9c4e 113
22222af9 114# A read-only meta-Boolean attribute.
027d819c 115
116=head2 colocated
117
118Returns true if the relationship type is one that requires that its readings
119occupy the same place in the collation.
120
121=cut
122
22222af9 123sub colocated {
124 my $self = shift;
125 return $self->type !~ /^(repetition|transposition)$/;
126}
127
027d819c 128=head2 nonlocal
129
130Returns true if the relationship scope is anything other than 'local'.
131
132=cut
133
22222af9 134sub nonlocal {
135 my $self = shift;
136 return $self->scope ne 'local';
137}
138
139no Moose;
140__PACKAGE__->meta->make_immutable;
141
1421;