Alt-CWB-ambs

 view release on metacpan or  search on metacpan

t/31_cqp_dickens.t.dont_run  view on Meta::CPAN

}
print ".";
@result2 = $CQP->exec_rows("group A match s_len by match novel_title"); # two attributes (not inverse ordering)
$sum = 0;
foreach $row (@result2) { $sum += $row->[2] }
if ($sum != $size) {
  print "\n!! group output doesn't sum to number of matches ($sum vs. $size)\n";
  exit 1;
}
print ". ok\n";
print "   sample output:";
foreach $row (@result) {
  print "  ", $row->[0], " (", $row->[1], ")";
}
print "\n";

# step 20: test the count command (a variant of sort) on a subset of the named query from step 17
print " - frequencies of match strings ... ";
$CQP->exec("A = NP");
$CQP->exec("reduce A to 10000");
($size) = $CQP->exec("size A");
@result = $CQP->exec_rows('count A by word %c descending');
$sum = 0;
foreach $row (@result) { $sum += $row->[0] }
if ($sum != $size) {
  print "\n!! match frequencies don't sum to number of matches ($sum vs. $size)\n";
  exit 1;
}
print "ok\n";
my ($f, $first, $match) = @{$result[0]};
printf "   most frequent simple NP:  f=%d  \"%s\"  [#%d..#%d]\n", $f, $match, $first, $first + $f - 1;

# step 21: create named query with undump method and compare with subsequent dump
@table = ([10, 20, 15],
	  [112, 120, -1],
	  [80, 83, 75],	       # forces CQP to create sort index automatically
	  [147, 151, 160]);
$rows = @table;
print " - undumping $rows matches ... ";
$CQP->undump("B", @table);
print "dump ... ";
@table2 = $CQP->dump("B");
$rows2 = @table2;
if ($rows2 != $rows) {
  print "\n!! number of rows in query match ($rows2) differs from undump size ($rows)\n";
  exit 1;
}
foreach $i (0 .. $rows-1) {
  $r1 = $table[$i];
  $r2 = $table2[$i];
  if ($r1->[0] != $r2->[0] or 
      $r1->[1] != $r2->[1] or 
      $r1->[2] != $r2->[2] or 
      $r2->[3] != -1) {
    print "\n!! returned row #".($i+1)." [@$r2] differs from undumped table [@$r1]\n";
    exit 1;
  }
}
print "ok\n";

# step 22: test asynchronous execution
print " - testing asynchronous command execution ... ";
$dickens_found = 0;
$CQP->run("show corpora");
while (defined($_ = $CQP->getline)) {
  $dickens_found = 1 if /^DICKENS$/
}
if (not $dickens_found) {
  print "\n!! corpus DICKENS not found in output of 'show corpora'\n";
  exit 1;
}
print "ok\n";

# step 23: test progress bar handler during query, set keyword, and group commands (should not affect other commands)
print " - testing progress bar handler ...\n";
sub my_progress_handler {
  my $total = $_[0];
  my $message = $_[3];
  my $percent = $_[4];
  printf "     Progress: %3d%s ", $total, '%';
  if (not defined $percent) {
    print $message, "\r";
  }
  else {
    print " " x 30, "\r";
  }
}
$CQP->set_progress_handler(\&my_progress_handler);
$CQP->progress_on;
$CQP->exec('A = [pos = "JJ"] []* "things?" within s');
$CQP->exec("group A matchend word by match lemma"); # ignore output of group command
$CQP->progress_off;
($size) = $CQP->exec("size A");
print "\n - got $size matches\n";

# that's it -- we've passed the test
print "Congratulations. All tests passed.\n";
exit 0;





( run in 1.603 second using v1.01-cache-2.11-cpan-364913b4093 )