@@ -26,7 +26,12 @@ has units => (is => 'ro',
26
26
required => 1,
27
27
coerce => \&_units_array2hash);
28
28
29
- has delta => (is => ' rw' , default => sub { \&delta_nominal });
29
+ has delta => (is => ' rw' ,
30
+ default => sub { \&delta_nominal },
31
+ trigger => sub ($self , $d ) {
32
+ $self -> delta($self -> _deltas-> {$d })
33
+ if exists $self -> _deltas-> {$d };
34
+ });
30
35
31
36
has coincidence => (is => ' lazy' , init_arg => undef );
32
37
@@ -42,6 +47,17 @@ has _expected => (is => 'lazy',
42
47
init_arg => undef ,
43
48
builder => ' _build_expected' );
44
49
50
+ has _deltas => (is => ' ro' ,
51
+ init_arg => undef ,
52
+ default => sub { +{
53
+ nominal => \&delta_nominal,
54
+ interval => \&delta_interval,
55
+ ordinal => \&delta_ordinal,
56
+ ratio => \&delta_ratio,
57
+ jaccard => \&delta_jaccard,
58
+ masi => \&delta_masi
59
+ } });
60
+
45
61
sub alpha ($self ) {
46
62
my $d_o = sum(map {
47
63
my $v = $_ ;
@@ -192,7 +208,7 @@ sub _build_expected($self) {
192
208
{coder2 => 3, coder3 => 2});
193
209
my $sk = 'Statistics::Krippendorff'->new(units => \@units);
194
210
my $alpha1 = $sk->alpha;
195
- $sk->delta(\&Statistics::Krippendorff::delta_nominal ); # Same as default.
211
+ $sk->delta('nominal' ); # Same as default.
196
212
my $alpha2 = $sk->alpha;
197
213
198
214
my $ski = 'Statistics::Krippendorff'->new(
@@ -206,7 +222,7 @@ sub _build_expected($self) {
206
222
207
223
my $sk = 'Statistics::Krippendorff'->new(
208
224
units => \@units,
209
- delta => \&Statistics::Krippendorff::delta_nominal );
225
+ delta => 'nominal' );
210
226
211
227
The constructor. It accepts the following named arguments:
212
228
@@ -243,7 +259,7 @@ to validate this precondition, call C<is_valid>.
243
259
An optional argument defaulting to delta_nominal. You can specify any function
244
260
C<f($self, $v1, $v2) > that compares the two values C<$v1 > and C<$v2 > and
245
261
returns their distance (a number between 0 and 1). Several common methods are
246
- predefined:
262
+ predefined, you can use a code reference like C< &Statistics::Krippendorff::delta_nominal > or just a string C< nominal > :
247
263
248
264
=head4 delta_nominal
249
265
@@ -289,6 +305,7 @@ Returns Krippendorff's alpha.
289
305
=head2 delta
290
306
291
307
$sk->delta(sub($self, $v1, $v2) {});
308
+ $sk->delta('jaccard');
292
309
293
310
The difference function used to calculate the alpha. You can specify it in the
294
311
constructor (see above), but you can later change it so something else, too.
0 commit comments