Phonology/Syllable.pm

filter: Statementstmt 95.8% 210 / 219 Branchbran 88.6% 78 / 88 Conditioncond 86.3% 57 / 66 MC/DCmcdc 70.5% 24 / 34 Subroutinesub 91.6% 44 / 48 Podpod 77.7% 7 / 9 totaltotal 90.5% 420 / 464 CC 76 SCAR 16.3
CC
76
Cov
92%
syllabify
12.3
__ANON__
8.0
__ANON__
8.0
CRAP 5.1
« Phonology/Features.pm ↑ Summary Phonology/Segment/Boundary.pm »
1 #!/usr/bin/perl
2  
3 package Lingua::Phonology::Syllable;
4  
5 =head1 NAME
6  
7 Lingua::Phonology::Syllable;
8  
9 =head1 SYNOPSIS
10  
11 use Lingua::Phonology;
12 use Lingua::Phonology::Syllable;
13  
14 my $phono = Lingua::Phonology->new();
15 $phono->features->loadfile;
16 $phono->symbols->loadfile;
17  
18 # Create a new Syllable object
19 my $syll = new Lingua::Phonology::Syllable;
20  
21 # Create an input word
22 my @word = $phono->symbols->segment('t','a','k','r','o','t');
23  
24 # Allow onset clusters and simple codas
25 $syll->set_complex_onset;
26 $syll->set_coda;
27  
28 # Syllabify the word
29 $syll->syllabify(@word);
30  
31 my $count = $syll->count_syll;
32 print "Count: $count\n"; # prints "Count: 2"
33  
34 # @word now has features set to indicate a syllabification of
35 # <ta><krot>
36  
37 =head1 DESCRIPTION
38  
39 Syllabifies an input word of Lingua::Phonology::Segment objects according
40 to a set of parameters. The parameters used are well-known linguistic
41 parameters, so most kinds of syllabification can be handled in just a few
42 lines of code by setting the appropriate values.
43  
44 This module uses a special set of features to indicate syllabification. These
45 features are added to the feature set of the input segments. The features added
46 are arranged in a heirarchy as follows:
47  
48 SYLL scalar Non-zero if the segment has been syllabified
49 |-onset privative True if the segment is part of the onset
50 |-Rime privative True if the segment is part of the Rime (i.e. nucleus or coda)
51 |-nucleus privative True if the segment is the nucleus
52 |-coda privative True if the segment is part of the coda
53 SON scalar An integer indicating the calculated sonority of the segment
54  
55 The module will set these features so that subsequent processing by
56 Lingua::Phonology::Rules will correctly split the word up into domains or tiers
57 on these features.
58  
59 The algorithm and parameters used to syllabify an input word are described
60 in the L<"ALGORITHM"> and L<"PARAMETERS"> sections.
61  
62 =cut
63  
64 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 8 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 8 ▶use Lingua::Phonology::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 8 ▶use Lingua::Phonology::Rules;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 8 ▶use Lingua::Phonology::Functions qw/adjoin flat_adjoin/;
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 8 our $VERSION = 0.3;
73  
74 2 ▶sub err ($) { _err($_[0]) if warnings::enabled() };
Subroutine err: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 2 2
75  
76 # Build accessors for our properties. Hashes in name => default format
77 8 our %bool = (
78 onset => 1,
79 complex_onset => 0,
80 coda => 0,
81 complex_coda => 0
82 );
83 8 for my $name (keys %bool) {
84 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
85 226 ▶ *$name = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
86 226 my $self = shift;
87 226 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 117 109 226
88 117 ▶ if ($_[0]) { $self->{ATTR}->{$name} = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) { } 44 73 117
89 73 else { $self->{ATTR}->{$name} = 0; }
90 }
91 226 return $self->{ATTR}->{$name};
92 32 };
93 13 ▶ *{"set_$name"} = sub { (shift)->$name(1) };
Subroutine __ANON__: called CC=1 SCAR=0.0
94 8 ▶ *{"no_$name"} = sub { (shift)->$name(0) };
Subroutine __ANON__: called CC=1 SCAR=0.0
95 }
96  
97 8 our %int = (
98 min_coda_son => 0,
99 onset_son_dist => 1,
100 coda_son_dist => 1,
101 max_edge_son => 100,
102 min_nucl_son => 3
103 );
104 8 for my $name (keys %int) {
105 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
106 461 ▶ *$name = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
107 461 my $self = shift;
108 461 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 109 352 461
109 109 $self->{ATTR}->{$name} = int shift;
110 }
111 461 return $self->{ATTR}->{$name};
112 40 };
113 }
114  
115 8 our %hash = (
116 sonorous => { sonorant => 1,
117 approximant => 1,
118 aperture => 1,
119 vocoid => 1 }
120 );
121 8 for my $name (keys %hash) {
122 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
123 163 ▶ *$name = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
124 163 my $self = shift;
125 163 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 23 140 163
126 23 my $href = shift;
127 23 ▶ return err "Argument to $name() must be a hash reference" unless _is($href, 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless &_is($href, "HASH") 1 22 23
128 22 $self->{ATTR}->{$name} = $href;
129 }
130 162 return $self->{ATTR}->{$name};
131 8 };
132 }
133  
134 our %code = (
135 113 ▶ clear_seg => sub {1},
Subroutine __ANON__: called CC=1 SCAR=0.0
136 0 ▶ begin_adjoin => sub {0},
Subroutine __ANON__: not called CC=1 SCAR=6.9
137 0 ▶ end_adjoin => sub {0}
Subroutine __ANON__: not called CC=1 SCAR=6.9
138 8 );
139 8 for my $name (keys %code) {
140 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
141 238 ▶ *$name = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
142 238 my $self = shift;
143 238 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 69 169 238
144 69 my $cref = shift;
145 69 ▶ return err "Argument to $name must be a code reference" unless _is($cref, 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
unless &_is($cref, "CODE") 0 69 69
146 69 $self->{ATTR}->{$name} = $cref;
147 }
148 238 return $self->{ATTR}->{$name};
149 24 };
150 }
151
152 18 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
153 18 my $proto = shift;
154 18 ▶ my $class = ref($proto) || $proto;
Condition66%2/3
ref $proto || $proto
l!l&&r!l&&!r
1170
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table66%2/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
155 18 my $self = bless { RULES => new Lingua::Phonology::Rules, ATTR => {} }, $class;
156
157 # Initialize $self w/ defaults
158 18 $self->$_($bool{$_}) for keys(%bool);
159 18 $self->$_($int{$_}) for keys(%int);
160 18 $self->$_($hash{$_}) for keys(%hash);
161 18 $self->$_($code{$_}) for keys(%code);
162
163 # Prepare the rules. This is the most important part
164 8 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
165 $self->{RULES}->add_rule(
166 # Calculate all sonorities
167 CalcSon => {
168 138 ▶ do => sub { $_[0]->SON($self->sonority($_[0])) }
Subroutine __ANON__: called CC=1 SCAR=0.0
169 },
170  
171 # Clear old syllabification
172 Clear => {
173 138 ▶ where => sub { $self->clear_seg->(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
174 125 ▶ do => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
175 125 $_[0]->delink('SYLL', 'onset', 'Rime', 'nucleus', 'coda');
176 }
177 },
178  
179 # Make CV syllables
180 CoreSyll => {
181 138 ▶ where => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
182 138 my $son = $_[0]->SON;
183 138 ▶ return 0 if defined $_[0]->SYLL;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0]->SYLL 25 113 138
184 return (
185 113 ▶ ($son > $self->max_edge_son) || # Can't be an edge OR
Condition100%9/9
$son > $self->max_edge_son || $son >= $self->min_nucl_son && ($son >= $_[-1]->SON && $son >= $_[1]->SON)
l!l&&r!l&&!r
93470
$son >= $self->min_nucl_son and ($son >= $_[-1]->SON and $son >= $_[1]->SON)
!ll&&!rl&&r
66434
$son >= $_[-1]->SON and $son >= $_[1]->SON
!ll&&!rl&&r
2234
MC/DC100%4/4
$son > $self->max_edge_son || $son >= $self->min_nucl_son && ($son >= $_[-1]->SON && $son >= $_[1]->SON)
$son > $self->max_edge_son $son >= $self->min_nucl_son $son >= $_[-1]->SON $son >= $_[1]->SON
Truth table100%5/5
A || B and C and D
A= $son > $self->max_edge_sonB= $son >= $self->min_nucl_sonC= $son >= $_[-1]->SOND= $son >= $_[1]->SON
ABCDresult
1XXX1
01111
00XX0
010X0
01100
186 (
187 ($son >= $self->min_nucl_son) && # Is allowed to be a nucleus AND
188 ($son >= $_[-1]->SON && $son >= $_[1]->SON) # Is a local sonority peak
189 )
190 );
191 },
192 43 ▶ do => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
193 43 $_[0]->nucleus(1); $_[0]->Rime(1); $_[0]->SYLL(1); # Make yourself a nucleus
194 # Make preceding C an onset if . . .
195 43 ▶ if ( $self->onset # onsets allowed
Branch: 1 branch
BranchTrueFalseTotal
if ($self->onset and $_[-1]->SON <= $_[0]->SON and $_[-1]->SON <= $self->max_edge_son and not $_[-1]->SYLL) 23 20 43
Condition88%8/9
$self->onset and $_[-1]->SON <= $_[0]->SON and $_[-1]->SON <= $self->max_edge_son and not $_[-1]->SYLL
!ll&&!rl&&r
16423
$self->onset and $_[-1]->SON <= $_[0]->SON and $_[-1]->SON <= $self->max_edge_son
!ll&&!rl&&r
13327
$self->onset and $_[-1]->SON <= $_[0]->SON
!ll&&!rl&&r
13030
MC/DC75%3/4
$self->onset and $_[-1]->SON <= $_[0]->SON and $_[-1]->SON <= $self->max_edge_son and not $_[-1]->SYLL
$self->onset $_[-1]->SON <= $_[0]->SON $_[-1]->SON <= $self->max_edge_son not $_[-1]->SYLL
Truth table80%4/5
A and B and C and not(D)
A= $self->onsetB= $_[-1]->SON <= $_[0]->SONC= $_[-1]->SON <= $self->max_edge_sonD= not $_[-1]->SYLL
ABCDresult
0XXX0
10XX0
110X0
11100
11111
196 && $_[-1]->SON <= $_[0]->SON # less sonorous than you AND
197 && $_[-1]->SON <= $self->max_edge_son # allowed to be non-nucleus AND
198 && not $_[-1]->SYLL # not already syllabified
199 ) {
200 23 $_[-1]->onset(1); flat_adjoin('SYLL', $_[0], $_[-1]);
201 }
202 }
203 },
204  
205 ComplexOnset => {
206 direction => 'leftward',
207 102 ▶ where => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
208 102 ▶ (not $_[0]->SYLL) # not yet syllabified
Branch: 1 branch
BranchTrueFalseTotal
not $_[0]->SYLL and $_[1]->onset and $_[0]->SON <= $self->max_edge_son and $_[1]->SON - $_[0]->SON >= $self->min_son_dist 18 84 102
Condition83%5/6
not $_[0]->SYLL and $_[1]->onset and $_[0]->SON <= $self->max_edge_son
!ll&&!rl&&r
84018
not $_[0]->SYLL and $_[1]->onset
!ll&&!rl&&r
562818
MC/DC66%2/3
not $_[0]->SYLL and $_[1]->onset and $_[0]->SON <= $self->max_edge_son
not $_[0]->SYLL $_[1]->onset $_[0]->SON <= $self->max_edge_son
Truth table75%3/4
not(A) and B and C
A= not $_[0]->SYLLB= $_[1]->onsetC= $_[0]->SON <= $self->max_edge_son
ABCresult
0XX0
10X0
1100
1111
209 && $_[1]->onset # following seg is an onset
210 && $_[0]->SON <= $self->max_edge_son # this can be an onset
211 && (($_[1]->SON - $_[0]->SON) >= $self->min_son_dist) # sonority distance respected
212 },
213 10 ▶ do => sub { adjoin('onset', $_[1], $_[0]); flat_adjoin('SYLL', $_[1], $_[0]); }
Subroutine __ANON__: called CC=1 SCAR=0.0
214 },
215  
216 Coda => {
217 94 ▶ where => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
218 94 ▶ (not $_[0]->onset) # not an onset
Branch: 1 branch
BranchTrueFalseTotal
not $_[0]->onset and $_[-1]->nucleus and $_[0]->SON <= $self->max_edge_son and $_[0]->SON >= $self->min_coda_son 16 78 94
Condition100%6/6
not $_[0]->onset and $_[-1]->nucleus and $_[0]->SON <= $self->max_edge_son
!ll&&!rl&&r
75316
not $_[0]->onset and $_[-1]->nucleus
!ll&&!rl&&r
284719
MC/DC100%3/3
not $_[0]->onset and $_[-1]->nucleus and $_[0]->SON <= $self->max_edge_son
not $_[0]->onset $_[-1]->nucleus $_[0]->SON <= $self->max_edge_son
Truth table100%4/4
not(A) and B and C
A= not $_[0]->onsetB= $_[-1]->nucleusC= $_[0]->SON <= $self->max_edge_son
ABCresult
0XX0
10X0
1100
1111
219 && $_[-1]->nucleus # follows a nucleus
220 && $_[0]->SON <= $self->max_edge_son # allowed to be an edge
221 && $_[0]->SON >= $self->min_coda_son # allowed to be a coda
222 },
223 16 ▶ do => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
224 16 $_[0]->coda(1);
225 16 $_[0]->delink('nucleus');
226 16 flat_adjoin('Rime', $_[-1], $_[0]);
227 16 flat_adjoin('SYLL', $_[-1], $_[0]);
228 }
229 },
230  
231 ComplexCoda => {
232 direction => 'rightward',
233 91 ▶ where => sub {
Subroutine __ANON__: called CC=5 SCAR=16.3
234 91 ▶ (not $_[0]->SYLL)
Branch: 1 branch
BranchTrueFalseTotal
not $_[0]->SYLL and $_[-1]->coda and $_[0]->SON <= $self->max_edge_son and $_[0]->SON >= $self->min_coda_son and $_[-1]->SON - $_[0]->SON >= $self->min_son_dist 7 84 91
Condition77%7/9
not $_[0]->SYLL and $_[-1]->coda and $_[0]->SON <= $self->max_edge_son and $_[0]->SON >= $self->min_coda_son
!ll&&!rl&&r
8407
not $_[0]->SYLL and $_[-1]->coda and $_[0]->SON <= $self->max_edge_son
!ll&&!rl&&r
8407
not $_[0]->SYLL and $_[-1]->coda
!ll&&!rl&&r
72127
MC/DC50%2/4
not $_[0]->SYLL and $_[-1]->coda and $_[0]->SON <= $self->max_edge_son and $_[0]->SON >= $self->min_coda_son
not $_[0]->SYLL $_[-1]->coda $_[0]->SON <= $self->max_edge_son $_[0]->SON >= $self->min_coda_son
Truth table60%3/5
not(A) and B and C and D
A= not $_[0]->SYLLB= $_[-1]->codaC= $_[0]->SON <= $self->max_edge_sonD= $_[0]->SON >= $self->min_coda_son
ABCDresult
0XXX0
10XX0
110X0
11100
11111
235 && $_[-1]->coda
236 && $_[0]->SON <= $self->max_edge_son
237 && $_[0]->SON >= $self->min_coda_son
238 && (($_[-1]->SON - $_[0]->SON) >= $self->min_son_dist)
239 },
240 1 ▶ do => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
241 1 adjoin('coda', $_[-1], $_[0]);
242 1 flat_adjoin('Rime', $_[-1], $_[0]);
243 1 flat_adjoin('SYLL', $_[-1], $_[0])
244 }
245 },
246  
247 BeginAdjoin => {
248 direction => 'leftward',
249 36 ▶ where => sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
250 36 ▶ my $cond1 = 1 if ((not $_[0]->SYLL) && $_[1]->onset && $self->begin_adjoin->(@_));
Branch: 1 branch
BranchTrueFalseTotal
if not $_[0]->SYLL and $_[1]->onset and $self->begin_adjoin->(@_) 1 35 36
Condition83%5/6
not $_[0]->SYLL and $_[1]->onset and $self->begin_adjoin->(@_)
!ll&&!rl&&r
3501
not $_[0]->SYLL and $_[1]->onset
!ll&&!rl&&r
3231
MC/DC66%2/3
not $_[0]->SYLL and $_[1]->onset and $self->begin_adjoin->(@_)
not $_[0]->SYLL $_[1]->onset $self->begin_adjoin->(@_)
Truth table75%3/4
not(A) and B and C
A= not $_[0]->SYLLB= $_[1]->onsetC= $self->begin_adjoin->(@_)
ABCresult
0XX0
10X0
1100
1111
251 36 my $cond2 = 1;
252 36 my $i = -1;
253 36 ▶ while ($cond2 && not $_[$i]->BOUNDARY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond2 and not $_[$i]->BOUNDARY) 32 36 68
Condition100%3/3
$cond2 and not $_[$i]->BOUNDARY
!ll&&!rl&&r
29732
MC/DC100%2/2
$cond2 and not $_[$i]->BOUNDARY
$cond2 not $_[$i]->BOUNDARY
Truth table100%3/3
A and not(B)
A= $cond2B= not $_[$i]->BOUNDARY
ABresult
0X0
100
111
254 32 ▶ $cond2 = 0 if ($_[$i]->SYLL);
Branch: 1 branch
BranchTrueFalseTotal
if $_[$i]->SYLL 29 3 32
255 32 $i--;
256 }
257 36 ▶ return ($cond1 && $cond2);
Condition66%2/3
$cond1 && $cond2
!ll&&!rl&&r
3501
MC/DC50%1/2
$cond1 && $cond2
$cond1 $cond2
Truth table66%2/3
A && B
A= $cond1B= $cond2
ABresult
0X0
100
111
258 },
259 1 ▶ do => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
260 1 adjoin('onset', $_[1], $_[0]);
261 1 flat_adjoin('SYLL', $_[1], $_[0]);
262 }
263 },
264  
265 EndAdjoin => {
266 direction => 'rightward',
267 47 ▶ where => sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
268 47 ▶ my $cond1 = 1 if ((not $_[0]->SYLL) && $_[-1]->coda && $self->end_adjoin->(@_));
Branch: 1 branch
BranchTrueFalseTotal
if not $_[0]->SYLL and $_[-1]->coda and $self->end_adjoin->(@_) 2 45 47
Condition83%5/6
not $_[0]->SYLL and $_[-1]->coda and $self->end_adjoin->(@_)
!ll&&!rl&&r
4502
not $_[0]->SYLL and $_[-1]->coda
!ll&&!rl&&r
4232
MC/DC66%2/3
not $_[0]->SYLL and $_[-1]->coda and $self->end_adjoin->(@_)
not $_[0]->SYLL $_[-1]->coda $self->end_adjoin->(@_)
Truth table75%3/4
not(A) and B and C
A= not $_[0]->SYLLB= $_[-1]->codaC= $self->end_adjoin->(@_)
ABCresult
0XX0
10X0
1100
1111
269 47 my $cond2 = 1;
270 47 my $i = 1;
271 47 ▶ while ($cond2 && not $_[$i]->BOUNDARY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond2 and not $_[$i]->BOUNDARY) 42 47 89
Condition100%3/3
$cond2 and not $_[$i]->BOUNDARY
!ll&&!rl&&r
40742
MC/DC100%2/2
$cond2 and not $_[$i]->BOUNDARY
$cond2 not $_[$i]->BOUNDARY
Truth table100%3/3
A and not(B)
A= $cond2B= not $_[$i]->BOUNDARY
ABresult
0X0
100
111
272 42 ▶ $cond2 = 0 if ($_[$i]->SYLL);
Branch: 1 branch
BranchTrueFalseTotal
if $_[$i]->SYLL 40 2 42
273 42 $i++;
274 }
275 47 ▶ return ($cond1 && $cond2);
Condition66%2/3
$cond1 && $cond2
!ll&&!rl&&r
4502
MC/DC50%1/2
$cond1 && $cond2
$cond1 $cond2
Truth table66%2/3
A && B
A= $cond1B= $cond2
ABresult
0X0
100
111
276 },
277 2 ▶ do => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
278 2 adjoin('coda', $_[-1], $_[0]);
279 2 flat_adjoin('Rime', $_[-1], $_[0]);
280 2 flat_adjoin('SYLL', $_[-1], $_[0])
281 }
282 },
283  
284 # This rule exists purely for data-collection purposes (see count_unparsed)
285 Unparsed => {
286 138 ▶ where => sub { not $_[0]->SYLL },
Subroutine __ANON__: called CC=1 SCAR=0.0
287 }
288  
289 18 );
290  
291 # Be blessed
292 18 return $self;
293 }
294  
295 14 ▶sub syllabify {
Subroutine syllabify: called CC=11 SCAR=25.1
Pod documented
296 14 my $self = shift;
297  
298 # Check for valid input
299 14 for (@_) {
300 138 ▶ return err("Bad input to syllabify()") unless _is_seg($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &_is_seg($_) 0 138 138
301 }
302  
303 # Add the necessary features
304 14 $_[0]->featureset->add_feature(
305 SYLL => { type => 'scalar' },
306 onset => { type => 'privative' },
307 Rime => { type => 'privative' },
308 nucleus => { type => 'privative' },
309 coda => { type => 'privative' },
310 SON => { type => 'scalar' },
311 );
312 14 $_[0]->featureset->add_child('SYLL', 'onset', 'Rime');
313 14 $_[0]->featureset->add_child('Rime', 'nucleus', 'coda');
314  
315 # Optimize the rule order
316 14 my @order = ('Clear', 'CalcSon', 'CoreSyll');
317 14 ▶ push(@order, 'ComplexOnset') if $self->complex_onset;
Branch: 1 branch
BranchTrueFalseTotal
if $self->complex_onset 10 4 14
318 14 ▶ push(@order, 'Coda') if $self->coda;
Branch: 1 branch
BranchTrueFalseTotal
if $self->coda 10 4 14
319 14 ▶ push(@order, 'ComplexCoda') if $self->complex_coda;
Branch: 1 branch
BranchTrueFalseTotal
if $self->complex_coda 9 5 14
320 14 ▶ push(@order, 'BeginAdjoin') if $self->begin_adjoin != $code{begin_adjoin};
Branch: 1 branch
BranchTrueFalseTotal
if $self->begin_adjoin != $Lingua::Phonology::Syllable::code{"begin_adjoin"} 4 10 14
321 14 ▶ push(@order, 'EndAdjoin') if $self->end_adjoin != $code{end_adjoin};
Branch: 1 branch
BranchTrueFalseTotal
if $self->end_adjoin != $Lingua::Phonology::Syllable::code{"end_adjoin"} 5 9 14
322 14 push(@order, 'Unparsed');
323 14 $self->{RULES}->order(@order);
324  
325 # Are we in a rule (are these really RuleSegments)?
326 14 ▶ if (_is_ruleseg $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_is_ruleseg($_[0])) 0 14 14
327 # Rewind the word (it fucks us up to start in the middle)
328 0 ▶ unshift(@_, pop(@_)) while not $_[-1]->BOUNDARY;
Branch: 1 branch
BranchTrueFalseTotal
$_[-1]->BOUNDARY or do { unshift @_, pop @_ } 0 0 0
329 # Get rid of boundary segments
330 0 ▶ pop @_ while $_[-1]->BOUNDARY;
Branch: 1 branch
BranchTrueFalseTotal
$_[-1]->BOUNDARY and do { pop @_ } 0 0 0
331 }
332  
333 # Apply all rules
334 14 $self->{RULES}->apply_all(\@_);
335 }
336  
337 0 ▶sub count_syll {
Subroutine count_syll: not called CC=1 SCAR=6.9
Pod documented
338 0 my $self = shift;
339 0 $self->{RULES}->count->{CoreSyll};
340 }
341  
342 0 ▶sub count_unparsed {
Subroutine count_unparsed: not called CC=1 SCAR=6.9
Pod documented
343 0 my $self = shift;
344 0 $self->{RULES}->count->{Unparsed};
345 }
346  
347 # Calculate a segment's sonority
348 139 ▶sub sonority {
Subroutine sonority: called CC=3 SCAR=11.0
Pod documented
349 139 my $self = shift;
350 139 my $seg = shift;
351 139 my $son = 0;
352 139 for (keys(%{$self->sonorous})) {
353 540 ▶ $son += $self->{ATTR}->{sonorous}->{$_} if $seg->$_;
Branch: 1 branch
BranchTrueFalseTotal
if $seg->$_ 173 367 540
354 }
355 139 return $son;
356 }
357  
358 # min_son_dist sets both coda_son and onset_son
359 28 ▶sub min_son_dist {
Subroutine min_son_dist: called CC=2 SCAR=6.9
Pod documented
360 28 my $self = shift;
361  
362 28 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 25 28
363 3 my $val = shift;
364 3 $self->coda_son_dist($val);
365 3 $self->onset_son_dist($val);
366 }
367 28 return $self->onset_son_dist;
368  
369 }
370  
371 # Sets the direction
372 6 ▶sub direction {
Subroutine direction: called CC=2 SCAR=6.9
Pod documented
373 6 my ($self, $val) = @_;
374 6 ▶ if (defined($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 5 1 6
375 5 $self->{RULES}->direction('CoreSyll', $val);
376 5 $self->{RULES}->direction('Coda', $val);
377 }
378 6 return $self->{ATTR}->{direction} = $self->{RULES}->direction('CoreSyll');
379 }
380  
381 6 ▶sub loadfile {
Subroutine loadfile: called CC=3 SCAR=11.0
Pod undocumented
382 6 my ($self, $file) = @_;
383  
384 # Load defaults, but defaults are loaded with new()
385 6 ▶ return 1 if not defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 4 2 6
386  
387 2 my $parse;
388 2 eval { $parse = _parse_from_file($file, 'syllable') };
389 2 ▶ return err $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 1 2
390  
391 1 $self->_load_from_struct($parse);
392 }
393  
394 3 ▶sub _load_from_struct {
Subroutine _load_from_struct: called CC=8 SCAR=20.8
395 3 my ($self, $struct) = @_;
396  
397 3 for (keys %$struct) {
398 # Accomodate set_ and no_ entries
399 38 my $bool = 1;
400 38 ▶ $bool = 1 if s/^set_//;
Branch: 1 branch
BranchTrueFalseTotal
if s/^set_// 5 33 38
401 38 ▶ $bool = 0 if s/^no_//;
Branch: 1 branch
BranchTrueFalseTotal
if s/^no_// 3 35 38
402 38 ▶ if (exists $bool{$_}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $Lingua::Phonology::Syllable::bool{$_}) { } 12 26 38
elsif (exists $Lingua::Phonology::Syllable::hash{$_}) { } 3 23 26
elsif (exists $Lingua::Phonology::Syllable::code{$_}) { } 9 14 23
403 12 $self->$_($bool);
404 }
405 elsif (exists $hash{$_}) {
406 3 my $l = $_;
407 3 $self->$_( {map { $_ => $struct->{$l}->{feature}->{$_}->{score} } keys %{$struct->{$l}->{feature}}} );
408 }
409 elsif (exists $code{$_}) {
410 9 my $c = _parse_ext $struct->{$_};
411  
412 9 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 9 9
413 0 err("Errors processing $_ : $@");
414 }
415 else {
416 9 $self->$_($c);
417 }
418 }
419 # Most general, applicable for integers, direction, min_son_dist, etc.
420 else {
421 14 $self->$_($struct->{$_}->{value});
422 }
423 }
424 3 1;
425 }
426
427  
428 2 ▶sub _to_str {
Subroutine _to_str: called CC=8 SCAR=20.8
429 2 my ($self, $file) = @_;
430  
431 2 require B::Deparse;
432  
433 2 my $href = {};
434 2 for (keys %{$self->{ATTR}}) {
435 27 ▶ if (exists $bool{$_}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $Lingua::Phonology::Syllable::bool{$_}) { } 8 19 27
elsif (exists $Lingua::Phonology::Syllable::hash{$_}) { } 2 17 19
elsif (exists $Lingua::Phonology::Syllable::code{$_}) { } 6 11 17
436 8 ▶ if ($self->$_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->$_) { } 5 3 8
437 5 $href->{"set_$_"} = {};
438 }
439 else {
440 3 $href->{"no_$_"} = {};
441 }
442 }
443 elsif (exists $hash{$_}) {
444 2 my $l = $_;
445 2 $href->{$l}->{feature} = {};
446 2 for (keys %{$self->{ATTR}->{$l}}) {
447 6 $href->{$l}->{feature}->{$_} = { score => $self->{ATTR}->{$l}->{$_} };
448 }
449 }
450 elsif (exists $code{$_}) {
451 6 my $d = B::Deparse->new('-x7', '-p', '-si4');
452 6 $d->ambient_pragmas(strict => 'all', warnings => 'all');
453 6 ▶ my $code = _deparse_ext $self->{ATTR}->{$_}, $d or err $@;
Branch: 1 branch
BranchTrueFalseTotal
my $code = &_deparse_ext($self->{"ATTR"}{$_}, $d) or &err($@) 6 0 6
454  
455 6 $href->{$_} = [ $code . ' ' ]; # Extra whitespace for helping indent
456 }
457 # Takes car of %int and others
458 else {
459 11 $href->{$_} = { value => $self->$_ };
460 }
461 }
462  
463 2 _string_from_struct({ syllable => $href });
464 }
465  
466 8 1;
467  
468 __END__
« Phonology/Features.pm ↑ Summary Phonology/Segment/Boundary.pm »