Skip to content

Commit

Permalink
Show number of bad word occurrences in SQ dialog
Browse files Browse the repository at this point in the history
Since bad words are...bad, display how many there are, so PPer is
incentivized to locate and correct them.

Renaming of old `badwordfreq` variable to `badspellingfreq` to
avoid confusion with count of bad words from the BWL
  • Loading branch information
windymilla committed Sep 24, 2023
1 parent 39f421c commit 7aadeac
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/lib/Guiguts/ErrorCheck.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ sub errorcheckpop_up {
-width => 16
)->grid( -padx => 10, -row => 0, -column => $gcol++ );

# Spell Query bad word count sits under the Run Checks button
if ( $errorchecktype eq 'Spell Query' ) {
$gcol--;
$::lglobal{sqbadwordcountlbl} =
$ptopframeb->Label()->grid( -padx => 0, -row => 1, -column => $gcol++ );
}

$ptopframeb->Button(
-command => sub {
errorcheckcopy();
Expand Down Expand Up @@ -649,6 +656,12 @@ sub errorcheckpop_up {
} else {
errsortrefresh($errorchecktype);
eccountupdate($countqueries);
if ( $errorchecktype eq "Spell Query" ) {
my $numbadwords = sqgetnumbadwords();
my $numbadwordslbl = $numbadwords > 0 ? "*$numbadwords* bad word" : "";
$numbadwordslbl .= "s" if $numbadwords > 1;
$::lglobal{sqbadwordcountlbl}->configure( -text => $numbadwordslbl );
}
}

$::lglobal{errorchecklistbox}->update;
Expand Down Expand Up @@ -1481,8 +1494,9 @@ sub booklouperun {
#
# Block to make Spell Query dictionary hash local & persistent
{
my %sqglobaldict = ();
my %sqbadwordfreq = ();
my %sqglobaldict = ();
my %sqbadspellingfreq = ();
my %sqbadwordcount = ();

# Codes returned by spellquerywordok()
my $SQWORDOKYES = 0; # Word in dictionary, or meets other criteria for being OK
Expand Down Expand Up @@ -1538,8 +1552,9 @@ sub booklouperun {
next if $wd =~ /^['$APOS]*$/; # OK if nothing left in string but zero or more quotes

# Format message - increment word frequency; final total gets appended later when populating dialog
$sqbadwordfreq{$wd}++;
my $badwd = $wordok == $SQWORDOKBAD ? "***" : ""; # Flag bad word to higher routine with asterisks
$sqbadspellingfreq{$wd}++;
my $badwd = $wordok == $SQWORDOKBAD ? "***" : ""; # Flag bad word to higher routine with asterisks
$sqbadwordcount{$wd}++ if $badwd;
my $error = sprintf( "%d:%-2d - %s%s", $step, $col, $wd, $badwd );
utf8::encode($error);
print $logfile "$error\n";
Expand Down Expand Up @@ -1728,7 +1743,7 @@ sub booklouperun {
# Return how many times bad word referred to in error message was found during the check
sub spellqueryfrequency {
my $line = shift;
return $sqbadwordfreq{$1} if $line =~ /^\d+:\d+ +- ([^*]+)/; # Ignore asterisks marking bad words
return $sqbadspellingfreq{$1} if $line =~ /^\d+:\d+ +- ([^*]+)/; # Ignore asterisks marking bad words
return 0;
}

Expand All @@ -1741,9 +1756,19 @@ sub booklouperun {
#
# Clear the spell query frequency counts
sub spellqueryclearcounts {
delete $sqbadwordfreq{$_} for keys %sqbadwordfreq;
delete $sqbadspellingfreq{$_} for keys %sqbadspellingfreq;
delete $sqbadwordcount{$_} for keys %sqbadwordcount;
}

#
# Get number of bad words used in file
sub sqgetnumbadwords {
my $numbadwords = 0;
for my $key ( keys %sqbadwordcount ) {
$numbadwords += $sqbadwordcount{$key};
}
return $numbadwords;
}
} # end of variable-enclosing block

#
Expand Down

0 comments on commit 7aadeac

Please sign in to comment.