[LON-CAPA-cvs] cvs: modules /gerd/harvesting lonrecommender.pm
www
www at source.lon-capa.org
Sat Jul 14 11:04:34 EDT 2012
www Sat Jul 14 15:04:34 2012 EDT
Modified files:
/modules/gerd/harvesting lonrecommender.pm
Log:
Return the maximum counts and maximum association frequency, so the results
can be normalized
Index: modules/gerd/harvesting/lonrecommender.pm
diff -u modules/gerd/harvesting/lonrecommender.pm:1.4 modules/gerd/harvesting/lonrecommender.pm:1.5
--- modules/gerd/harvesting/lonrecommender.pm:1.4 Sat Jul 14 13:58:17 2012
+++ modules/gerd/harvesting/lonrecommender.pm Sat Jul 14 15:04:34 2012
@@ -5,7 +5,7 @@
#
# MODIFY $datapath VARIABLE FOR LOCATION OF DATA FILES
#
-# $Id: lonrecommender.pm,v 1.4 2012/07/14 13:58:17 www Exp $
+# $Id: lonrecommender.pm,v 1.5 2012/07/14 15:04:34 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -80,7 +80,8 @@
#
# Return the resources that the resources in the argument are associated with
# by having been used in the same folder
-# Takes an array of resource keys, returns a hash with resource keys as keys
+# Takes an array of resource keys, returns maximum frequency and
+# a hash with resource keys as keys
# and frequency as values
#
@@ -88,6 +89,7 @@
my (@with)=@_;
my %output=();
my %hash=();
+ my $max=0;
#
# The associations database has entries: key -> other1:weight1,other2:weight2
# to show which other resources have been used in the same context
@@ -99,12 +101,13 @@
my ($tother,$tweight)=split(/\:/,$other);
if ($tweight) {
$output{$tother}+=$tweight;
+ if ($output{$tother}>$max) { $max=$output{$tother}; }
}
}
}
untie(%hash);
foreach my $key (@with) { delete($output{$key}); }
- return %output;
+ return ($max,%output);
}
@@ -323,12 +326,14 @@
my @urls=@_;
my %output=();
my %hash=();
+ my $max=0;
tie(%hash, 'GDBM_File', $datapath.'dbfiles/count.db',&GDBM_READER(),0640);
foreach my $url (@urls) {
$output{$url}=$hash{$url};
+ if ($output{$url}>$max) { $max=$output{$url}; }
}
untie(%hash);
- return(%output);
+ return($max,%output);
}
# =================================================================================
@@ -389,7 +394,7 @@
my %taxos=&taxoids(3,5,8,90,900,1450,13624,31415);
my %urls=&urlres(3,5,8,90,900,1450,13624,31415);
- my %counts=&counts(3,5,8,90,900,1450,13624,31415);
+ my ($max,%counts)=&counts(3,5,8,90,900,1450,13624,31415);
foreach my $key (keys(%taxos)) {
$r->print($key.' '.$urls{$key}.' '.$counts{$key}.' => '.$taxos{$key}.' '.$taxonomy_categories{'cleartext_'.$taxos{$key}}."<br />\n");
More information about the LON-CAPA-cvs
mailing list