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/homer.txt", "Homer: The Odyssey preface"); |
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 $word_count = 0; |
my $word_count = 0; |
21 |
my $max_words = 100; |
my $max_words = 10; |
22 |
|
|
23 |
my $res; |
my $res; |
24 |
|
|
27 |
ok(open(U, "t/homer.txt"), "open homer.txt"); |
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 .= "\n" if ($full_text); |
$full_text = "$line: "; |
|
$full_text = "paragraph $p\n\n"; |
|
34 |
|
|
35 |
diag "paragraph $p"; |
my %usage; |
36 |
|
|
37 |
my %usage; |
my @words = split(/\s+/,lc($_)); |
38 |
|
|
39 |
my @words = split(/\s+/,lc($text)); |
foreach (@words) { |
40 |
|
$usage{$_}++; |
41 |
|
} |
42 |
|
|
43 |
foreach (@words) { |
foreach my $word (@words) { |
|
$usage{$_}++; |
|
|
} |
|
44 |
|
|
45 |
foreach my $word (@words) { |
next if ($word eq ''); |
46 |
|
|
47 |
$words{$word} += $usage{$word}; |
$words{$word} += $usage{$word}; |
48 |
|
|
49 |
$res->{$word}->{$p} = $usage{$word}; |
$res->{$word}->{$line} = $usage{$word}; |
50 |
|
|
51 |
$t->B_search( |
$t->B_search( |
52 |
Key => $word, |
Key => $word, |
53 |
Data => { "$p" => { |
Data => { "$line" => { |
54 |
t => "Ulyss paragraph $p", |
t => "Odyssey line $line", |
55 |
f => $usage{$word}, |
f => $usage{$word}, |
|
}, |
|
56 |
}, |
}, |
57 |
Insert => 1, |
}, |
58 |
Append => 1, |
Insert => 1, |
59 |
); |
Append => 1, |
60 |
|
); |
|
$word_count++; |
|
|
|
|
|
$full_text .= "$word "; |
|
61 |
|
|
62 |
last if ($max_words && $word_count >= $max_words); |
$word_count++; |
|
} |
|
63 |
|
|
64 |
$text = ''; |
$full_text .= "$word "; |
65 |
|
|
|
last if ($max_words && $word_count >= $max_words); |
|
|
} 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); |
100 |
my $total_words = scalar keys %words; |
my $total_words = scalar keys %words; |
101 |
|
|
102 |
cmp_ok($t->to_jsfind("./html/homer"), '==', $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); |