[LON-CAPA-cvs] cvs: modules /gerd/harvesting recomprocs.pl

www www at source.lon-capa.org
Sun Jun 24 14:13:54 EDT 2012


www		Sun Jun 24 18:13:54 2012 EDT

  Added files:                 
    /modules/gerd/harvesting	recomprocs.pl 
  Log:
  Routines to read out the dbfiles generated by rectrans.pl
  
  

Index: modules/gerd/harvesting/recomprocs.pl
+++ modules/gerd/harvesting/recomprocs.pl
use strict;
use GDBM_File;
my $datapath='/home/www/loncapa/modules/gerd/harvesting/';

# =================================================================================
#
# 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
# and frequency as values
#

sub associated {
   my (@with)=@_;
   my %output=();
   my %hash;
#
# The associations database has entries: key -> other1:weight1,other2:weight2
# to show which other resources have been used in the same context
#
   tie(%hash, 'GDBM_File', $datapath.'dbfiles/associations.db',&GDBM_READER(),0640);
   foreach my $key (@with) {
       my $assoc=$hash{$key};
       foreach my $other (split(/\,/,$assoc)) {
          my ($tother,$tweight)=split(/\:/,$other);
          if ($tweight) {
             $output{$tother}+=$tweight;
          }
       }
   }
   untie(%hash);
   foreach my $key (@with) { delete($output{$key}); }
   return %output;
}

# =================================================================================

my $parm=shift;
print "Parameter: $parm\n";
my %stuff=&associated(split(/\s*\,\s*/,$parm));
foreach my $key (keys(%stuff)) {
    print $key." ".$stuff{$key}."\n";
}




More information about the LON-CAPA-cvs mailing list