@@ -26,7 +26,12 @@ has units => (is => 'ro',
2626 required => 1,
2727 coerce => \&_units_array2hash);
2828
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+ });
3035
3136has coincidence => (is => ' lazy' , init_arg => undef );
3237
@@ -42,6 +47,17 @@ has _expected => (is => 'lazy',
4247 init_arg => undef ,
4348 builder => ' _build_expected' );
4449
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+
4561sub alpha ($self ) {
4662 my $d_o = sum(map {
4763 my $v = $_ ;
@@ -192,7 +208,7 @@ sub _build_expected($self) {
192208 {coder2 => 3, coder3 => 2});
193209 my $sk = 'Statistics::Krippendorff'->new(units => \@units);
194210 my $alpha1 = $sk->alpha;
195- $sk->delta(\&Statistics::Krippendorff::delta_nominal ); # Same as default.
211+ $sk->delta('nominal' ); # Same as default.
196212 my $alpha2 = $sk->alpha;
197213
198214 my $ski = 'Statistics::Krippendorff'->new(
@@ -206,7 +222,7 @@ sub _build_expected($self) {
206222
207223 my $sk = 'Statistics::Krippendorff'->new(
208224 units => \@units,
209- delta => \&Statistics::Krippendorff::delta_nominal );
225+ delta => 'nominal' );
210226
211227The constructor. It accepts the following named arguments:
212228
@@ -243,7 +259,7 @@ to validate this precondition, call C<is_valid>.
243259An optional argument defaulting to delta_nominal. You can specify any function
244260C<f($self, $v1, $v2) > that compares the two values C<$v1 > and C<$v2 > and
245261returns 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 > :
247263
248264=head4 delta_nominal
249265
@@ -289,6 +305,7 @@ Returns Krippendorff's alpha.
289305=head2 delta
290306
291307 $sk->delta(sub($self, $v1, $v2) {});
308+ $sk->delta('jaccard');
292309
293310The difference function used to calculate the alpha. You can specify it in the
294311constructor (see above), but you can later change it so something else, too.
0 commit comments