瀏覽代碼

Make "most used words" case-insensitive

Christoph Berg 21 年之前
父節點
當前提交
2a7d89929e
共有 3 個文件被更改,包括 17 次插入17 次删除
  1. 1 0
      docs/Changelog
  2. 3 2
      modules/Pisg/HTMLGenerator.pm
  3. 13 15
      modules/Pisg/Parser/Logfile.pm

+ 1 - 0
docs/Changelog

@@ -13,6 +13,7 @@ pisg (0.64) - ??
    * Made Logfile accept wildcards, sanitized NFiles behaviour on multiple
    * Made Logfile accept wildcards, sanitized NFiles behaviour on multiple
      LogDirs.
      LogDirs.
    * No "Userpic" headline was shown when there were only DefaultPics.
    * No "Userpic" headline was shown when there were only DefaultPics.
+   * Make "most used words" case-insensitive.
 
 
 pisg (0.63) - Wed Jan, 12th 2005
 pisg (0.63) - Wed Jan, 12th 2005
    Morten:
    Morten:

+ 3 - 2
modules/Pisg/HTMLGenerator.pm

@@ -1724,7 +1724,7 @@ sub _mostusedword
             next if is_ignored($popular[$i]);
             next if is_ignored($popular[$i]);
 
 
             my $a = $count + 1;
             my $a = $count + 1;
-            my $popular = $self->_format_word($popular[$i]);
+            my $popular = $self->_format_word($self->{stats}->{word_upcase}{$popular[$i]});
             my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
             my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
             my $lastused = $self->_format_word($self->{stats}->{wordnicks}{$popular[$i]});
             my $lastused = $self->_format_word($self->{stats}->{wordnicks}{$popular[$i]});
             my $class;
             my $class;
@@ -1810,7 +1810,8 @@ sub _mostreferencednicks
         for(my $i = 0; $i < $self->{cfg}->{nickhistory}; $i++) {
         for(my $i = 0; $i < $self->{cfg}->{nickhistory}; $i++) {
             last if $i >= @popular;
             last if $i >= @popular;
             my $a = $i + 1;
             my $a = $i + 1;
-            my $popular   = $self->_format_word($popular[$i]);
+            my $popular   = is_nick($popular[$i]) || $self->{stats}->{word_upcase}{$popular[$i]} || $popular[$i];
+            $popular      = $self->_format_word($popular[$i]);
             my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
             my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
             my $lastused  = $self->_format_word($self->{stats}->{wordnicks}{$popular[$i]} || "");
             my $lastused  = $self->_format_word($self->{stats}->{wordnicks}{$popular[$i]} || "");
             # this is undefined when a nick is referenced before being used
             # this is undefined when a nick is referenced before being used

+ 13 - 15
modules/Pisg/Parser/Logfile.pm

@@ -605,14 +605,10 @@ sub _parse_words
         # Also ignore stuff from URLs.
         # Also ignore stuff from URLs.
         next if ($word =~ m/^https?$|^\/\//o);
         next if ($word =~ m/^https?$|^\/\//o);
 
 
-	# uniquify nicks
-	if (my $realnick = is_nick($word)) {
-            $stats->{wordcounts}{$realnick}++;
-            $stats->{wordnicks}{$realnick} = $nick;
-	} else {
-            $stats->{wordcounts}{$word}++;
-            $stats->{wordnicks}{$word} = $nick;
-	}
+        my $lcword = lc $word;
+        $stats->{wordcounts}{$lcword}++;
+        $stats->{wordnicks}{$lcword} = $nick;
+        $stats->{word_upcase}{$lcword} ||= $word; # remember first-seen case
     }
     }
 }
 }
 
 
@@ -643,13 +639,15 @@ sub _uniquify_nicks {
     my ($stats) = @_;
     my ($stats) = @_;
 
 
     foreach my $word (keys %{ $stats->{wordcounts} }) {
     foreach my $word (keys %{ $stats->{wordcounts} }) {
-        if (my $realnick = is_nick($word)) {
-	    # The lc() is an attempt at being case insensitive.
-	    if (lc($realnick) ne lc($word)) {
-	        $stats->{wordcounts}{$realnick} += $stats->{wordcounts}{$word};
-	        delete $stats->{wordcounts}{$word};
-	        delete $stats->{wordnicks}{$word};
-	    }
+        if (my $realnick = lc(is_nick($word))) {
+            if ($realnick ne $word) { # word is always lc
+                $stats->{wordcounts}{$realnick} += $stats->{wordcounts}{$word};
+                $stats->{wordnicks}{$realnick} ||= $stats->{wordnicks}{$word};
+                $stats->{word_upcase}{$realnick} ||= $stats->{word_upcase}{$word};
+                delete $stats->{wordcounts}{$word};
+                delete $stats->{wordnicks}{$word};
+                delete $stats->{word_upcase}{$word};
+            }
         }
         }
     }
     }
 }
 }