diff options
author | John Ankarström <john@ankarstrom.se> | 2020-11-11 01:43:39 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2020-11-11 01:43:39 +0100 |
commit | 1cd3a3d6c7fb6899b88b65694841cabc00d10fc1 (patch) | |
tree | 5b1697d2331bc6a01b76e5a52378a583ce296b1d | |
parent | 87c49bd96602bf44aaf255adc237a22236c1290b (diff) | |
download | rf-1cd3a3d6c7fb6899b88b65694841cabc00d10fc1.tar.gz |
polish
-rwxr-xr-x[-rw-r--r--] | rf.pl | 35 |
1 files changed, 27 insertions, 8 deletions
@@ -7,7 +7,7 @@ use warnings; my $format_full = '(%a %y)'; my $format_extra = '(%y)'; -my $format_list = '%a (%y). %t. %q. %n, %d. %c: %p.'; +my $format_list = '%a (%y). %t. %q. %n, %d. %c: %p. {Available: %w.}'; # Internal variables @@ -46,7 +46,9 @@ while (<>) { push @lines, $_; } +$i = -1; for (@lines) { + $i++; # Inline reference if (/^\.R([fx]) +(.*)/) { my ($fld, $def) = ($1, $2); @@ -55,18 +57,32 @@ for (@lines) { my $winner = 0; my @words = split /\s/, $def; my @points; + + # replace '' with preceding word + for (@words) { + if ($_ eq "''") { + $_ = $lines[$i-1]; + $_ =~ s/^.*\s(\S+)\s*$/$1/; + } + } + for (my $i = 0; $i < scalar @refs; $i++) { $points[$i] = 0 if not defined $points[$i]; - $points[$i] += 7 if likeness($refs[$i]{a}, @words); - $points[$i] += 4 if likeness($refs[$i]{y}, @words); - $points[$i] += 1 if likeness($refs[$i]{t}, @words); - $points[$i] += 1 if likeness($refs[$i]{q}, @words); + $points[$i] += 100 if likeness($refs[$i]{a}, @words); + $points[$i] += 50 if likeness($refs[$i]{y}, @words); + $points[$i] += 1 * likeness($refs[$i]{t}, @words); + $points[$i] += 1 * likeness($refs[$i]{q}, @words); $winner = $i if $points[$i] > $points[$winner]; } + if (not defined $winner) { - print STDERR "Reference '$def' could not be resolved.\n"; + print STDERR "Error: Reference '$def' could not be resolved.\n"; exit 1; } + if ($points[$winner] < 11) { + print STDERR "Warning: Guessing that reference '$def' refers to " . fmt($format_full, $winner) . ".\n"; + } + if ($fld eq 'f') { no warnings; print $prefix . fmt($format_full, $winner) . "$suffix\n"; @@ -105,6 +121,8 @@ sub fmt { } } $fmt =~ s/ +/ /g; + $fmt =~ s/([(]) */$1/; + $fmt =~ s/ *([.,)])/$1/; $fmt =~ s/^ *//; $fmt =~ s/ *$//; return $fmt; @@ -127,9 +145,10 @@ sub fmta { sub likeness { my ($string, @strings) = @_; + my $r = 0; return 0 if not defined $string; for (@strings) { - return 1 if index($string, $_) != -1; + $r += 1 if index($string, $_) != -1; } - return 0; + return $r; } |