start to add a proper and extensible relationship typology
[scpubgit/stemmatology.git] / base / lib / Text / Tradition / Collation / RelationshipType.pm
1 package Text::Tradition::Collation::RelationshipType;
2
3 use Moose;
4
5 =head1 NAME
6
7 Text::Tradition::Collation::RelationshipType - describes a syntactic,
8 semantic, etc. relationship that can be made between two readings
9
10 =head1 DESCRIPTION
11
12 Text::Tradition is a library for representation and analysis of collated
13 texts, particularly medieval ones.  A relationship connects two readings
14 within a collation, usually when they appear in the same place in different
15 texts.
16
17 =head1 CONSTRUCTOR
18
19 =head2 new
20
21 Creates a new relationship type. Usually called via
22 $collation->register_relationship_type. Options include:
23
24 =over 4
25
26 =item * name - (Required string) The name of this relationship type.
27
28 =item * bindlevel - (Required int) How tightly the relationship binds. A
29 lower number indicates a closer binding. If A and B are related at
30 bindlevel 0, and B and C at bindlevel 1, it implies that A and C have the
31 same relationship as B and C do.
32
33 =item * is_weak - (Default false) Whether this relationship should be
34 replaced silently by a stronger type if requested. This is used primarily
35 for the internal 'collated' relationship, only to be used by parsers.
36
37 =item * is_colocation - (Default true) Whether this relationship implies
38 that the readings in question have parallel locations.
39
40 =item * is_transitive - (Default $self->is_colocation) Whether this
41 relationship type is transitive - that is, if A is related to B and C this
42 way, is B necessarily related to C?
43
44 =item * is_generalizable - Whether this relationship can have a non-local
45 scope.
46
47 =item * record_sub - A subroutine to canonify the reading text before 
48 determining whether individual readings match. Defaults to no canonization.
49
50 =back
51
52 =head1 ACCESSORS
53
54 =head2 name
55
56 =head2 bindlevel
57
58 =head2 is_weak
59
60 =head2 is_colocation
61
62 =head2 is_transitive
63
64 =head2 is_generalizable
65
66 =head2 record_sub
67
68 See the option descriptions above.
69
70 =cut
71
72 has 'name' => (
73         is => 'ro',
74         isa => 'Str',
75         required => 1,
76         );
77         
78 has 'bindlevel' => (
79         is => 'ro',
80         isa => 'Int',
81         required => 1
82         );
83         
84 has 'is_weak' => (
85         is => 'ro',
86         isa => 'Bool',
87         default => 0,
88         );
89         
90 has 'is_colocation' => (
91         is => 'ro',
92         isa => 'Bool',
93         default => 1
94         );
95         
96 has 'is_transitive' => (
97         is => 'ro',
98         isa => 'Bool',
99         default => 1
100         );
101         
102 has 'is_generalizable' => (
103         is => 'ro',
104         isa => 'Bool',
105         lazy => 1,
106         default => sub { $_[0]->is_colocation }
107         );
108         
109 has 'record_sub' => (
110         is => 'ro',
111         isa => 'CodeRef',
112         default => sub { sub { $_[0]->text } }
113         );
114         
115 # TODO Define extra validation conditions here
116         
117 no Moose;
118 __PACKAGE__->meta->make_immutable;
119
120 1;