1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
|
# indexer, Dobrica Pavlinusic <dpavlin@rot13.org> 2002-01-28 |
4 |
|
# options: -q quiet |
5 |
|
# -d debug |
6 |
|
# -v verbose |
7 |
|
|
8 |
use strict; |
use strict; |
9 |
use DBI; |
use DBI; |
10 |
|
use Getopt::Std; |
11 |
|
|
12 |
my $sadrzaj=0; |
my $sadrzaj=0; |
13 |
my $nr=0; |
my $nr=0; |
19 |
|
|
20 |
my $nn_dir="."; # dir u kojem su wget-ani fileovi |
my $nn_dir="."; # dir u kojem su wget-ani fileovi |
21 |
|
|
22 |
|
my %opts; |
23 |
|
getopts("vqd", \%opts); |
24 |
|
|
25 |
|
my $brojeva=0; |
26 |
|
my $zakona=0; |
27 |
|
|
28 |
#-------------------------------------------------------------------- |
#-------------------------------------------------------------------- |
29 |
|
|
103 |
$tmp_word = $word.$add; |
$tmp_word = $word.$add; |
104 |
} |
} |
105 |
if ($tmp_word =~ m/$regexp/ix) { |
if ($tmp_word =~ m/$regexp/ix) { |
106 |
# print "$word -> $tmp_word\t-$sub, +$add, regexp: $regexp\n"; |
print "$word -> $tmp_word\t-$sub, +$add, regexp: $regexp\n" if ($opts{d}); |
107 |
push @out,lc($tmp_word); |
push @out,lc($tmp_word); |
108 |
} |
} |
109 |
} |
} |
125 |
my @files = grep { /^CijeliBrojS/ && -f "$nn_dir/$_" } readdir(DIR); |
my @files = grep { /^CijeliBrojS/ && -f "$nn_dir/$_" } readdir(DIR); |
126 |
closedir(DIR); |
closedir(DIR); |
127 |
|
|
128 |
|
my $sth=$dbh->prepare("insert into nn (br,god,nr,aname,title,title_czs) values (?,?,?,?,?,?)") || die $dbh->errstr(); |
129 |
|
|
130 |
|
|
131 |
foreach my $file (@files) { |
foreach my $file (@files) { |
132 |
open(IN,$file) || die "can't open $file: $!"; |
open(IN,$file) || die "can't open $file: $!"; |
133 |
|
|
134 |
if ($file=~m/god=(\d+)\&br=(\d+)/) { |
if ($file=~m/god=(\d+)\&br=(\d+)/) { |
135 |
($br,$god) = ($2,$1); |
($br,$god) = ($2,$1); |
136 |
print "$file -- $2 -- $1\n"; |
print "$file -- $2 -- $1\n" if (! $opts{q}); |
137 |
|
$brojeva++; |
138 |
} |
} |
139 |
|
|
140 |
while(<IN>) { |
while(<IN>) { |
142 |
s/\015//g; # kill cr |
s/\015//g; # kill cr |
143 |
tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2 |
tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2 |
144 |
|
|
145 |
$sadrzaj++ if (m,<div class=sadrzaj>,); |
if (m,<div class=sadrzaj>,) { |
146 |
|
$sadrzaj++; |
147 |
if ($sadrzaj) { |
next; |
|
if (s/<a href="#([^"]+)">\s*(\d+)\.\s*<[^>]+>//i) { |
|
|
($aname,$nr) = ($1,$2); |
|
|
$aname = $1 if ($aname =~ m/Javascript:Mojdok\(\d+,\d+,\d+,(\d+)\);/); |
|
|
} |
|
|
$naslov.=$_; |
|
148 |
} |
} |
149 |
|
|
150 |
if ($sadrzaj && m,</div>,) { |
if ($sadrzaj && m,</div>,) { |
151 |
$sadrzaj--; |
$sadrzaj--; |
152 |
$naslov=~s/\s+/ /g; |
$naslov=~s/\s+/ /g; |
153 |
$naslov=~s/<[^>]+>//g; |
$naslov=~s/<[^>]+>//g; |
154 |
$naslov=~s/^\s+//g; |
$naslov=~s/^\s+//g; |
155 |
$naslov=~s/\s+$//g; |
$naslov=~s/\s+$//g; |
156 |
print "$god $br $nr: $naslov\n"; |
print "$god $br $nr: $naslov\n" if ($opts{v}); |
157 |
my $naslov_czs = lc($naslov); |
my $naslov_czs = lc($naslov); |
158 |
$naslov_czs =~ tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/; |
$naslov_czs =~ tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/; |
159 |
$naslov_czs =~ tr/a-zA-Z/ /cs; # non a-z -> space |
$naslov_czs =~ tr/a-zA-Z/ /cs; # non a-z -> space |
160 |
$naslov_czs = join(" ",normalize_word(split(/ /,$naslov_czs))); |
$naslov_czs = join(" ",normalize_word(split(/ /,$naslov_czs))); |
161 |
$dbh->do("insert into nn (br,god,nr,aname,title,title_czs) values ($br,$god,$nr,'$aname','$naslov','$naslov_czs')") || die $dbh->errstr(); |
$sth->execute($br,$god,$nr,$aname,$naslov,$naslov_czs) || die $dbh->errstr(); |
162 |
$naslov=""; |
$naslov=""; |
163 |
$nr=0; |
$nr=0; |
164 |
|
$zakona++; |
165 |
|
} |
166 |
|
|
167 |
|
if ($sadrzaj) { |
168 |
|
if (s/<a href="#([^"]+)">\s*(\d+)\.\s*<[^>]+>//i) { |
169 |
|
($aname,$nr) = ($1,$2); |
170 |
|
} elsif (s/<a href="Javascript:Mojdok\((\d+),(\d+),(\w+),(\d+)\)[^>]*>//i) { |
171 |
|
($nr,$aname) = ($3,$4); |
172 |
|
die "conflict in godina: $1 != $god" if ($god != $1); |
173 |
|
die "conflict in broj: $2 != $br" if ($br != $2); |
174 |
|
} else { |
175 |
|
die "can't find nr in line: $_"; |
176 |
|
} |
177 |
|
$naslov.=$_; |
178 |
|
$naslov=~s/^\s*$nr\.*\s*//g; |
179 |
} |
} |
180 |
|
|
181 |
} |
} |
182 |
|
|
183 |
close(IN); |
close(IN); |
184 |
} |
} |
185 |
|
|
186 |
$dbh->do("vacuum") || die $dbh->errstr(); |
$dbh->do("vacuum") || die $dbh->errstr(); |
187 |
|
print "Ukupno $brojeva brojeva NN, sa $zakona zakona...\n" if (! $opts{q}); |