sort kandidates by score, and if same prefer longer one
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 16 Nov 2023 11:55:54 +0000 (12:55 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 16 Nov 2023 11:55:54 +0000 (12:55 +0100)
upari.pl

index df05e11..7720bc2 100755 (executable)
--- a/upari.pl
+++ b/upari.pl
@@ -56,6 +56,23 @@ sub candidates {
                        }
                }
        }
+=for description
+       for limit 0.6 to work, we need to prefer longer results over shorter ones:
+       MERGE A0246A 3078-8326 (
+         { key => "A4065A", s => 0.666666666666667 },
+         { key => "ANDREJA0246A", s => 0.666666666666667 },
+  ) val=[3]
+  .++ A0246A-3078-8326 1 .++ A0246A-3078-8326 2 result val=[3, 1, 2] result_elements=3
+=cut
+
+       if ( $#candidates > 0 ) {
+               print "XXX candidates before = ",dump( \@candidates ),$/;
+               @candidates = sort {
+                       $b->{s} <=> $a->{s}     # hi -> low
+                       or length($b->{key}) <=> length($a->{key})
+               } @candidates;
+               print "XXX candidates after  = ",dump( \@candidates ),$/;
+       }
        return @candidates;
 }
 
@@ -106,7 +123,8 @@ foreach my $nr ( 1 .. 4 ) {
 
 
 
-foreach my $l ( 0 .. 9 ) { # 0.9 - 0.7 -- 0.6 is too lax
+#foreach my $l ( 0 .. 5 ) { # 0.9 - 0.7 -- 0.6 is too lax
+foreach my $l ( qw( 2 3 4 5 ) ) {
        my $limit = 0.9 - "0.$l";
 warn "XXX limit $limit\n";
 
@@ -134,7 +152,7 @@ foreach my $id ( sort keys %{ $stat->{_} } ) {
                my ( $num, $key_id ) = split(/-/,$id,2);
                my @candidates = candidates $num => $key_id, $limit; #, 0.7; # XXX 0.9 too high, 0.8 better, 0.7 too lax
                if ( @candidates ) {
-                       print "MERGE $num $key_id ", dump( @candidates ), ' val=', dump( \@val ), $/;
+                       print "MERGE ",scalar @candidates, " $num $key_id ", dump( @candidates ), ' val=', dump( \@val ), $/;
                        my @keys = map { $_->{key} } @candidates;
                        my  $m_id = $id; # "$keys[0]-$key_id";
                        foreach my $i ( 0 .. $#keys ) {