3 |
use strict; |
use strict; |
4 |
use warnings; |
use warnings; |
5 |
|
|
6 |
use Test::More tests => 5; |
use Test::More tests => 7; |
7 |
use blib; |
use blib; |
8 |
use jsFind; |
use jsFind; |
9 |
use Data::Dumper; |
use Data::Dumper; |
16 |
|
|
17 |
my $line = 0; |
my $line = 0; |
18 |
my $text = ''; |
my $text = ''; |
19 |
my %words; |
my %words_usage; |
20 |
my $word_count = 0; |
my $word_count = 0; |
21 |
my $max_words = 10; |
my $max_words; |
22 |
|
#$max_words = 100; |
23 |
|
|
24 |
my $res; |
my $res; |
25 |
|
|
45 |
|
|
46 |
next if ($word eq ''); |
next if ($word eq ''); |
47 |
|
|
48 |
$words{$word} += $usage{$word}; |
$words_usage{"$word $line"} = $usage{$word}; |
49 |
|
|
50 |
$res->{$word}->{$line} = $usage{$word}; |
$res->{$word}->{$line} = $usage{$word}; |
51 |
|
|
74 |
my $test_data = Dumper($res); |
my $test_data = Dumper($res); |
75 |
$test_data =~ s/=>/:/gs; |
$test_data =~ s/=>/:/gs; |
76 |
$test_data =~ s/\$VAR1/var test_data/; |
$test_data =~ s/\$VAR1/var test_data/; |
77 |
open(JS, "> html/test_data.js") || die "can't open test_data.js: $!"; |
ok(open(JS, "> html/test_data.js"), "test_data.js"); |
78 |
print JS $test_data; |
print JS $test_data; |
79 |
close(JS); |
close(JS); |
80 |
|
|
81 |
ok($test_data, "test_data saved"); |
ok($test_data, "test_data saved"); |
82 |
|
|
83 |
#my $sum = 0; |
my $sum = 0; |
84 |
#foreach my $w (keys %words) { |
ok(open(TD, "> homer_freq.txt"), "homer_freq.txt"); |
85 |
# print STDERR "$w: $words{$w}\n"; |
foreach my $w (keys %words_usage) { |
86 |
# $sum += $words{$w}; |
print TD "$w: $words_usage{$w}\n"; |
87 |
#} |
$sum += $words_usage{$w}; |
88 |
|
} |
89 |
|
close(TD); |
90 |
|
diag "homer_freq.txt created"; |
91 |
|
|
92 |
if (open(T,"> homer_text.txt")) { |
if (open(T,"> homer_text.txt")) { |
93 |
print T $full_text; |
print T $full_text; |
101 |
} |
} |
102 |
diag "homer_words.txt created"; |
diag "homer_words.txt created"; |
103 |
|
|
104 |
my $total_words = scalar keys %words; |
my $total_words = scalar keys %words_usage; |
105 |
|
|
106 |
cmp_ok($t->to_jsfind("./html/homer"), '==', $total_words, " jsfind index with $total_words words"); |
cmp_ok($t->to_jsfind(dir=>"./html/homer"), '==', $total_words, " jsfind index with $total_words words"); |
107 |
|
|
108 |
print Dumper($t); |
#print Dumper($t); |