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); |
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); |