/[nn]/find3.pl
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 /find3.pl

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

revision 1.2 by dpavlin, Tue Feb 5 12:58:30 2002 UTC revision 1.5 by dpavlin, Wed Jun 19 10:58:59 2002 UTC
# Line 1  Line 1 
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;
# Line 13  my $aname;     ## ancor name na originalnim Line 19  my $aname;     ## ancor name na originalnim
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    
# Line 92  sub normalize_word { Line 103  sub normalize_word {
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                  }                  }
# Line 114  opendir(DIR,$nn_dir) || warn "opendir: $ Line 125  opendir(DIR,$nn_dir) || warn "opendir: $
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>) {
# Line 138  foreach my $file (@files) { Line 153  foreach my $file (@files) {
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) {                  if ($sadrzaj) {
168                          if (s/<a href="#([^"]+)">\s*(\d+)\.\s*<[^>]+>//i) {                          if (s/<a href="#([^"]+)">\s*(\d+)\.\s*<[^>]+>//i) {
169                                  ($aname,$nr) = ($1,$2);                                  ($aname,$nr) = ($1,$2);
170                          } elsif (s/<a href="Javascript:Mojdok\((\d+),(\d+),(\d+),(\d+)\)[^>]*>//i) {                          } elsif (s/<a href="Javascript:Mojdok\((\d+),(\d+),(\w+),(\d+)\)[^>]*>//i) {
171                                  ($nr,$aname) = ($3,$4);                                  ($nr,$aname) = ($3,$4);
172                                  die "conflict in godina: $1 != $god"  if ($god != $1);                                  die "conflict in godina: $1 != $god"  if ($god != $1);
173                                  die "conflict in broj: $2 != $br"  if ($br != $2);                                  die "conflict in broj: $2 != $br"  if ($br != $2);
# Line 159  foreach my $file (@files) { Line 175  foreach my $file (@files) {
175                                  die "can't find nr in line: $_";                                  die "can't find nr in line: $_";
176                          }                          }
177                          $naslov.=$_;                          $naslov.=$_;
178                            $naslov=~s/^\s*$nr\.*\s*//g;
179                  }                  }
180                                    
181          }          }
# Line 167  foreach my $file (@files) { Line 184  foreach my $file (@files) {
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});

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.26