/[jsFind]/trunk/t/10homer.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/10homer.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/t/10ulyss.pl revision 20 by dpavlin, Mon Oct 4 19:51:05 2004 UTC trunk/t/10homer.t revision 25 by dpavlin, Thu Oct 7 17:30:03 2004 UTC
# Line 10  use Data::Dumper; Line 10  use Data::Dumper;
10    
11  BEGIN { use_ok('jsFind'); }  BEGIN { use_ok('jsFind'); }
12    
13  my $t = new jsFind B => 100;  my $t = new jsFind B => 10;
14    
15  ok(-e "t/ulyss12.txt", "The Project Gutenberg EBook of Ulysses, by James Joyce");  ok(-e "t/homer.txt", "Homer: The Odyssey preface");
16    
17  my $p = 0;  my $line = 0;
18  my $text = '';  my $text = '';
19  my %words;  my %words;
20  my $max = 1;  my $word_count = 0;
21    my $max_words = 10;
22    
23  my $res;  my $res;
24    
25  ok(open(U, "t/ulyss12.txt"), "open ulyss12.txt");  my $full_text;
26    
27    ok(open(U, "t/homer.txt"), "open homer.txt");
28  while(<U>) {  while(<U>) {
29          chomp;          chomp;
30          if (/^\s*$/) {          $line++;
31                  $p++;          next if (/^\s*$/);
32    
33            $full_text = "$line: ";
34    
35                  diag "paragraph $p";          my %usage;
36    
37                  my %usage;          my @words = split(/\s+/,lc($_));
38                  foreach (split(/\s+/,lc($text))) {  
39                          $usage{$_}++;          foreach (@words) {
40                  }                  $usage{$_}++;
41            }
42    
43                  foreach my $word (keys %usage) {          foreach my $word (@words) {
44    
45                          $words{$word} += $usage{$word};                  next if ($word eq '');
46    
47                          $res->{$word}->{$p} = $usage{$word};                  $words{$word} += $usage{$word};
48    
49                          $t->B_search(                  $res->{$word}->{$line} = $usage{$word};
50                                  Key => $word,  
51                                  Data => { "$p" => {                  $t->B_search(
52                                          t => "Ulyss paragraph $p",                          Key => $word,
53                                          f => $usage{$word},                          Data => { "$line" => {
54                                          },                                  t => "Odyssey line $line",
55                                    f => $usage{$word},
56                                  },                                  },
57                                  Insert => 1,                          },
58                                  Append => 1,                          Insert => 1,
59                          );                          Append => 1,
60                  }                  );
61    
62                  $text = '';                  $word_count++;
63    
64                  last if ($max && $max == $p);                  $full_text .= "$word ";
65          } else {  
                 $text .= $_;  
66          }          }
67    
68            $full_text = "\n";
69    
70            last if ($max_words && $word_count >= $max_words);
71  }  }
72    
73  my $test_data = Dumper($res);  my $test_data = Dumper($res);
# Line 76  ok($test_data, "test_data saved"); Line 85  ok($test_data, "test_data saved");
85  #       $sum += $words{$w};  #       $sum += $words{$w};
86  #}  #}
87    
88    if (open(T,"> homer_text.txt")) {
89            print T $full_text;
90            close(T);
91    }
92    diag "homer_text.txt created";
93    
94    if (open(T,"> homer_words.txt")) {
95            print T $t->to_string;
96            close(T);
97    }
98    diag "homer_words.txt created";
99    
100  my $total_words = scalar keys %words;  my $total_words = scalar keys %words;
101    
102  cmp_ok($t->to_jsfind("./html/ulyss"), '==', $total_words, " jsfind index with $total_words words");  cmp_ok($t->to_jsfind("./html/homer"), '==', $total_words, " jsfind index with $total_words words");
103    
104    print Dumper($t);

Legend:
Removed from v.20  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26