You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2007/02/11 18:14:36 UTC

svn commit: r506070 - in /spamassassin/trunk/masses: runGA tenpass/split-log-into-buckets-cached

Author: jm
Date: Sun Feb 11 09:14:35 2007
New Revision: 506070

URL: http://svn.apache.org/viewvc?view=rev&rev=506070
Log:
add new log-splitting script which caches the results

Added:
    spamassassin/trunk/masses/tenpass/split-log-into-buckets-cached   (with props)
Modified:
    spamassassin/trunk/masses/runGA

Modified: spamassassin/trunk/masses/runGA
URL: http://svn.apache.org/viewvc/spamassassin/trunk/masses/runGA?view=diff&rev=506070&r1=506069&r2=506070
==============================================================================
--- spamassassin/trunk/masses/runGA (original)
+++ spamassassin/trunk/masses/runGA Sun Feb 11 09:14:35 2007
@@ -35,17 +35,13 @@
 echo "[Generating 90/10 split ham]"
 mkdir $LOGDIR/NSBASE $LOGDIR/SPBASE
 cd $LOGDIR/NSBASE
-../../tenpass/split-log-into-buckets-random 10 < ../../ORIG/ham-$NAME.log > /dev/null
-cat split-[1-9].log > ham.log
-rm -f split-[1-9].log
-mv split-10.log ham-test.log
+../../tenpass/split-log-into-buckets-cached \
+    9:ham.log 1:ham-test.log ../../ORIG/ham-$NAME.log
 
 echo "[Generating 90/10 split spam]"
 cd ../SPBASE
-../../tenpass/split-log-into-buckets-random 10 < ../../ORIG/spam-$NAME.log > /dev/null
-cat split-[1-9].log > spam.log
-rm -f split-[1-9].log
-mv split-10.log spam-test.log
+../../tenpass/split-log-into-buckets-cached \
+    9:spam.log 1:spam-test.log ../../ORIG/spam-$NAME.log
 cd ../..
 
 echo "[Setting up for gen run]"

Added: spamassassin/trunk/masses/tenpass/split-log-into-buckets-cached
URL: http://svn.apache.org/viewvc/spamassassin/trunk/masses/tenpass/split-log-into-buckets-cached?view=auto&rev=506070
==============================================================================
--- spamassassin/trunk/masses/tenpass/split-log-into-buckets-cached (added)
+++ spamassassin/trunk/masses/tenpass/split-log-into-buckets-cached Sun Feb 11 09:14:35 2007
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+#
+# split-log-into-buckets-cached x:output [y:output2 ...]
+#
+# Split a mass-check log into several identically-sized buckets, evenly
+# taking messages from all checked corpora and preserving comments,
+# writing output to the files listed on the line.
+# It does this evenly by running through all buckets sequentially
+# as each line is read.
+# 
+# Each output file must be listed, and the count of the "n" buckets
+# for that file specified; so for example 1 file can contain
+# 9 buckets.
+#
+# This variant operates randomly (as per -random) but caches results.
+
+my $input;
+my @outs = ();
+foreach my $arg (@ARGV) {
+  if ($arg =~ /^(\d+):(.*)$/) {
+    my $c = $1;
+    my $out = $2;
+    print "Creating $out with $c buckets\n";
+    push (@outs, { c => $c, out => $out });
+  }
+  else {
+    print "Reading from $arg\n";
+    $input = $arg;
+  }
+}
+
+die "usage\n" unless $input;
+
+my @instat = stat($input);
+my $rebuild = 0;
+foreach my $out (@outs) {
+  my @outstat = stat($out->{out});
+  if (!($outstat[9] && $instat[9] && $instat[9] < $outstat[9])) {
+    $rebuild = 1;
+  }
+}
+
+if ($rebuild == 0) {
+  print "Existing outputs are up-to-date\n";
+}
+
+my %buckets = ();
+my $numbuckets = 0;
+foreach my $out (@outs) {
+  my $last = $numbuckets + $out->{c};
+  for ( ; $numbuckets < $last; $numbuckets++) {
+    # exploit the auto-syncing semantics of >>
+    open ($buckets{$numbuckets}, ">>".$out->{out});
+  }
+}
+
+srand (1);      # explicitly static seed, for reproducability
+
+open (IN, "<$input") or die "cannot open $input";
+while (<IN>) {
+  select $buckets{1+int(rand()*$numbuckets)}; print $_;
+}
+close IN;
+
+foreach my $i (1 .. $numbuckets) {
+  close $buckets{$i};
+}
+

Propchange: spamassassin/trunk/masses/tenpass/split-log-into-buckets-cached
------------------------------------------------------------------------------
    svn:executable = *