Commit | Line | Data |
22222af9 |
1 | package Text::Tradition::Collation::Relationship; |
2 | |
3 | use Moose; |
4 | use Moose::Util::TypeConstraints; |
5 | |
0fa07e25 |
6 | enum 'RelationshipType' => qw( spelling orthographic grammatical lexical |
c84275ff |
7 | collated repetition transposition ); |
22222af9 |
8 | |
4633f9e4 |
9 | enum 'RelationshipScope' => qw( local document global ); |
22222af9 |
10 | |
11 | no Moose::Util::TypeConstraints; |
12 | |
027d819c |
13 | =head1 NAME |
14 | |
15 | Text::Tradition::Collation::Relationship - represents a syntactic or semantic |
16 | relationship between two readings |
17 | |
18 | =head1 DESCRIPTION |
19 | |
20 | Text::Tradition is a library for representation and analysis of collated |
21 | texts, particularly medieval ones. A relationship connects two readings |
22 | within a collation, usually when they appear in the same place in different |
23 | texts. |
24 | |
25 | =head1 CONSTRUCTOR |
26 | |
27 | =head2 new |
28 | |
29 | Creates a new relationship. Usually called via $collation->add_relationship. |
30 | Options include: |
31 | |
22222af9 |
32 | =over 4 |
33 | |
0fa07e25 |
34 | =item * type - Can be one of spelling, orthographic, grammatical, lexical, |
35 | collated, repetition, transposition. All but the last two are only valid |
36 | relationships between readings that occur at the same point in the text. |
37 | The 'collated' relationship should only be used by parsers to align readings |
38 | in the graph when the input information would otherwise be lost, e.g. from |
39 | an alignment table. |
22222af9 |
40 | |
0fa07e25 |
41 | =item * displayform - (Optional) The reading that should be displayed if the |
42 | related 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 |
46 | readings holds always, independent of context, either within this tradition |
47 | or 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 |
52 | corrected independently. |
22222af9 |
53 | |
0fa07e25 |
54 | =item * non_independent - (Optional) True if the variant is unlikely to have |
55 | occurred 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 | |
73 | See the option descriptions above. |
74 | |
22222af9 |
75 | =cut |
76 | |
77 | has 'type' => ( |
78 | is => 'ro', |
79 | isa => 'RelationshipType', |
80 | required => 1, |
81 | ); |
82 | |
83 | has 'reading_a' => ( |
84 | is => 'ro', |
85 | isa => 'Str', |
86 | required => 1, |
87 | ); |
88 | |
89 | has 'reading_b' => ( |
90 | is => 'ro', |
91 | isa => 'Str', |
92 | required => 1, |
93 | ); |
94 | |
732e9c4e |
95 | has 'displayform' => ( |
96 | is => 'ro', |
97 | isa => 'Str', |
98 | predicate => 'has_displayform', |
99 | ); |
100 | |
22222af9 |
101 | has 'scope' => ( |
102 | is => 'ro', |
103 | isa => 'RelationshipScope', |
104 | default => 'local', |
105 | ); |
4633f9e4 |
106 | |
107 | has 'annotation' => ( |
108 | is => 'ro', |
109 | isa => 'Str', |
31aaf446 |
110 | predicate => 'has_annotation', |
4633f9e4 |
111 | ); |
22222af9 |
112 | |
113 | has 'non_correctable' => ( |
114 | is => 'ro', |
115 | isa => 'Bool', |
116 | ); |
117 | |
118 | has '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 | |
127 | Returns true if the relationship type is one that requires that its readings |
128 | occupy the same place in the collation. |
129 | |
130 | =cut |
131 | |
22222af9 |
132 | sub colocated { |
133 | my $self = shift; |
134 | return $self->type !~ /^(repetition|transposition)$/; |
135 | } |
136 | |
027d819c |
137 | =head2 nonlocal |
138 | |
139 | Returns true if the relationship scope is anything other than 'local'. |
140 | |
141 | =cut |
142 | |
22222af9 |
143 | sub nonlocal { |
144 | my $self = shift; |
145 | return $self->scope ne 'local'; |
146 | } |
147 | |
148 | no Moose; |
149 | __PACKAGE__->meta->make_immutable; |
150 | |
151 | 1; |