Skip to content

Commit

Permalink
Item2486: Daniel Oderbolz added logarithmic normalization of term wei…
Browse files Browse the repository at this point in the history
…ghts, making it very nice tag clouds

git-svn-id: http://svn.foswiki.org/trunk/TagCloudPlugin@5763 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Dec 10, 2009
1 parent 1453f18 commit ab6062c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions data/System/TagCloudPlugin.txt
Expand Up @@ -100,6 +100,8 @@ Parameters:
(default: 10)
* =lowercase=: switch on/off converting terms to lowercase
(default: off)
* =normalize=: method to normalize the term counts, either logarithmic or linear
(default: log)
* =plural=: switch on/off counting plurals, if set to off plural terms are matched
to their singular form (caution: very rudimentary and assuming the input data is all english,
use stopwords="on" to get good results)
Expand Down Expand Up @@ -191,6 +193,7 @@ Cloud for the above text:
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: |   |
| 10 Dec 2009: | added logarithmic normalization (Foswiki:Main/DanielOderbolz) |
| 25 Nov 2009: | fixed grouping in case sensitive tag clouds |
| 03 Sep 2009: | made sorting case insensitive; added case sensitive extra param |
| 25 Aug 2009: | added custom fields for terms in the tagcloud (Foswiki:Main.OliverKrueger) |
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/TagCloudPlugin.pm
Expand Up @@ -24,7 +24,7 @@ use vars qw(
);

$VERSION = '$Rev$';
$RELEASE = 'v2.11';
$RELEASE = 'v2.20';
$NO_PREFS_IN_TOPIC = 1;
$SHORTDESCRIPTION = 'Renders a tag cloud given a list of terms';

Expand Down
20 changes: 20 additions & 0 deletions lib/Foswiki/Plugins/TagCloudPlugin/Core.pm
Expand Up @@ -349,6 +349,9 @@ our %stopWords = (
},
);

use constant NORMALIZE_LINEAR => 0;
use constant NORMALIZE_LOG => 1;

###############################################################################
sub writeDebug {
print STDERR '- TagCloudPlugin - '.$_[0]."\n" if DEBUG;
Expand Down Expand Up @@ -382,6 +385,7 @@ sub handleTagCloud {
my $theGroup = $params->{group} || '';
my $theFilter = $params->{filter} || 'off';
my $theLimit = $params->{limit};
my $theNormalize = $params->{normalize} || 'log' ;

unless (defined($theHeader) || defined($theFooter)) {
$theHeader = '<div class="tagCloud">';
Expand All @@ -403,6 +407,15 @@ sub handleTagCloud {
$theStopWords = 'off' unless $theStopWords =~ /^(on|off)$/;
$thePlural = 'on' unless $thePlural =~ /^(on|off)$/;

if ($theNormalize eq 'linear') {
$theNormalize = NORMALIZE_LINEAR;
} elsif ($theNormalize =~ /log(arithmic)?/) {
$theNormalize = NORMALIZE_LOG;
} else {
$theNormalize = NORMALIZE_LINEAR; # default
}


# build class map
my %classMap = ();
if ($theMap) {
Expand Down Expand Up @@ -447,6 +460,7 @@ sub handleTagCloud {
my $stopWords;
$stopWords = getStopWords($theLanguage)
if $theStopWords eq 'on';

foreach my $term (split(/$theSplit/, $theTerms)) {
$term =~ s/^\s*(.*?)\s*$/$1/o;
#writeDebug("term=$term");
Expand Down Expand Up @@ -488,10 +502,16 @@ sub handleTagCloud {
my $floor = -1;
my $ceiling = 0;
foreach my $term (keys %termCount) {

# normalization
$termCount{$term} = log($termCount{$term}) if $theNormalize == NORMALIZE_LOG;

# truncation
if ($termCount{$term} < $theMin) {
delete $termCount{$term};
next;
}

$ceiling = $termCount{$term}
if $termCount{$term} > $ceiling;
$floor = $termCount{$term}
Expand Down

0 comments on commit ab6062c

Please sign in to comment.