7 use Data::Dump qw/dump/;
14 my $debug = $ENV{DEBUG} || 0;
23 # Bib-1 @and @and @and @and @and @and @and @or
28 # @attr 1=16 dewey (godina)
29 # @attr 1=21 subject-holding
30 # @attr 1=12 control-no
31 # @attr 1=1007 standard-id
43 1016 => 'fti_au,fti_pr:',
50 my $dbname = 'bibliografija';
51 my $pg_user = $ENV{PGUSER} || '';
52 my $pg_passwd = $ENV{PGPASSWD} || '';
53 my $pg_host = $ENV{PGHOST} || '';
58 my ( $self, $query ) = @_;
60 utf8::decode( $query );
61 warn "QUERY",dump( $query );
63 die "ERROR need query" unless defined $query;
68 my $table = lc $self->{database};
69 $table =~ s/^crosbi-//g;
71 $self->{_table} = $table;
77 ,ARRAY( select napomena from rad_napomena where rad_napomena.id = $table.id ) as rad_napomena
78 ,ARRAY( select projekt from rad_projekt where rad_projekt.id = $table.id ) as rad_projekt
79 ,ARRAY( select datum from rad_godina where rad_godina.id = $table.id ) as rad_godina
80 ,ARRAY( select sifra from rad_podrucje where rad_podrucje.id = $table.id ) as rad_podrucje
81 ,ARRAY( select url from url where url.id = $table.id ) as url
83 inner join rad_ustanova using (id) -- sifra
86 @and = ( qq{ rad_ustanova.sifra = ? } );
87 @exec = ( 130 ); # FIXME ustanova
91 warn "## parse_fti [$query]";
93 if ( $query =~ s/^(fti_.+):\s*// ) {
96 warn "INVALID QUERY no fti_xxx: [$query]";
99 my $tsquery = join(' & ', split(/\s+/,$query) );
102 foreach my $f ( split(/,/,$fti) ) {
103 push @or, "$f @@ to_tsquery('english',?)";
104 push @exec, $tsquery;
106 push @and, "( " . join(" or ", @or) . ")";
109 if ( $query =~ / AND / ) {
110 foreach my $and ( split(/ AND /, $query) ) {
113 } elsif ( $query =~ m/fti_.+:/ ) {
115 } else { # no " AND " in query
116 my $tsquery = join(' & ', split(/\s+/,$query) );
117 push @and, "( fti_au @@ to_tsquery('english',?) or fti_pr @@ to_tsquery('english',?) )";
118 push @exec, $tsquery, $tsquery;
122 $sql .= "where " . join(" and ", @and);
124 warn "XXX SQL = ",$sql, dump( @exec );
126 my $dbh = DBI->connect_cached("dbi:Pg:dbname=$dbname;host=$pg_host", $pg_user, $pg_passwd, {AutoCommit => 0});
128 my $sth = $dbh->prepare( $sql );
130 $sth->execute( @exec );
132 my $hits = $sth->rows;
134 $self->{_sth} = $sth;
136 warn "# [$query] $hits hits\n";
138 return $self->{hits} = $hits;
141 my $langrecode008 = {
146 'Esperanto' => 'epo',
154 'Madžarski' => 'hun',
155 'Makedonski' => 'mac',
156 'nizozemski' => 'dut',
159 'Portugalski' => 'por',
160 'portugalski' => 'por',
162 'Rumunjski' => 'rum',
163 'rumunjski' => 'rum',
166 'slovenski' => 'slv',
173 'ukrajinski' => 'ukr',
176 'hrvatsko-francuski' => 'mul',
180 my ($self,$format) = @_;
184 my $sth = $self->{_sth} || die "ERROR no _sth";
185 my $row = $sth->fetchrow_hashref;
187 warn "## row = ",dump($row) if $ENV{DEBUG};
189 warn "ERROR: no row" unless $row;
191 my $id = $row->{id} || die "ERROR no id";
193 my $marc = MARC::Record->new;
194 $marc->encoding('UTF-8');
196 my $leader = $marc->leader;
198 # /srv/webpac2/conf/crosbi/2016-12-12/casopis-dbi2marc.pl
201 ## LDR 06 - a - language material
202 ## LDR 07 - a - monographic component part
204 $leader =~ s/^(.....)...(.+)/$1naa$2/;
206 ## LDR 17 - Encoding level ; 7 - minimal level, u - unknown
207 ## LDR 18 - i = isbd ; u = unknown
209 $leader =~ s/^(.{17})..(.+)/$1ui$2/;
211 $marc->leader( $leader );
212 warn "# leader [$leader]";
215 ### 008 - All materials
217 ## 008 - 00-05 - Date entered on file
219 my $f008 = $1 . $2 . $3 if $row->{time_date} =~ m/\d\d(\d\d)-(\d\d)-(\d\d)/;
221 ## 008 06 - Type of date/Publication status
225 ## 008 07-10 - Date 1
227 $f008 .= substr( $row->{rad_godina}->[0] ,0,4);
229 ## 008 11-14 - Date 2
233 $f008 .= ' ' x ( 15 - length($f008) ); # pad to 15 position
234 ## 008 15-17 - Place of publication, production, or execution - ako nema 102, popunjava se s |
237 ## 008 29 - Conference publication
238 $f008 .= ' ' x ( 29 - length($f008) );
239 $f008 .= $self->{_table} eq 'zbornik' ? '1' : '0';
241 ## 008 35-37 - Language
242 $f008 .= ' ' x ( 35 - length($f008) ); # pad to 35 position
243 if ( my $lng = $langrecode008->{ $row->{jezik} } ) {
246 warn "INFO unknown jezik [$row->{jezik}] insert into langrecode008!";
249 $f008 .= ' ' x ( 38 - length($f008) );
250 ## 008 38 - Modified record
252 ## 008 39 - Cataloging source - d (other)
255 warn "# 008 ",length($f008);
257 $marc->add_fields('008', $f008); # FIXME - mglavica check
260 if ( my $doi = $row->{doi} ) {
262 $marc->add_fields('024','7',' ',
271 ## marc 035a - System Number
272 ## polje moze sadrzavati slova i razmake
273 ## moguc problem u pretrazivanju ako ima zagrade, kako bi trebalo po standardu
275 $marc->add_fields('035',' ',' ',
276 a => join('', '(CROSBI)', $row->{id})
282 $marc->add_fields('040',' ',' ',
290 # i1=0 - Item not a translation/does not include a translation
291 # i1=1 - Item is or includes a translation
292 # i1=' ' - No information provided
295 # ponovljivo potpolje (041a) - marc_repeatable_subfield
296 # koristi se kad ima vise od jednog jezika, ili kad se radi o prijevodu
298 $marc->add_fields('041',' ',' ', map {
300 } split(/-/, $row->{jezik}));
305 ## i1 = 0 zza anonimne publikacije, i1 = 1 ako postoji 700 ili 710
306 ## i2 = pretpostavlja se na temelju clana na pocetku naslova i jezika
308 my ( $first_author, $authors ) = split(/ ;\s*/,$row->{autori});
310 $marc->add_fields(100,'1',' ','a' => $first_author );
314 my $naslov = $row->{naslov}; # XXX title?
317 $naslov =~ m/^Eine / ? 5 :
318 $naslov =~ m/(Die|Das|Der|Ein|Les|Los|The) / ? 4 :
319 $naslov =~ m/^(Um|Un|An|La|Le|Lo|Il) / ? 3 :
320 $naslov =~ m/^(A|L) / ? 2 :
321 $naslov =~ m/^L'/ ? 2 :
324 $marc->add_fields(245,'1',$i2,
325 'a' => $naslov . ' /',
326 'c' => $row->{autori} . '.',
329 $marc->add_fields(246,'3',' ',
330 'i' => 'Naslov na engleskom:',
335 my ( $prefix, $from, $to ) = @_;
338 $out = $prefix . $from;
339 $out .= '-' . $to if $to;
344 # fake date for Koha import
345 $marc->add_fields(260,' ',' ',
349 $marc->add_fields(300,' ',' ',
350 a => page_range('',$row->{stranica_prva},$row->{stranica_zadnja}),
354 $marc->add_fields(363,' ',' ',
355 a => $row->{volumen},
358 ) if $row->{volumen};
360 # /data/FF/crosbi/2016-12-12/casopis-rad_napomena.sql
362 foreach my $napomena ( @{ $row->{rad_napomena} } ) {
363 $marc->add_fields(500,' ',' ',
364 a => substr($napomena, 0, 9999), # XXX marc limit for one subfield is 4 digits in dictionary
368 $marc->add_fields(520,' ',' ',
369 a => substr($row->{sazetak}, 0, 9999)
373 if ( $row->{rad_projekt} ) {
374 $marc->add_fields(536,' ',' ',
380 $marc->add_fields(546,' ',' ',
384 foreach my $v ( @{ $row->{rad_podrucje} } ) {
385 $marc->add_fields(690,' ',' ',
391 $marc->add_fields(693,' ',' ',
392 a => $row->{kljucne_rijeci},
396 $marc->add_fields(693,' ',' ',
397 a => $row->{key_words},
402 if ( $row->{autori} =~ m/ ; / ) {
403 my @a = split(/ ; /, $row->{autori});
404 shift @a; # skip first
405 $marc->add_fields(700,'1',' ',
413 my $last_delimiter = '';
415 my $value = shift @_;
416 my $delimiter = shift @_;
417 my ( $before,$after ) = ( '', '' );
418 ( $before, $value, $after ) = @$value if ( ref $value eq 'ARRAY' );
419 $out .= $last_delimiter . $before . $value . $after if $value;
420 $last_delimiter = $delimiter || last;
427 if ( $self->{_table} =~ m/(casopis|preprint)/ ) {
429 $marc->add_fields(773,'0',' ',
430 t => $row->{casopis},
432 # g => "$row->{volumen} ($row->{godina}), $row->{broj} ;" . page_range(' str. ',$row->{stranica_prva}, $row->{stranica_zadnja}),
433 g => combine( $row->{volumen}, ' ', [ '(', $row->{godina}, ')' ], ', ', $row->{broj}, ' ;', page_range(' str. ',$row->{stranica_prva}, $row->{stranica_zadnja}) ),
436 } elsif ( $self->{_table} =~ m/rknjiga/ ) {
438 # rknjiga-dbi2marc.pl
439 $marc->add_fields(773,'0',' ',
441 # d => "$row->{grad} : $row->{nakladnik}, $row->{godina}",
442 d => combine( $row->{grad}, ' : ', $row->{nakladnik}, ', ', $row->{godina} ),
444 h => $row->{ukupno_stranica},
445 n => $row->{uredink},
447 g => page_range('str. ',$row->{stranica_prva}, $row->{stranica_zadnja}),
450 } elsif ( $self->{_table} =~ m/zbornik/ ) {
452 # zbornik-dbi2marc.pl
453 $marc->add_fields(773,'0',' ',
455 # d => "$row->{grad} : $row->{nakladnik}, $row->{godina}",
456 d => combine( $row->{grad}, ' : ', $row->{nakladnik}, ', ', $row->{godina} ),
458 h => $row->{ukupno_stranica},
459 n => $row->{uredink},
461 g => page_range('str. ',$row->{stranica_prva}, $row->{stranica_zadnja}),
465 die "ERROR: 773 undefined in row ",dump($row);
469 if ( my $file = $row->{datoteka} ) {
470 $marc->add_fields(856,' ',' ',
471 u => "http://bib.irb.hr/datoteka/$file",
476 $marc->add_fields(856,' ',' ',
477 u => $row->{openurl},
478 ) if $row->{openurl};
480 foreach my $url ( @{ $row->{url} } ) {
481 $marc->add_fields(856,' ',' ',
494 c => $f942c->{ $self->{_table} } || die "ERROR no table $self->{_table} in ".dump($f942c),
497 if ( $row->{status_rada} ) {
500 g => $row->{status_rada}
504 if ( $self->{_table} =~ m/(casopis|preprint)/ ) {
506 if ( $row->{kategorija} =~ m/Znanstveni/ ) {
507 push @f942, t => '1.01'
508 } elsif ( $row->{kategorija} =~ m/Strucni/ ) {
509 push @f942, t => '1.04';
511 warn "ERROR kategorija $row->{kategorija}";
514 } elsif ( $self->{_table} =~ m/rknjiga/ ) {
516 if ( $row->{kategorija} =~ m/Znanstveni/ ) {
517 push @f942, t => '1.16.1';
518 } elsif ( $row->{kategorija} =~ m/Pregledni/ ) {
519 push @f942, t => '1.16.2';
520 } elsif ( $row->{kategorija} =~ m/Strucni/ ) {
521 push @f942, t => '1.17';
523 warn "ERROR kategorija $row->{kategorija}";
526 } elsif ( $self->{_table} =~ m/zbornik/ ) {
528 push @f942, v => $row->{vrst_recenzije};
531 die "ERROR _table $self->{_table}";
534 $marc->add_fields(942,' ',' ',
537 z => join(' - ', grep { defined $_ } ($row->{kategorija}, $row->{vrst_sudjelovanja}, $row->{vrsta_rada})),
541 $marc->add_fields(999,' ',' ',
547 # diag "# hash ",dump($hash);
548 diag "# marc\n", $marc->as_formatted if $ENV{DEBUG};
550 $self->save_marc( "$id.marc", $marc->as_usmarc );